:root {
  --vellum: #f8f0dd; --vellum-hi: #fdf8ec;
  --ink: #1d2340; --ink-soft: #4a4a58;
  --lapis: #1b3a8a; --lapis-deep: #142c6b; --lapis-tint: #e6e9f3;
  --gold: #7a5a10; --gold-leaf: #f2d58a; --gold-hair: #c3a04f;
  --right: #1d5a3a; --right-tint: #e4efdf;
  --wrong: #8a2420; --wrong-tint: #f7e4dc;
  --serif: "Iowan Old Style", "New York", ui-serif, Palatino, Georgia, serif;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 21px; line-height: 1.5; -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100dvh; display: flex; flex-direction: column; font-family: var(--serif); color: var(--ink); background: var(--vellum); }
h2, h3, p, dl, dd { margin: 0; }
:focus-visible { outline: 3px solid var(--lapis); outline-offset: 3px; }
[tabindex="-1"]:focus { outline: none; }

#masthead { display: flex; align-items: center; justify-content: center; gap: .55rem; padding: .55rem 16px .6rem; border-bottom: 1px solid var(--gold-hair); box-shadow: 0 3px 0 -2px var(--vellum), 0 3px 0 -1px var(--gold-hair); }
.mark { width: 48px; height: 48px; display: block; }
#site-title { margin: 0; font-size: 1.5rem; line-height: 1.1; font-weight: 600; color: var(--lapis-deep); }

main { flex: 1; width: 100%; max-width: 40rem; margin: 0 auto; padding: 1.1rem 16px 1.5rem; }
#screen-loading { padding: 2rem 0; text-align: center; color: var(--ink-soft); font-style: italic; }

button { display: block; width: 100%; min-height: 60px; font: inherit; color: var(--ink); cursor: pointer; }
.lapis { background: var(--lapis); color: var(--vellum-hi); border: 1px solid var(--lapis-deep); border-radius: 3px; padding: .5rem 1rem; font-weight: 600; box-shadow: inset 0 0 0 2px var(--lapis), inset 0 0 0 3px var(--gold-hair); }
.outline { background: none; border: 1.5px solid var(--lapis); border-radius: 3px; color: var(--lapis-deep); font-weight: 600; padding: .5rem 1rem; }
.quiet { background: none; border: 0; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 4px; font-size: .9rem; margin-top: .5rem; }
@media (hover: hover) { .lapis:hover { background: var(--lapis-deep); box-shadow: inset 0 0 0 2px var(--lapis-deep), inset 0 0 0 3px var(--gold-hair); } .outline:hover { background: var(--lapis-tint); } }

/* Home */
#screen-home h2 { font-size: 1.5rem; line-height: 1.2; font-weight: 600; color: var(--lapis-deep); }
#daily-status { margin: .25rem 0 .75rem; }
.col-a h2 + #daily-status + button + h2 { margin-top: 1.75rem; }
#stats { margin-top: .3rem; }
#stats > div { display: flex; justify-content: space-between; align-items: baseline; padding: .4rem 0; border-bottom: 1px solid var(--gold-hair); }
#stats dd { font-weight: 600; color: var(--lapis-deep); }
.col-b { margin-top: 2rem; }
#screen-home h3 { margin: 1.25rem 0 0; font-size: .82rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); }
.modes button { display: flex; justify-content: space-between; align-items: center; min-height: 58px; padding: .3rem .1rem; background: none; border: 0; border-bottom: 1px solid var(--gold-hair); text-align: left; color: var(--lapis-deep); }
.modes button::after { content: "›"; font-size: 1.4rem; line-height: 1; color: var(--gold); margin-left: .5rem; }
@media (hover: hover) { .modes button:hover { background: var(--lapis-tint); } }
details { margin-top: 1rem; }
summary { min-height: 58px; display: flex; align-items: center; font-weight: 600; color: var(--lapis-deep); cursor: pointer; border-bottom: 1px solid var(--gold-hair); }

/* Quiz */
.quiz-meta { display: flex; justify-content: space-between; gap: 1rem; font-size: .82rem; color: var(--ink-soft); padding-bottom: .4rem; border-bottom: 1px solid var(--gold-hair); }
#quiz-progress { white-space: nowrap; font-weight: 600; color: var(--lapis-deep); }
#question-text { margin: 1.05rem 0 1.05rem; font-size: 1.5rem; line-height: 1.28; font-weight: 600; color: var(--lapis-deep); }
#question-text::first-letter {
  float: left; font-size: 2.15em; line-height: 1; font-weight: 600;
  color: var(--gold-leaf); background: var(--lapis); border: 2px solid var(--gold-hair);
  padding: .1em .16em .12em; margin: .06em .16em 0 0;
}
#options { counter-reset: opt; display: grid; gap: .5rem; }
#options button {
  counter-increment: opt; display: flex; align-items: center; gap: .65rem; min-height: 64px; padding: .5rem .75rem;
  background: var(--vellum-hi); border: 1.5px solid var(--gold); border-radius: 3px; text-align: left; line-height: 1.3;
}
#options button::before { content: counter(opt, upper-alpha); flex: none; font-size: .85rem; font-weight: 600; color: var(--lapis-deep); width: 1.1rem; }
@media (hover: hover) { #options button:enabled:hover { background: var(--lapis-tint); border-color: var(--lapis); } }
#options button:disabled { cursor: default; color: var(--ink-soft); border-color: var(--gold-hair); }
#options button[data-state="correct"] { color: var(--right); background: var(--right-tint); border: 3px solid var(--right); font-weight: 600; }
#options button[data-state="incorrect"] { color: var(--wrong); background: var(--wrong-tint); border: 3px dashed var(--wrong); }
#options button[data-state]::before { color: inherit; }
#feedback { margin-top: 1.1rem; }
#feedback-result { font-size: 1.25rem; font-weight: 600; line-height: 1.3; color: var(--lapis-deep); }
#feedback strong { display: block; margin-top: .4rem; color: var(--gold); font-size: .95rem; }
#feedback-explanation { margin: .2rem 0 1rem; }

/* Results */
#screen-results { text-align: center; }
#screen-results h2 { font-size: 1.1rem; font-weight: 400; font-style: italic; color: var(--ink-soft); margin-top: .75rem; }
#result-score { font-size: 2.6rem; line-height: 1.15; font-weight: 600; color: var(--lapis-deep); }
#result-streak { margin-bottom: .25rem; }
#result-note { margin-bottom: .75rem; color: var(--ink-soft); font-size: .9rem; }
#share-status { min-height: 1.5em; margin: .35rem 0; font-style: italic; }
#screen-results label { display: block; text-align: left; font-size: .85rem; color: var(--ink-soft); }
textarea { display: block; width: 100%; font: .9rem/1.4 var(--serif); color: var(--ink); padding: .5rem; margin-bottom: .75rem; background: var(--vellum-hi); border: 1px solid var(--gold); border-radius: 3px; resize: vertical; }

footer { padding: .6rem 16px 1rem; border-top: 1px solid var(--gold-hair); font-size: .78rem; color: var(--ink-soft); text-align: center; }

@media (min-width: 760px) {
  #site-title { font-size: 1.8rem; }
  .mark { width: 60px; height: 60px; }
  #question-text { font-size: 1.8rem; }
  #options { grid-template-columns: 1fr 1fr; }
  #screen-quiz, #screen-results, #screen-loading, #screen-error { max-width: 38rem; margin-inline: auto; }
}
/* Marginal vines only where the column has room to itself. */
@media (min-width: 1120px) {
  body { background: url(../assets/vine.svg) left 28px top 0 repeat-y, url(../assets/vine.svg) right 28px top 0 repeat-y, var(--vellum); }
  main { max-width: 44rem; }
  #masthead, footer { background: var(--vellum); }
  #screen-home { display: grid; grid-template-columns: 1fr 1fr; gap: 2.5rem; align-items: start; }
  .col-b { margin-top: 0; }
}
@media (prefers-reduced-motion: reduce) { :not(.help-frames *), *::before, *::after { animation: none !important; transition: none !important; } }

.foot-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 22px; margin: 0; padding: 0; list-style: none; }
.foot-links a { display: inline-flex; align-items: center; min-height: 44px; color: var(--lapis-deep); text-underline-offset: 3px; }
.brand { display: flex; align-items: center; gap: inherit; color: inherit; text-decoration: none; }
.prose ol, .prose ul { margin: .7em 0 0; padding-left: 1.3em; }
.prose li + li { margin-top: .5em; }
.prose { overflow-wrap: break-word; }
.prose h1 { margin: 0; }
.prose h3 { margin: 1.2em 0 0; }
.prose table { width: 100%; margin-top: .8em; border-collapse: collapse; }
.prose th, .prose td { padding: .4em 0; text-align: left; }
.prose th:last-child, .prose td:last-child { text-align: right; }
.play-link a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; }

/* Content pages */
.site-note { margin-top: 1.75rem; padding-top: 1rem; border-top: 1px solid var(--gold-hair); font-size: .88rem; color: var(--ink-soft); text-align: center; }
.site-note a, .prose a { color: var(--lapis-deep); text-underline-offset: 3px; }
.prose { font-size: .88rem; line-height: 1.55; }
.prose h1 { font-size: 1.75rem; line-height: 1.15; font-weight: 600; color: var(--lapis-deep); }
.prose h2 { margin-top: 1.7em; padding-bottom: .2em; border-bottom: 1px solid var(--gold-hair); font-size: 1.22rem; line-height: 1.25; font-weight: 600; color: var(--lapis-deep); }
.prose h3 { font-size: 1rem; line-height: 1.3; font-weight: 600; color: var(--ink); }
.prose p { margin-top: .8em; }
.prose .lede { font-size: 1.12rem; line-height: 1.4; }
.prose .updated { color: var(--ink-soft); font-style: italic; }
.play-link { margin-top: 2em; }

/* Challenges, stats and sharing */
#challenge-note { margin-bottom: .6rem; padding: .3rem .7rem; border-left: 3px solid var(--gold-hair); color: var(--ink-soft); }
#challenge-banner { margin-bottom: 1rem; padding: .7rem .9rem; text-align: center; background: var(--vellum-hi); border: 1px solid var(--gold-hair); box-shadow: inset 0 0 0 3px var(--vellum-hi), inset 0 0 0 4px var(--gold-hair); }
#challenge-banner h2 { font-size: 1.25rem; color: var(--lapis-deep); }
#challenge-detail { color: var(--ink-soft); margin: .2rem 0 .5rem; }
#streak-note { color: var(--gold); font-style: italic; }
#streak-note:empty, #result-note:empty, #result-streak:empty, #code-status:empty { display: none; }
#more-stats { margin-top: .7rem; border-top: 1px solid var(--gold-hair); padding-top: .3rem; }
#more-stats summary { min-height: 44px; display: flex; align-items: center; color: var(--lapis-deep); cursor: pointer; }
#more-stats h3 { margin: .7rem 0 .2rem; font-size: .9rem; color: var(--gold); }
.rows { margin: 0; padding: 0; list-style: none; font-size: .9rem; }
.rows li { display: flex; justify-content: space-between; gap: .7rem; padding: .15rem 0; border-bottom: 1px dotted var(--gold-hair); }
.fine { font-size: .8rem; color: var(--ink-soft); margin-top: .2rem; }
#recent-bars { display: flex; align-items: flex-end; gap: 2px; height: 44px; }
#recent-bars i { flex: 1; max-width: 12px; background: var(--lapis); }
#code-box { width: 100%; font: .75rem/1.3 ui-monospace, monospace; background: var(--vellum-hi); border: 1px solid var(--gold-hair); color: var(--ink); padding: .3rem; }
.code-actions { display: flex; flex-wrap: wrap; gap: 0 1rem; }
.code-actions button { width: auto; min-height: 44px; margin: 0; }
#vs { display: grid; grid-template-columns: 1fr 1fr; gap: .2rem .7rem; margin: .6rem 0; padding: .6rem; border: 1px solid var(--gold-hair); background: var(--vellum-hi); text-align: center; }
#vs span { display: block; font-size: 1.5rem; line-height: 1.2; }
#vs small { color: var(--ink-soft); font-size: .85rem; }
#vs-line { grid-column: 1 / -1; font-style: italic; color: var(--ink-soft); }
#countdown-line { color: var(--ink-soft); margin: .3rem 0 .6rem; }
#screen-results label[for="challenge-name"] { display: block; margin-top: .5rem; font-size: .9rem; color: var(--ink-soft); }
#challenge-name { display: block; width: 100%; min-height: 48px; font: inherit; padding: .3rem .5rem; margin-bottom: .4rem; background: var(--vellum-hi); color: var(--ink); border: 1px solid var(--gold-hair); }
#screen-results .outline, #screen-results .lapis { margin-top: .5rem; }
#share-options { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.share-opt { flex: 1 1 30%; width: auto; min-height: 48px; display: flex; align-items: center; justify-content: center; background: none; border: 1px solid var(--lapis); border-radius: 3px; color: var(--lapis-deep); font: inherit; font-size: .9rem; text-decoration: none; cursor: pointer; }

:root { --h-bg:#fdf8ec;--h-ink:#1d2340;--h-btn:#1b3a8a;--h-btn-ink:#fdf8ec;--h-radius:4px;--h-font:var(--serif); }
/* First-visit walkthrough. Only transform and opacity animate. */
.help-btn { position: fixed; z-index: 6; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); width: 44px; height: 44px; min-width: 0; min-height: 0; padding: 0; border-radius: 50%; border: 1px solid var(--h-ink); background: var(--h-bg); color: var(--h-ink); font: 600 20px/1 var(--h-font); cursor: pointer; }
.help-card, .help-strip { position: fixed; z-index: 7; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); max-width: 440px; margin: 0 auto; background: var(--h-bg); color: var(--h-ink); border: 1px solid var(--h-ink); border-radius: var(--h-radius); box-shadow: 0 6px 22px rgba(0,0,0,.28); font: 15px/1.35 var(--h-font); }
.help-card { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; align-items: center; padding: 10px; }
.help-card.help-top { top: max(8px, env(safe-area-inset-top)); bottom: auto; right: 60px; }
.help-text { margin: 0; font: 15px/1.35 var(--h-font); color: var(--h-ink); }
.help-row { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; }
.help-ok { flex: 1; min-height: 44px; min-width: 0; width: auto; padding: 0 18px; border: 1px solid var(--h-btn); border-radius: var(--h-radius); background: var(--h-btn); color: var(--h-btn-ink); font: 600 16px/1.2 var(--h-font); cursor: pointer; }
.help-link { min-height: 44px; min-width: 44px; width: auto; padding: 0 8px; border: 0; background: none; color: var(--h-ink); font: 15px/1.2 var(--h-font); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.help-link:hover, .help-ok:hover { background: none; color: var(--h-ink); }
.help-ok:hover { background: var(--h-btn); color: var(--h-btn-ink); }
.help-strip { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 0 8px; }
.help-x { width: 44px; height: 44px; min-width: 0; padding: 0; border: 0; background: none; color: var(--h-ink); font-size: 22px; cursor: pointer; }
.help-demo { --s: 1; --freeze: 0s; --d: 5s; position: relative; width: calc(130px * var(--s)); height: calc(110px * var(--s)); overflow: hidden; border-radius: var(--h-radius); }
.help-frame { position: absolute; left: 0; top: 0; width: 130px; height: 110px; transform: scale(var(--s)); transform-origin: 0 0; }
.help-frame svg { display: block; width: 130px; height: 110px; }
.help-frame svg * { transform-box: fill-box; transform-origin: center; }
.help-tick { position: absolute; width: 0; height: 0; animation: help-tick var(--d) linear var(--loops) both; }
.help-paused * { animation-play-state: paused !important; }
.help-frames { --s: .5; width: 130px; height: 55px; }
.help-frames .help-frame:nth-child(2) { left: 65px; }
.help-frames * { animation-delay: var(--freeze) !important; animation-play-state: paused !important; animation-iteration-count: 1 !important; }
.help-dialog { width: min(92vw, 420px); max-height: 92dvh; overflow: auto; padding: 18px; border: 1px solid var(--h-ink); border-radius: var(--h-radius); background: var(--h-bg); color: var(--h-ink); }
.help-dialog::backdrop { background: rgba(0,0,0,.5); }
.help-dialog .help-demo { --s: 1.8; margin: 0 auto; }
.help-dialog .help-frames { --s: .9; width: 234px; height: 99px; }
.help-dialog .help-frames .help-frame:nth-child(2) { left: 117px; }
.help-title { margin: 0 0 10px; font: 600 21px/1.2 var(--h-font); color: var(--h-ink); }
.help-title:focus { outline: none; }
.help-dialog > .help-link { display: block; margin: 0 auto; }
.help-dialog > .help-text { margin-top: 8px; }
.help-legend { list-style: none; margin: 12px 0 0; padding: 0; font: 15px/1.3 var(--h-font); }
.help-legend li { display: flex; align-items: center; gap: 10px; padding: 3px 0; border: 0; }
.help-swatch { flex: none; width: 36px; height: 24px; display: inline-flex; align-items: center; justify-content: center; }
.help-swatch svg { width: 24px; height: 24px; }
.help-more { display: inline-flex; align-items: center; min-height: 44px; font: 15px/1.2 var(--h-font); color: var(--h-ink); }
.help-dialog .help-ok { display: block; width: 100%; margin-top: 6px; }
.help-how { display: block; margin: 0 auto; min-height: 44px; padding: 0 8px; border: 0; background: none; color: inherit; font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.help-rule { margin: 4px 0 0; }
@media (min-width: 900px) { .help-card, .help-strip { left: auto; right: 16px; width: 400px; } .help-card.help-top { right: 60px; } }
@media (prefers-reduced-motion: no-preference) { .help-pulse { animation: help-pulse 1.1s ease-in-out 1; } }
@keyframes help-tick { from, to { opacity: 0; } }
@keyframes help-pulse { 0%, 100% { transform: scale(1); } 45% { transform: scale(1.025); } }
.bd-tap { animation: bd-tap var(--d) linear var(--loops) both; }
.bd-mark { animation: bd-mark var(--d) linear var(--loops) both; }
.bd-ref { animation: bd-ref var(--d) linear var(--loops) both; }
@keyframes bd-tap { 0%, 18% { opacity: 0; } 26% { opacity: .5; } 36%, 100% { opacity: 0; } }
@keyframes bd-mark { 0%, 30% { opacity: 0; } 38%, 100% { opacity: 1; } }
@keyframes bd-ref { 0%, 52% { opacity: 0; transform: translateY(14px); } 64%, 100% { opacity: 1; transform: none; } }
#first-note { margin: .4rem 0 .7rem; color: var(--ink-soft); font-size: .92rem; }
@media (max-width: 560px) { #masthead { justify-content: flex-start; padding-right: 60px; } }

/* Keep the note and footer below the fold until the first screen renders (CLS). */
#screen-loading:not([hidden]) { min-height: 100svh; }
