/* Styles repris de metrodoku.fr (tokens, grille, cartes, modales), couleurs de lignes STAR */
:root {
    --page-bg: #f4f7fb;
    --surface: #fff;
    --surface-muted: #e8edf3;
    --surface-subtle: #ececec;
    --text: #1f2933;
    --strong: #111827;
    --muted: #4b5563;
    --border: #111;
    --border-soft: #333;
    --hover: #e0f0ff;
    --hover-muted: #eef2f7;
    --primary: #0a0082;
    --ok-bg: #dcfce7;
    --ok: #1f6f3b;
    --err-bg: #fee2e2;
    --err: #a12b2b;
    --info-bg: #dbeafe;
    --info: #1d4f91;
    --lineA: #e2231a;
    --lineB: #00a650;
    --r: 10px;
    --shadow: 0 24px 64px rgba(15, 23, 42, .22)
}

* {
    box-sizing: border-box
}

body {
    margin: 0;
    background: var(--page-bg);
    color: var(--text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    text-align: center;
    -webkit-tap-highlight-color: transparent
}

button {
    font: inherit;
    color: inherit
}

.container {
    width: min(100% - 32px, 760px);
    margin: 0 auto
}

.site-header {
    padding: 14px 0 0
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap
}

.brand {
    margin: 0;
    font-size: clamp(1.8rem, 7vw, 2.4rem);
    font-weight: 800;
    letter-spacing: -.02em
}

.brand a {
    color: var(--strong);
    text-decoration: none
}

.nav {
    display: flex;
    align-items: center;
    gap: 16px
}

.nav-link {
    background: none;
    border: 0;
    padding: 4px 0;
    color: var(--muted);
    font-weight: 600;
    font-size: .92rem;
    cursor: pointer
}

.nav-link:hover {
    color: var(--strong);
    text-decoration: underline
}

.streak {
    display: flex;
    align-items: center;
    gap: 3px;
    font-weight: 700
}

.streak svg {
    width: 20px;
    height: 20px;
    fill: #f97316
}

.divider {
    border: 0;
    border-top: 1px solid #d1d5db;
    margin: 14px 0
}

.mode-heading {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700
}

.mode-heading .date {
    color: var(--muted);
    font-weight: 500
}

.game-topbar,
.game-bottombar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin: 14px auto;
    max-width: 760px
}

.game-topbar {
    justify-content: center
}

.score {
    font-weight: 700
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    max-width: 760px;
    margin: 0 auto
}

.cell,
.header-col,
.header-row,
.corner {
    position: relative;
    display: grid;
    padding: 8px;
    border-radius: var(--r);
    background: var(--surface);
    font-weight: 700;
    min-width: 0
}

.cell::before,
.header-col::before,
.header-row::before,
.corner::before {
    content: "";
    grid-area: 1/1;
    padding-top: 100%
}

.cell>*,
.header-col>*,
.header-row>* {
    grid-area: 1/1;
    min-width: 0
}

.header-col,
.header-row,
.corner {
    place-items: center;
    background: var(--surface-muted);
    font-size: .85rem
}

.corner {
    visibility: hidden;
    background: transparent
}

.cell {
    place-items: stretch;
    border: 2px solid var(--border);
    cursor: pointer;
    transition: background-color .2s, border-color .2s;
    text-align: left
}

.cell:hover,
.cell.selected {
    background: var(--hover)
}

.cell:disabled {
    opacity: 1
}

.cell.correct {
    padding: 0;
    overflow: hidden;
    cursor: default
}

.cell.correct:hover {
    background: var(--surface)
}

.fact-trigger {
    cursor: pointer;
    border: 0;
    transition: background-color .2s
}

.fact-trigger:hover,
.fact-trigger:focus-visible {
    background: #dce4ee;
    outline: 0
}

.fact-label {
    text-align: center;
    line-height: 1.15;
    padding: 0 4px;
    overflow-wrap: anywhere
}

.fact-badge {
    position: absolute;
    top: 7px;
    right: 7px;
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    border-radius: 999px;
    background: #d7dfe7;
    color: rgba(28, 35, 45, .62);
    font-size: .5rem;
    font-weight: 800;
    line-height: 14px;
    text-align: center
}

.cell.success-flash {
    animation: ok 1.2s ease forwards
}

.cell.wrong-flash {
    animation: ko 1.6s ease forwards
}

@keyframes ok {
    0% {
        background: #bbf7d0
    }

    35% {
        background: #22c55e
    }

    100% {
        background: var(--surface)
    }
}

@keyframes ko {
    0% {
        background: #fca5a5
    }

    35% {
        background: #ef4444
    }

    100% {
        background: var(--surface)
    }
}

.grid.solution-mode .cell {
    cursor: pointer
}

.grid.solution-mode .cell:hover {
    background: var(--hover-muted)
}

.answer-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    padding: 0 12px 10px
}

.answer-band {
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(100% + 24px);
    min-height: 25px;
    margin: 0 -12px 8px;
    padding: 5px 8px;
    background: var(--surface-subtle);
    color: var(--muted);
    font-size: .62rem;
    font-weight: 800;
    line-height: 1.15
}

.answer-title {
    padding-bottom: 5px;
    border-bottom: 2px solid var(--border);
    font-size: clamp(.72rem, 1.8vw, .94rem);
    line-height: 1.15;
    overflow-wrap: anywhere
}

.answer-lines {
    display: flex;
    gap: 3px;
    margin-top: auto;
    padding-top: 8px
}

.line-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    color: #fff;
    font-size: .72rem;
    font-weight: 800
}

.line-icon.A {
    background: var(--lineA)
}

.line-icon.B {
    background: var(--lineB)
}

.abandon-button {
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    font-weight: 700;
    font-size: .85rem;
    cursor: pointer
}

.abandon-button:disabled {
    opacity: .4;
    cursor: default
}

.mistake-counter {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: .9rem
}

.mistake-dots {
    display: flex;
    gap: 5px
}

.mistake-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--border)
}

.mistake-dot.filled {
    background: var(--border)
}

.feedback {
    max-width: 760px;
    margin: 12px auto 0;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: .9rem;
    font-weight: 600;
    min-height: 40px
}

.feedback.info {
    background: var(--info-bg);
    color: var(--info)
}

.feedback.success {
    background: var(--ok-bg);
    color: var(--ok)
}

.feedback.error {
    background: var(--err-bg);
    color: var(--err)
}

.site-footer {
    margin: 28px auto 24px;
    color: var(--muted);
    font-size: .78rem
}

.overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(15, 23, 42, .5)
}

.overlay[hidden] {
    display: none
}

.answer-overlay {
    align-items: flex-start;
    padding-top: 72px
}

.autocomplete {
    position: relative;
    width: min(360px, 100%)
}

#station-input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--surface);
    border-radius: var(--r);
    background: var(--surface);
    font: inherit;
    font-size: 16px
}

#station-input:focus {
    outline: 0;
    box-shadow: 0 0 0 4px rgba(0, 120, 212, .25)
}

.autocomplete-list {
    margin-top: 4px;
    max-height: min(320px, 50vh);
    overflow-y: auto;
    border-radius: var(--r);
    background: var(--surface);
    text-align: left
}

.ac-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-top: 1px solid #e5e7eb;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.ac-used-tag {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
}

.ac-item:first-child {
    border-top: 0
}

.ac-item:hover,
.ac-item[aria-selected=true] {
    background: var(--hover)
}

.ac-item.used {
    color: #9ca3af;
    cursor: default
}

.ac-item.used:hover {
    background: var(--surface)
}

.ac-name {
    font-weight: 600
}

.ac-empty {
    padding: 14px;
    color: var(--muted)
}

.ac-lines {
    display: flex;
    gap: 3px;
    flex: none
}

.modal {
    position: relative;
    width: min(520px, 100%);
    max-height: min(82vh, 760px);
    overflow-y: auto;
    padding: 28px;
    border: 2px solid var(--border-soft);
    background: var(--surface);
    color: var(--border);
    text-align: left;
    box-shadow: var(--shadow)
}

.modal h3 {
    margin: 0 0 10px;
    font-size: 1.35rem;
    line-height: 1.15;
    padding-right: 34px
}

.modal p,
.modal li {
    line-height: 1.55;
    color: #374151
}

.modal ul {
    padding-left: 20px;
    margin: 8px 0
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 999px;
    background: var(--hover-muted);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer
}

.actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 22px
}

.btn {
    padding: 12px 14px;
    border: 2px solid var(--border-soft);
    background: var(--surface);
    font-weight: 700;
    cursor: pointer
}

.btn.primary {
    background: var(--strong);
    color: #fff;
    border-color: var(--strong)
}

.sol-list {
    list-style: none;
    padding: 0 !important
}

.sol-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-top: 1px solid #e5e7eb
}

.sol-list li:first-child {
    border: 0
}

.big-score {
    font-size: 2.2rem;
    font-weight: 800;
    margin: 6px 0
}

.share-grid {
    font-size: 1.5rem;
    letter-spacing: 2px;
    line-height: 1.3;
    white-space: pre
}

@media(max-width:640px) {
    .container {
        width: min(100% - 20px, 760px)
    }

    .grid {
        gap: 4px
    }

    .cell,
    .header-col,
    .header-row {
        padding: 5px
    }

    .header-col,
    .header-row {
        font-size: .62rem
    }

    .fact-badge {
        top: 4px;
        right: 4px;
        min-width: 12px;
        height: 12px;
        font-size: .42rem;
        line-height: 12px
    }

    .answer-band {
        font-size: .5rem;
        min-height: 20px;
        margin-bottom: 5px
    }

    .answer-title {
        font-size: .66rem
    }

    .line-icon {
        width: 18px;
        height: 18px;
        font-size: .6rem
    }

    .answer-overlay {
        padding: 24px 12px 16px
    }

    .modal {
        padding: 22px
    }

    .nav {
        gap: 12px
    }

    .abandon-button {
        padding: 10px;
        font-size: .78rem
    }
}

@media(prefers-reduced-motion:reduce) {

    .cell.success-flash,
    .cell.wrong-flash {
        animation: none
    }
}