:root {
    --page-bg: #2e2015;
    --page-bg-deep: #1f140d;
    --page-glow: rgba(120, 75, 35, 0.22);
    --panel: #efe1bf;
    --panel-strong: #f5ead0;
    --panel-edge: #b18b5d;
    --panel-edge-strong: #8f6844;
    --ink: #322015;
    --ink-soft: rgba(50, 32, 21, 0.76);
    --ink-faint: rgba(50, 32, 21, 0.54);
    --accent: #7f1d1d;
    --accent-strong: #5d130f;
    --gold: #c48d2e;
    --gold-soft: #e5c98d;
    --neutral-map: #c9b383;
    --map-stroke: #6d5036;
    --success: #295f38;
    --error: #8f2f24;
    --shadow: 0 16px 36px rgba(20, 10, 4, 0.2);
    --radius-xl: 26px;
    --radius-lg: 20px;
    --radius-md: 16px;
    --radius-pill: 999px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    font-family: "Cormorant Garamond", serif;
    background:
        radial-gradient(circle at top left, var(--page-glow), transparent 26%),
        radial-gradient(circle at 85% 14%, rgba(196, 141, 46, 0.12), transparent 20%),
        linear-gradient(180deg, rgba(31, 20, 13, 0.96), rgba(46, 32, 21, 1));
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0.08;
    background-image:
        linear-gradient(transparent 0, rgba(255, 255, 255, 0.18) 50%, transparent 100%),
        radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.2), transparent 35%),
        radial-gradient(circle at 80% 80%, rgba(0, 0, 0, 0.22), transparent 40%);
    mix-blend-mode: soft-light;
}

button,
input {
    font: inherit;
}

code {
    padding: 0.12rem 0.38rem;
    border-radius: 0.4rem;
    background: rgba(50, 32, 21, 0.1);
    font-size: 0.94em;
}

.page-shell {
    width: min(100%, 1640px);
    margin: 0 auto;
    padding: 1.2rem;
}

.panel {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-xl);
    border: 2px solid var(--panel-edge);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 22%),
        linear-gradient(180deg, var(--panel-strong), var(--panel));
    box-shadow: var(--shadow);
}

.panel::before {
    content: "";
    position: absolute;
    inset: 10px;
    border-radius: calc(var(--radius-xl) - 8px);
    border: 1px solid rgba(120, 74, 42, 0.12);
    pointer-events: none;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.2rem;
    margin-bottom: 1.2rem;
}

.brand-block,
.session-bar {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.brand-crest {
    width: 60px;
    height: 60px;
    flex: 0 0 60px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 18px;
    border: 2px solid var(--panel-edge-strong);
    background:
        linear-gradient(135deg, #8d2d23, #5e1812);
    color: #f6e6bf;
    font-family: "Cinzel", serif;
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.eyebrow {
    margin: 0 0 0.24rem;
    color: var(--accent);
    font-family: "Cinzel", serif;
    font-size: 0.75rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.topbar h1,
.section-head h2,
.login-card h2 {
    margin: 0;
    font-family: "Cinzel", serif;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.05;
}

.topbar h1 {
    font-size: clamp(1.8rem, 3vw, 2.8rem);
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 1rem;
}

.section-head.compact {
    align-items: center;
    margin-bottom: 0.8rem;
}

.section-head h2 {
    font-size: clamp(1.55rem, 2.2vw, 2.25rem);
}

.section-note,
.question-status,
.login-copy,
.rules-list,
.stat-meta {
    color: var(--ink-soft);
}

.session-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 46px;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-pill);
    border: 1px solid rgba(122, 84, 53, 0.25);
    background: rgba(255, 248, 230, 0.72);
}

.session-color {
    width: 13px;
    height: 13px;
    border-radius: 999px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    background: var(--gold);
}

.session-color.neutral {
    background: #b7ac95;
}

.ghost-button,
.primary-button,
.option-button {
    appearance: none;
    border: 0;
    cursor: pointer;
    transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.ghost-button,
.primary-button {
    min-height: 46px;
    padding: 0.82rem 1.1rem;
    border-radius: var(--radius-pill);
    font-family: "Cinzel", serif;
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.ghost-button {
    color: var(--ink);
    border: 1px solid rgba(122, 84, 53, 0.26);
    background: rgba(255, 248, 230, 0.68);
}

.primary-button {
    color: #fff8ee;
    background: linear-gradient(180deg, #8d2d23, #6b1e18);
    box-shadow: 0 10px 18px rgba(107, 30, 24, 0.18);
}

.ghost-button:hover,
.ghost-button:focus-visible,
.primary-button:hover,
.primary-button:focus-visible,
.option-button:hover,
.option-button:focus-visible,
.close-button:hover,
.close-button:focus-visible {
    transform: translateY(-1px);
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.38fr) minmax(320px, 0.82fr);
    gap: 1.2rem;
    align-items: start;
}

.map-panel,
.sidebar {
    min-width: 0;
}

.map-panel {
    padding: 1.2rem;
}

.sidebar {
    display: grid;
    gap: 1.2rem;
}

.question-panel,
.leaderboard-panel,
.info-panel {
    padding: 1.15rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.stat-card {
    padding: 0.95rem;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(122, 84, 53, 0.22);
    background: rgba(255, 249, 236, 0.68);
}

.stat-label {
    display: block;
    color: var(--ink-faint);
    font-size: 0.86rem;
    margin-bottom: 0.45rem;
}

.stat-value {
    display: block;
    font-size: clamp(1.75rem, 2.2vw, 2.4rem);
    line-height: 1;
    margin-bottom: 0.2rem;
    font-family: "Cinzel", serif;
}

.stat-value-small {
    font-size: clamp(1.15rem, 1.9vw, 1.55rem);
}

.map-shell {
    position: relative;
    min-height: 660px;
    padding: 0.75rem;
    border-radius: var(--radius-lg);
    border: 2px solid rgba(111, 77, 48, 0.34);
    background:
        linear-gradient(180deg, rgba(248, 236, 205, 0.52), rgba(227, 203, 160, 0.52)),
        #d8bc8d;
}

.map-glow {
    display: none;
}

.district-map {
    width: 100%;
    height: auto;
    min-height: 620px;
    display: block;
}

.district {
    --district-fill: var(--neutral-map);
    fill: var(--district-fill);
    stroke: var(--map-stroke);
    stroke-width: 1.5;
    vector-effect: non-scaling-stroke;
    cursor: pointer;
    transition: fill 0.12s ease, stroke 0.12s ease, stroke-width 0.12s ease, opacity 0.12s ease;
}

.district:hover,
.district:focus-visible {
    stroke: #5f1a16;
    stroke-width: 2.3;
    outline: none;
}

.district.is-selected {
    stroke: #f7e4b6;
    stroke-width: 3.4;
}

.district.is-yours {
    stroke: #f0dca7;
}

.district.is-frontier {
    stroke: #7b2d1c;
}

.district.is-locked {
    opacity: 0.45;
}

.map-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 2rem;
    text-align: center;
    color: var(--ink-soft);
}

.map-tooltip {
    position: fixed;
    z-index: 50;
    max-width: 240px;
    padding: 0.72rem 0.85rem;
    border-radius: 16px;
    border: 1px solid rgba(122, 84, 53, 0.22);
    background: rgba(253, 247, 232, 0.96);
    color: var(--ink);
    box-shadow: var(--shadow);
    pointer-events: none;
    transform: translate(-50%, -100%);
}

.map-tooltip span {
    display: block;
    line-height: 1.35;
}

.tooltip-title {
    font-family: "Cinzel", serif;
    font-weight: 700;
    margin-bottom: 0.2rem;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 0.95rem;
    color: var(--ink-soft);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.legend-swatch {
    width: 16px;
    height: 16px;
    border-radius: 999px;
    border: 1px solid rgba(90, 57, 30, 0.2);
}

.legend-swatch.neutral {
    background: var(--neutral-map);
}

.legend-swatch.yours {
    background: #8d2d23;
}

.legend-swatch.rival {
    background: #a7804f;
}

.question-card {
    padding: 1rem;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(122, 84, 53, 0.22);
    background: rgba(255, 248, 230, 0.7);
}

.question-label {
    margin: 0 0 0.35rem;
    color: var(--ink-faint);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.question-card h3 {
    margin: 0 0 1rem;
    font-size: 1.3rem;
    line-height: 1.24;
}

.options-list {
    display: grid;
    gap: 0.7rem;
}

.option-button,
.option-note {
    width: 100%;
    padding: 0.9rem 0.95rem;
    border-radius: var(--radius-md);
    border: 1px solid rgba(122, 84, 53, 0.2);
    background: rgba(255, 251, 241, 0.86);
    color: var(--ink);
    text-align: left;
    line-height: 1.4;
}

.option-button {
    font-size: 1.02rem;
}

.option-button:hover,
.option-button:focus-visible {
    border-color: rgba(127, 29, 29, 0.42);
    background: #fff7e6;
}

.option-button:disabled {
    opacity: 0.7;
    cursor: wait;
}

.option-note {
    color: var(--ink-soft);
}

.feedback-box {
    margin-bottom: 0.9rem;
    padding: 0.88rem 0.95rem;
    border-radius: 16px;
    font-weight: 600;
    border: 1px solid transparent;
}

.feedback-box.hidden {
    display: none;
}

.feedback-box.success {
    background: rgba(41, 95, 56, 0.1);
    border-color: rgba(41, 95, 56, 0.24);
    color: var(--success);
}

.feedback-box.error {
    background: rgba(143, 47, 36, 0.1);
    border-color: rgba(143, 47, 36, 0.24);
    color: var(--error);
}

.leaderboard-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0.7rem;
}

.leaderboard-row,
.leaderboard-empty {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.82rem 0.92rem;
    border-radius: 16px;
    border: 1px solid rgba(122, 84, 53, 0.2);
    background: rgba(255, 248, 230, 0.72);
}

.leaderboard-rank {
    width: 2rem;
    flex: 0 0 2rem;
    font-family: "Cinzel", serif;
    color: var(--ink-faint);
}

.leaderboard-color {
    width: 14px;
    height: 14px;
    border-radius: 999px;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.leaderboard-name {
    flex: 1;
    font-weight: 700;
}

.leaderboard-score {
    color: var(--accent);
    font-weight: 700;
}

.rules-list {
    margin: 0;
    padding-left: 1.1rem;
    display: grid;
    gap: 0.62rem;
    line-height: 1.48;
    font-size: 1.02rem;
}

.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(29, 18, 11, 0.66);
}

.login-overlay[hidden] {
    display: none;
}

.login-card {
    position: relative;
    width: min(100%, 540px);
    padding: 1.35rem;
    border-radius: 28px;
    border: 2px solid var(--panel-edge);
    background:
        linear-gradient(180deg, var(--panel-strong), var(--panel));
    box-shadow: var(--shadow);
}

.login-card h2 {
    font-size: clamp(2rem, 4vw, 2.9rem);
    margin-bottom: 0.55rem;
}

.login-form {
    display: grid;
    gap: 0.95rem;
    margin-top: 1.15rem;
}

.field {
    display: grid;
    gap: 0.48rem;
}

.field span {
    color: var(--ink-faint);
    font-size: 0.92rem;
}

.field input {
    width: 100%;
    min-height: 52px;
    padding: 0.92rem 1rem;
    border-radius: 15px;
    border: 1px solid rgba(122, 84, 53, 0.25);
    background: rgba(255, 253, 247, 0.9);
    color: var(--ink);
    outline: none;
}

.field input:focus {
    border-color: rgba(127, 29, 29, 0.42);
    box-shadow: 0 0 0 3px rgba(127, 29, 29, 0.09);
}

.close-button {
    position: absolute;
    top: 0.9rem;
    right: 0.9rem;
    width: 42px;
    height: 42px;
    border-radius: 999px;
    border: 1px solid rgba(122, 84, 53, 0.18);
    background: rgba(255, 250, 238, 0.9);
    color: var(--ink);
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
}

.toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 80;
    max-width: min(92vw, 420px);
    padding: 0.95rem 1rem;
    border-radius: 16px;
    color: #fff8ef;
    background: linear-gradient(180deg, #8d2d23, #6b1e18);
    box-shadow: var(--shadow);
}

.toast.error {
    background: linear-gradient(180deg, #9f3b2c, #812418);
}

.toast[hidden] {
    display: none;
}

@media (max-width: 1260px) {
    .content-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .page-shell {
        padding: 0.9rem;
    }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .session-bar {
        width: 100%;
        flex-wrap: wrap;
    }

    .map-shell {
        min-height: 500px;
    }

    .district-map {
        min-height: 470px;
    }
}

@media (max-width: 640px) {
    .page-shell {
        padding: 0.7rem;
    }

    .topbar,
    .map-panel,
    .question-panel,
    .leaderboard-panel,
    .info-panel,
    .login-card {
        border-radius: 22px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .brand-block,
    .session-bar {
        width: 100%;
    }

    .ghost-button,
    .primary-button {
        width: 100%;
    }

    .map-shell {
        min-height: 390px;
        padding: 0.45rem;
    }

    .district-map {
        min-height: 350px;
    }

    .toast {
        left: 0.7rem;
        right: 0.7rem;
        bottom: 0.7rem;
        max-width: none;
    }
}
