:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #d8dee6;
    --primary: #2563eb;
    --danger: #dc2626;
    --header-height: 58px;
    --edit-height: 48px;
    --rail-width: 64px;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

button,
input,
select {
    font: inherit;
}

#map {
    width: 100%;
    height: 100%;
    background: #78b5d6;
}

.leaflet-container {
    font: inherit;
    background: #78b5d6;
}

/* v15: the GeoJSON polygons ARE the map. No raster/tile provider is used. */
.leaflet-tile-pane {
    display: none;
}

/* ==============================
   WORKSPACE SHELL
============================== */

#knowledgeWorkspace {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    grid-template-rows: var(--header-height) var(--edit-height) minmax(0, 1fr);
    background: var(--bg);
}

#knowledgeWorkspace.open {
    display: grid;
}

.workspace-header {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    background: #fff;
    border-bottom: 1px solid var(--border);
}

.workspace-header-left,
.workspace-header-right {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.workspace-header-left {
    flex: 1 1 auto;
}

.workspace-header-right {
    flex: 0 0 auto;
}

.workspace-title-input {
    width: min(420px, 36vw);
    min-width: 180px;
    padding: 5px 8px;
    border: 1px solid transparent;
    border-radius: 7px;
    outline: none;
    background: transparent;
    color: var(--text);
    font-size: 18px;
    font-weight: 750;
}

.workspace-title-input:hover,
.workspace-title-input:focus {
    border-color: var(--border);
    background: #f8fafc;
}

.compact-label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
}

.button,
.toolbar-action,
.color-target-button,
.rail-tool {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.button:hover,
.toolbar-action:hover,
.color-target-button:hover,
.rail-tool:hover {
    background: #f3f4f6;
}

.button:active,
.toolbar-action:active,
.color-target-button:active,
.rail-tool:active {
    transform: translateY(1px);
}

.button {
    min-height: 34px;
    padding: 6px 10px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.button-primary {
    border-color: #1d4ed8;
    background: var(--primary);
    color: #fff;
}

.button-primary:hover {
    background: #1d4ed8;
}

.button-danger {
    border-color: #fecaca;
    background: #fff5f5;
    color: #b91c1c;
}

.button-secondary {
    background: #f9fafb;
}

/* ==============================
   PALETTES
============================== */

.color-palette {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
}

.color-swatch {
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
    padding: 0;
    border: 2px solid #fff;
    border-radius: 6px;
    outline: 1px solid #cbd5e1;
    background: var(--swatch);
    cursor: pointer;
    transition: transform 100ms ease, outline-color 100ms ease, box-shadow 100ms ease;
}

.compact-palette .color-swatch {
    width: 19px;
    height: 19px;
    flex-basis: 19px;
    border-radius: 5px;
}

.color-swatch:hover {
    transform: translateY(-1px) scale(1.06);
}

.color-swatch.selected {
    outline: 2px solid #2563eb;
    box-shadow: 0 0 0 2px #dbeafe;
}

/* ==============================
   TOP EDIT TOOLBAR
============================== */

.edit-toolbar {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    overflow: hidden;
    background: #fbfcfd;
    border-bottom: 1px solid var(--border);
}

.color-targets {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
}

.color-target-button {
    min-height: 30px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 7px;
    border-radius: 7px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
}

.color-target-button.active {
    border-color: #93c5fd;
    background: #eff6ff;
    color: #1d4ed8;
}

.color-preview {
    width: 13px;
    height: 13px;
    border: 1px solid #94a3b8;
    border-radius: 4px;
    background: #fff;
}

.board-palette {
    flex: 0 0 auto;
}

.board-palette .color-swatch {
    width: 19px;
    height: 19px;
    flex-basis: 19px;
    border-radius: 5px;
}

.edit-divider {
    width: 1px;
    height: 26px;
    flex: 0 0 1px;
    background: var(--border);
}

.line-width-control {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
    white-space: nowrap;
}

.line-width-control input {
    width: 78px;
}

.toolbar-action {
    min-height: 30px;
    padding: 4px 8px;
    border-radius: 7px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.danger-lite {
    color: #b91c1c;
}

.edit-spacer {
    flex: 1 1 auto;
}

.arrow-help {
    overflow: hidden;
    color: #64748b;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==============================
   BOARD LAYOUT + LEFT TOOL RAIL
============================== */

.board-layout {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-columns: var(--rail-width) minmax(0, 1fr);
}

.tool-rail {
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 8px 6px;
    overflow: hidden;
    background: #fff;
    border-right: 1px solid var(--border);
}

.rail-tool {
    min-height: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 4px 2px;
    border-radius: 8px;
    font-size: 9px;
    font-weight: 750;
    line-height: 1.1;
}

.rail-tool.active {
    border-color: #93c5fd;
    background: #dbeafe;
    color: #1d4ed8;
}

.rail-icon {
    font-size: 19px;
    line-height: 1;
}

.rail-divider {
    height: 1px;
    margin: 2px 5px;
    background: var(--border);
}

/* ==============================
   WHITEBOARD
============================== */

#whiteboardViewport {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background-color: #f8fafc;
    background-image:
        linear-gradient(#e9edf2 1px, transparent 1px),
        linear-gradient(90deg, #e9edf2 1px, transparent 1px);
    background-size: 24px 24px;
}

#whiteboardViewport .canvas-container {
    position: absolute !important;
    inset: 0;
}

#whiteboardViewport canvas {
    display: block;
}

#boardHint {
    position: absolute;
    left: 12px;
    bottom: 12px;
    z-index: 3;
    max-width: 760px;
    padding: 6px 9px;
    border: 1px solid rgba(203, 213, 225, 0.9);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    color: #64748b;
    font-size: 11px;
    pointer-events: none;
    backdrop-filter: blur(5px);
}

#workspaceStatus {
    position: fixed;
    right: 14px;
    bottom: 12px;
    z-index: 10001;
    padding: 5px 9px;
    border: 1px solid rgba(203, 213, 225, 0.85);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: #64748b;
    font-size: 11px;
    pointer-events: none;
}

@media (max-width: 1050px) {
    .arrow-help {
        display: none;
    }

    .workspace-title-input {
        width: 28vw;
    }

    .compact-label {
        display: none;
    }

    .compact-palette .color-swatch:nth-child(n+7) {
        display: none;
    }
}

@media (max-width: 760px) {
    :root {
        --rail-width: 56px;
    }

    .workspace-header-right .compact-palette {
        display: none;
    }

    .workspace-title-input {
        width: 34vw;
        min-width: 130px;
        font-size: 15px;
    }

    .board-palette .color-swatch:nth-child(n+7) {
        display: none;
    }

    .color-target-button {
        padding-inline: 5px;
    }

    .line-width-control {
        display: none;
    }
}

/* ==============================
   V5: SAVE STATE / TERRITORY COLOR
============================== */

button:disabled,
.button:disabled,
.toolbar-action:disabled {
    cursor: not-allowed;
    opacity: 0.42;
    transform: none !important;
}

.button-primary:disabled {
    border-color: #94a3b8;
    background: #94a3b8;
    color: #f8fafc;
}

.workspace-region-color {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
    white-space: nowrap;
}

.workspace-region-color-dot {
    width: 16px;
    height: 16px;
    border: 2px solid #fff;
    border-radius: 5px;
    outline: 1px solid #94a3b8;
    background: #22c55e;
}

.history-action {
    min-width: 62px;
}

/* ==============================
   V5: MAP EXPANSION CONTROL
============================== */

.empire-control {
    width: 238px;
    padding: 10px;
    border: 1px solid rgba(148, 163, 184, 0.55) !important;
    border-radius: 12px !important;
    background: rgba(255, 255, 255, 0.96) !important;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
    color: #111827;
    backdrop-filter: blur(7px);
}

.empire-control-title {
    margin-bottom: 7px;
    font-size: 12px;
    font-weight: 800;
}

.empire-control-palette {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.empire-color-swatch {
    width: 100%;
    height: 24px;
    padding: 0;
    border: 2px solid #fff;
    border-radius: 7px;
    outline: 1px solid #cbd5e1;
    background: var(--swatch);
    cursor: pointer;
    transition: transform 100ms ease, box-shadow 100ms ease, outline-color 100ms ease;
}

.empire-color-swatch:hover {
    transform: translateY(-1px);
}

.empire-color-swatch.selected {
    outline: 2px solid #111827;
    box-shadow: 0 0 0 2px #dbeafe;
}

.empire-control-legend {
    display: flex;
    gap: 12px;
    margin-top: 9px;
    color: #64748b;
    font-size: 10px;
}

.empire-control-legend span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.legend-box {
    width: 11px;
    height: 11px;
    border: 1px solid #94a3b8;
    border-radius: 3px;
}

.legend-available {
    background: #d9dee3;
}

.legend-locked {
    background: #aab3bd;
}

.empire-control-status {
    min-height: 30px;
    margin-top: 8px;
    padding-top: 7px;
    border-top: 1px solid #e2e8f0;
    color: #475569;
    font-size: 10px;
    line-height: 1.35;
}

.empire-control-status.warning {
    color: #b45309;
    font-weight: 750;
}

/* ==============================
   V5: UNSAVED CHANGES MODAL
============================== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.48);
    backdrop-filter: blur(3px);
}

.modal-backdrop.open {
    display: flex;
}

.modal-card {
    width: min(440px, 100%);
    padding: 22px;
    border: 1px solid #d8dee6;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

.modal-card h2 {
    margin: 0 0 8px;
    font-size: 19px;
}

.modal-card p {
    margin: 0;
    color: #64748b;
    font-size: 13px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

@media (max-width: 760px) {
    .empire-control {
        width: 205px;
    }

    .workspace-region-color {
        display: none;
    }

    .history-action {
        min-width: auto;
    }
}

/* ==============================
   PORT ACTION
============================== */

.button-port {
    border-color: #7dd3fc;
    background: #f0f9ff;
    color: #0369a1;
}

.button-port:hover:not(:disabled) {
    border-color: #38bdf8;
    background: #e0f2fe;
}

.button-port.active-port {
    border-color: #0284c7;
    background: #0284c7;
    color: #fff;
}

/* ==============================
   V14: AUTH + CLOUD ACCOUNT
============================== */

.auth-gate {
    position: fixed;
    inset: 0;
    z-index: 30000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 20%, rgba(37, 99, 235, 0.18), transparent 34%),
        radial-gradient(circle at 80% 75%, rgba(20, 184, 166, 0.16), transparent 36%),
        rgba(15, 23, 42, 0.88);
    backdrop-filter: blur(8px);
}

.auth-gate.open {
    display: flex;
}

.auth-card {
    width: min(430px, 100%);
    padding: 26px;
    border: 1px solid rgba(203, 213, 225, 0.72);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 30px 90px rgba(15, 23, 42, 0.38);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 22px;
}

.auth-brand-mark {
    display: grid;
    width: 46px;
    height: 46px;
    place-items: center;
    border-radius: 14px;
    background: #111827;
    color: #fff;
    font-size: 15px;
    font-weight: 900;
    letter-spacing: 0.05em;
}

.auth-brand h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.15;
}

.auth-brand p {
    margin: 4px 0 0;
    color: #64748b;
    font-size: 13px;
}

.auth-mode-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-bottom: 18px;
    padding: 4px;
    border-radius: 10px;
    background: #f1f5f9;
}

.auth-mode {
    min-height: 36px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    font-weight: 800;
}

.auth-mode.active {
    background: #fff;
    color: #111827;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
}

.auth-form {
    display: grid;
    gap: 13px;
}

.auth-form label {
    display: grid;
    gap: 6px;
    color: #475569;
    font-size: 12px;
    font-weight: 800;
}

.auth-form input {
    width: 100%;
    min-height: 42px;
    padding: 9px 11px;
    border: 1px solid #cbd5e1;
    border-radius: 9px;
    outline: none;
    background: #fff;
    color: #111827;
}

.auth-form input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.auth-submit {
    width: 100%;
    min-height: 42px;
    margin-top: 2px;
}

.auth-message {
    min-height: 20px;
    margin-top: 13px;
    color: #64748b;
    font-size: 12px;
    line-height: 1.45;
}

.auth-message[data-type="error"] {
    color: #b91c1c;
}

.auth-message[data-type="success"] {
    color: #047857;
}

.auth-config-help {
    display: none;
    margin-top: 12px;
    padding: 11px;
    border: 1px solid #fed7aa;
    border-radius: 9px;
    background: #fff7ed;
    color: #9a3412;
    font-size: 11px;
    line-height: 1.5;
}

.auth-config-help.visible {
    display: block;
}

.auth-config-help code {
    font-size: 10px;
}

.account-bar {
    position: fixed;
    top: 10px;
    left: 56px;
    z-index: 1200;
    display: none;
    align-items: center;
    gap: 8px;
    max-width: calc(100vw - 330px);
    padding: 6px 7px 6px 10px;
    border: 1px solid rgba(148, 163, 184, 0.5);
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 5px 18px rgba(15, 23, 42, 0.14);
    backdrop-filter: blur(6px);
}

.account-bar.visible {
    display: flex;
}

.account-email {
    overflow: hidden;
    max-width: 220px;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #334155;
    font-size: 11px;
    font-weight: 800;
}

.cloud-sync-status {
    padding-left: 8px;
    border-left: 1px solid #e2e8f0;
    color: #64748b;
    font-size: 10px;
    white-space: nowrap;
}

.cloud-sync-status[data-state="syncing"] {
    color: #1d4ed8;
}

.cloud-sync-status[data-state="synced"] {
    color: #047857;
}

.cloud-sync-status[data-state="error"] {
    color: #b91c1c;
    font-weight: 800;
}

@media (max-width: 760px) {
    .account-bar {
        left: 50px;
        max-width: calc(100vw - 60px);
    }

    .account-email {
        display: none;
    }
}

/* v14 cloud synchronization states */
.cloud-sync-status[data-state="pending"] {
    color: #a16207;
    font-weight: 800;
}

.cloud-sync-status[data-state="offline"] {
    color: #b45309;
    font-weight: 800;
}


/* ==============================
   REALTIME STATUS (v15)
============================== */
.realtime-status {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: #475569;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.realtime-status[data-state="live"] {
    color: #166534;
    border-color: #bbf7d0;
    background: #f0fdf4;
}

.realtime-status[data-state="degraded"],
.realtime-status[data-state="error"] {
    color: #9a3412;
    border-color: #fed7aa;
    background: #fff7ed;
}

/* ==============================
   REVIEW ENGINE (v16)
============================== */
.review-summary-status {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: #475569;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.review-summary-status[data-state="stable"] {
    color: #166534;
    border-color: #bbf7d0;
    background: #f0fdf4;
}

.review-summary-status[data-state="due"] {
    color: #854d0e;
    border-color: #fde68a;
    background: #fffbeb;
}

.review-summary-status[data-state="overdue"],
.review-summary-status[data-state="unstable"] {
    color: #9a3412;
    border-color: #fed7aa;
    background: #fff7ed;
}

.review-status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    max-width: 180px;
    overflow: hidden;
    padding: 4px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    background: #f8fafc;
    color: #475569;
    font-size: 10px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.review-status-badge[data-status="stable"] {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}

.review-status-badge[data-status="due"] {
    border-color: #fde68a;
    background: #fffbeb;
    color: #854d0e;
}

.review-status-badge[data-status="overdue"],
.review-status-badge[data-status="unstable"] {
    border-color: #fed7aa;
    background: #fff7ed;
    color: #9a3412;
}

.button-review {
    border-color: #c4b5fd;
    background: #f5f3ff;
    color: #6d28d9;
}

.button-review:hover:not(:disabled) {
    border-color: #a78bfa;
    background: #ede9fe;
}

.review-overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(248, 250, 252, 0.97);
    backdrop-filter: blur(10px);
}

.review-overlay.open {
    display: flex;
}

.review-overlay.revealed {
    align-items: flex-end;
    background: rgba(248, 250, 252, 0.06);
    backdrop-filter: none;
}

.review-panel {
    width: min(520px, calc(100vw - 100px));
    padding: 22px;
    border: 1px solid #cbd5e1;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
    text-align: center;
}

.review-overlay.revealed .review-panel {
    margin-bottom: 28px;
    padding: 14px 16px;
}

.review-overlay-eyebrow {
    margin-bottom: 5px;
    color: #7c3aed;
    font-size: 11px;
    font-weight: 850;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.review-panel h2 {
    margin: 0 0 8px;
    font-size: 22px;
}

.review-panel p {
    margin: 0 auto 16px;
    max-width: 430px;
    color: #64748b;
    font-size: 13px;
    line-height: 1.5;
}

.review-reveal-button {
    min-width: 150px;
}

.review-rating-label {
    margin-bottom: 8px;
    color: #475569;
    font-size: 11px;
    font-weight: 800;
}

.review-rating-buttons {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
}

.review-rating.again {
    border-color: #fecaca;
    background: #fff1f2;
    color: #be123c;
}

.review-rating.hard {
    border-color: #fed7aa;
    background: #fff7ed;
    color: #c2410c;
}

.review-rating.good {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
}

.review-rating.easy {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #15803d;
}

.review-cancel {
    margin-top: 12px;
    border: 0;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    font-size: 11px;
    text-decoration: underline;
}

#whiteboardViewport.review-recall-active .canvas-container,
#whiteboardViewport.review-recall-active #boardHint {
    filter: blur(8px);
    opacity: 0.2;
}

@media (max-width: 900px) {
    .review-status-badge {
        display: none;
    }

    .review-summary-status {
        display: none;
    }
}

/* ==============================
   EMPIRE STABILITY (v17)
============================== */
.stability-summary-status {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: #475569;
    font-size: 11px;
    font-weight: 750;
    white-space: nowrap;
}

.stability-summary-status[data-state="stable"] {
    color: #166534;
    border-color: #bbf7d0;
    background: #f0fdf4;
}

.stability-summary-status[data-state="warning"] {
    color: #854d0e;
    border-color: #fde68a;
    background: #fffbeb;
}

.stability-summary-status[data-state="locked"] {
    color: #991b1b;
    border-color: #fecaca;
    background: #fef2f2;
}

.empire-control-status.stability-warning {
    color: #92400e;
    font-weight: 700;
}

.empire-control-status.stability-locked {
    color: #991b1b;
    font-weight: 850;
}


/* ==============================
   BETA READY UX (v18)
============================== */
.auth-secondary-actions {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
}

.auth-link-button {
    padding: 2px 0;
    border: 0;
    background: transparent;
    color: #2563eb;
    cursor: pointer;
    font-size: 11px;
    font-weight: 750;
}

.auth-link-button:hover { text-decoration: underline; }

.beta-review-button {
    min-height: 28px;
    padding: 4px 8px;
    border-color: #c4b5fd;
    background: #f5f3ff;
    color: #6d28d9;
}

.beta-stats-panel {
    position: fixed;
    left: 12px;
    bottom: 14px;
    z-index: 1150;
    width: 264px;
    padding: 11px 12px;
    border: 1px solid rgba(148, 163, 184, 0.5);
    border-radius: 13px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
    backdrop-filter: blur(7px);
}

.beta-stats-title {
    margin-bottom: 8px;
    color: #334155;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.03em;
}

.beta-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.beta-stats-grid > div {
    min-width: 0;
    padding: 6px 4px;
    border-radius: 8px;
    background: #f8fafc;
    text-align: center;
}

.beta-stats-grid strong,
.beta-stats-grid span { display: block; }
.beta-stats-grid strong { color: #0f172a; font-size: 14px; }
.beta-stats-grid span { margin-top: 2px; color: #64748b; font-size: 8px; line-height: 1.15; }

.map-loading-badge {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 1500;
    transform: translate(-50%, -50%);
    padding: 9px 13px;
    border: 1px solid rgba(148, 163, 184, 0.55);
    border-radius: 999px;
    background: rgba(255,255,255,.94);
    box-shadow: 0 8px 24px rgba(15,23,42,.14);
    color: #475569;
    font-size: 12px;
    font-weight: 800;
}

.onboarding-card { width: min(590px, 100%); }
.onboarding-progress { display: flex; justify-content: flex-end; margin-bottom: 6px; color: #94a3b8; font-size: 11px; font-weight: 800; }
.onboarding-step { display: none; }
.onboarding-step.active { display: block; }
.onboarding-eyebrow { margin-bottom: 5px; color: #7c3aed; font-size: 10px; font-weight: 900; letter-spacing: .09em; text-transform: uppercase; }
.onboarding-step h2 { margin-bottom: 9px; font-size: 24px; }
.onboarding-step p { font-size: 14px; }
.onboarding-loop { display: flex; align-items: center; justify-content: center; gap: 9px; margin: 22px 0 8px; padding: 14px; border-radius: 12px; background: #f8fafc; color: #334155; font-size: 12px; font-weight: 850; }
.onboarding-loop b { color: #94a3b8; }
.onboarding-color-palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; margin-top: 20px; }
.onboarding-color-palette button { height: 38px; border: 3px solid #fff; border-radius: 10px; outline: 1px solid #cbd5e1; background: var(--swatch); cursor: pointer; }
.onboarding-color-palette button.selected { outline: 3px solid #111827; box-shadow: 0 0 0 3px #dbeafe; }
.onboarding-tip { margin-top: 18px; padding: 12px; border: 1px solid #bfdbfe; border-radius: 10px; background: #eff6ff; color: #1e40af; font-size: 12px; line-height: 1.45; }
.onboarding-actions { justify-content: space-between; }

.first-territory-coach {
    position: fixed;
    left: 50%;
    bottom: 18px;
    z-index: 1450;
    display: flex;
    align-items: center;
    gap: 14px;
    width: min(520px, calc(100vw - 30px));
    transform: translateX(-50%);
    padding: 11px 12px 11px 14px;
    border: 1px solid #c4b5fd;
    border-radius: 13px;
    background: rgba(250, 245, 255, .97);
    box-shadow: 0 10px 35px rgba(15,23,42,.18);
}
.first-territory-coach > div { flex: 1; min-width: 0; }
.first-territory-coach strong, .first-territory-coach span { display: block; }
.first-territory-coach strong { color: #5b21b6; font-size: 12px; }
.first-territory-coach span { margin-top: 2px; color: #64748b; font-size: 10px; }
.first-territory-coach button { border: 0; background: transparent; color: #64748b; cursor: pointer; font-size: 20px; }

.review-queue-progress {
    position: fixed;
    top: 58px;
    left: 50%;
    z-index: 1300;
    display: flex;
    align-items: center;
    gap: 10px;
    transform: translateX(-50%);
    padding: 6px 9px 6px 12px;
    border: 1px solid #c4b5fd;
    border-radius: 999px;
    background: rgba(245,243,255,.97);
    box-shadow: 0 6px 18px rgba(15,23,42,.12);
    color: #5b21b6;
    font-size: 11px;
    font-weight: 850;
}
.review-queue-progress button { border: 0; background: transparent; color: #7c3aed; cursor: pointer; font-size: 10px; font-weight: 850; text-decoration: underline; }

.account-settings-card { width: min(500px, 100%); }
.account-settings-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.modal-close-button { border: 0; background: transparent; color: #64748b; cursor: pointer; font-size: 24px; line-height: 1; }
.account-settings-email { margin: 0 0 16px !important; color: #334155 !important; font-weight: 750; }
.account-settings-section { display: grid; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid #e2e8f0; }
.account-settings-section label { color: #475569; font-size: 11px; font-weight: 850; }
.account-settings-section input { min-height: 40px; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 8px; outline: none; }
.account-settings-section input:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.account-danger-zone { padding: 13px; border: 1px solid #fecaca; border-radius: 10px; background: #fff7f7; }
.account-danger-zone p { font-size: 11px; }

.app-error-banner {
    position: fixed;
    left: 50%;
    top: 18px;
    z-index: 40000;
    display: flex;
    align-items: center;
    gap: 14px;
    width: min(620px, calc(100vw - 28px));
    transform: translateX(-50%);
    padding: 10px 10px 10px 14px;
    border: 1px solid #fecaca;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 12px 38px rgba(15,23,42,.2);
}
.app-error-banner > div { flex: 1; }
.app-error-banner strong, .app-error-banner span { display: block; }
.app-error-banner strong { color: #991b1b; font-size: 12px; }
.app-error-banner span { margin-top: 2px; color: #64748b; font-size: 10px; }

.beta-toast {
    position: fixed;
    right: 16px;
    bottom: 18px;
    z-index: 41000;
    max-width: 360px;
    padding: 10px 13px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 10px 30px rgba(15,23,42,.18);
    color: #334155;
    font-size: 11px;
    font-weight: 750;
}
.beta-toast[data-type="success"] { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }
.beta-toast[data-type="warning"] { border-color: #fde68a; background: #fffbeb; color: #854d0e; }
.beta-toast[data-type="error"] { border-color: #fecaca; background: #fef2f2; color: #991b1b; }

@media (max-width: 980px) {
    .beta-stats-panel { width: 230px; }
    .beta-stats-grid span { display: none; }
    #startReviewQueueButton { display: none; }
}

@media (max-width: 760px) {
    .beta-stats-panel { left: 8px; bottom: 8px; width: 190px; padding: 8px; }
    .beta-stats-title { display: none; }
    .account-bar #accountSettingsButton { display: none; }
    .onboarding-loop { gap: 5px; font-size: 10px; }
}

/* HTML hidden must win over component display declarations.
   Without this, e.g. .app-error-banner { display:flex } makes a
   hidden error banner visible on every load. */
[hidden] {
    display: none !important;
}


/* ==============================
   V19 REVIEW QUESTIONS + QUIZ
============================== */

.review-summary-status[data-state="unsecured"],
.review-status-badge[data-status="unsecured"] {
    color: #6d28d9;
    border-color: #ddd6fe;
    background: #f5f3ff;
}

.review-quiz-panel {
    width: min(620px, calc(100vw - 80px));
    text-align: left;
}

.review-quiz-progress {
    margin-bottom: 8px;
    color: #64748b;
    font-size: 11px;
    font-weight: 800;
}

.review-answer-options {
    display: grid;
    gap: 9px;
    margin: 16px 0;
}

.review-answer-option {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    color: #334155;
    cursor: pointer;
    transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

.review-answer-option:hover {
    border-color: #a78bfa;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, .08);
}

.review-answer-option input {
    margin-top: 2px;
}

.review-answer-option.correct {
    border-color: #86efac;
    background: #f0fdf4;
}

.review-answer-option.wrong {
    border-color: #fda4af;
    background: #fff1f2;
}

.review-answer-feedback {
    margin: 4px 0 12px;
    padding: 9px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 800;
}

.review-answer-feedback[data-result="correct"] {
    color: #166534;
    background: #f0fdf4;
}

.review-answer-feedback[data-result="wrong"] {
    color: #9f1239;
    background: #fff1f2;
}

.review-answer-feedback[data-result="warning"] {
    color: #92400e;
    background: #fffbeb;
}

.review-submit-answer {
    min-width: 150px;
}

.review-setup-card {
    width: min(500px, 100%);
}

.review-setup-eyebrow {
    margin-bottom: 5px;
    color: #7c3aed;
    font-size: 10px;
    font-weight: 900;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.review-questions-card {
    width: min(780px, 100%);
    max-height: min(88vh, 860px);
    overflow: auto;
}

.review-questions-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.review-questions-header p {
    margin: 5px 0 0;
    color: #64748b;
    font-size: 12px;
}

.review-questions-list {
    display: grid;
    gap: 8px;
    margin: 18px 0;
}

.review-questions-empty {
    padding: 14px;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
    color: #64748b;
    font-size: 12px;
}

.review-question-list-item {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
}

.review-question-list-number {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #f5f3ff;
    color: #6d28d9;
    font-size: 11px;
    font-weight: 900;
}

.review-question-list-content {
    min-width: 0;
}

.review-question-list-content strong,
.review-question-list-content span {
    display: block;
}

.review-question-list-content strong {
    color: #1e293b;
    font-size: 12px;
}

.review-question-list-content span {
    margin-top: 3px;
    color: #64748b;
    font-size: 10px;
}

.review-question-list-actions {
    display: flex;
    gap: 6px;
}

.review-question-form {
    display: grid;
    gap: 12px;
    padding-top: 16px;
    border-top: 1px solid #e2e8f0;
}

.review-question-form h3 {
    margin: 0;
    font-size: 15px;
}

.review-question-form label {
    display: grid;
    gap: 6px;
    color: #475569;
    font-size: 11px;
    font-weight: 850;
}

.review-question-form textarea,
.review-question-form select,
.review-question-option-text {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #0f172a;
    font: inherit;
    outline: none;
}

.review-question-form textarea:focus,
.review-question-form select:focus,
.review-question-option-text:focus {
    border-color: #8b5cf6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, .1);
}

.review-question-options-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: #475569;
    font-size: 11px;
    font-weight: 850;
}

.review-question-options-heading small {
    color: #94a3b8;
    font-weight: 700;
}

.review-question-options {
    display: grid;
    gap: 7px;
}

.review-question-option-row {
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr) 28px;
    align-items: center;
    gap: 7px;
}

.review-question-correct {
    width: 16px;
    height: 16px;
    justify-self: center;
}

.review-question-remove-option {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: #fff1f2;
    color: #be123c;
    cursor: pointer;
    font-size: 18px;
}

.beta-stats-grid {
    grid-template-columns: repeat(5, 1fr);
}

@media (max-width: 760px) {
    .review-question-list-item {
        grid-template-columns: 24px minmax(0, 1fr);
    }
    .review-question-list-actions {
        grid-column: 2;
    }
    .review-quiz-panel {
        width: min(620px, calc(100vw - 30px));
    }
}

@media (min-width: 761px) { .beta-stats-panel { width: 310px; } }


/* ==============================
   V21 UI FACELIFT
============================== */
:root {
    --bg: #eef3f8;
    --panel: rgba(255,255,255,0.96);
    --text: #172033;
    --muted: #617086;
    --border: #d9e3ee;
    --primary: #1d75f0;
    --danger: #e5484d;
    --radius-sm: 12px;
    --radius-md: 18px;
    --radius-lg: 24px;
    --shadow-soft: 0 10px 30px rgba(15, 23, 42, 0.10);
    --shadow-card: 0 16px 42px rgba(15, 23, 42, 0.12);
}

html, body {
    color: var(--text);
    background: linear-gradient(180deg, #f3f7fb 0%, #edf3f8 100%);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#map,
.leaflet-container {
    background:
        radial-gradient(circle at 18% 18%, rgba(255,255,255,0.14), transparent 22%),
        radial-gradient(circle at 82% 10%, rgba(255,255,255,0.08), transparent 20%),
        linear-gradient(180deg, #87c4ea 0%, #73b7e3 100%);
}

.button,
.toolbar-action,
.color-target-button,
.rail-tool {
    border-color: #d8e2ee;
    border-radius: 14px;
    box-shadow: 0 1px 0 rgba(255,255,255,0.55) inset;
}

.button {
    min-height: 40px;
    padding: 8px 14px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 800;
}

.button-primary {
    border-color: #1667d8;
    background: linear-gradient(180deg, #1f83ff 0%, #1d75f0 100%);
    color: #fff;
    box-shadow: 0 10px 24px rgba(29, 117, 240, 0.22);
}

.button-primary:hover {
    background: linear-gradient(180deg, #1875ec 0%, #1667d8 100%);
}

.button-secondary {
    background: rgba(255,255,255,0.82);
}

.button-review {
    border-color: #d9c7ff;
    background: #f8f4ff;
    color: #6e40d7;
}

.button-port {
    border-color: #9dd5fb;
    background: linear-gradient(180deg, #19a0ff 0%, #0d86dc 100%);
    color: #fff;
}

.button-danger {
    border-color: #f3c0c2;
    background: #fff7f7;
    color: #cf2f35;
}

.auth-card,
.modal-card,
.account-bar,
.empire-control,
.beta-stats-panel,
.first-territory-coach,
.review-queue-progress,
.app-error-banner,
.beta-toast {
    border: 1px solid rgba(214, 224, 236, 0.95) !important;
    border-radius: 22px !important;
    box-shadow: var(--shadow-card) !important;
    background: rgba(255,255,255,0.94) !important;
    backdrop-filter: blur(10px);
}

.auth-card { padding: 28px; }
.auth-brand-mark {
    border-radius: 16px;
    background: linear-gradient(180deg, #1d2434 0%, #0f172a 100%);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.22);
}
.auth-brand p { color: #708198; }

.account-bar {
    top: 14px;
    left: 88px;
    gap: 10px;
    max-width: calc(100vw - 340px);
    padding: 8px 10px 8px 12px;
    border-radius: 22px;
}

.account-email {
    max-width: 250px;
    padding-right: 8px;
    color: #223049;
    font-size: 15px;
    font-weight: 900;
}

.cloud-sync-status,
.realtime-status,
.review-summary-status,
.stability-summary-status {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 6px 12px;
    border: 1px solid #dbe4ee;
    border-radius: 999px;
    background: rgba(248,250,252,0.92);
    color: #48576b;
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
}

.cloud-sync-status {
    padding-left: 12px;
    border-left: 1px solid #dbe4ee;
}

.cloud-sync-status[data-state="synced"],
.realtime-status[data-state="live"],
.review-summary-status[data-state="stable"],
.stability-summary-status[data-state="stable"] {
    border-color: #cdecd8;
    background: #eefaf1;
    color: #22824d;
}

.review-summary-status[data-state="due"],
.stability-summary-status[data-state="warning"] {
    border-color: #f5dfac;
    background: #fff9ea;
    color: #a06a00;
}

.workspace-header {
    gap: 16px;
    padding: 16px 18px 10px;
    background: linear-gradient(180deg, rgba(255,255,255,0.98) 0%, rgba(255,255,255,0.95) 100%);
    border-bottom: 1px solid #e2e8f0;
}

.workspace-title-input {
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 18px;
    font-weight: 900;
}

.workspace-region-color,
.review-status-badge {
    min-height: 38px;
    padding: 8px 12px;
    border: 1px solid #dbe4ee;
    border-radius: 999px;
    background: #f8fafc;
    font-size: 13px;
    font-weight: 800;
}

.review-status-badge[data-status="stable"] {
    border-color: #cdecd8;
    background: #eefaf1;
    color: #22824d;
}

.edit-toolbar {
    gap: 10px;
    padding: 12px 16px;
    background: rgba(249, 251, 253, 0.96);
    border-bottom: 1px solid #e2e8f0;
}

.color-target-button,
.toolbar-action {
    min-height: 38px;
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 13px;
    font-weight: 800;
}

.color-target-button { color: #4d5c70; }
.color-target-button.active {
    border-color: #9ec7ff;
    background: #edf5ff;
    color: #1d75f0;
}

.color-preview {
    width: 16px;
    height: 16px;
    border-radius: 5px;
}

.board-palette .color-swatch,
.compact-palette .color-swatch,
.color-swatch {
    width: 24px;
    height: 24px;
    flex-basis: 24px;
    border-radius: 8px;
    outline: 1px solid #ced8e3;
}

.line-width-control { font-size: 13px; }
.line-width-control input { width: 130px; }

.arrow-help {
    color: #748396;
    font-size: 12px;
}

.board-layout {
    grid-template-columns: 86px minmax(0, 1fr);
}

.tool-rail {
    gap: 10px;
    padding: 12px 10px;
    background: rgba(255,255,255,0.98);
}

.rail-tool {
    min-height: 74px;
    gap: 6px;
    padding: 8px 4px;
    border-radius: 18px;
    font-size: 14px;
    font-weight: 850;
}

.rail-tool.active {
    background: linear-gradient(180deg, #eef5ff 0%, #e1efff 100%);
    box-shadow: inset 0 0 0 1px #b7d4ff;
}

.rail-icon {
    font-size: 27px;
}

#whiteboardViewport {
    background-color: #f8fafc;
    background-image:
        linear-gradient(rgba(219, 228, 238, 0.72) 1px, transparent 1px),
        linear-gradient(90deg, rgba(219, 228, 238, 0.72) 1px, transparent 1px);
    background-size: 32px 32px;
}

#boardHint,
#workspaceStatus {
    border-radius: 16px;
    background: rgba(255,255,255,0.92);
    box-shadow: var(--shadow-soft);
    color: #5f7187;
    font-size: 13px;
}

#boardHint {
    left: 18px;
    bottom: 18px;
    padding: 10px 14px;
    max-width: 640px;
}

#workspaceStatus {
    right: 18px;
    bottom: 18px;
    padding: 8px 14px;
}

.leaflet-control-zoom,
.leaflet-bar:not(.empire-control) {
    overflow: hidden;
    border: 1px solid rgba(214,224,236,0.95) !important;
    border-radius: 18px !important;
    box-shadow: var(--shadow-soft);
}

.leaflet-control-zoom a,
.leaflet-bar a {
    width: 46px !important;
    height: 46px !important;
    line-height: 44px !important;
    border-bottom: 1px solid #e3ebf4 !important;
    background: rgba(255,255,255,0.95) !important;
    color: #223049 !important;
    font-size: 28px !important;
}

.leaflet-control-zoom a:last-child,
.leaflet-bar a:last-child {
    border-bottom: 0 !important;
}

.empire-control {
    width: 312px;
    padding: 18px 18px 16px;
}

.empire-control-title {
    margin-bottom: 4px;
    color: #162033;
    font-size: 24px;
    font-weight: 900;
}

.empire-control::before {
    content: "Choose a color for your territories.";
    display: block;
    margin-bottom: 14px;
    color: #6a7890;
    font-size: 14px;
    font-weight: 600;
}

.empire-control-palette { gap: 10px; }

.empire-color-swatch {
    height: 48px;
    border-radius: 14px;
    outline: 1px solid #d2dce7;
}

.empire-color-swatch.selected {
    outline: 3px solid #1d2434;
    box-shadow: 0 0 0 3px rgba(219,235,255,0.95);
}

.empire-control-legend {
    gap: 18px;
    margin-top: 14px;
    font-size: 14px;
}

.legend-box {
    width: 14px;
    height: 14px;
    border-radius: 4px;
}

.legend-available { background: #edf2f7; }
.legend-locked { background: #a6b2c0; }

.empire-control-status {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid #e6edf5;
    color: #46566c;
    font-size: 14px;
    line-height: 1.5;
}

.beta-stats-panel {
    left: 16px;
    bottom: 16px;
    width: 420px;
    padding: 18px 20px;
}

.beta-stats-title {
    margin-bottom: 14px;
    color: #223049;
    font-size: 16px;
    font-weight: 900;
}

.beta-stats-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
}

.beta-stats-grid > div {
    padding: 10px 8px;
    border-radius: 16px;
    background: linear-gradient(180deg, #fbfdff 0%, #f5f8fc 100%);
}

.beta-stats-grid strong { font-size: 28px; }
.beta-stats-grid span {
    margin-top: 6px;
    color: #69788d;
    font-size: 12px;
    line-height: 1.25;
}

.onboarding-tip,
.review-answer-feedback,
.review-questions-empty {
    border-radius: 14px;
}

.first-territory-coach {
    gap: 16px;
    width: min(560px, calc(100vw - 32px));
    padding: 14px 16px;
}
.first-territory-coach strong { font-size: 14px; }
.first-territory-coach span { font-size: 12px; }

.review-queue-progress {
    top: 76px;
    padding: 8px 12px 8px 16px;
    font-size: 13px;
}

.map-loading-badge {
    padding: 11px 16px;
    border-radius: 999px;
    font-size: 14px;
}

.app-error-banner strong { font-size: 14px; }
.app-error-banner span { font-size: 12px; }
.beta-toast { font-size: 13px; }

.leaflet-tooltip {
    border: 1px solid #dbe4ee;
    border-radius: 16px;
    padding: 12px 14px;
    background: rgba(255,255,255,0.96);
    box-shadow: var(--shadow-soft);
    color: #223049;
}

@media (max-width: 1200px) {
    .account-bar { max-width: calc(100vw - 300px); }
    .beta-stats-panel { width: 360px; }
    .beta-stats-grid strong { font-size: 24px; }
    .empire-control { width: 286px; }
}

@media (max-width: 980px) {
    .account-bar {
        left: 74px;
        max-width: calc(100vw - 90px);
        gap: 8px;
        padding: 8px 10px;
    }

    .account-email { font-size: 13px; max-width: 180px; }
    .cloud-sync-status,
    .realtime-status,
    .review-summary-status,
    .stability-summary-status { font-size: 11px; min-height: 32px; padding: 5px 10px; }

    .beta-stats-panel {
        width: 320px;
        padding: 14px;
    }
    .beta-stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .board-layout { grid-template-columns: 68px minmax(0, 1fr); }
    .tool-rail { padding: 8px 6px; }
    .rail-tool { min-height: 62px; border-radius: 14px; font-size: 11px; }
    .rail-icon { font-size: 22px; }
    .button { min-height: 36px; font-size: 12px; }
    .workspace-header { padding: 12px 12px 8px; }
    .edit-toolbar { padding: 8px 10px; }
    .beta-stats-panel { width: 260px; }
    .beta-stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .beta-stats-grid strong { font-size: 22px; }
    .beta-stats-grid span { font-size: 11px; }
    .empire-control {
        width: 250px;
        padding: 14px;
    }
    .empire-control-title { font-size: 18px; }
    .empire-control::before { font-size: 12px; }
    .empire-color-swatch { height: 38px; border-radius: 12px; }
    .leaflet-control-zoom a,
    .leaflet-bar a {
        width: 40px !important;
        height: 40px !important;
        line-height: 38px !important;
        font-size: 24px !important;
    }
}

/* ==============================
   V22 PRODUCT UI
============================== */

/* Full-width product header on the map. */
.account-bar {
    top: 14px;
    left: 16px;
    right: 16px;
    max-width: none;
    min-height: 66px;
    gap: 10px;
    padding: 8px 10px 8px 14px;
    border-radius: 20px !important;
    align-items: center;
}

.top-brand,
.top-user-chip,
.top-status-item {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
}

.top-brand {
    gap: 10px;
    padding-right: 16px;
    border-right: 1px solid #e4ebf3;
}

.top-brand-icon {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 10px;
    background: #fff8dd;
    color: #e2a100;
}

.top-brand-icon svg,
.top-status-icon svg,
.button-icon svg,
.metric-icon svg,
.coach-icon svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.top-brand-icon svg { width: 24px; height: 24px; }
.top-brand-name {
    color: #14213a;
    font-size: 18px;
    font-weight: 950;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.top-user-chip {
    gap: 8px;
    padding: 4px 10px 4px 4px;
    border-right: 1px solid #e4ebf3;
}

.top-user-avatar {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border: 4px solid #e6f0ff;
    border-radius: 50%;
    background: #3278ee;
    color: #fff;
    font-size: 13px;
    font-weight: 950;
}

.account-email {
    max-width: 190px;
    padding-right: 0;
    color: #223049;
    font-size: 12px;
    font-weight: 850;
}

.top-status-item {
    gap: 7px;
    min-height: 42px;
    padding: 5px 9px;
    border-right: 1px solid #e7edf4;
}

.top-status-icon {
    display: grid;
    width: 26px;
    height: 26px;
    place-items: center;
    flex: 0 0 26px;
    border-radius: 9px;
    background: #f3f7fb;
    color: #3e7ee8;
}

.top-status-icon svg {
    width: 17px;
    height: 17px;
}

.live-dot-icon {
    background: #e8faf0;
}
.live-dot-icon span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c77a;
    box-shadow: 0 0 0 5px rgba(34,199,122,0.12);
}

.top-status-item .cloud-sync-status,
.top-status-item .realtime-status,
.top-status-item .review-summary-status,
.top-status-item .stability-summary-status {
    min-height: auto;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #40516a;
    font-size: 11px;
    font-weight: 850;
}

.top-status-item .cloud-sync-status[data-state="synced"],
.top-status-item .realtime-status[data-state="live"],
.top-status-item .review-summary-status[data-state="stable"],
.top-status-item .stability-summary-status[data-state="stable"] {
    border: 0;
    background: transparent;
    color: #267e52;
}

.top-bar-spacer { flex: 1 1 auto; min-width: 8px; }
.top-action-button {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}
.button-icon {
    width: 17px;
    height: 17px;
    flex: 0 0 17px;
}

/* Keep Leaflet controls below the header. */
.leaflet-top.leaflet-left,
.leaflet-top.leaflet-right {
    top: 90px;
}

/* Empire chooser becomes a real side card. */
.empire-control {
    width: 310px;
    padding: 17px 18px 16px;
}
.empire-control-title {
    font-size: 20px;
    letter-spacing: -0.02em;
}
.empire-control::before {
    margin-top: 1px;
    margin-bottom: 14px;
    color: #6d7d91;
    font-size: 12px;
}
.empire-color-swatch { height: 40px; }
.empire-control-status {
    font-size: 12px;
}

/* Bottom progress card with icon-led metrics. */
.beta-stats-panel {
    width: 470px;
    padding: 16px 18px 14px;
}
.beta-stats-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.beta-stats-title {
    margin: 0;
    font-size: 15px;
}
.beta-stats-subtitle {
    margin-top: 2px;
    color: #8290a3;
    font-size: 10px;
}
.beta-stats-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
}
.beta-stats-grid > div {
    position: relative;
    display: grid;
    justify-items: start;
    gap: 2px;
    padding: 4px 12px;
    border-radius: 0;
    background: transparent;
    text-align: left;
}
.beta-stats-grid > div + div {
    border-left: 1px solid #e7edf4;
}
.metric-icon {
    display: grid !important;
    width: 28px;
    height: 28px;
    margin-bottom: 4px;
    place-items: center;
    border-radius: 9px;
}
.metric-icon svg { width: 17px; height: 17px; }
.metric-blue { color: #347bf1 !important; background: #edf4ff; }
.metric-violet { color: #7855de !important; background: #f4efff; }
.metric-cyan { color: #0d8fb1 !important; background: #e9f8fb; }
.metric-green { color: #199968 !important; background: #eaf8f2; }
.metric-anchor { color: #3774de !important; background: #edf4ff; }
.beta-stats-grid strong {
    font-size: 20px;
    line-height: 1.05;
}
.beta-stats-grid span:not(.metric-icon) {
    margin-top: 2px;
    color: #728198;
    font-size: 10px;
}

/* Shared hint card pattern. */
.coach-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}
.coach-icon {
    display: grid;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    place-items: center;
    border-radius: 50%;
    background: #fff7dd;
    color: #e8a400;
}
.coach-icon svg { width: 22px; height: 22px; }
.coach-copy {
    min-width: 0;
    flex: 1 1 auto;
}
.coach-copy strong,
.coach-copy span { display: block; }
.coach-copy strong {
    color: #1d2a40;
    font-size: 13px;
    font-weight: 900;
}
.coach-copy span {
    margin-top: 3px;
    color: #6d7d91;
    font-size: 11px;
    line-height: 1.45;
}
.coach-close {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #94a1b1;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
}
.coach-close:hover { background: #f3f6f9; color: #4a5a70; }

.first-territory-coach {
    left: auto;
    right: 18px;
    bottom: 18px;
    width: 350px;
    transform: none;
    padding: 14px;
}

/* Board tip is now a dismissible widget in the upper-right. */
#boardHint.board-coach {
    left: auto;
    right: 18px;
    top: 18px;
    bottom: auto;
    z-index: 5;
    width: 340px;
    max-width: calc(100% - 36px);
    padding: 14px;
    border: 1px solid #dce6f0;
    border-radius: 18px;
    background: rgba(255,255,255,0.96);
    box-shadow: var(--shadow-card);
    pointer-events: auto;
    backdrop-filter: blur(10px);
}

/* Whiteboard navigator / mini map. */
.board-navigator {
    position: absolute;
    left: 18px;
    bottom: 18px;
    z-index: 6;
    width: 270px;
    padding: 8px;
    border: 1px solid #d9e3ee;
    border-radius: 18px;
    background: rgba(255,255,255,0.96);
    box-shadow: var(--shadow-card);
    backdrop-filter: blur(10px);
}
.board-navigator canvas {
    display: block;
    width: 100%;
    height: 118px;
    border-radius: 12px;
    background: #f6f9fc;
    cursor: crosshair;
}
.board-navigator-controls {
    display: grid;
    grid-template-columns: 38px 1fr 38px 38px;
    gap: 7px;
    margin-top: 8px;
}
.board-navigator-controls button {
    min-height: 34px;
    border: 1px solid #dce5ee;
    border-radius: 10px;
    background: #fff;
    color: #34445a;
    cursor: pointer;
    font-size: 14px;
    font-weight: 850;
}
.board-navigator-controls button:hover { background: #f3f7fb; }

/* V22 lets the board use the extra bottom-left space occupied by the navigator. */
#workspaceStatus { bottom: 18px; }

/* Slightly stronger workspace hierarchy. */
.workspace-header {
    min-height: 72px;
    padding: 12px 16px;
}
.workspace-header-left { gap: 12px; }
.workspace-title-input {
    font-size: 19px;
    letter-spacing: -0.02em;
}
.workspace-header-right { gap: 9px; }
.edit-toolbar { min-height: 58px; }

@media (max-width: 1320px) {
    .top-brand-name { display: none; }
    .top-brand { padding-right: 10px; }
    .top-status-item { padding-inline: 6px; }
    .account-email { max-width: 130px; }
    .beta-stats-panel { width: 420px; }
}

@media (max-width: 1080px) {
    .top-user-chip { display: none; }
    .top-status-item:nth-of-type(5) { display: none; }
    .beta-stats-panel { width: 350px; }
    .beta-stats-grid > div { padding-inline: 8px; }
    .beta-stats-grid strong { font-size: 18px; }
}

@media (max-width: 820px) {
    .account-bar {
        left: 8px;
        right: 8px;
        min-height: 58px;
        padding: 6px 8px;
    }
    .top-status-item { display: none; }
    .top-bar-spacer { display: block; }
    .leaflet-top.leaflet-left,
    .leaflet-top.leaflet-right { top: 78px; }
    .beta-stats-panel { width: 300px; }
    .beta-stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 10px; }
    .beta-stats-grid > div + div { border-left: 0; }
    .first-territory-coach { width: min(340px, calc(100vw - 24px)); right: 12px; bottom: 12px; }
    .board-navigator { width: 230px; left: 10px; bottom: 10px; }
    #boardHint.board-coach { right: 10px; top: 10px; width: 300px; }
}

/* ==============================
   V24 VIEDZA MAP: MULTI-WORLD
============================== */

.world-mode-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 5px 10px;
    border: 1px solid #dce6f0;
    border-radius: 14px;
    background: #f8fbff;
    color: #33445a;
    cursor: pointer;
    transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}
.world-mode-button:hover {
    border-color: #b9d2ef;
    background: #eef6ff;
}
.world-mode-button:active { transform: translateY(1px); }
.world-mode-icon {
    display: grid;
    width: 28px;
    height: 28px;
    place-items: center;
    border-radius: 9px;
    background: #eef4ff;
    color: #3979e8;
    font-size: 17px;
    font-weight: 900;
}
.world-mode-button[data-mode="journey"] .world-mode-icon {
    background: #ecf9f4;
    color: #1d9b70;
}
.world-mode-copy {
    display: grid;
    gap: 0;
    text-align: left;
}
.world-mode-copy small {
    color: #8a98aa;
    font-size: 8px;
    font-weight: 850;
    letter-spacing: .05em;
    line-height: 1.05;
    text-transform: uppercase;
}
.world-mode-copy strong {
    color: #2a3a50;
    font-size: 11px;
    font-weight: 900;
    line-height: 1.2;
}
.world-mode-chevron { color: #8a98aa; font-size: 12px; }

.world-mode-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-top: 18px;
}
.world-mode-card {
    display: flex;
    align-items: flex-start;
    gap: 13px;
    min-width: 0;
    padding: 16px;
    border: 1px solid #dce5ef;
    border-radius: 18px;
    background: #fff;
    color: #25354b;
    cursor: pointer;
    text-align: left;
    transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}
.world-mode-card:hover {
    border-color: #b9cee7;
    background: #fbfdff;
    transform: translateY(-1px);
}
.world-mode-card.selected {
    border-color: #80b3f4;
    background: #f5f9ff;
    box-shadow: 0 0 0 3px rgba(61, 125, 232, 0.10);
}
.world-mode-card[data-world-mode-option="journey"].selected {
    border-color: #7bcfb0;
    background: #f4fcf8;
    box-shadow: 0 0 0 3px rgba(29, 155, 112, 0.09);
}
.world-mode-card-icon {
    display: grid;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    place-items: center;
    border-radius: 14px;
    font-size: 22px;
    font-weight: 900;
}
.world-mode-card-icon.empire { background: #edf3ff; color: #3e78df; }
.world-mode-card-icon.journey { background: #eaf9f3; color: #168f66; }
.world-mode-card-copy {
    display: grid;
    min-width: 0;
    gap: 5px;
}
.world-mode-card-copy strong {
    color: #19283d;
    font-size: 16px;
    font-weight: 950;
}
.world-mode-card-copy span {
    color: #5e6e84;
    font-size: 12px;
    line-height: 1.45;
}
.world-mode-card-copy em {
    color: #8996a7;
    font-size: 10px;
    font-style: normal;
    font-weight: 750;
    line-height: 1.35;
}
.onboarding-mode-grid { margin-top: 20px; }
.beta-limit-note {
    margin-top: 15px;
    padding: 11px 12px;
    border: 1px solid #dfe7f0;
    border-radius: 13px;
    background: #f8fafc;
    color: #627187;
    font-size: 11px;
    line-height: 1.45;
}
.beta-limit-note strong { color: #3b4b61; }

.world-mode-modal-card { width: min(690px, 100%); }
.world-mode-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}
.world-mode-modal-header h2 { margin: 0; }
.world-mode-modal-header p {
    margin: 6px 0 0;
    color: #68788d;
    font-size: 12px;
    line-height: 1.45;
}

.account-world-summary {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 9px;
    margin: -4px 0 8px;
    padding: 10px 12px;
    border: 1px solid #e0e7ef;
    border-radius: 12px;
    background: #f8fafc;
}
.account-world-summary span { color: #7c899b; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.account-world-summary strong { color: #27384e; font-size: 12px; }
.account-world-summary .auth-link-button { justify-self: end; }

/* Map-side card adapts to either mode. */
.empire-control-mode {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 7px;
    padding: 4px 8px;
    border: 1px solid #dce5ee;
    border-radius: 999px;
    background: #f5f8fc;
    color: #617086;
    font-size: 9px;
    font-weight: 900;
    letter-spacing: .05em;
    text-transform: uppercase;
}
.empire-control-mode[data-mode="journey"] {
    border-color: #cce9dd;
    background: #effaf5;
    color: #27815f;
}
.empire-control-subtitle {
    margin: 3px 0 13px;
    color: #6d7d91;
    font-size: 12px;
    line-height: 1.4;
}
.empire-control::before { display: none !important; }
.empire-control-legend [data-legend="locked"][hidden] { display: none !important; }

body.world-mode-journey .metric-anchor {
    color: #168f66 !important;
    background: #eaf9f3;
}

@media (max-width: 1200px) {
    .world-mode-copy small { display: none; }
    .world-mode-chevron { display: none; }
}

@media (max-width: 1080px) {
    .world-mode-button { padding-inline: 8px; }
    .world-mode-copy { display: none; }
}

@media (max-width: 820px) {
    .world-mode-button { min-height: 38px; }
    .world-mode-icon { width: 26px; height: 26px; }
    .world-mode-grid { grid-template-columns: 1fr; }
}

/* ==============================
   V24 MULTI-WORLD + DENSITY FIXES
============================== */

/* Top bar: reduce crowding without losing status clarity. */
.account-bar {
    gap: 6px;
    min-height: 58px;
    padding: 6px 8px 6px 10px;
}
.top-brand { gap: 8px; padding-right: 10px; }
.top-brand-icon { width: 30px; height: 30px; border-radius: 9px; }
.top-brand-icon svg { width: 21px; height: 21px; }
.top-brand-name { font-size: 16px; }
.top-user-chip { gap: 6px; padding: 3px 7px 3px 3px; }
.top-user-avatar { width: 30px; height: 30px; border-width: 3px; font-size: 11px; }
.account-email { max-width: 145px; font-size: 10px; }
.top-status-item { gap: 5px; min-height: 36px; padding: 4px 6px; }
.top-status-icon { width: 22px; height: 22px; flex-basis: 22px; border-radius: 7px; }
.top-status-icon svg { width: 14px; height: 14px; }
.top-status-item .cloud-sync-status,
.top-status-item .realtime-status,
.top-status-item .review-summary-status,
.top-status-item .stability-summary-status { font-size: 9px; }
.top-action-button,
.beta-review-button {
    min-height: 34px;
    padding: 6px 9px;
    border-radius: 11px;
    font-size: 10px;
}
.button-icon { width: 14px; height: 14px; flex-basis: 14px; }

.world-mode-button {
    min-width: 0;
    max-width: 190px;
    min-height: 36px;
    gap: 6px;
    padding: 4px 7px;
    border-radius: 11px;
}
.world-mode-icon { width: 24px; height: 24px; font-size: 14px; border-radius: 7px; }
.world-mode-copy { min-width: 0; }
.world-mode-copy small { font-size: 7px; }
.world-mode-copy strong {
    max-width: 120px;
    overflow: hidden;
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Bottom stats: keep labels inside the card on common laptop widths. */
.beta-stats-panel { width: 430px; padding: 14px 15px 12px; }
.beta-stats-grid > div { min-width: 0; padding: 4px 9px; }
.metric-icon { width: 25px; height: 25px; margin-bottom: 3px; border-radius: 8px; }
.metric-icon svg { width: 15px; height: 15px; }
.beta-stats-grid strong { font-size: 18px; }
.beta-stats-grid span:not(.metric-icon) {
    max-width: 100%;
    overflow-wrap: anywhere;
    font-size: 9px;
    line-height: 1.2;
}
.beta-stats-subtitle { font-size: 9px; }

/* Workspace can wrap its actions instead of clipping them. */
#knowledgeWorkspace { grid-template-rows: auto auto minmax(0, 1fr); }
.workspace-header {
    min-height: 60px;
    gap: 8px;
    padding: 8px 10px;
}
.workspace-header-left { min-width: 240px; gap: 8px; }
.workspace-header-right {
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}
.workspace-title-input { width: min(330px, 30vw); min-width: 150px; font-size: 16px; }
.workspace-header .button,
.workspace-region-color,
.review-status-badge {
    min-height: 32px;
    padding: 5px 8px;
    border-radius: 10px;
    font-size: 10px;
}
.edit-toolbar {
    min-height: 48px;
    gap: 6px;
    padding: 7px 9px;
    overflow-x: auto;
    overflow-y: hidden;
}
.color-target-button,
.toolbar-action { min-height: 31px; padding: 5px 8px; font-size: 10px; }
.line-width-control { font-size: 10px; }
.line-width-control input { width: 80px; }
.board-palette .color-swatch,
.color-swatch { width: 20px; height: 20px; flex-basis: 20px; }

/* World manager. */
.world-manager-card {
    width: min(760px, 100%);
    max-height: min(88vh, 820px);
    overflow: auto;
}
.world-list {
    display: grid;
    gap: 8px;
    margin-top: 18px;
}
.world-list-empty {
    padding: 14px;
    border: 1px dashed #cad6e3;
    border-radius: 14px;
    background: #f8fafc;
    color: #6a788b;
    font-size: 12px;
}
.world-list-item {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    align-items: center;
    gap: 11px;
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid #dce5ef;
    border-radius: 14px;
    background: #fff;
    color: #26374d;
    cursor: pointer;
    text-align: left;
}
.world-list-item:hover:not(:disabled) { border-color: #b9cee7; background: #fbfdff; }
.world-list-item.active,
.world-list-item:disabled {
    border-color: #a9c9ef;
    background: #f4f8fe;
    cursor: default;
    opacity: 1;
}
.world-list-icon {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border-radius: 11px;
    font-size: 18px;
    font-weight: 900;
}
.world-list-icon.empire { background: #edf3ff; color: #3e78df; }
.world-list-icon.journey { background: #eaf9f3; color: #168f66; }
.world-list-copy { min-width: 0; }
.world-list-copy strong,
.world-list-copy span { display: block; }
.world-list-copy strong {
    overflow: hidden;
    color: #1f2e42;
    font-size: 13px;
    font-weight: 900;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.world-list-copy span { margin-top: 2px; color: #78869a; font-size: 10px; }
.world-list-action { color: #4b78bd; font-size: 10px; font-weight: 850; }

.world-create-section {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid #e4ebf2;
}
.world-create-heading strong,
.world-create-heading span { display: block; }
.world-create-heading strong { color: #24354b; font-size: 13px; }
.world-create-heading span { margin-top: 2px; color: #7a8798; font-size: 10px; }
.world-name-field {
    display: grid;
    gap: 5px;
    margin-top: 13px;
    color: #667589;
    font-size: 10px;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.world-name-field input {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid #ced9e5;
    border-radius: 11px;
    outline: none;
    background: #fff;
    color: #23334a;
    font-size: 13px;
    font-weight: 700;
    text-transform: none;
    letter-spacing: normal;
}
.world-name-field input:focus {
    border-color: #75a9ec;
    box-shadow: 0 0 0 3px rgba(61,125,232,.10);
}
.world-create-mode-grid { margin-top: 12px; }
.world-create-mode-grid .world-mode-card { padding: 12px; }
.world-create-mode-grid .world-mode-card-copy strong { font-size: 14px; }
.world-create-mode-grid .world-mode-card-copy span { font-size: 11px; }
.world-mode-card[data-create-world-mode="journey"].selected {
    border-color: #7bcfb0;
    background: #f4fcf8;
    box-shadow: 0 0 0 3px rgba(29,155,112,.09);
}
.world-create-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.account-world-summary-v24 {
    grid-template-columns: auto minmax(0,1fr) auto auto auto;
}
.account-world-summary-v24 strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.account-world-mode-label { margin-left: 6px; }

@media (max-width: 1500px) {
    .top-brand-name { display: none; }
    .account-email { max-width: 105px; }
    .status-live { display: none; }
    .world-mode-button { max-width: 160px; }
    .world-mode-copy strong { max-width: 95px; }
}

@media (max-width: 1280px) {
    .top-user-chip { display: none; }
    .status-cloud { display: none; }
    .beta-stats-panel { width: 380px; }
    .workspace-header-left { min-width: 200px; }
    .workspace-title-input { width: 240px; }
}

@media (max-width: 1040px) {
    .status-review { display: none; }
    .top-action-button { padding-inline: 7px; }
    .top-action-button .button-icon { display: none; }
    .beta-stats-panel { width: 330px; }
    .beta-stats-grid > div { padding-inline: 6px; }
    .beta-stats-grid strong { font-size: 16px; }
    .workspace-header-right .workspace-region-color { display: none; }
}

@media (max-width: 820px) {
    .status-stability { display: none; }
    .world-mode-copy { display: grid; }
    .world-mode-button { max-width: 130px; }
    .world-mode-copy strong { max-width: 74px; }
    .world-mode-copy small { display: block; }
    .world-mode-grid { grid-template-columns: 1fr; }
    .account-world-summary-v24 { grid-template-columns: auto minmax(0,1fr) auto; }
    .account-world-mode-label,
    .account-world-summary-v24 #accountWorldModeValue { display: none; }
}

/* Final overflow guards for user-created names and compact widgets. */
.empire-control-title,
.beta-stats-title,
.coach-copy strong,
.coach-copy span,
.world-mode-modal-header p,
.account-world-summary {
    overflow-wrap: anywhere;
}
.empire-control { max-width: calc(100vw - 28px); }
.first-territory-coach { max-width: calc(100vw - 28px); }
.board-coach { max-width: calc(100% - 28px) !important; }

/* ==============================
   V24.2 WORLD DELETION
============================== */
.world-list-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 38px;
    align-items: stretch;
    gap: 7px;
}

.world-list-row .world-list-item {
    min-width: 0;
}

.world-delete-button {
    display: grid;
    width: 38px;
    min-width: 38px;
    place-items: center;
    border: 1px solid #efd1d3;
    border-radius: 12px;
    background: #fffafa;
    color: #c43c43;
    cursor: pointer;
    font-size: 14px;
    transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.world-delete-button:hover {
    border-color: #e7aeb2;
    background: #fff1f2;
}

.world-delete-button:active { transform: translateY(1px); }
.world-delete-button:focus-visible {
    outline: 3px solid rgba(220, 38, 38, .16);
    outline-offset: 2px;
}

.delete-world-card {
    width: min(460px, 100%);
    text-align: left;
}

.delete-world-card h2 {
    margin: 3px 0 8px;
}

.delete-world-card > p {
    margin: 0;
    color: #66758a;
    font-size: 12px;
    line-height: 1.55;
}

.delete-world-icon {
    display: grid;
    width: 44px;
    height: 44px;
    margin-bottom: 12px;
    place-items: center;
    border: 1px solid #f1c8cb;
    border-radius: 14px;
    background: #fff3f4;
    font-size: 20px;
}

.delete-world-name {
    margin-top: 14px;
    padding: 10px 12px;
    overflow: hidden;
    border: 1px solid #e3e9f0;
    border-radius: 12px;
    background: #f8fafc;
    color: #26364b;
    font-size: 12px;
    font-weight: 900;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.delete-world-confirm {
    border-color: #d83b42;
    background: #dc3f46;
    color: #fff;
}

.delete-world-confirm:hover { background: #c9343a; }

@media (max-width: 560px) {
    .world-list-row { grid-template-columns: minmax(0, 1fr) 36px; gap: 5px; }
    .world-delete-button { width: 36px; min-width: 36px; }
}


/* ==============================
   V25 ONBOARDING + WORLD MANAGER POLISH
============================== */
.onboarding-card {
    width: min(760px, 100%);
}
.onboarding-lead {
    max-width: 680px;
    color: #53647a;
    line-height: 1.55;
}
.onboarding-use-cases {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin: 12px 0 16px;
}
.onboarding-use-cases span {
    padding: 6px 9px;
    border: 1px solid #dbe5ef;
    border-radius: 999px;
    background: #f7f9fc;
    color: #526277;
    font-size: 10px;
    font-weight: 800;
}
.world-mode-intro {
    display: grid;
    gap: 3px;
    margin: 15px 0 9px;
}
.world-mode-intro strong {
    color: #26384e;
    font-size: 12px;
}
.world-mode-intro span {
    color: #718095;
    font-size: 10px;
    line-height: 1.4;
}
.onboarding-mode-grid .world-mode-card,
.world-create-mode-grid .world-mode-card {
    min-width: 0;
}
.onboarding-mode-grid .world-mode-card-copy span,
.world-create-mode-grid .world-mode-card-copy span {
    line-height: 1.35;
}
.world-list-item.active {
    cursor: pointer;
}
.world-list-item.active:hover {
    border-color: #b9cee7;
    background: #f7fbff;
}
@media (max-width: 760px) {
    .onboarding-card { width: min(620px, 100%); }
    .onboarding-use-cases { gap: 5px; }
    .onboarding-use-cases span { padding: 5px 7px; font-size: 9px; }
}

/* ==============================
   V26 RICH WHITEBOARD + AUTH LANDING
============================== */
#knowledgeWorkspace {
    grid-template-rows: var(--header-height) auto minmax(0, 1fr);
}

.toolbar-stack {
    min-width: 0;
    background: rgba(249,251,253,.98);
    border-bottom: 1px solid #e2e8f0;
}

.toolbar-stack .edit-toolbar {
    border-bottom: 0;
}

.text-format-toolbar {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 46px;
    padding: 6px 14px 10px;
    overflow-x: auto;
    background: rgba(249,251,253,.98);
    border-top: 1px solid #edf2f7;
    scrollbar-width: thin;
}

.text-format-toolbar[hidden] { display: none !important; }

.text-format-group {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex: 0 0 auto;
    padding-right: 9px;
    border-right: 1px solid #dbe4ee;
}

.text-format-group:last-child { border-right: 0; }
.text-format-group > label {
    color: #617086;
    font-size: 11px;
    font-weight: 850;
}

.text-font-group select,
.text-font-group input[type="number"] {
    min-height: 32px;
    border: 1px solid #d6e0eb;
    border-radius: 9px;
    background: #fff;
    color: #223049;
    font-size: 12px;
    font-weight: 750;
    outline: none;
}

.text-font-group select { width: 132px; padding: 5px 8px; }
.text-font-group input[type="number"] { width: 58px; padding: 5px 7px; }

.text-format-button {
    min-width: 32px;
    min-height: 32px;
    padding: 4px 8px;
    border: 1px solid #d6e0eb;
    border-radius: 9px;
    background: #fff;
    color: #334155;
    cursor: pointer;
    font-size: 13px;
    font-weight: 800;
}

.text-format-button:hover { background: #f2f6fb; border-color: #bdcad8; }
.text-format-button.active { border-color: #8bbcff; background: #eaf3ff; color: #1768c9; }
.text-format-button:disabled { opacity: .4; cursor: not-allowed; }
.text-format-wide { min-width: 88px; }
.underline-glyph { text-decoration: underline; text-underline-offset: 2px; }

.text-color-tools { gap: 8px; }
.text-color-control {
    display: inline-flex !important;
    align-items: center;
    gap: 5px;
}
.text-color-control input[type="color"] {
    width: 30px;
    height: 30px;
    padding: 2px;
    border: 1px solid #d6e0eb;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
}

#copyBoardSelection:disabled,
#pasteBoardClipboard:disabled { opacity: .38; }

.tool-rail {
    overflow-y: auto;
    scrollbar-width: thin;
}

.review-questions-card {
    width: min(960px, calc(100vw - 32px));
    max-height: min(94vh, 920px);
    padding: 22px 24px;
}

.review-question-form {
    grid-template-columns: minmax(0, 1fr) 180px;
    column-gap: 14px;
    row-gap: 10px;
    padding: 14px 16px 12px;
}

.review-question-form-header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}
.review-question-form-header h3 { margin: 0; }
.review-question-save-top { min-width: 142px; }
.review-question-options-heading,
.review-question-options,
#reviewQuestionMessage,
.review-question-secondary-actions { grid-column: 1 / -1; }
.review-question-secondary-actions { margin-top: 0; }

.review-question-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.review-question-option-row { min-width: 0; }

.auth-gate {
    padding: 28px;
    overflow-x: hidden;
    overflow-y: auto;
    background:
        radial-gradient(circle at 15% 12%, rgba(48,130,246,.22), transparent 32%),
        radial-gradient(circle at 85% 78%, rgba(20,184,166,.17), transparent 34%),
        linear-gradient(135deg, #0f172a 0%, #16263f 52%, #0d2235 100%);
}

.auth-shell {
    width: min(1180px, 100%);
    margin: auto;
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(360px, .72fr);
    gap: 24px;
    align-items: stretch;
}

.auth-story {
    min-width: 0;
    display: grid;
    align-content: start;
    gap: 18px;
    padding: 30px;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 28px;
    background: rgba(255,255,255,.08);
    box-shadow: 0 30px 90px rgba(0,0,0,.22);
    backdrop-filter: blur(12px);
    color: #fff;
}

.auth-story-kicker {
    margin-bottom: 7px;
    color: #93c5fd;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .09em;
    text-transform: uppercase;
}
.auth-story h2 {
    max-width: 700px;
    margin: 0;
    font-size: clamp(28px, 3vw, 48px);
    line-height: 1.04;
    letter-spacing: -.035em;
}
.auth-story p {
    max-width: 720px;
    margin: 12px 0 0;
    color: #c6d3e2;
    font-size: 15px;
    line-height: 1.6;
}
.auth-story-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 14px;
}
.auth-story-tags span {
    padding: 6px 9px;
    border: 1px solid rgba(255,255,255,.15);
    border-radius: 999px;
    background: rgba(255,255,255,.07);
    color: #e6edf7;
    font-size: 11px;
    font-weight: 750;
}

.auth-product-preview {
    min-width: 0;
    padding: 8px;
    border: 1px solid rgba(255,255,255,.13);
    border-radius: 22px;
    background: rgba(255,255,255,.06);
}
.auth-product-preview video,
.auth-product-preview img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 16px;
}
.auth-product-preview .auth-product-preview-fallback {
    display: none;
}
@media (prefers-reduced-motion: reduce) {
    .auth-product-preview video { display: none; }
    .auth-product-preview .auth-product-preview-fallback { display: block; }
}

.auth-story-modes {
    display: grid;
    grid-template-columns: repeat(2, minmax(0,1fr));
    gap: 10px;
}
.auth-story-modes > div {
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid rgba(255,255,255,.11);
    border-radius: 15px;
    background: rgba(255,255,255,.055);
}
.auth-story-modes strong,
.auth-story-modes span { display: block; }
.auth-story-modes strong { color: #fff; font-size: 13px; }
.auth-story-modes span { margin-top: 4px; color: #b8c7d8; font-size: 11px; line-height: 1.45; }

.auth-shell .auth-card {
    width: 100%;
    align-self: center;
    padding: 30px;
}

@media (max-width: 980px) {
    .auth-shell { grid-template-columns: 1fr; max-width: 720px; }
    .auth-story { padding: 24px; }
    .auth-shell .auth-card { max-width: 520px; justify-self: center; }
    .review-question-options { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .auth-gate { padding: 14px; }
    .auth-story { padding: 18px; border-radius: 20px; }
    .auth-story h2 { font-size: 28px; }
    .auth-story-modes { grid-template-columns: 1fr; }
    .auth-shell .auth-card { padding: 22px; border-radius: 20px !important; }
    .review-questions-card { padding: 16px; max-height: 96vh; }
    .review-question-form { grid-template-columns: 1fr; padding: 12px; }
    .review-question-form > * { grid-column: 1 !important; }
    .review-question-form-header { align-items: flex-start; }
    .review-question-save-top { min-width: 120px; }
    .text-format-toolbar { padding-inline: 10px; }
}

/* Keep the question editor and its primary action visible without scrolling the whole dialog. */
.review-questions-list {
    max-height: 170px;
    overflow-y: auto;
    padding-right: 3px;
}

/* ==============================
   V27 MAP NAVIGATION + MOVABLE TEXT TOOLS
============================== */

/* Text formatting now floats above the board and can be moved by the user. */
.text-format-toolbar {
    position: fixed;
    z-index: 10040;
    left: 120px;
    top: 132px;
    width: max-content;
    max-width: calc(100vw - 24px);
    min-height: 48px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    overflow: visible;
    border: 1px solid #d5e0eb;
    border-radius: 16px;
    background: rgba(255,255,255,.97);
    box-shadow: 0 14px 36px rgba(15,23,42,.18);
    backdrop-filter: blur(10px);
}
.text-format-toolbar.dragging {
    user-select: none;
    box-shadow: 0 18px 46px rgba(15,23,42,.24);
}
.text-format-drag-handle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 5px 8px 5px 5px;
    border-right: 1px solid #dbe4ee;
    color: #526277;
    cursor: grab;
    touch-action: none;
    font-size: 11px;
    white-space: nowrap;
}
.text-format-drag-handle:active { cursor: grabbing; }
.text-format-drag-icon {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 7px;
    background: #eef4fa;
    color: #748397;
    font-size: 14px;
    letter-spacing: -2px;
}
.text-format-drag-handle strong { font-size: 11px; }

/* Map-side color panel: minimizable, labelable and clearer about naval progression. */
.empire-control {
    transition: width 160ms ease, padding 160ms ease;
}
.empire-control-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}
.empire-control-head-copy { min-width: 0; }
.empire-control-toggle {
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid #d7e1ec;
    border-radius: 10px;
    background: #f7fafc;
    color: #506176;
    cursor: pointer;
    font-size: 18px;
    font-weight: 700;
}
.empire-control-toggle:hover { background: #eef4fa; }
.empire-control-body[hidden],
.empire-control-collapsed-summary[hidden] { display: none !important; }
.empire-control.collapsed {
    width: 210px !important;
    padding: 11px 12px !important;
}
.empire-control.collapsed .empire-control-mode { margin-bottom: 4px; }
.empire-control.collapsed .empire-control-title {
    max-width: 125px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
}
.empire-control-collapsed-summary {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-top: 8px;
    color: #526277;
    font-size: 11px;
    font-weight: 800;
}
.empire-color-label-preview {
    display: inline-block;
    flex: 0 0 15px;
    width: 15px;
    height: 15px;
    border: 2px solid #fff;
    border-radius: 5px;
    outline: 1px solid #aebcca;
}
.empire-color-label-editor {
    display: grid;
    grid-template-columns: 18px minmax(0,1fr) auto;
    align-items: end;
    gap: 7px;
    margin-top: 12px;
    padding: 9px;
    border: 1px solid #e1e8f0;
    border-radius: 12px;
    background: #f8fafc;
}
.empire-color-label-editor label { min-width: 0; }
.empire-color-label-editor small {
    display: block;
    margin-bottom: 3px;
    color: #7a889a;
    font-size: 8px;
    font-weight: 900;
    letter-spacing: .05em;
    text-transform: uppercase;
}
.empire-color-label-input {
    width: 100%;
    min-width: 0;
    height: 29px;
    padding: 5px 7px;
    border: 1px solid #d3dde8;
    border-radius: 8px;
    background: #fff;
    color: #25354a;
    font-size: 10px;
    font-weight: 750;
    outline: none;
}
.empire-color-label-input:focus { border-color: #86b8fa; box-shadow: 0 0 0 2px rgba(29,117,240,.1); }
.empire-color-label-save {
    height: 29px;
    padding: 0 8px;
    border: 1px solid #c8d8eb;
    border-radius: 8px;
    background: #fff;
    color: #2768b5;
    cursor: pointer;
    font-size: 9px;
    font-weight: 900;
}
.empire-color-label-save:hover { background: #eef6ff; }

.empire-coastal-progress {
    margin-top: 11px;
    padding: 9px 10px;
    border: 1px solid #dce7f1;
    border-radius: 11px;
    background: #f8fbfe;
}
.empire-coastal-progress[hidden] { display: none !important; }
.empire-coastal-progress-row {
    display: grid;
    gap: 2px;
}
.empire-coastal-count { color: #26384e; font-size: 10px; }
.empire-coastal-hint { color: #718096; font-size: 8px; line-height: 1.3; }
.empire-coastal-progress-track {
    height: 5px;
    margin-top: 7px;
    overflow: hidden;
    border-radius: 999px;
    background: #dce6f0;
}
.empire-coastal-progress-fill {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: #1688ca;
    transition: width 180ms ease;
}

.beta-coastal-progress {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 9px;
    padding: 8px 10px;
    border-top: 1px solid #e5ebf2;
    color: #536479;
}
.beta-coastal-progress[hidden] { display: none !important; }
.beta-coastal-dot {
    display: grid;
    place-items: center;
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    border-radius: 9px;
    background: #eaf6fd;
    color: #0f7fb9;
    font-size: 14px;
}
.beta-coastal-progress > span:last-child { min-width: 0; }
.beta-coastal-progress strong,
.beta-coastal-progress small { display: block; }
.beta-coastal-progress strong { font-size: 10px; color: #34465d; }
.beta-coastal-progress small { margin-top: 2px; color: #7a899b; font-size: 8px; line-height: 1.3; }

/* Hover / click map index for fast topic navigation. */
.territory-drawer {
    position: fixed;
    z-index: 1260;
    right: 0;
    top: 50%;
    width: min(390px, calc(100vw - 8px));
    max-height: min(68vh, 700px);
    display: grid;
    grid-template-columns: 44px minmax(0,1fr);
    transform: translateY(-50%) translateX(calc(100% - 44px));
    transition: transform 180ms ease;
    pointer-events: auto;
}
.territory-drawer:hover,
.territory-drawer:focus-within,
.territory-drawer.open {
    transform: translateY(-50%) translateX(0);
}
.territory-drawer-handle {
    align-self: center;
    min-height: 182px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 4px;
    border: 1px solid rgba(199,211,224,.95);
    border-right: 0;
    border-radius: 15px 0 0 15px;
    background: rgba(255,255,255,.97);
    box-shadow: -6px 10px 24px rgba(15,23,42,.11);
    color: #41536a;
    cursor: pointer;
}
.territory-drawer-handle-icon { font-size: 17px; }
.territory-drawer-handle-label {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-size: 9px;
    font-weight: 900;
    letter-spacing: .05em;
    text-transform: uppercase;
}
.territory-drawer-handle-count {
    min-width: 22px;
    padding: 3px 5px;
    border-radius: 999px;
    background: #eaf3ff;
    color: #1768c9;
    font-size: 9px;
    font-weight: 900;
}
.territory-drawer-panel {
    min-width: 0;
    max-height: min(68vh, 700px);
    display: flex;
    flex-direction: column;
    padding: 13px;
    border: 1px solid rgba(199,211,224,.95);
    border-right: 0;
    border-radius: 16px 0 0 16px;
    background: rgba(255,255,255,.98);
    box-shadow: -12px 14px 34px rgba(15,23,42,.14);
    backdrop-filter: blur(10px);
}
.territory-drawer-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}
.territory-drawer-eyebrow {
    display: block;
    color: #8390a2;
    font-size: 8px;
    font-weight: 900;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.territory-drawer-title {
    display: block;
    margin-top: 2px;
    color: #24354b;
    font-size: 15px;
}
.territory-drawer-close {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #718096;
    cursor: pointer;
    font-size: 20px;
}
.territory-drawer-close:hover { background: #f0f4f8; }
.territory-drawer-search {
    width: 100%;
    height: 34px;
    margin-top: 10px;
    padding: 6px 9px;
    border: 1px solid #d7e0ea;
    border-radius: 10px;
    background: #f9fbfd;
    color: #26384e;
    font-size: 11px;
    outline: none;
}
.territory-drawer-search:focus { border-color: #91bdf4; background: #fff; }
.territory-drawer-list {
    min-height: 0;
    display: grid;
    gap: 6px;
    margin-top: 9px;
    overflow-y: auto;
    padding-right: 2px;
}
.territory-drawer-item {
    min-width: 0;
    display: grid;
    grid-template-columns: 13px minmax(0,1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border: 1px solid transparent;
    border-radius: 11px;
    background: #f8fafc;
    cursor: pointer;
    outline: none;
}
.territory-drawer-item:hover,
.territory-drawer-item:focus {
    border-color: #bdd4ef;
    background: #eef6ff;
}
.territory-drawer-dot {
    width: 11px;
    height: 11px;
    border: 2px solid #fff;
    border-radius: 4px;
    outline: 1px solid #acb9c7;
}
.territory-drawer-item-copy { min-width: 0; }
.territory-drawer-item-copy strong,
.territory-drawer-item-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.territory-drawer-item-copy strong { color: #2b3e55; font-size: 11px; }
.territory-drawer-item-copy small { margin-top: 2px; color: #7a899b; font-size: 8px; }
.territory-drawer-open {
    min-height: 27px;
    padding: 4px 7px;
    border: 1px solid #c9d9eb;
    border-radius: 8px;
    background: #fff;
    color: #2768b5;
    cursor: pointer;
    font-size: 8px;
    font-weight: 900;
}
.territory-drawer-open:hover { background: #eaf4ff; }
.territory-drawer-empty {
    padding: 18px 10px;
    color: #8190a2;
    font-size: 10px;
    text-align: center;
}

@media (max-width: 760px) {
    .text-format-toolbar {
        max-width: calc(100vw - 16px);
        gap: 6px;
        padding: 7px;
    }
    .text-format-drag-handle strong { display: none; }
    .territory-drawer { width: min(330px, calc(100vw - 4px)); }
    .territory-drawer-panel { padding: 10px; }
    .empire-control.collapsed { width: 178px !important; }
}

/* ==============================
   V28 CLOSED BETA + UX POLISH
============================== */

/* Registration legal/invite controls. */
.auth-terms-row {
    display: flex;
    grid-template-columns: none !important;
    align-items: flex-start;
    gap: 9px !important;
    color: #66768b !important;
    font-size: 11px !important;
    font-weight: 650 !important;
    line-height: 1.45;
}
.auth-terms-row[hidden],
.auth-form label[hidden] { display: none !important; }

/* Let tall auth content scroll from its actual top edge on short screens. */
.auth-gate.open { display: block; }
.auth-terms-row input {
    width: 16px !important;
    min-height: 16px !important;
    height: 16px;
    flex: 0 0 16px;
    margin: 2px 0 0;
    padding: 0 !important;
    box-shadow: none !important;
}
.inline-legal-link {
    padding: 0;
    border: 0;
    background: transparent;
    color: #286fc7;
    cursor: pointer;
    font: inherit;
    font-weight: 850;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.auth-legal-links {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 5px;
    color: #96a2b2;
    font-size: 10px;
}
.auth-legal-links .auth-link-button { font-size: 10px; }

/* Email/account dropdown frees space in the map header. */
.top-user-menu-wrap {
    position: relative;
    flex: 0 0 auto;
}
.top-user-menu-button {
    min-height: 38px;
    border: 0;
    border-right: 1px solid #e4ebf3;
    background: transparent;
    color: inherit;
    cursor: pointer;
}
.top-user-menu-button:hover { background: #f6f9fc; }
.top-user-menu-button:focus-visible { outline: 2px solid #82b4f5; outline-offset: 2px; }
.top-user-menu-chevron {
    color: #8695a8;
    font-size: 12px;
    transition: transform 120ms ease;
}
.top-user-menu-button[aria-expanded="true"] .top-user-menu-chevron { transform: rotate(180deg); }
.account-menu {
    position: absolute;
    z-index: 52000;
    top: calc(100% + 9px);
    left: 0;
    width: 205px;
    padding: 7px;
    border: 1px solid #d9e3ed;
    border-radius: 14px;
    background: rgba(255,255,255,.99);
    box-shadow: 0 16px 40px rgba(15,23,42,.18);
}
.account-menu[hidden] { display: none !important; }
.account-menu button {
    width: 100%;
    min-height: 36px;
    padding: 8px 10px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: #35465d;
    cursor: pointer;
    font-size: 11px;
    font-weight: 800;
    text-align: left;
}
.account-menu button:hover { background: #f2f6fa; }
.account-menu-divider { height: 1px; margin: 5px 4px; background: #e5ebf2; }
.account-menu .account-menu-danger { color: #bd3038; }
.account-menu .account-menu-danger:hover { background: #fff1f2; }

/* Legal documents are readable but deliberately lightweight for beta. */
.legal-card {
    width: min(700px, 100%);
    max-height: min(88vh, 820px);
    display: flex;
    flex-direction: column;
}
.legal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}
.legal-header h2 { margin: 0; }
.legal-scroll {
    min-height: 0;
    margin-top: 12px;
    padding-right: 8px;
    overflow-y: auto;
    color: #53647a;
    font-size: 12px;
    line-height: 1.62;
}
.legal-scroll h3 {
    margin: 18px 0 4px;
    color: #26384e;
    font-size: 13px;
}
.legal-scroll p { margin: 7px 0; }
.legal-note {
    margin-top: 20px !important;
    padding: 11px 12px;
    border: 1px solid #e0e7ef;
    border-radius: 11px;
    background: #f8fafc;
    color: #718096;
    font-size: 10px;
}

/* Bottom-left stats panel can be tucked away; coastal progress stays in the color card. */
.beta-stats-toggle {
    width: 30px;
    height: 30px;
    display: grid;
    flex: 0 0 30px;
    place-items: center;
    padding: 0;
    border: 1px solid #d7e1ec;
    border-radius: 10px;
    background: #f7fafc;
    color: #506176;
    cursor: pointer;
    font-size: 18px;
    font-weight: 800;
}
.beta-stats-toggle:hover { background: #eef4fa; }
.beta-stats-body { display: block; }
.beta-stats-panel.collapsed {
    width: 230px !important;
    padding: 10px 11px !important;
}
.beta-stats-panel.collapsed .beta-stats-heading { margin-bottom: 0; }
.beta-stats-panel.collapsed .beta-stats-subtitle,
.beta-stats-panel.collapsed .beta-stats-body { display: none; }
.beta-stats-panel.collapsed .beta-stats-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Keep the map index lower than the color/expansion panel. */
.territory-drawer {
    top: auto !important;
    bottom: 82px;
    max-height: min(52vh, 560px);
    transform: translateX(calc(100% - 44px));
}
.territory-drawer:hover,
.territory-drawer:focus-within,
.territory-drawer.open {
    transform: translateX(0);
}
.territory-drawer-panel { max-height: min(52vh, 560px); }

/* Slightly denser board creation rail leaves more room for the canvas. */
.board-layout { grid-template-columns: 74px minmax(0, 1fr); }
.tool-rail { gap: 6px; padding: 8px 7px; }
.rail-tool {
    min-height: 58px;
    gap: 3px;
    padding: 5px 3px;
    border-radius: 13px;
    font-size: 10px;
}
.rail-icon { font-size: 21px; }

/* Hint users that intermediate arrow handles are removable. */
.arrow-help { max-width: 500px; }

@media (max-width: 1080px) {
    .top-user-menu-wrap .top-user-chip { display: inline-flex; }
    .account-email { max-width: 105px; }
}

@media (max-width: 760px) {
    .account-menu { left: -4px; width: 190px; }
    .beta-stats-panel.collapsed { width: 185px !important; }
    .territory-drawer { bottom: 60px; }
    .board-layout { grid-template-columns: 64px minmax(0, 1fr); }
    .rail-tool { min-height: 52px; font-size: 9px; }
    .rail-icon { font-size: 19px; }
}
