/* Fonts, self-hosted (SIL Open Font License, see fonts/*-LICENSE.txt) */
@font-face { font-family: "Saira Stencil One"; font-weight: 400; font-display: swap; src: url("fonts/saira-stencil-one-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: Oswald; font-weight: 400; font-display: swap; src: url("fonts/oswald-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: Oswald; font-weight: 500; font-display: swap; src: url("fonts/oswald-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: Oswald; font-weight: 600 700; font-display: swap; src: url("fonts/oswald-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: Barlow; font-weight: 400; font-display: swap; src: url("fonts/barlow-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: Barlow; font-weight: 400; font-style: italic; font-display: swap; src: url("fonts/barlow-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: Barlow; font-weight: 700; font-display: swap; src: url("fonts/barlow-latin-700-normal.woff2") format("woff2"); }

/* Stencil on a military crate: cream, khaki and brick red */
:root {
    --bg: #efe6cf;
    --surface: #f8f2e1;
    --text: #2a2c1c;
    --muted: #66684f;
    --border: #c9c0a3;
    --accent: #4b5320;
    --accent-text: #efe6cf;
    --match: #4b5320;
    --match-text: #efe6cf;
    --solved: #4b5320;
    --error: #b5452e;
    --stripe: #b5452e;
    --mono: Oswald, "Arial Narrow", sans-serif;
    --stencil: "Saira Stencil One", Impact, sans-serif;
    --label: Oswald, "Arial Narrow", sans-serif;
    color-scheme: light;
}

/* Dark theme, switched off for now: nothing sets data-theme="dark". To bring it back,
   wrap this rule in @media (prefers-color-scheme: dark) with a plain :root selector,
   set color-scheme back to "light dark" and restore the dark theme-color meta tags. */
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #22241a;
    --surface: #2e3122;
    --text: #efe6cf;
    --muted: #a7a58a;
    --border: #4a4d36;
    --accent: #a7b56a;
    --accent-text: #22241a;
    --match: #a7b56a;
    --match-text: #22241a;
    --solved: #a7b56a;
    --error: #e07a5f;
    --stripe: #c4573f;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 Barlow, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input { font: inherit; color: inherit; }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* The game, and on desktop the side panel next to it */
.layout { display: flex; justify-content: center; }
.app {
    display: flex; flex-direction: column;
    flex: 0 1 640px; min-width: 0; min-height: 100dvh;
    padding: 0 16px;
}
.puzzle { flex: 1; padding-bottom: 16px; }

/* Header */
.header { display: flex; align-items: center; gap: 12px; padding: 16px 0 10px; border-bottom: 4px solid var(--stripe); }
.header__score { margin: 0 0 0 auto; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.header__title { margin: 0; font-family: var(--stencil); font-weight: 400; font-size: 1.7rem; line-height: 36px; letter-spacing: .06em; text-transform: uppercase; }
.header__button {
    width: 36px; height: 36px; border-radius: 0; flex: none; display: inline-flex; align-items: center; justify-content: center; padding: 0; color: var(--text);
    border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 700;
}
@media (max-width: 400px) {
    .header { gap: 6px; }
    .header__title { font-size: 1.25rem; }
    .header__score { font-size: .8rem; }
    .header__button { width: 32px; height: 32px; }
}
a.header__button { text-decoration: none; }
.header__button[aria-expanded="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* Levels */
.levels { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 16px 0 20px; }
.levels__item {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    height: 52px; padding: 0; color: var(--text); border-radius: 0; border: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
.levels__item:disabled { opacity: .45; cursor: default; }
.levels__number { font-family: var(--stencil); font-weight: 400; font-size: 1.1rem; line-height: 1; }
.levels__day { font-family: var(--label); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.levels__item--today .levels__day { color: var(--accent); font-weight: 700; }
.levels__status { position: absolute; top: 2px; right: 4px; font-size: .6rem; color: var(--muted); }
.levels__item--solved .levels__status { color: var(--solved); font-weight: 700; }
.levels__status svg { display: block; width: 10px; height: 10px; margin-top: 3px; }
.levels__item--upcoming { border-style: dashed; }
.levels__item--current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* Codes: the target and the attempts share the same grid (same box padding, same
   cell size), so that a character is at the same place in all of them. */
.code {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(28px, 1fr)); gap: 3px;
    font-family: var(--mono); font-size: 1rem;
}
.code__char {
    display: flex; align-items: center; justify-content: center;
    height: 2em; border-radius: 0;
    background: var(--surface); border: 1px solid var(--border); font-weight: 500;
}
.code__char--space { background: transparent; border-style: dashed; }
.code--attempt .code__char--match { background: var(--match); color: var(--match-text); border-color: transparent; }

/* Target */
.target { margin-bottom: 20px; }
.target__meta { margin: 0 0 8px; color: var(--muted); font-family: var(--label); font-size: .9rem; letter-spacing: .12em; text-transform: uppercase; }
/* Same padding and border width as an attempt, but invisible, to keep the alignment */
.code--target { padding: 10px; border: 2px solid transparent; }

/* Result */
.result { margin-bottom: 20px; text-align: center; }
.result p { margin: 0 0 8px; }
.result__title { font-weight: 700; font-size: 1.1rem; color: var(--solved); }
.result__solution { font-size: 1.2rem; }
.result__detail { color: var(--muted); font-size: .9rem; }
.result__link { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }
.result__subtitle { font-weight: 700; margin-top: 16px !important; }
.result__rules { display: inline-block; margin: 0 0 8px; padding-left: 1.4em; text-align: left; font-size: .9rem; }
.result__hint { color: var(--muted); font-size: .85rem; margin: 12px 0 0 !important; }
.result__button {
    padding: 10px 24px; border: 0; border-radius: 0; background: var(--accent); color: var(--accent-text);
    font-weight: 700; cursor: pointer;
}

/* Zupple promotion, under a solved message */
.promo {
    display: flex; align-items: center; gap: 12px; max-width: 360px; margin: 20px auto; padding: 10px 14px 10px 10px;
    border: 1px solid var(--border); border-radius: 0; background: var(--surface);
    color: inherit; text-decoration: none; text-align: left;
}
.promo:hover { border-color: var(--accent); }
.promo:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.promo__image { flex: none; border-radius: 0; }
.promo__body { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.promo__title { font-weight: 700; font-size: .9rem; }
.promo__text { color: var(--muted); font-size: .8rem; }
.promo__cta { color: var(--accent); font-size: .8rem; font-weight: 600; }

/* Attempts */
.attempts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.attempt {
    display: flex; flex-direction: column; gap: 6px;
    padding: 10px; border-radius: 0; background: var(--surface); border: 2px solid var(--border);
}
.attempt--reusable { cursor: pointer; }
.attempt--reusable:hover { border-color: var(--accent); }
.attempt--reusable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.attempt__number { color: var(--muted); font-size: .8rem; }
.attempt--elsewhere { border-style: dashed; }
.attempt__note { font-size: .8rem; }
.attempt__guess {
    display: flex; align-items: baseline; gap: 8px;
    font-family: var(--mono); color: var(--muted); font-size: .9rem; overflow-wrap: anywhere;
}
.attempt__check { margin-left: auto; color: var(--solved); font-weight: 700; font-size: 1.1rem; }
.attempt--success { border-color: var(--solved); }
.attempt--repeated, .attempt--reusable.attempt--repeated:hover { border-color: var(--error); }
.empty { color: var(--muted); font-size: .95rem; }
.empty__link { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }

/* Guess form, sticky at the bottom */
/* Stays at the bottom of the screen, above the virtual keyboard on mobile */
.guess {
    position: sticky; bottom: 0;
    display: flex; flex-wrap: wrap; gap: 8px; margin: 0 -16px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--bg); border-top: 1px solid var(--border);
}
.guess[hidden] { display: none; }
/*
 * On touch screens, the virtual keyboard hides the top of the page while typing:
 * the encoded message is repeated above the field.
 */
.guess .guess__target { display: none; flex-basis: 100%; }
@media (pointer: coarse) {
    .guess:focus-within .guess__target { display: flex; }
}
.code--mini { display: flex; flex-wrap: wrap; gap: 2px; font-size: .85rem; }
.code--mini .code__char { min-width: 1.6em; height: 1.8em; }
.guess input {
    flex: 1; min-width: 0; padding: 12px 14px; border-radius: 0;
    border: 1px solid var(--border); background: var(--surface);
    font-family: var(--mono); font-size: 1rem; letter-spacing: .08em; text-transform: uppercase;
}
.guess input::placeholder { text-transform: none; }
.guess input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.guess button {
    padding: 0 20px; border: 0; border-radius: 0; background: var(--accent); color: var(--accent-text);
    font-family: var(--label); font-weight: 600; letter-spacing: .2em; text-transform: uppercase; cursor: pointer;
}
.guess .guess__next { padding: 0 16px; font-size: 1.2rem; }
.guess .guess__next[hidden] { display: none; }
.guess--pending button { opacity: .6; }
.error { color: var(--error); margin: 0 0 12px; }

/* Side panel (help or notes): full screen over the game on mobile, next to it on desktop */
.panel {
    position: fixed; inset: 0; z-index: 10; overflow: auto;
    padding: 16px; background: var(--bg);
}
.panel[hidden], .panel__section[hidden] { display: none; }
/* Muted body text: only titles, codes and values stand out */
.panel__section, .prose { color: var(--muted); }
.panel__header, .rules__title, .panel code:not([class]), .prose code:not([class]), .stats__value, .result__rules { color: var(--text); }
.panel strong:not([class]), .prose strong:not([class]) { color: var(--accent); }
.prose a:not([class]) { color: var(--accent); }
/* Same height as the game header (36px buttons below a 16px padding), so both rows line up on desktop */
.panel__header { display: flex; align-items: center; gap: 12px; min-height: 36px; margin-bottom: 12px; }
.panel__header h2 { margin: 0; font-size: 1.25rem; flex: 1; }
.panel__close {
    width: 36px; height: 36px; border-radius: 0; flex: none;
    border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 1.3rem; line-height: 1;
}
.panel__action {
    flex: none; height: 36px; padding: 0 12px; border-radius: 0;
    border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: .85rem;
}
.rules__title { margin: 20px 0 4px; font-size: 1rem; }
.rules { margin: 0; padding-left: 1.2em; }
.rules li { margin: 4px 0; }
.rules__example { display: block; color: var(--muted); font-size: .85rem; }
.rules li + li { margin-top: 8px; }
.panel code, .prose code { font-family: var(--mono); font-weight: 700; }
.panel__muted { color: var(--muted); font-size: .9rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.stats__caption { margin: 16px 0 6px; font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.stats__caption:first-child { margin-top: 0; }
.stats__tile { display: flex; flex-direction: column; padding: 12px; border-radius: 0; border: 1px solid var(--border); background: var(--surface); }
.stats__value { margin: 0; font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats__label { color: var(--muted); font-size: .8rem; }
.history { margin: 0; padding: 0; list-style: none; }
.history__item { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.history__result { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.panel__section--notes { display: flex; flex-direction: column; height: 100%; }
.panel__notes {
    flex: 1; min-height: 240px; width: 100%; resize: none;
    padding: 12px; border-radius: 0; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: .95rem/1.5 var(--mono);
}
.panel__notes:focus { outline: 2px solid var(--accent); outline-offset: 0; }
/* Tabs between rules, advanced rules and about: in the panel and on the content pages */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.tabs__item {
    display: inline-flex; align-items: center; height: 36px;
    padding: 0 14px; border-radius: 0; border: 1px solid var(--border); background: var(--surface);
    color: var(--text); font-size: .9rem; font-weight: 600; text-decoration: none;
}
.tabs__item:hover { border-color: var(--accent); }
.tabs__item[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.page .tabs { margin: 4px 0 8px; }
.panel__header[hidden] { display: none; }
.panel__title { margin: 8px 0 12px; font-size: 1.25rem; color: var(--text); }

/* Footer of the help panel and of the content pages */
.footer { margin: 32px 0 16px; padding-top: 12px; border-top: 1px solid var(--border); color: var(--muted); font-size: .8rem; }
.footer a, .prose .footer a { color: inherit; }

/* Content pages (rules, about, legal…), for search engines and without JavaScript */
.page { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.header__home { color: inherit; font-weight: 700; text-decoration: none; }
/* Stamp next to the title until the launch (Calendar::LAUNCH) */
.header__beta {
    display: inline-block; margin-left: .3em; padding: 1px 5px; vertical-align: .55em;
    border: 2px solid var(--stripe); color: var(--stripe); transform: rotate(-6deg);
    font: 600 .7rem/1.2 var(--label); letter-spacing: .12em; text-transform: uppercase;
}
.page__title { margin: 16px 0 12px; font-size: 1.5rem; color: var(--text); }
.page__play { margin: 32px 0 0; }
/* Usage stats page (GET /stats/{token}) */
.stats-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stats-table th, .stats-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: right; vertical-align: top; }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; white-space: nowrap; }
.stats-table th { color: var(--text); font: 600 .75rem/1.3 var(--label); letter-spacing: .06em; text-transform: uppercase; }
.stats-table td { color: var(--text); }
.stats-table small { color: var(--muted); font-size: .75rem; }
.stats-table__today td { background: var(--surface); font-weight: 700; }
.page__play .result__button { display: inline-block; text-decoration: none; }

@media (max-width: 959px) {
    body.has-panel { overflow: hidden; }
}
@media (min-width: 960px) {
    .panel {
        position: sticky; top: 0; z-index: auto; flex: 0 0 360px;
        height: 100dvh; border-left: 1px solid var(--border);
    }
    .panel__close { display: none; }
}
