/* A quiet daily puzzle: ivory and charcoal, a centered serif clue, and color to mark answers. */

:root {
    --bg: #f7f5ef;
    --card: #fcfbf7;
    --tile: #e9e7df;
    --ink: #272923;
    --ink-soft: #54564f;
    --muted: #696b62;
    --line: #d7d5cc;
    --line-strong: #a5a69a;
    --selected: #34382f;
    --selected-ink: #f7f5ef;
    --correct: #cbdcc8;
    --correct-ink: #20452d;
    --wrong: #cfccc3;
    --wrong-ink: #474942;
    --highlight: #eee0ae;
    --highlight-ink: #4d401c;
    --accent: #365b40;
    --accent-ink: #fcfbf7;
    --toast: #272923;
    --toast-ink: #f7f5ef;
    --backdrop: rgba(39, 41, 35, 0.42);

    --font-display: "DM Serif Display", Georgia, serif;
    --font-ui: "Libre Franklin", "Helvetica Neue", Arial, sans-serif;
    --font-tile: "Archivo", "Arial Narrow", sans-serif;
    --font-body: "Libre Franklin", "Helvetica Neue", Arial, sans-serif;
    --radius: 5px;
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #232521;
        --card: #292c26;
        --tile: #30332d;
        --ink: #f0eee5;
        --ink-soft: #c3c5ba;
        --muted: #afb2a5;
        --line: #45483f;
        --line-strong: #797e6f;
        --selected: #e4e5d9;
        --selected-ink: #232521;
        --correct: #3c634a;
        --correct-ink: #f0eee5;
        --wrong: #55574f;
        --wrong-ink: #f0eee5;
        --highlight: #cbbb83;
        --highlight-ink: #292718;
        --accent: #bad0b6;
        --accent-ink: #232521;
        --toast: #f0eee5;
        --toast-ink: #232521;
        --backdrop: rgba(0, 0, 0, 0.6);

        color-scheme: dark;
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

/* Small typed labels used throughout */
.label {
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

/* Header */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 76px;
    max-width: 880px;
    margin: 0 auto;
    padding: 0 max(24px, env(safe-area-inset-right)) 0 max(24px, env(safe-area-inset-left));
    border-bottom: 1px solid var(--line);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 27px;
    line-height: 1;
}

.brand-mark { width: 24px; height: 24px; flex: none; }
/* A bracket over three tiles: one clue stretching across several words. */
.brand-mark .mark-line { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.brand-mark .mark-tile { fill: var(--accent); }

.topbar-actions { display: flex; align-items: center; gap: 6px; }

.topbar-button {
    min-height: 44px;
    padding: 8px 0 8px 12px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    font-family: var(--font-ui);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: color 0.15s;
}
.topbar-button:hover { color: var(--ink-soft); }
.topbar-button:focus-visible, .day-arrow:focus-visible, .brand:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
}

/* Layout */

.game {
    width: 100%;
    max-width: 608px;
    margin: 0 auto;
    padding: 16px 24px 48px;
}

/* Day navigation */

.day-nav {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    align-items: center;
    min-height: 44px;
}

.day-arrow {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    color: var(--muted);
    transition: background-color 0.15s, color 0.15s;
}
.day-arrow:hover { background: var(--card); color: var(--ink); }
.day-arrow svg { width: 18px; height: 18px; }
.day-arrow.is-hidden { visibility: hidden; }

.day-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 400;
    color: var(--ink-soft);
}

/* Clue */

.clue-section {
    margin: 20px 0 24px;
    text-align: center;
}

.clue {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(44px, 12vw, 64px);
    line-height: 1.1;
    white-space: nowrap;
}
.clue.is-loading {
    width: 40%;
    height: 0.9em;
    margin: 0.12em auto;
    border-radius: 3px;
}

.clue-note {
    margin: 8px 0 0;
    color: var(--ink-soft);
    font-size: 17px;
    line-height: 1.4;
}

.notice {
    margin: 0 0 14px;
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    text-align: center;
    font-size: 14px;
    color: var(--ink-soft);
}

/* Status line: words found and mistakes made */

.status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    font-family: var(--font-ui);
    font-size: 13px;
}

.status-found { font-weight: 600; }
.status-mistakes { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }

.strikes { display: inline-flex; gap: 4px; }
.strike {
    width: 12px;
    height: 12px;
    border: 1.5px solid var(--ink-soft);
    border-radius: 2px;
    transition: background-color 0.25s, border-color 0.25s;
}
.strike.is-used { background: var(--ink); border-color: var(--ink); }

.game.is-loading .status { visibility: hidden; }

/* Board */

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

.tile {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr);  /* keep long words from widening the column past the padding */
    place-items: center;
    aspect-ratio: 5 / 3;
    min-width: 0;
    min-height: 44px;
    padding: 4px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--tile);
    color: var(--ink);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.12s var(--ease-out);
}

.tile-label {
    position: relative;
    display: block;
    max-width: 100%;
    font-family: var(--font-tile);
    font-weight: 600;
    font-stretch: 90%;
    font-size: clamp(11px, 3.4vw, 16px);
    line-height: 1.2;
    letter-spacing: 0;
    text-align: center;
    text-transform: uppercase;
    overflow-wrap: normal;
    word-break: keep-all;
}

.tile:not(:disabled):hover { border-color: var(--line-strong); }
.tile:not(:disabled):active { transform: scale(0.96); }
.tile:disabled { cursor: default; }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tile.is-selected,
.tile.is-selected:not(:disabled):hover {
    border-color: var(--selected);
    background: var(--selected);
    color: var(--selected-ink);
}

.tile.is-correct {
    border-color: var(--correct);
    background: var(--correct);
    color: var(--correct-ink);
    animation: confirm 0.35s var(--ease-out);
}

.tile.is-wrong {
    background: var(--wrong);
    color: var(--wrong-ink);
}

/* Missed answers remain distinct from the answers the player found. */
.tile.is-missed {
    background: var(--highlight);
    color: var(--highlight-ink);
}

.is-skeleton, .clue.is-loading {
    background: linear-gradient(100deg, var(--line) 40%, var(--card) 50%, var(--line) 60%) var(--line);
    background-size: 200% 100%;
    animation: shimmer 1.4s linear infinite;
}
.tile.is-skeleton { border-color: transparent; cursor: default; }

/* Actions */

.actions {
    display: flex;
    justify-content: center;
    margin-top: 28px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 190px;
    height: 48px;
    padding: 0 22px;
    border: 1px solid var(--ink);
    border-radius: var(--radius);
    background: var(--ink);
    color: var(--bg);
    font-family: var(--font-ui);
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
}
.button:not(:disabled):hover { background: var(--ink-soft); border-color: var(--ink-soft); }
.button:disabled { background: transparent; border-color: var(--line-strong); color: var(--muted); cursor: default; }
.button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.button-accent { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.button-accent:not(:disabled):hover { border-color: var(--accent); background: var(--accent); filter: brightness(1.08); }

/* Error state */

.error-panel { padding: 48px 20px; text-align: center; }
.error-panel p { margin: 0 0 24px; font-size: 18px; color: var(--ink-soft); }
.error-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* Toasts */

.toasts {
    position: fixed;
    top: 72px;
    left: 0;
    right: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 9px 14px;
    border-radius: var(--radius);
    background: var(--toast);
    color: var(--toast-ink);
    font-family: var(--font-ui);
    font-weight: 500;
    font-size: 13px;
    animation: toast-in 0.2s var(--ease-out);
}
.toast.is-leaving { animation: toast-out 0.25s ease-in forwards; }

/* Dialogs */

dialog {
    width: min(440px, calc(100% - 32px));
    max-height: calc(100% - 32px);
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
    color: var(--ink);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.22);
}
dialog::backdrop { background: var(--backdrop); }
dialog[open] { animation: dialog-in 0.3s var(--ease-out); }
dialog[open]::backdrop { animation: fade-in 0.3s ease-out; }

.dialog-body { position: relative; padding: 24px 24px 24px; }

.dialog-close {
    position: absolute;
    top: 12px;
    right: 12px;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
.dialog-close:hover { background: var(--bg); color: var(--ink); }
.dialog-close svg { width: 18px; height: 18px; }

.dialog-title {
    margin: 6px 40px 6px 0;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 28px;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

.dialog-subtitle { margin: 0 0 20px; color: var(--ink-soft); }

.help-list { margin: 14px 0 20px; padding-left: 18px; }
.help-list li { margin-bottom: 8px; }
.help-list li::marker { color: var(--muted); }

.example {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
}
.example-clue { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.example-clue strong { font-family: var(--font-display); font-weight: 400; font-size: 22px; }
.example-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
}
.example-row .tile { aspect-ratio: auto; height: 44px; cursor: default; animation: none; }
.example-row .tile-label { font-size: 12px; }
.example-note { margin: 10px 0 0; font-size: 13px; color: var(--muted); }

.results-answer {
    margin-bottom: 18px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
    text-align: center;
}
.results-clue {
    margin: 2px 0 12px;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 30px;
}
/* The answers: a row of chips, or with reasons, one answer per line with its reason beside it. */
.answers { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 0; padding: 0; list-style: none; }
.answers li { display: contents; }
.answers.has-reasons {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px 12px;
    align-items: baseline;
    text-align: left;
}
.answers.has-reasons .chip { justify-self: start; }
.reason { font-size: 14px; line-height: 1.35; color: var(--ink-soft); }
.chip {
    padding: 5px 9px;
    border-radius: 4px;
    font-family: var(--font-tile);
    font-weight: 600;
    font-stretch: 90%;
    font-size: 13px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.chip.is-found { background: var(--correct); color: var(--correct-ink); }
.chip.is-missed { background: var(--highlight); color: var(--highlight-ink); }

.trail {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    margin-bottom: 20px;
}
.trail span { width: 20px; height: 20px; border-radius: 3px; }
.trail .is-correct { background: var(--correct); }
.trail .is-wrong { background: var(--wrong); }

/* Stats: a row of totals, and in the stats dialog, games by mistakes made. */
.results-stats {
    margin-bottom: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}
.stat-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    text-align: center;
}
.stat { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.stat-value {
    font-family: var(--font-display);
    font-size: 30px;
    line-height: 1;
    font-variant-numeric: lining-nums tabular-nums;
}
.stat .label { font-size: 10px; letter-spacing: 0.06em; }

.chart-title { margin: 24px 0 10px; }
.chart { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.chart-row { display: grid; grid-template-columns: 36px minmax(0, 1fr); align-items: center; gap: 10px; }
.chart-key {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-soft);
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.chart-bar {
    justify-self: start;
    min-width: 26px;
    padding: 3px 8px;
    border-radius: 3px;
    background: var(--wrong);
    color: var(--wrong-ink);
    font-size: 13px;
    font-weight: 600;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.chart .is-today .chart-bar { background: var(--selected); color: var(--selected-ink); }

.stats-note { margin: 20px 0 0; font-size: 13px; color: var(--muted); }

/* Read by screen readers, not shown. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.results-actions { display: flex; flex-direction: column; align-items: center; gap: 14px; }

.countdown { display: flex; align-items: baseline; gap: 8px; }
.countdown strong { font-family: var(--font-ui); font-size: 18px; font-variant-numeric: tabular-nums; }

.text-link {
    font-size: 14px;
    font-weight: 500;
    color: var(--ink-soft);
    text-underline-offset: 3px;
}
.text-link:hover { color: var(--ink); }

/* Animation */

@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes confirm { 40% { transform: scale(1.05); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(16px); } }

@media (max-width: 420px) {
    .topbar { min-height: 64px; margin: 0 16px; padding: 0; }
    .topbar-button { font-size: 13px; }
    .game { padding: 8px 12px 32px; }
    .day-label { font-size: 12px; }
    .clue-section { margin: 16px 0 20px; }
    .clue-note { font-size: 15px; }
    .status { gap: 8px; margin-bottom: 12px; padding-top: 12px; font-size: 11px; }
    .status-mistakes { gap: 6px; }
    .strike { width: 10px; height: 10px; }
    .grid { gap: 5px; }
    .tile { aspect-ratio: 5 / 4; min-height: 44px; padding: 4px 3px; }
    .tile-label { font-stretch: 80%; }
    .actions { margin-top: 24px; }
}

@media (max-width: 380px) {
    .stat-value { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
