:root {
    --primary-color: #d2c09e;
    --secondary-color: #603000;
    --primary-dark: #4a2200;
    --primary-light: #e8d8bc;
    --text-on-secondary: #f5ead8;
    --text-on-primary: #3a1800;
    /* Brown-tinted neutrals used to propagate the palette to buttons/tables. */
    --border-brown: #c9b9a0;
    --border-brown-strong: #a98e6a;
    --text-muted-brown: #7a6a52;
    --surface-brown: #f6f0e4;
    --surface-brown-2: #efe6d4;
}

html, body {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

a, .btn-link {
    color: var(--secondary-color);
}

.btn-primary {
    color: var(--text-on-secondary);
    background-color: var(--secondary-color);
    border-color: var(--primary-dark);
}

.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
    color: var(--text-on-secondary);
    background-color: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem var(--primary-color);
}

.content {
    padding-top: 1.1rem;
}

h1:focus {
    outline: none;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid #e50000;
}

.validation-message {
    color: #e50000;
}

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred."
    }

.darker-border-checkbox.form-check-input {
    border-color: #929292;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
    text-align: start;
}

.map-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.map-toolbar {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin-bottom: 0.75rem;
}

.map-world-label {
    color: var(--secondary-color);
    font-weight: 600;
}

.map-world-select {
    border: 1px solid var(--border-brown-strong);
    border-radius: 0.35rem;
    padding: 0.3rem 0.55rem;
    background: #fff;
    color: var(--text-on-primary);
}

.map-nuke-input {
    width: 6rem;
    border: 1px solid var(--border-brown-strong);
    border-radius: 0.35rem;
    padding: 0.3rem 0.55rem;
    background: #fff;
    color: var(--text-on-primary);
}

.map-display-options {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    margin-left: 0.5rem;
}

.map-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--secondary-color);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

.map-toggle input {
    cursor: pointer;
}

.map-tab {
    border: 1px solid var(--secondary-color);
    background: var(--primary-light);
    color: var(--text-on-primary);
    padding: 0.35rem 0.8rem;
    border-radius: 0.35rem;
    font-weight: 600;
}

.map-tab.active {
    background: var(--secondary-color);
    color: var(--text-on-secondary);
}

.map-shell {
    position: relative;
    width: 1000px;
    height: 1000px;
    border: 1px solid #ccd5df;
    background: #f8fbff;
    overflow: hidden;
}

.map-canvas {
    position: relative;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(to right, rgba(40, 60, 90, 0.08) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(40, 60, 90, 0.08) 1px, transparent 1px);
    background-size: calc(100% / 20) calc(100% / 20);
}

.village-point {
    position: absolute;
    width: 6px;
    height: 6px;
    margin-left: -3px;
    margin-top: -3px;
    background: #2f4f6f;
    border: 1px solid #0f2032;
    border-radius: 2px;
}

.village-point.recent-conquer {
    border: 2px solid #f4cf00;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.map-caption {
    margin-top: 0.6rem;
    color: #344b61;
}

/* ---- Defense report side panel (overlay on the map shell) ---- */
.defense-report-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 360px;
    max-width: 80%;
    height: 100%;
    background: #ffffff;
    border-left: 1px solid #ccd5df;
    box-shadow: -4px 0 14px rgba(20, 40, 70, 0.18);
    display: flex;
    flex-direction: column;
    z-index: 20;
}

.defense-report-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f4f8fc;
}

.defense-report-title {
    font-weight: 600;
    color: #1e3a5f;
}

.defense-report-close {
    border: none;
    background: transparent;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    color: #56708a;
    padding: 0 0.25rem;
}

.defense-report-close:hover {
    color: #1e3a5f;
}

.defense-report-body {
    padding: 0.75rem;
    overflow: auto;
}

.defense-report-meta {
    margin: 0 0 0.6rem;
    color: #344b61;
    font-size: 0.9rem;
}

.defense-report-empty {
    color: #6b7c8e;
    font-style: italic;
}

.defense-report-img {
    width: 100%;
    height: auto;
    border: 1px solid #d6dee7;
    border-radius: 4px;
}

.defense-report-star {
    color: #ffb400;
}

/* ---- Defense map incomings sidebar panel (below the map, scrollable list) ---- */
.defense-incoming-panel {
    margin-top: 0.75rem;
    border: 1px solid #ccd5df;
    border-radius: 6px;
    background: #fff;
    max-height: 340px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.defense-incoming-head {
    display: flex;
    align-items: center;
    padding: 0.45rem 0.75rem;
    background: #f4f8fc;
    border-bottom: 1px solid #dde5ef;
    flex-shrink: 0;
}

.defense-incoming-title {
    font-weight: 600;
    color: #1e3a5f;
    font-size: 0.9rem;
}

.defense-incoming-body {
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.defense-incoming-row {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid #edf2f7;
    border-left: 3px solid #b0bec5;
    font-size: 0.85rem;
}

.defense-incoming-row:last-child {
    border-bottom: none;
}

.defense-incoming-row.attack_small  { border-left-color: #f0c040; }
.defense-incoming-row.attack_medium { border-left-color: #e07030; }
.defense-incoming-row.attack_large  { border-left-color: #c02020; }
.defense-incoming-row.attack        { border-left-color: #7a9ab0; }

.defense-incoming-meta {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.defense-incoming-size {
    font-weight: 700;
    font-size: 0.75rem;
    min-width: 1.2rem;
    text-align: center;
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    background: #e5eaf0;
    color: #344b61;
}

.defense-incoming-size.attack_small  { background: #fef3cc; color: #7a5800; }
.defense-incoming-size.attack_medium { background: #fde0c8; color: #7a3000; }
.defense-incoming-size.attack_large  { background: #fccfcf; color: #7a0000; }

.defense-incoming-dest {
    color: #1e3a5f;
    flex: 1;
}

.defense-incoming-time {
    color: #6b7c8e;
    font-size: 0.82rem;
    white-space: nowrap;
}

.defense-incoming-exact {
    display: block;
    color: #93a3b4;
    font-size: 0.72rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.defense-incoming-src {
    color: #56708a;
    font-size: 0.82rem;
    padding-left: 1.7rem;
}

.defense-incoming-notes-row {
    padding-left: 1.7rem;
}

.defense-incoming-notes {
    color: #2d5a8e;
    font-size: 0.82rem;
    cursor: pointer;
    border-bottom: 1px dotted #b0c8e0;
}

.defense-incoming-notes:hover {
    color: #1040a0;
}

.defense-incoming-notes.defense-incoming-notes-empty {
    color: #9ab0c4;
    font-style: italic;
}

.defense-incoming-notes-input {
    width: 100%;
    font-size: 0.82rem;
    padding: 0.15rem 0.35rem;
    border: 1px solid #90b0d0;
    border-radius: 3px;
    background: #f4f8fc;
    color: #1e3a5f;
    outline: none;
}

.defense-incoming-notes-input:focus {
    border-color: #3a7abf;
    background: #fff;
}

/* Plain, sortable incomings table (intentionally utilitarian, not styled like a card). */
.defense-incoming-table-wrap {
    margin-top: 0.75rem;
    overflow-x: auto;
}

.defense-incoming-hint {
    margin-left: 0.6rem;
    font-size: 0.75rem;
    color: #8090a0;
    font-weight: normal;
}

.defense-incoming-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.defense-incoming-table th,
.defense-incoming-table td {
    border: 1px solid #cdd6df;
    padding: 0.25rem 0.45rem;
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

.defense-incoming-table thead th {
    background: #eef2f6;
    font-weight: 600;
    user-select: none;
}

.defense-incoming-table th.di-sortable {
    cursor: pointer;
}

.defense-incoming-table th.di-sortable:hover {
    background: #e2e8ef;
}

.defense-incoming-table tbody tr:nth-child(even) {
    background: #fafbfc;
}

.defense-incoming-table .di-coord,
.defense-incoming-table .di-num,
.defense-incoming-table .di-exact {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.defense-incoming-table .di-num {
    text-align: right;
}

.defense-incoming-table .di-size {
    text-align: center;
    font-weight: 700;
}

.defense-incoming-table .di-size.attack_small  { background: #fef3cc; color: #7a5800; }
.defense-incoming-table .di-size.attack_medium { background: #fde0c8; color: #7a3000; }
.defense-incoming-table .di-size.attack_large  { background: #fccfcf; color: #7a0000; }

.defense-incoming-table .di-time .di-rel {
    display: block;
    font-weight: 600;
}

.defense-incoming-table .di-time .di-exact {
    display: block;
    font-size: 0.72rem;
    color: #6a7a88;
}

.defense-incoming-table .di-notes {
    white-space: normal;
    min-width: 9rem;
}


/* ---- VillageMap component (draggable canvas map) ---- */
.vm-shell {
    position: relative;
    width: 100%;
    height: 100%;
}

.vm-host {
    position: absolute;
    inset: 0;
    overflow: hidden;
    touch-action: none;
}

.vm-canvas {
    display: block;
    touch-action: none;
}

.vm-controls {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    z-index: 5;
}

.vm-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--secondary-color);
    background: rgba(255, 255, 255, 0.92);
    color: var(--secondary-color);
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1;
    border-radius: 0.3rem;
    cursor: pointer;
}

.vm-btn:hover {
    background: var(--primary-light);
}

.vm-tooltip {
    position: fixed;
    z-index: 50;
    pointer-events: none;
    background: rgba(20, 30, 44, 0.95);
    color: #f2f6fb;
    border: 1px solid #41617f;
    border-radius: 0.35rem;
    padding: 0.4rem 0.55rem;
    font-size: 0.82rem;
    max-width: 240px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}

.vm-tt-name {
    font-weight: 700;
    margin-bottom: 0.15rem;
}

.vm-tt-coord {
    color: #b8c6d6;
    font-weight: 400;
}

.vm-tt-row {
    line-height: 1.25;
}

.vm-tt-tribe {
    color: #ffd34d;
    margin-left: 0.3rem;
}

.vm-tt-barb {
    color: #c9b89a;
}

.vm-tt-conquer {
    color: #ffd34d;
}

.vm-tt-rel {
    font-weight: 600;
}

.vm-tt-rel-primary {
    color: #6f97ff;
}

.vm-tt-rel-ally {
    color: #7fcbff;
}

.vm-tt-rel-enemy {
    color: #ff7a7a;
}

/* ---- Op planner (target selection wrapper) ---- */
.op-plan-sub {
    color: #445970;
    margin-bottom: 0.75rem;
}

.op-server-clock {
    display: inline-block;
    margin-left: 0.75rem;
    padding: 0.1rem 0.5rem;
    border-radius: 0.4rem;
    background: #eef3f9;
    color: #1d3b5c;
    font-size: 0.9em;
    white-space: nowrap;
}

.op-roster {
    margin: 0.5rem 0 0.25rem;
    padding: 0.5rem 0.6rem;
    border: 1px solid #d7e0ec;
    border-radius: 0.5rem;
    background: #f7fafd;
}

.op-roster-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: #1d3b5c;
    margin-bottom: 0.35rem;
}

.op-roster-count {
    font-variant-numeric: tabular-nums;
    color: #41607f;
}

.op-roster-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 12rem;
    overflow-y: auto;
}

.op-roster-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.15rem 0;
    font-size: 0.92em;
}

.op-roster-item.pending .op-roster-name {
    color: #8a5b00;
}

.op-roster-time {
    margin-left: auto;
    color: #6b7c90;
    font-size: 0.88em;
    white-space: nowrap;
}

.op-plan-layout {
    display: flex;
    gap: 1rem;
    align-items: stretch;
}

.op-plan-map {
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
}

/* Make the shared map shell fill the planner column instead of its fixed size. */
.op-plan-map .map-shell {
    width: 100%;
    height: 70vh;
    min-height: 420px;
}

.op-plan-panel {
    flex: 0 0 300px;
    border: 1px solid #ccd5df;
    border-radius: 0.4rem;
    background: #f8fbff;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    max-height: 70vh;
}

.op-plan-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.op-plan-panel-head h5 {
    margin: 0;
}

.op-plan-clear {
    padding: 0;
}

.op-plan-empty {
    color: #5a6b7e;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.op-plan-targets {
    list-style: none;
    margin: 0.5rem 0;
    padding: 0;
    overflow-y: auto;
    flex: 1 1 auto;
}

.op-plan-target {
    position: relative;
    border: 1px solid #d6dee7;
    border-radius: 0.35rem;
    background: #fff;
    padding: 0.4rem 1.6rem 0.4rem 0.5rem;
    margin-bottom: 0.35rem;
}

.op-plan-target-main {
    display: flex;
    gap: 0.4rem;
    align-items: baseline;
}

.op-plan-target-coord {
    font-weight: 700;
    color: var(--secondary-color);
}

.op-plan-target-name {
    color: #34495f;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.op-plan-target-sub {
    font-size: 0.8rem;
    color: #5a6b7e;
    display: flex;
    gap: 0.4rem;
    align-items: baseline;
}

.op-plan-target-tribe {
    color: #b07d00;
    font-weight: 600;
}

.op-plan-target-pts {
    margin-left: auto;
}

.op-plan-barb {
    color: #8a7a5c;
}

.op-plan-remove {
    position: absolute;
    top: 0.3rem;
    right: 0.4rem;
    border: none;
    background: transparent;
    color: #8a3b2f;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}

.op-plan-add {
    margin-top: 0.5rem;
}

.op-plan-status {
    margin-top: 0.5rem;
    color: #2a6b3f;
    font-size: 0.85rem;
}

/* --- Anchored attack-type selector popup --- */
.op-type-popup {
    position: absolute;
    z-index: 30;
    transform: translate(-50%, calc(-100% - 18px));
    background: #fff;
    border: 1px solid var(--border-brown-strong);
    border-radius: 0.45rem;
    box-shadow: 0 6px 18px rgba(74, 34, 0, 0.25);
    padding: 0.4rem;
    pointer-events: auto;
}

.op-type-popup::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -7px;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-top: 7px solid #fff;
    filter: drop-shadow(0 1px 0 var(--border-brown-strong));
}

.op-type-popup-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}

.op-type-popup-coord {
    font-weight: 700;
    color: var(--secondary-color);
    font-size: 0.85rem;
}

.op-type-popup-close {
    border: none;
    background: transparent;
    color: #8a3b2f;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.op-type-popup-icons {
    display: flex;
    gap: 0.3rem;
}

.op-type-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    width: 56px;
    padding: 0.3rem 0.2rem;
    border: 1px solid var(--border-brown);
    border-radius: 0.35rem;
    background: var(--surface-brown);
    cursor: pointer;
}

.op-type-icon:hover {
    border-color: var(--secondary-color);
    background: var(--primary-light);
}

.op-type-icon.sel {
    border-color: var(--secondary-color);
    background: var(--secondary-color);
    color: var(--text-on-secondary);
}

.op-type-icon img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.op-type-icon span {
    font-size: 0.72rem;
    line-height: 1;
}

.op-type-popup-body {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.45rem;
    min-width: 230px;
}

.op-type-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--text-muted-brown);
}

.op-type-field select,
.op-type-field input {
    padding: 0.2rem 0.4rem;
    border: 1px solid var(--border-brown);
    border-radius: 0.3rem;
    min-width: 150px;
}

.op-type-add {
    align-self: stretch;
}

.op-type-status {
    margin: 0;
    color: #2a6b3f;
    font-size: 0.8rem;
}

/* On phones, the anchored attack-type popup can overflow the map edges. Dock it to the bottom
   of the viewport as a contained sheet so every control stays reachable and on-screen. */
@media (max-width: 640px) {
    .op-type-popup {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        bottom: 0 !important;
        transform: none !important;
        width: 100%;
        max-width: 100%;
        max-height: 85vh;
        overflow-y: auto;
        border-radius: 0.9rem 0.9rem 0 0;
        border-bottom: none;
        box-shadow: 0 -8px 24px rgba(74, 34, 0, 0.35);
        padding: 0.5rem 0.9rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
        -webkit-overflow-scrolling: touch;
    }

    /* Grab-handle affordance at the top of the docked sheet. */
    .op-type-popup::before {
        content: "";
        display: block;
        width: 2.75rem;
        height: 0.3rem;
        margin: 0.1rem auto 0.6rem;
        border-radius: 1rem;
        background: var(--border-brown-strong);
    }

    /* Hide the speech-bubble pointer once the popup is docked to the bottom. */
    .op-type-popup::after {
        display: none;
    }

    /* Keep the coord/close header pinned while the sheet body scrolls. */
    .op-type-popup-head {
        position: sticky;
        top: 0;
        z-index: 2;
        background: #fff;
        padding-bottom: 0.4rem;
        margin-bottom: 0.5rem;
        border-bottom: 1px solid var(--border-brown);
    }

    .op-type-popup-coord {
        font-size: 1rem;
    }

    /* Bigger, easier-to-hit close target. */
    .op-type-popup-close {
        font-size: 1.6rem;
        width: 2.25rem;
        height: 2.25rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Lay the attack-type icons out as an even, tappable grid. */
    .op-type-popup-icons {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
        gap: 0.5rem;
    }

    .op-type-icon {
        width: auto;
        min-height: 4rem;
        padding: 0.55rem 0.3rem;
        gap: 0.3rem;
    }

    .op-type-icon img {
        width: 34px;
        height: 34px;
    }

    .op-type-icon span {
        font-size: 0.8rem;
    }

    .op-type-popup-body {
        min-width: 0;
        gap: 0.7rem;
        margin-top: 0.7rem;
    }

    /* Stack field label above the control so wide selects get the full row width. */
    .op-type-field {
        flex-direction: column;
        align-items: stretch;
        gap: 0.25rem;
        font-size: 0.9rem;
    }

    .op-type-field select,
    .op-type-field input {
        min-width: 0;
        width: 100%;
        min-height: 2.75rem;
        font-size: 1rem;
        padding: 0.45rem 0.6rem;
    }

    /* Make the primary action a large, full-width, sticky button at the foot of the sheet. */
    .op-type-add {
        position: sticky;
        bottom: 0;
        min-height: 3rem;
        font-size: 1rem;
        font-weight: 600;
        margin-top: 0.25rem;
    }
}

@media (max-width: 800px) {
    .op-plan-layout {
        flex-direction: column;
    }

    .op-plan-panel {
        flex-basis: auto;
        max-height: none;
    }
}

/* --- Op creation form --- */
.op-create {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.75rem;
    padding: 0.6rem;
    border: 1px solid var(--border-brown);
    border-radius: 0.4rem;
    background: var(--surface-brown);
}

.op-create-name {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-brown);
    border-radius: 0.3rem;
    min-width: 180px;
}

.op-create label {
    font-size: 0.85rem;
    color: var(--text-muted-brown);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

/* --- Command builder --- */
.op-build {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.op-build-mode {
    display: flex;
    gap: 0.4rem;
}

.op-mode-btn {
    flex: 1 1 0;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border-brown);
    background: #fff;
    border-radius: 0.3rem;
    cursor: pointer;
    font-size: 0.85rem;
}

.op-mode-btn.active {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
    color: var(--text-on-secondary);
}

.op-build-slot {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border-brown);
    border-radius: 0.35rem;
    background: #fff;
}

.op-build-label {
    flex: 0 0 54px;
    font-weight: 700;
    color: var(--secondary-color);
    font-size: 0.8rem;
    text-transform: uppercase;
}

.op-build-val {
    color: var(--text-on-primary);
    font-weight: 600;
}

.op-build-val em {
    color: #5a6b7e;
    font-weight: 400;
    font-style: normal;
    margin-left: 0.3rem;
}

.op-build-empty {
    color: #97a4b3;
    font-size: 0.85rem;
}

.op-build-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted-brown);
}

.op-build-field select,
.op-build-field input {
    padding: 0.25rem 0.4rem;
    border: 1px solid var(--border-brown);
    border-radius: 0.3rem;
    min-width: 120px;
}

.op-landing {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border-brown);
    font-size: 0.85rem;
    color: var(--text-muted-brown);
}

.op-landing-input {
    padding: 0.25rem 0.4rem;
    border: 1px solid var(--border-brown);
    border-radius: 0.3rem;
}

.op-fang-thresh {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-muted-brown);
}

.op-fang-thresh .op-landing-input {
    width: 4.5rem;
}

.op-status-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.6rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border-brown);
}

.op-status-badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: #e2e8f0;
    color: #445970;
}

.op-status-badge.op-status-planned { background: var(--primary-light); color: var(--secondary-color); }
.op-status-badge.op-status-active { background: #dcfce7; color: #15803d; }
.op-status-badge.op-status-completed { background: #ede9fe; color: #6d28d9; }
.op-status-badge.op-status-cancelled { background: #fee2e2; color: #b91c1c; }

.op-build-landhint {
    margin: -0.2rem 0 0.4rem;
    font-size: 0.8rem;
    color: #5a6b7e;
}

/* --- Command list --- */
.op-cmd-list {
    margin-top: 1rem;
}

.op-earliest-landing {
    margin: 0 0 0.6rem;
    padding: 0.45rem 0.7rem;
    background: var(--surface-brown);
    border: 1px solid var(--border-brown);
    border-radius: 0.4rem;
    color: var(--text-on-primary);
}

.op-earliest-sub {
    margin-left: 0.5rem;
    color: var(--text-muted-brown);
    font-size: 0.85rem;
}

.op-nuke-breakdown {
    margin: 0 0 0.8rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border-brown);
    border-radius: 0.45rem;
    background: #fff;
}

.op-nuke-breakdown-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.45rem;
    color: var(--secondary-color);
    font-weight: 700;
}

.op-nuke-unassigned {
    color: #b91c1c;
    font-size: 0.82rem;
    font-weight: 600;
}

.op-nuke-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}

.op-nuke-table th,
.op-nuke-table td {
    padding: 0.3rem 0.45rem;
    border-bottom: 1px solid var(--border-brown);
    text-align: left;
}

.op-nuke-table th {
    color: var(--text-muted-brown);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.op-nuke-table tr:last-child td {
    border-bottom: 0;
}

.op-cmd-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.op-cmd-table th,
.op-cmd-table td {
    text-align: left;
    padding: 0.4rem 0.55rem;
    border-bottom: 1px solid var(--border-brown);
}

.op-cmd-table th {
    color: var(--secondary-color);
    font-weight: 600;
    border-bottom: 2px solid var(--border-brown-strong);
}

.op-cmd-coord {
    font-weight: 700;
    color: var(--secondary-color);
}

.op-cmd-player {
    color: var(--text-muted-brown);
    margin-left: 0.35rem;
}

.op-cmd-kind {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    border-radius: 0.25rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: #fff;
    background: #6b7785;
}

.op-cmd-kind-nuke { background: #e03a3a; }
.op-cmd-kind-fang { background: #ff8a3d; }
.op-cmd-kind-noble { background: #b06bff; }
.op-cmd-kind-nobletrain { background: #b06bff; }
.op-cmd-kind-fake { background: #9aa4b0; }
.op-cmd-kind-support { background: #4ab0ff; }

.op-unit-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    min-width: 132px;
}

.op-unit-icon {
    border: 1px solid var(--border-brown);
    background: #fff;
    color: var(--text-muted-brown);
    border-radius: 0.35rem;
    padding: 0.1rem 0.32rem;
    min-width: 2.25rem;
    line-height: 1;
    cursor: pointer;
}

.op-unit-icon:hover {
    border-color: var(--secondary-color);
    color: var(--secondary-color);
}

.op-unit-icon.sel {
    border-color: var(--secondary-color);
    background: #e7f2ff;
    color: var(--secondary-color);
    font-weight: 700;
}

.op-unit-glyph {
    display: inline-block;
    font-size: 0.65rem;
    letter-spacing: 0.02em;
}

.op-cmd-remove {
    position: static;
}

/* Tablet-only: keep the still-anchored attack-type popup inside the viewport.
   (At <=640px the popup becomes a full-width bottom sheet handled above.) */
@media (min-width: 641px) and (max-width: 768px) {
    .op-type-popup {
        max-width: calc(100vw - 1.5rem);
    }
}

/* =====================================================================
   Responsive / mobile styles (appended). Breakpoints: 768px tablet,
   480px phone. Only new rules below — nothing above is modified.
   ===================================================================== */
@media (max-width: 768px) {
    /* Tame large content padding on small screens. */
    .content {
        padding-top: 0.75rem;
    }

    /* Map / op toolbars: stack vertically, controls go full width. */
    .map-toolbar,
    .ops-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .map-toolbar .map-world-select,
    .map-toolbar .map-nuke-input {
        width: 100%;
    }

    /* Standalone map page: scale the fixed 1000x1000 shell to the
       viewport instead of forcing horizontal page scroll. The op
       planner keeps its own (more specific) .op-plan-map .map-shell. */
    .map-shell {
        width: 100%;
        height: 70vh;
        min-height: 360px;
    }

    /* Wide command table: let it scroll horizontally inside its list
       wrapper rather than overflowing the viewport. */
    .op-cmd-list {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .op-cmd-table {
        width: auto;
        min-width: 100%;
        white-space: nowrap;
    }

    /* Op creation form: stack fields and let inputs fill the row. */
    .op-create {
        flex-direction: column;
        align-items: stretch;
    }

    .op-create .op-create-name {
        width: 100%;
        min-width: 0;
    }

    .op-create label {
        justify-content: space-between;
    }

    /* Command builder fields: drop rigid min-widths so selects/inputs
       can shrink to the available width. */
    .op-build-field select,
    .op-build-field input,
    .op-type-field select,
    .op-type-field input {
        min-width: 0;
        flex: 1 1 auto;
    }

    .op-type-popup-body {
        min-width: 0;
    }
}

@media (max-width: 480px) {
    /* Slightly tighter map shell on phones. */
    .map-shell {
        height: 60vh;
        min-height: 300px;
    }

    /* Smaller type / padding for dense tables on phones. */
    .op-cmd-table {
        font-size: 0.8rem;
    }

    .op-cmd-table th,
    .op-cmd-table td {
        padding: 0.3rem 0.4rem;
    }

    /* Reduce banner padding. */
    .op-earliest-landing {
        padding: 0.4rem 0.55rem;
        font-size: 0.92rem;
    }
}

/* --- Admin: player links dashboard --- */
.link-add {
    margin: 0.75rem 0 1rem;
    padding: 0.75rem 0.85rem;
    border: 1px solid #d7e0ec;
    border-radius: 0.5rem;
    background: #f7fafd;
}

.link-add-title {
    font-size: 1.05rem;
    margin: 0 0 0.5rem;
    color: #1d3b5c;
}

.link-add-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.6rem;
}

.link-add-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.85rem;
    color: #41607f;
}

.link-add-field-grow {
    flex: 1 1 16rem;
}

.link-add-input {
    padding: 0.35rem 0.5rem;
    border: 1px solid #c5d2e2;
    border-radius: 0.3rem;
    min-width: 12rem;
    font-size: 0.95rem;
}

.link-add-field-grow .link-add-input {
    width: 100%;
}

.link-add-help {
    margin: 0.5rem 0 0;
    font-size: 0.82rem;
    color: #6b7c90;
}

.link-status {
    margin: 0.25rem 0 0.75rem;
    padding: 0.4rem 0.6rem;
    border-radius: 0.4rem;
    background: #eef7ee;
    color: #2c5d2c;
    font-size: 0.9rem;
}

.link-empty {
    color: #6b7c90;
}

.link-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
    gap: 0.75rem;
}

.link-tile {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.7rem 0.8rem;
    border: 1px solid #d7e0ec;
    border-radius: 0.5rem;
    background: #fff;
    box-shadow: 0 1px 2px rgba(29, 59, 92, 0.06);
}

.link-tile-head {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
}

.link-tile-name {
    font-weight: 600;
    font-size: 1.05rem;
    color: #1d3b5c;
}

.link-tile-tribe {
    color: #41607f;
    font-size: 0.9rem;
}

.link-tile-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.15rem 0.6rem;
    margin: 0;
    font-size: 0.88rem;
}

.link-tile-meta dt {
    color: #6b7c90;
    font-weight: 500;
}

.link-tile-meta dd {
    margin: 0;
    color: #233;
}

.link-mono,
.link-tile-meta .link-mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.82rem;
}

.link-muted {
    color: #8a99a8;
    font-size: 0.85em;
}

.link-badge {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    border-radius: 0.4rem;
    font-size: 0.85rem;
    font-weight: 500;
}

.link-badge-ok {
    background: #e6f4ea;
    color: #1e7a3a;
}

.link-badge-window {
    background: #fdf2e0;
    color: #8a5b00;
}

.link-tile-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    padding-top: 0.3rem;
    border-top: 1px solid #eef2f7;
}

.link-tile-nick {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    margin: 0.4rem 0 0.6rem;
}

.link-tile-nick .link-add-field {
    flex: 1 1 auto;
}

.link-tile-nick .link-add-input {
    min-width: 0;
    width: 100%;
}

/* ── Guild selector (top bar, multi-guild users only) ────────────────────── */
.guild-selector {
    appearance: none;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 6px;
    color: #e3e8f0;
    cursor: pointer;
    font-size: 0.82rem;
    max-width: 200px;
    padding: 0.25rem 1.6rem 0.25rem 0.6rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23aab' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    margin-right: 0.6rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.guild-selector:focus {
    outline: none;
    border-color: #7289da;
    box-shadow: 0 0 0 2px rgba(114,137,218,.35);
}

.guild-selector option {
    background: #2c2f33;
    color: #e3e8f0;
}
