/* ── The Sleutle, beta 2 ──────────────────────────────────────────────────────
   Newsprint rather than "vintage": cool off-white paper, true black ink, one
   spot colour (red) kept for stamps and corrections. Serif for reading,
   Franklin for labels and controls, typewriter only for stamps and case
   numbers. Tile colours are tuned to look printed on the page. */

:root {
    --paper:      #f5f4f0;
    --paper-alt:  #ebe9e3;
    --ink:        #121212;
    --ink-soft:   #3b3b3b;
    --muted:      #6b6b6b;
    --rule:       #121212;
    --hairline:   #d3d1ca;
    --spot:       #c4281c;   /* stamps, corrections */

    --tile-g:     #4e8a4b;
    --tile-y:     #c39b2a;
    --tile-b:     #707070;
    --tile-text:  #ffffff;

    --font-masthead: 'UnifrakturMaguntia', 'Old English Text MT', serif;
    --font-serif:    'Newsreader', Georgia, 'Times New Roman', serif;
    --font-sans:     'Libre Franklin', 'Franklin Gothic Medium', Arial, sans-serif;
    --font-mono:     'IBM Plex Mono', 'Courier New', monospace;

    --column: 620px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --paper:     #141414;
        --paper-alt: #202020;
        --ink:       #dadae2;
        --ink-soft:  #c8c8c8;
        --muted:     #959595;
        --rule:      #ebebeb;
        --hairline:  #363636;
        --spot:      #ef5b4c;
        --tile-y:    #b8932a;
        --tile-b:    #4b4b4b;
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --paper:     #141414;
    --paper-alt: #202020;
    --ink:       #dadae2;
    --ink-soft:  #c8c8c8;
    --muted:     #959595;
    --rule:      #ebebeb;
    --hairline:  #363636;
    --spot:      #ef5b4c;
    --tile-y:    #b8932a;
    --tile-b:    #4b4b4b;
    color-scheme: dark;
}

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

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

body {
    margin: 0 auto;
    max-width: var(--column);
    padding: 0 16px calc(24px + env(safe-area-inset-bottom));
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-serif);
    font-size: 18px;
    line-height: 1.5;
}

a { color: inherit; text-underline-offset: 3px; }
button { font: inherit; color: inherit; }

/* ── Masthead ──────────────────────────────────────────────────────────────── */
.masthead { position: relative; padding-top: 10px; }

.masthead-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-sans);
    font-size: 14px;
}

.sections-btn {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 6px 10px 6px 0;
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 14px;
}
.sections-icon,
.sections-icon::before,
.sections-icon::after {
    display: block;
    width: 16px;
    height: 2px;
    background: var(--ink);
    transition: transform 0.2s;
}
.sections-icon { position: relative; }
.sections-icon::before, .sections-icon::after { content: ''; position: absolute; left: 0; }
.sections-icon::before { top: -5px; }
.sections-icon::after  { top: 5px; }
.sections-btn[aria-expanded="true"] .sections-icon { background: transparent; }
.sections-btn[aria-expanded="true"] .sections-icon::before { transform: translateY(5px) rotate(45deg); }
.sections-btn[aria-expanded="true"] .sections-icon::after  { transform: translateY(-5px) rotate(-45deg); }

.edition {
    font-style: italic;
    font-family: var(--font-serif);
    color: var(--muted);
}

.nameplate {
    display: block;
    margin: 4px 0 4px;
    text-align: center;
    text-decoration: none;
    font-family: var(--font-masthead);
    font-weight: 400;
    font-size: clamp(44px, 13vw, 76px);
    line-height: 1.05;
}

.dateline {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0 3px;
    border-top: 1px solid var(--rule);
    border-bottom: 3px double var(--rule);
    font-size: 15px;
}
#datelineCase { font-family: var(--font-mono); font-size: 13px; align-self: center; }

/* Sections dropdown: a plain panel under the masthead */
.sections {
    position: absolute;
    top: 42px;
    left: 0;
    right: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    padding: 4px 18px;
    background: var(--paper);
    border: 1px solid var(--rule);
    border-top: 3px solid var(--rule);
}
.sections[hidden] { display: none; }
.sections a {
    padding: 12px 0;
    text-decoration: none;
    font-weight: 700;
    font-size: 21px;
    border-top: 1px solid var(--hairline);
}
.sections a:first-child { border-top: none; }
.sections a:hover { text-decoration: underline; }
.sections a[aria-current="page"] {
    text-decoration: underline;
    text-decoration-thickness: 2px;
}

/* ── Article typography ────────────────────────────────────────────────────── */
main { outline: none; padding-top: 22px; }

.loading { font-style: italic; color: var(--muted); text-align: center; }

/* Section label above a headline, as papers do: bold Franklin, not a typewriter */
.kicker {
    margin: 0 0 2px;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.kicker a { text-decoration: none; }
.kicker a:hover { text-decoration: underline; }

.headline {
    margin: 0 0 4px;
    font-weight: 700;
    font-size: clamp(30px, 8vw, 40px);
    line-height: 1.08;
    letter-spacing: -0.01em;
}
.dateplate {
    margin: 0 0 12px;
    font-size: 16px;
    color: var(--muted);
}
.intro {
    margin: 0 0 16px;
    font-size: 19px;
}
.section-head {
    margin: 30px 0 2px;
    padding-top: 8px;
    border-top: 2px solid var(--rule);
    font-weight: 700;
    font-size: 25px;
    line-height: 1.2;
}
.byline {
    margin: 0 0 8px;
    font-size: 16px;
    color: var(--ink-soft);
}

.case-tools {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: 4px 14px;
    margin-bottom: 18px;
    padding: 7px 0;
    border-top: 1px solid var(--hairline);
    border-bottom: 1px solid var(--hairline);
    font-family: var(--font-sans);
    font-size: 14px;
}
.mode-tag { color: var(--ink-soft); }
.mode-tag strong { color: var(--ink); font-weight: 700; }

.newcomer {
    margin: -8px 0 16px;
    padding: 8px 12px;
    background: var(--paper-alt);
    font-size: 16px;
}

@media (max-width: 480px) {
    .mode-hint { display: none; }
    .case-tools { margin-bottom: 14px; }
}

/* ── Board ─────────────────────────────────────────────────────────────────── */
.board {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin: 0 auto 12px;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.board-row {
    display: flex;
    gap: 6px;
}
.board-row.final { margin-top: 10px; }   /* gap before the answer row */
.board-row.shake { animation: shake 0.4s; }

.tile {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    /* shrink on short screens so board and keyboard fit together */
    width: clamp(40px, min(14vw, 6.3vh), 60px);
    aspect-ratio: 1;
    border-radius: 2px;
    font-family: var(--font-sans);
    font-weight: 800;
    font-size: clamp(20px, min(7vw, 3.5vh), 30px);
    color: var(--tile-text);
    cursor: pointer;
    transition: transform 0.08s;
}
.tile.g { background: var(--tile-g); }
.tile.y { background: var(--tile-y); }
.tile.b { background: var(--tile-b); }
.tile.blank {
    background: var(--paper);
    border: 2px solid var(--muted);
    color: var(--ink);
}

/* Given letters: serif capitals with an underline, so they read as "printed" */
.tile.given {
    cursor: default;
    font-family: var(--font-serif);
    font-weight: 700;
}
.tile.given::after {
    content: '';
    position: absolute;
    left: 28%;
    right: 28%;
    bottom: 16%;
    height: 2px;
    background: rgba(255, 255, 255, 0.85);
    pointer-events: none;
}

.tile.selected {
    outline: 3px solid var(--ink);
    outline-offset: 2px;
    z-index: 1;
}
.tile.pop { animation: pop 0.1s; }
.board.locked .tile { cursor: default; }

.status {
    min-height: 1.5em;
    margin: 0 0 12px;
    text-align: center;
    font-size: 17px;
}
.status.error { color: var(--spot); }
.status.info { font-style: italic; color: var(--ink-soft); }
.status.ok { font-weight: 600; }

.actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 18px;
}

.btn {
    display: inline-block;
    padding: 9px 18px;
    background: var(--paper);
    border: 1.5px solid var(--ink);
    border-radius: 3px;
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
}
.btn:hover { background: var(--paper-alt); }
.btn[hidden] { display: none; }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: var(--ink-soft); }
.btn:focus-visible, .tile:focus-visible, a:focus-visible, .key:focus-visible {
    outline: 3px solid var(--spot);
    outline-offset: 2px;
}

/* ── On-screen keyboard ────────────────────────────────────────────────────── */
.keyboard {
    margin: 0 -10px 14px;
}
.keyboard[hidden] { display: none; }
.key-row {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin-bottom: 6px;
}
.key-row:last-child { margin-bottom: 0; }
.key {
    flex: 1;
    max-width: 44px;
    height: clamp(42px, 5.9vh, 54px);
    padding: 0;
    background: var(--paper-alt);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 17px;
    touch-action: manipulation;
}
.key.wide {
    flex: 1.6;
    max-width: 72px;
    font-size: 14px;
    font-weight: 600;
}
.key:hover { background: var(--hairline); }
.key.check { background: var(--ink); color: var(--paper); }
.key.check:hover { background: var(--ink-soft); }
.key:active { background: var(--muted); color: var(--paper); }
.key-spacer { flex: 0.5; max-width: 22px; }

/* ── Past cases ────────────────────────────────────────────────────────────── */
.record {
    margin: 0 0 6px;
    font-size: 19px;
}
.record strong { font-weight: 700; }
.fine-print { margin: 0 0 8px; font-size: 15px; font-style: italic; color: var(--muted); }

.month-head {
    margin: 26px 0 0;
    padding-bottom: 3px;
    border-bottom: 2px solid var(--rule);
    font-weight: 700;
    font-size: 20px;
}
.case-list { list-style: none; margin: 0; padding: 0; }
.case-list li { border-bottom: 1px solid var(--hairline); }
.case-list a {
    display: grid;
    grid-template-columns: 4.6em 1fr auto;
    align-items: baseline;
    gap: 10px;
    padding: 9px 2px;
    text-decoration: none;
}
.case-list a:hover .case-date { text-decoration: underline; }
.case-num { font-family: var(--font-mono); font-size: 13px; color: var(--muted); }
.case-date { font-size: 18px; }
.case-date strong { font-weight: 700; }

/* A small rubber stamp: one of the few places the typewriter face appears */
.closed-mark {
    padding: 0 6px;
    border: 1.5px solid var(--spot);
    border-radius: 2px;
    color: var(--spot);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    transform: rotate(-3deg);
}
.open-mark { font-family: var(--font-sans); font-size: 13px; color: var(--muted); }

/* ── Archive ───────────────────────────────────────────────────────────────── */
.group-label {
    margin: 14px 0 6px;
    font-style: italic;
    font-size: 17px;
    color: var(--ink-soft);
}
.cell-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.cell-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: 1.5px solid var(--ink);
    border-radius: 2px;
    text-decoration: none;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 18px;
}
.cell-link:hover { background: var(--paper-alt); }
.cell-link.done { background: var(--tile-g); border-color: var(--tile-g); color: var(--tile-text); }

/* Specials and Logical sit in boxed panels below the difficulty levels,
   like a sidebar box in a paper */
.archive-box {
    margin-top: 30px;
    padding: 12px 16px 16px;
    border: 1px solid var(--rule);
    border-top-width: 3px;
}
.archive-box h2 { margin: 0 0 2px; font-size: 23px; line-height: 1.2; }
.archive-box .special-list li:last-child { border-bottom: none; padding-bottom: 0; }

.special-list { list-style: none; margin: 0; padding: 0; }
.special-list li { padding: 12px 0; border-bottom: 1px solid var(--hairline); }
.special-list a { font-size: 21px; font-weight: 700; text-decoration: none; }
.special-list a:hover { text-decoration: underline; }
.special-list p { margin: 2px 0 0; font-size: 15px; color: var(--ink-soft); }

/* ── How to play ───────────────────────────────────────────────────────────── */
.lesson {
    margin: 0 0 8px;
    padding: 14px 0 6px;
    border-top: 2px solid var(--rule);
}
.lesson h2 {
    margin: 0 0 6px;
    font-size: 24px;
    line-height: 1.2;
}
.lesson p { margin: 0 0 12px; }
.legend {
    display: grid;
    gap: 6px;
    margin: 0 0 14px;
    padding: 0;
    list-style: none;
    font-size: 16px;
}
.legend li { display: flex; align-items: center; gap: 10px; }
.swatch {
    flex: none;
    width: 22px;
    height: 22px;
    border-radius: 2px;
}
.swatch.g { background: var(--tile-g); }
.swatch.y { background: var(--tile-y); }
.swatch.b { background: var(--tile-b); }
.swatch.given {
    position: relative;
    background: var(--tile-b);
}
.swatch.given::after {
    content: 'T';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.secret {
    font-family: var(--font-sans);
    font-weight: 700;
    letter-spacing: 0.08em;
    padding: 1px 6px;
    border-radius: 2px;
    background: var(--ink);
    color: var(--paper);
}
.feedback-row {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin: 4px 0 8px;
}
.feedback-row .tile {
    width: 30px;
    font-size: 15px;
    cursor: default;
}

.mode-compare {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}
@media (max-width: 480px) { .mode-compare { grid-template-columns: 1fr; } }
.mode-compare h3 {
    margin: 0 0 2px;
    font-size: 19px;
}
.mode-compare p { margin: 0; font-size: 16px; }

/* ── Modal (solved) ────────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(10, 10, 10, 0.55);
}
.modal[hidden] { display: none; }
.modal-panel {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 26px 22px 20px;
    background: var(--paper);
    border-top: 4px solid var(--rule);
    text-align: center;
    animation: rise 0.25s ease-out;
}
.modal-close {
    position: absolute;
    top: 6px;
    right: 8px;
    padding: 4px 8px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
}
.stamp {
    display: inline-block;
    margin: 4px 0 16px;
    padding: 6px 14px;
    border: 4px solid var(--spot);
    border-radius: 4px;
    color: var(--spot);
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 26px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    transform: rotate(-6deg);
    animation: stamp 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
}
.modal-panel h2 { margin: 0 0 4px; font-size: 26px; line-height: 1.15; }
.solution-chain {
    margin: 10px 0 12px;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 16px;
    letter-spacing: 0.05em;
}
.modal-record { margin: 0 0 16px; font-size: 17px; }
.modal-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}
.share-fallback {
    display: none;
    width: 100%;
    height: 110px;
    margin-bottom: 12px;
    padding: 8px;
    background: var(--paper-alt);
    border: 1px solid var(--hairline);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 13px;
    resize: none;
}

.colophon {
    margin-top: 36px;
    padding-top: 10px;
    border-top: 1px solid var(--rule);
    font-size: 14px;
    color: var(--muted);
}

/* ── Motion ────────────────────────────────────────────────────────────────── */
@keyframes pop   { 50% { transform: scale(1.08); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes rise  { from { opacity: 0; transform: translateY(12px); } }
@keyframes stamp { from { opacity: 0; transform: rotate(-6deg) scale(2.2); } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── Puzzles with several answers ──────────────────────────────────── */
.answer-tally {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 12px;
    margin: 0 0 12px;
    font-family: var(--font-sans);
    font-size: 14px;
}
.answer-count { font-weight: 700; }
.answer-slots { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.slot {
    padding: 2px 8px;
    border: 1.5px dashed var(--muted);
    border-radius: 3px;
    font-family: var(--font-sans);
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--muted);
}
.slot.found {
    border-style: solid;
    border-color: var(--tile-g);
    background: var(--tile-g);
    color: var(--tile-text);
}
.modal .answer-slots { justify-content: center; margin: 4px 0 12px; }
.modal-panel { overflow-x: hidden; }   /* the tilted stamp pokes out sideways */
.modal-sub { margin: 0 0 2px; font-size: 17px; color: var(--ink-soft); }
.btn:disabled { opacity: 0.5; cursor: default; }


/* ── Privacy notice strip and page ────────────────────────────────────────── */
.privacy-strip {
    position: fixed;
    left: 50%;
    bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 40;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    width: min(600px, calc(100vw - 24px));
    padding: 12px 14px;
    transform: translateX(-50%);
    background: var(--paper);
    border: 1px solid var(--rule);
    border-top: 3px solid var(--rule);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    animation: rise 0.25s ease-out;
}
.privacy-strip p { margin: 0; font-size: 16px; flex: 1 1 240px; }
.privacy-strip-actions { display: flex; gap: 8px; }
.privacy-strip .btn { padding: 7px 12px; font-size: 14px; }
.privacy ul { margin: 0 0 12px; padding-left: 22px; }
.privacy li { margin-bottom: 4px; }
.player-id { display: block; margin-top: 8px; font-size: 15px; color: var(--ink-soft); }
.player-id code {
    font-family: var(--font-mono);
    font-size: 13px;
    padding: 1px 5px;
    background: var(--paper-alt);
    word-break: break-all;
    user-select: all;
}
.player-id .btn { padding: 4px 10px; font-size: 13px; vertical-align: middle; }
