/* ── Triviador ─────────────────────────────────────────────────────
   The conquest quiz. The map is the old Triviador board: a set of
   hand-drawn regions that are masked, coloured and clicked.          */

.td-page {
    --td-gold: var(--color-amber, #ffb020);
    --td-panel: var(--surface-2);
}

.td-page-head {
    margin-bottom: 12px;
}

.td-page .page-crumb {
    margin: 0 0 6px;
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.td-page .page-crumb a {
    color: var(--ink-dim);
    border: 0;
}

.td-page .page-crumb a:hover {
    color: var(--primary);
}

.td-screen[hidden] {
    display: none !important;
}

/* ── start ──────────────────────────────────────────────────────── */

.td-start {
    max-width: 980px;
}

.td-start-card .panel-body {
    padding: 18px;
}

.td-startgrid {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    gap: 28px;
}

.td-label {
    display: block;
    margin: 0 0 6px;
    color: var(--ink-dim);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.td-label + .td-input {
    margin-bottom: 18px;
}

.td-input {
    width: 100%;
    padding: 10px 12px;
    color: var(--ink);
    font: inherit;
    border: 1px solid var(--line);
    background: var(--surface-1);
    outline: none;
}

.td-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px rgba(var(--primary-rgb), 0.35);
}

.td-count {
    display: inline-flex;
    gap: 0;
    border: 1px solid var(--line);
}

.td-count button {
    min-width: 58px;
    padding: 8px 14px;
    color: var(--ink-dim);
    font-family: var(--font-mono);
    font-size: 15px;
    border: 0;
    border-right: 1px solid var(--line);
    background: var(--surface-1);
    cursor: pointer;
}

.td-count button:last-child {
    border-right: 0;
}

.td-count button:hover {
    color: var(--ink);
    background: var(--surface-3);
}

.td-count button.is-active {
    color: #04120d;
    background: var(--primary);
}

.td-hint,
.td-note {
    margin: 10px 0 0;
    color: var(--ink-faint);
    font-size: 12px;
    line-height: 1.55;
}

.td-startbtn {
    margin-top: 18px;
    width: 100%;
}

.td-best {
    margin: 12px 0 0;
    color: var(--td-gold);
    font-family: var(--font-mono);
    font-size: 12px;
}

.td-rules h3 {
    margin: 0 0 10px;
    color: var(--primary);
    font-family: var(--font-display);
    font-size: 15px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.td-rules ol {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin: 0;
    padding-left: 20px;
    color: var(--ink-dim);
    font-size: 13px;
    line-height: 1.55;
}

.td-rules li::marker {
    color: var(--primary);
    font-family: var(--font-mono);
}

.td-rules b {
    color: var(--ink);
}

/* ── the game shell ─────────────────────────────────────────────── */

.td-game {
    display: grid;
    grid-template-columns: 206px minmax(0, 1fr) 330px;
    gap: 12px;
    align-items: start;
}

.td-side,
.td-questioncol {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.td-main {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.td-panel .panel-body {
    padding: 10px;
}

.td-stagebar {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 36px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    background: var(--surface-2);
}

.td-stage {
    color: var(--primary);
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.td-round {
    color: var(--ink-faint);
    font-family: var(--font-mono);
    font-size: 11px;
}

/* ── players ────────────────────────────────────────────────────── */

.td-players {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.td-player {
    position: relative;
    display: grid;
    grid-template-columns: 10px 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 7px 8px;
    border: 1px solid var(--line);
    background: var(--surface-1);
}

.td-player.is-turn {
    border-color: var(--primary);
    box-shadow: 0 0 12px -3px rgba(var(--primary-rgb), 0.5);
}

.td-player.is-out {
    opacity: 0.42;
}

.td-player-swatch {
    width: 10px;
    height: 26px;
    border-radius: 1px;
    background: var(--c);
    box-shadow: 0 0 8px -1px var(--c);
}

.td-player-name {
    overflow: hidden;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.td-player-name small {
    display: block;
    color: var(--ink-faint);
    font-family: var(--font-mono);
    font-size: 10px;
}

.td-player-score {
    color: var(--td-gold);
    font-family: var(--font-mono);
    font-size: 13px;
}

/* ── log ────────────────────────────────────────────────────────── */

.td-log {
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-height: 260px;
    overflow-y: auto;
    scrollbar-width: thin;
}

.td-log p {
    margin: 0;
    padding-bottom: 5px;
    color: var(--ink-dim);
    font-size: 12px;
    line-height: 1.45;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.td-log p b {
    color: var(--ink);
}

.td-log p .td-log-mark {
    color: var(--primary);
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
}

/* ── map ────────────────────────────────────────────────────────── */

.td-mapwrap {
    position: relative;
    overflow: auto;
    border: 1px solid var(--line);
    background:
        radial-gradient(ellipse at 50% 40%, rgba(var(--primary-rgb), 0.08), transparent 60%),
        #080d0b;
    scrollbar-width: thin;
}

.td-map-world {
    position: relative;
    width: 100%;
    min-width: 620px;
    aspect-ratio: 1491 / 807;
    background:
        radial-gradient(ellipse at 50% 50%, rgba(240, 210, 150, 0.06), transparent 62%),
        repeating-linear-gradient(0deg, transparent 0 39px, rgba(255, 255, 255, 0.018) 39px 40px),
        repeating-linear-gradient(90deg, transparent 0 39px, rgba(255, 255, 255, 0.018) 39px 40px);
}

.td-terr {
    position: absolute;
    display: block;
    padding: 0;
    overflow: visible;
    border: 0;
    background: transparent;
    cursor: default;
}

.td-terr-tex {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    opacity: 0.72;
    filter: sepia(0.4) saturate(0.75) brightness(0.72) contrast(1.05);
    transition: filter 0.15s ease, opacity 0.15s ease;
    pointer-events: none;
}

.td-terr-tint {
    position: absolute;
    inset: 0;
    background: transparent;
    mask-repeat: no-repeat;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-size: 100% 100%;
    transition: opacity 0.15s ease, filter 0.15s ease;
    pointer-events: none;
}

.td-terr-info {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    color: #fff;
    font-family: var(--font-mono);
    font-size: clamp(10px, 1.2vw, 15px);
    font-weight: 700;
    text-shadow: 0 1px 3px #000, 0 0 8px rgba(0, 0, 0, 0.9);
    pointer-events: none;
}

.td-terr-base {
    color: var(--td-gold);
    font-size: 13px;
    line-height: 1;
}

.td-terr.is-selectable,
.td-terr.is-attackable {
    cursor: pointer;
    z-index: 3;
}

.td-terr.is-selectable .td-terr-tex,
.td-terr.is-attackable .td-terr-tex {
    filter: sepia(0.2) saturate(1) brightness(1.12) contrast(1.05);
    opacity: 0.95;
}

.td-terr.is-selectable .td-terr-tint {
    animation: td-pick 1.1s ease-in-out infinite;
    box-shadow: inset 0 0 0 2px var(--primary);
}

.td-terr.is-attackable .td-terr-tint {
    background: rgba(255, 60, 90, 0.5);
    animation: td-attack 0.9s ease-in-out infinite;
}

.td-terr.is-selectable:hover .td-terr-tex,
.td-terr.is-attackable:hover .td-terr-tex {
    filter: sepia(0) saturate(1.4) brightness(1.4) contrast(1.05);
}

.td-terr.is-last {
    z-index: 4;
}

.td-terr.is-last .td-terr-tint {
    animation: td-flash 0.55s ease-out 2;
}

@keyframes td-pick {
    0%, 100% { opacity: 0.35; }
    50% { opacity: 0.72; }
}

@keyframes td-attack {
    0%, 100% { opacity: 0.28; }
    50% { opacity: 0.62; }
}

@keyframes td-flash {
    0% { opacity: 1; filter: brightness(2.2); }
    100% { opacity: 0.7; filter: brightness(1); }
}

/* ── the action line under the map ──────────────────────────────── */

.td-actions {
    display: flex;
    align-items: center;
    min-height: 42px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    background: var(--surface-2);
}

.td-actionhint {
    color: var(--ink-dim);
    font-size: 13px;
}

.td-actionhint b {
    color: var(--primary);
}

/* ── the question panel ─────────────────────────────────────────── */

.td-questioncol {
    position: sticky;
    top: 12px;
}

.td-questionpanel .panel-body {
    min-height: 260px;
}

.td-idle {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 220px;
    color: var(--ink-faint);
    text-align: center;
}

.td-idle .spr {
    color: var(--primary);
    opacity: 0.55;
}

.td-idle p {
    margin: 0;
    font-size: 13px;
}

.td-qwrap {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.td-qwho {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.td-qwho span {
    padding: 2px 7px;
    font-family: var(--font-mono);
    font-size: 10px;
    border: 1px solid var(--line);
    background: var(--surface-1);
}

.td-qtext {
    color: var(--ink);
    font-size: 15px;
    line-height: 1.45;
}

.td-qsub {
    color: var(--ink-faint);
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.td-numform {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
}

.td-numform input {
    min-width: 0;
    padding: 9px 10px;
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 16px;
    border: 1px solid var(--line);
    background: var(--surface-1);
    outline: none;
}

.td-numform input:focus {
    border-color: var(--primary);
}

.td-numform .btn {
    padding: 8px 14px;
}

.td-answers {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.td-answer {
    padding: 9px 10px;
    color: var(--ink);
    font-size: 12px;
    line-height: 1.35;
    text-align: left;
    border: 1px solid var(--line);
    background: var(--surface-1);
    cursor: pointer;
    transition: border-color 0.12s ease, background 0.12s ease;
}

.td-answer:hover:not(:disabled) {
    border-color: var(--primary);
    background: var(--surface-3);
}

.td-answer:disabled {
    cursor: default;
    opacity: 0.55;
}

.td-answer.is-right {
    color: #04120d;
    border-color: var(--ok);
    background: var(--ok);
    opacity: 1;
}

.td-answer.is-wrong {
    color: #fff;
    border-color: var(--bad);
    background: rgba(255, 77, 109, 0.28);
    opacity: 1;
}

.td-timer {
    height: 4px;
    overflow: hidden;
    background: var(--surface-3);
}

.td-timer span {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--primary);
    transform-origin: left center;
    transition: transform 0.1s linear, background 0.2s ease;
}

.td-timer.is-low span {
    background: var(--bad);
}

.td-reveal {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 8px;
    border: 1px solid var(--line);
    background: var(--surface-1);
}

.td-reveal-title {
    color: var(--primary);
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.td-reveal p {
    margin: 0;
    color: var(--ink-dim);
    font-size: 12px;
}

.td-reveal b {
    color: var(--ink);
}

.td-result-rows {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 4px;
}

.td-result-row {
    display: grid;
    grid-template-columns: 8px 1fr auto auto;
    gap: 6px;
    align-items: center;
    color: var(--ink-dim);
    font-size: 11px;
}

.td-result-row .sw {
    width: 8px;
    height: 8px;
    background: var(--c);
}

.td-result-row .v {
    font-family: var(--font-mono);
    color: var(--ink);
}

.td-result-row .ok {
    color: var(--ok);
}

.td-result-row .no {
    color: var(--bad);
}

/* ── result ─────────────────────────────────────────────────────── */

.td-result {
    max-width: 760px;
    margin: 0 auto;
}

.td-result-card .panel-body {
    padding: 20px;
}

.td-result-card h2 {
    margin: 0 0 4px;
    font-family: var(--font-display);
    font-size: 24px;
}

.td-result-sub {
    margin: 0 0 16px;
    color: var(--ink-dim);
    font-size: 13px;
}

.td-scoreboard {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.td-sbrow {
    display: grid;
    grid-template-columns: 26px 14px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--line);
    background: var(--surface-1);
}

.td-sbrow.is-win {
    border-color: var(--td-gold);
    background: linear-gradient(90deg, rgba(255, 176, 32, 0.1), transparent);
}

.td-sbrank {
    color: var(--ink-faint);
    font-family: var(--font-mono);
    font-size: 14px;
}

.td-sbrow.is-win .td-sbrank {
    color: var(--td-gold);
}

.td-sbswatch {
    width: 14px;
    height: 26px;
    background: var(--c);
    box-shadow: 0 0 10px -2px var(--c);
}

.td-sbname {
    overflow: hidden;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.td-sbname small {
    display: block;
    color: var(--ink-faint);
    font-family: var(--font-mono);
    font-size: 10px;
}

.td-sbscore {
    color: var(--td-gold);
    font-family: var(--font-mono);
    font-size: 16px;
}

.td-result-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

/* ── narrow screens ─────────────────────────────────────────────── */

@media (max-width: 1240px) {
    .td-game {
        grid-template-columns: 180px minmax(0, 1fr);
    }

    .td-questioncol {
        position: static;
        grid-column: 1 / -1;
    }

    .td-questionpanel .panel-body {
        min-height: 0;
    }

    .td-idle {
        min-height: 90px;
    }
}

@media (max-width: 860px) {
    .td-startgrid {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    .td-game {
        grid-template-columns: 1fr;
    }

    .td-side {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        align-items: start;
    }

    .td-logpanel {
        max-height: 220px;
    }

    .td-map-world {
        min-width: 560px;
    }
}

@media (max-width: 560px) {
    .td-side {
        grid-template-columns: 1fr;
    }

    .td-map-world {
        min-width: 520px;
    }

    .td-sbrow {
        grid-template-columns: 22px 12px 1fr auto;
        gap: 7px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .td-terr.is-selectable .td-terr-tint,
    .td-terr.is-attackable .td-terr-tint,
    .td-terr.is-last .td-terr-tint {
        animation: none;
    }
}
