:root {
  --paper: #F4EFE4; --ink: #1E1B18; --oxblood: #8C2F23; --ink-soft: #5A5349;
  --hairline: #1E1B1855; --tint: #8C2F2314;
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 .12 0 0 0 0 .1 0 0 0 0 .09 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
  --gutter: 16px; --tray-gap: 6px;
  color-scheme: light;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 1.0625rem/1.5 var(--serif);
  background-image: var(--grain);
}
h1, h2, p, dl, dd, ol, blockquote { margin: 0; padding: 0; }
button, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { color: var(--ink-soft); cursor: default; }
:focus-visible { outline: 2px solid var(--oxblood); outline-offset: 2px; }

.masthead { max-width: 1160px; margin: 0 auto; padding: 14px var(--gutter) 0; }
.wordmark { display: flex; align-items: center; gap: 12px; font-size: clamp(1.75rem, 7.6vw, 2.5rem); font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.wordmark img { flex: none; display: block; width: 1.25em; height: 1.25em; }
.masthead::after { content: ""; display: block; margin-top: 12px; height: 5px; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--ink); }
nav { display: flex; flex-wrap: wrap; align-items: center; column-gap: 18px; margin-top: 6px; }
nav button { min-height: 44px; padding: 0 2px; font-size: 1rem; }
body[data-mode="daily"] #btn-daily, body[data-mode="practice"] #btn-practice { font-weight: 700; color: var(--oxblood); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 6px; }
body[data-mode="daily"] #btn-new { display: none; }
.difficulty { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-size: 1rem; color: var(--ink-soft); }
.difficulty span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
select { min-height: 44px; padding: 0 6px; background: transparent; border: 0; border-bottom: 1px solid var(--hairline); border-radius: 0; color: var(--ink); }

main { max-width: 1160px; margin: 0 auto; padding: 0 var(--gutter) 40px; }
.slug { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 0; font-style: italic; color: var(--ink-soft); font-size: 1rem; }
.slug-right { display: inline-flex; gap: 16px; font-variant-numeric: tabular-nums; font-style: normal; }
#timer, #hint-count { color: var(--ink); }

#board { container-type: inline-size; --longest: 8; padding: 6px 0 14px; }
.word { display: inline-flex; align-items: flex-end; white-space: nowrap; margin: 0 .55em 10px 0; --cell: min(var(--cap, 32px), calc(100cqi / (var(--longest) + 1))); font-size: 16px; }
.cell { display: grid; grid-template-rows: 32px 16px; width: var(--cell); height: 54px; padding: 0 1px; justify-items: center; align-items: end; border-radius: 0; position: relative; }
.cell::after { content: ""; position: absolute; left: 2px; right: 2px; top: 34px; height: 1px; background: var(--ink); }
.guess, .cipher { grid-column: 1; line-height: 1; }
.cell[data-guess=""] .guess { display: none; }
.cell[data-guess=""] .cipher { grid-row: 1; align-self: end; padding-bottom: 3px; font-size: 25px; font-weight: 600; color: var(--ink); text-shadow: 0 1px 0 #fff8; }
.cell:not([data-guess=""]) .guess { grid-row: 1; align-self: end; padding-bottom: 3px; font-size: 25px; font-weight: 700; color: var(--oxblood); }
.cell:not([data-guess=""]) .cipher { grid-row: 2; align-self: end; font-size: 12px; color: var(--ink-soft); }
.cell[data-selected] { background: var(--tint); }
.cell[data-selected]::after { height: 3px; background: var(--oxblood); }
.cell[data-conflict] .guess, .cell[data-wrong] .guess { background: var(--oxblood); color: var(--paper) !important; padding: 2px 3px 3px; text-decoration: underline wavy 1px; text-underline-offset: 1px; }
.punct { font-size: 25px; font-weight: 600; line-height: 1; padding-bottom: 22px; }

#tray { position: sticky; bottom: 0; background: var(--paper) var(--grain); border-top: 1px solid var(--hairline); margin-inline: -10px; padding: 0 0 calc(8px + env(safe-area-inset-bottom)); }
#message { min-height: 1.5em; padding-top: 4px; text-align: center; font-style: italic; font-size: .9375rem; color: var(--oxblood); }
#controls { display: grid; grid-template-columns: 1fr auto 1fr 1fr; margin-bottom: 6px; }
#controls button { min-height: 44px; font-size: 1rem; white-space: nowrap; }
#controls button:not(:disabled):hover { color: var(--oxblood); }
#keyboard { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--tray-gap); }
.key-row { display: contents; }
#keyboard button { height: 46px; min-width: 0; border: 1px solid var(--ink); border-radius: 2px; font-size: 1.125rem; font-weight: 600; box-shadow: inset 0 -2px 0 #1E1B181f; }
#keyboard button:not(:disabled):active { background: var(--ink); color: var(--paper); }
#keyboard button[data-used] { border-color: var(--hairline); color: var(--ink-soft); font-weight: 400; box-shadow: none; }
body:has(#result:not([hidden])) #tray { display: none; }
body:has(#result:not([hidden])) .cell:not([data-guess=""]) .guess { color: var(--ink); }
body:has(#result:not([hidden])) .cell .cipher { display: none; }
body:has(#result:not([hidden])) .cell { height: 38px; }
body:has(#result:not([hidden])) .cell::after { display: none; }
body:has(#result:not([hidden])) .punct { padding-bottom: 6px; }

h2 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.2; padding-bottom: 6px; border-bottom: 2px solid var(--oxblood); margin-bottom: 12px; }
#result { padding: 22px 0 8px; scroll-margin-top: 10px; }
#result-text { font-size: 1.5rem; line-height: 1.35; text-wrap: pretty; }
.attribution { margin-top: 10px; font-style: italic; }
.tally { margin-top: 2px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.share-label { display: block; margin-top: 18px; font-size: .9375rem; color: var(--ink-soft); }
#share-text { display: block; width: 100%; margin-top: 4px; padding: 8px 0 8px 12px; background: none; border: 0; border-left: 2px solid var(--hairline); border-radius: 0; resize: none; font-size: 1rem; }
.share-row { margin-top: 12px; display: flex; align-items: center; gap: 12px; }
#btn-share { min-height: 46px; padding: 0 22px; background: var(--oxblood); color: var(--paper); border-radius: 2px; font-weight: 600; }
#share-status { font-style: italic; }

#how, #stats, #archive { margin-top: 32px; }
.streak { font-size: 5rem; font-weight: 700; line-height: 1; color: var(--oxblood); letter-spacing: -.03em; font-variant-numeric: lining-nums; margin-bottom: 10px; }
dl { display: grid; grid-template-columns: 1fr auto; }
dt, dd { padding: 7px 0; border-bottom: 1px solid var(--hairline); }
dd { text-align: right; font-variant-numeric: tabular-nums; }
#archive-list { list-style: none; display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; }
#archive-list button { width: 100%; min-height: 44px; text-align: left; border-bottom: 1px solid var(--hairline); font-size: 1rem; }
#archive-list button:hover { color: var(--oxblood); }
#archive-list button[data-solved] { color: var(--oxblood); }
#btn-archive-more { min-height: 44px; margin-top: 6px; text-decoration: underline; text-underline-offset: 4px; }

@media (min-width: 720px) {
  .word { --cell: min(46px, calc(100cqi / (var(--longest) + 1))); }
  .cell { height: 62px; grid-template-rows: 38px 18px; }
  .cell::after { top: 40px; }
  .cell[data-guess=""] .cipher, .cell:not([data-guess=""]) .guess, .punct { font-size: 33px; }
  .punct { padding-bottom: 24px; }
  #keyboard { grid-template-columns: repeat(13, 1fr); }
  #tray { position: static; margin-inline: 0; }
  #controls { display: flex; justify-content: center; gap: 28px; }
  #controls button { padding: 0 8px; }
}
@media (min-width: 1000px) {
  .wordmark { font-size: 2.75rem; }
  .masthead { display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 24px; }
  .masthead::after { grid-column: 1 / -1; }
  nav { margin: 0; }
  .difficulty { margin-left: 8px; }
  main { display: grid; grid-template-columns: minmax(0, 1fr) 300px; column-gap: 48px; grid-auto-rows: min-content; }
    .col-main { grid-column: 1; }
  .col-side { grid-column: 2; align-self: start; }
  #how { margin-top: 16px; }
  #how, #stats, #archive { border-left: 1px solid var(--oxblood); margin-left: -24px; padding-left: 24px; margin-top: 0; padding-top: 16px; }
  #archive-list button { font-size: .9375rem; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* Content pages */
a.wordmark { color: inherit; text-decoration: none; }
main.prose { display: block; padding-top: 6px; }
.prose > * { max-width: 40rem; }
.prose p, .prose ul { margin: 0 0 14px; }
.prose ul { padding-left: 1.25em; }
.prose li { margin-bottom: 6px; }
.prose h1 { font-size: clamp(2rem, 8vw, 2.75rem); font-weight: 700; letter-spacing: -.02em; line-height: 1.1; margin: 10px 0 16px; }
.prose h2 { margin-top: 30px; }
.prose h3 { font-size: 1.125rem; line-height: 1.3; margin: 20px 0 4px; }
.prose a, .site-note a { color: var(--oxblood); text-underline-offset: 3px; }
.prose .back a { display: inline-flex; align-items: center; min-height: 44px; font-style: italic; }
.prose kbd { font: inherit; font-weight: 700; }
.site-note, .site-footer { max-width: 1160px; margin: 0 auto; padding-inline: var(--gutter); }
.site-note { padding-bottom: 12px; }
.site-note p { max-width: 40rem; color: var(--ink-soft); }
.site-footer { padding-bottom: 24px; }
.site-footer nav { margin: 0; padding-top: 8px; border-top: 1px solid var(--hairline); column-gap: 22px; }
.site-footer a { display: inline-flex; align-items: center; min-height: 44px; color: var(--ink); text-underline-offset: 3px; }

/* Retention: results panel, sheet, stats extras */
.banner { margin-top: 12px; padding: 10px 12px; border-left: 3px solid var(--oxblood); background: var(--tint); font-style: italic; }
.compare { margin-top: 6px; color: var(--ink-soft); }
.versus { margin-top: 10px; padding: 10px 12px; background: var(--tint); }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.result-actions button { min-height: 46px; padding: 0 10px; border: 1px solid var(--oxblood); border-radius: 2px; color: var(--oxblood); }
.result-actions #btn-stats { grid-column: 1 / -1; border: 0; text-decoration: underline; text-underline-offset: 4px; min-height: 40px; }
.result-actions #btn-next { grid-column: 1 / -1; background: var(--oxblood); color: var(--paper); font-weight: 600; }
#btn-share { background: none; color: var(--oxblood); font-weight: 400; }
.sheet-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.sheet-row a, .sheet-row button { min-height: 44px; display: inline-flex; align-items: center; padding: 0 14px; border: 1px solid var(--hairline); border-radius: 2px; color: var(--oxblood); }
.sheet-status { font-style: italic; }
.sheet-copy, #backup-box { width: 100%; font: inherit; font-size: .875rem; padding: 8px; margin-top: 8px; background: none; border: 1px solid var(--hairline); }
.countdown { margin-top: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.spark { display: block; width: 100%; height: 40px; margin-top: 12px; color: var(--oxblood); }
.note { color: var(--ink-soft); font-size: .9375rem; margin-top: 6px; }
#stats h3 { margin-top: 18px; font-size: 1rem; }
#stats ol { list-style: none; padding: 0; margin: 6px 0 0; font-size: .9375rem; }
#stats ol li { padding: 5px 0; border-bottom: 1px solid var(--hairline); }
#stats details { margin-top: 14px; }
#stats summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--oxblood); }
#collection-list cite { font-style: italic; color: var(--ink-soft); }
#btn-nav-stats { text-decoration: none; }

/* First-visit help: fixed so it never shifts the game. */
.help-btn { position: fixed; z-index: 40; top: 8px; right: 8px; width: 44px; height: 44px; border: 1px solid var(--h-ink); border-radius: 50%; background: var(--h-bg); color: var(--h-ink); font-size: 1.25rem; font-weight: 700; line-height: 1; }
.help-card { position: fixed; z-index: 50; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); max-height: 56dvh; overflow: auto; padding: 12px 14px; background: var(--h-bg); color: var(--h-ink); border: 1px solid var(--h-ink); border-radius: 6px; box-shadow: 0 8px 24px #0004; animation: help-in .2s ease-out; }
.help-text { margin: 8px 0 0; font-size: 1rem; line-height: 1.35; }
.help-row { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.help-row .help-quiet:first-child { margin-right: auto; }
.help-quiet { min-height: 44px; padding: 0 8px; background: none; color: var(--h-soft); font-size: .9375rem; text-decoration: underline; text-underline-offset: 3px; }
.help-primary { min-height: 44px; padding: 0 18px; border-radius: 3px; background: var(--h-accent); color: var(--h-bg); font-weight: 700; }
.help-link { min-height: 44px; padding: 0 4px; background: none; color: var(--h-accent); font: inherit; text-decoration: underline; text-underline-offset: 3px; }
.help-strip { position: fixed; z-index: 40; top: 8px; left: 8px; right: 60px; display: flex; align-items: center; justify-content: space-between; padding: 0 8px; background: var(--h-bg); border: 1px solid var(--h-ink); border-radius: 4px; }
.help-dialog { width: min(440px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); padding: 12px 16px 16px; background: var(--h-bg); color: var(--h-ink); border: 1px solid var(--h-ink); border-radius: 6px; }
.help-dialog::backdrop { background: #0006; }
.help-top { display: flex; align-items: center; justify-content: space-between; }
.help-top h2 { margin: 0; padding: 0; border: 0; font-size: 1.375rem; }
.help-legend { list-style: none; margin: 8px 0 0; padding: 0; font-size: .9375rem; }
.help-legend li { display: flex; align-items: center; gap: 10px; padding: 5px 0; border-top: 1px solid var(--h-line); line-height: 1.3; }
.help-more { display: inline-flex; align-items: center; min-height: 44px; color: var(--h-accent); text-underline-offset: 3px; }
.help-stage { display: flex; gap: 10px; justify-content: center; }
.help-frame { flex: 1 1 0; min-width: 0; }
.help-frame-label { display: block; font-size: .8125rem; color: var(--h-soft); }
.demo { position: relative; flex: 1 1 auto; min-width: 0; padding: 4px 0; }
.demo-pointer { position: absolute; left: 0; top: 0; width: 26px; height: 26px; margin: -13px 0 0 -13px; border: 2px solid var(--h-accent); border-radius: 50%; background: var(--h-tint); transition: transform .3s ease; pointer-events: none; }
@keyframes help-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes help-pulse { 50% { transform: scale(1.08); } }
@media (min-width: 720px) { .help-card { left: auto; right: 16px; width: 330px; max-height: calc(100dvh - 90px); } }
:root { --h-bg: var(--paper); --h-ink: var(--ink); --h-soft: var(--ink-soft); --h-accent: var(--oxblood); --h-line: var(--hairline); --h-tint: var(--tint); }
#board[data-help-pulse] .cell[data-selected] { animation: help-pulse .7s ease-in-out 2; }
@media (min-width: 1000px) {
  .help-card { top: 120px; bottom: auto; right: max(16px, calc((100vw - 1160px) / 2 + 16px)); width: 316px; }
}
@media (min-width: 1000px) and (max-width: 1259px) { .masthead { padding-right: 60px; } }

/* Given and hint letters: a dark block, unlike the red letters a player guesses. */
.cell[data-locked] { cursor: default; }
.cell[data-locked]:not([data-guess=""]):not([data-conflict]) .guess { background: var(--ink); color: var(--paper); padding: 2px 4px 3px; border-radius: 2px; font-weight: 600; }
body:has(#result:not([hidden])) .cell[data-locked]:not([data-guess=""]) .guess { background: none; color: var(--ink); padding: 0 0 3px; }

/* Always-visible key to the board. */
#legend { font-size: .875rem; line-height: 1.5; color: var(--ink-soft); padding-bottom: 8px; }
#legend strong { color: var(--ink); font-weight: 700; }
#legend-keys { display: flex; flex-wrap: wrap; gap: 2px 12px; }
#legend-keys span { white-space: nowrap; }
#letters-left { font-variant-numeric: tabular-nums; }
.sw { font-style: normal; display: inline-grid; place-items: center; min-width: 1.5em; height: 1.5em; margin-right: 3px; font-weight: 700; line-height: 1; border-radius: 2px; }
.sw-guess { color: var(--oxblood); }
.sw-given { background: var(--ink); color: var(--paper); font-weight: 600; }
.sw-select { background: var(--tint); color: var(--ink); box-shadow: inset 0 -3px 0 var(--oxblood); }
.sw-used { border: 1px solid var(--hairline); color: var(--ink-soft); font-weight: 400; }
.sw-bad { background: var(--oxblood); color: var(--paper); text-decoration: underline wavy 1px; text-underline-offset: 1px; }
body:has(#result:not([hidden])) #legend { display: none; }

/* Walkthrough board, built from the real cell and key styles. */
.demo-board { display: block; }
.demo-board .word { --cell: 32px; font-size: 16px; margin: 0 .5em 4px 0; }
.demo-board .cell { height: 54px; grid-template-rows: 32px 16px; cursor: default; }
.demo-board .cell::after { top: 34px; }
.demo-board .cell[data-guess=""] .cipher, .demo-board .cell:not([data-guess=""]) .guess { font-size: 25px; }
.demo-keys { display: flex; gap: 6px; margin-top: 4px; }
.demo-key { width: 40px; height: 40px; border: 1px solid var(--ink); border-radius: 2px; display: grid; place-items: center; font-size: 1.125rem; font-weight: 600; box-shadow: inset 0 -2px 0 #1E1B181f; }
.demo-key[data-used] { border-color: var(--hairline); color: var(--ink-soft); font-weight: 400; box-shadow: none; }
.demo-key[data-press] { background: var(--ink); color: var(--paper); }
.demo-note { min-height: 1.4em; margin-top: 4px; font-style: italic; font-size: .875rem; color: var(--oxblood); }

/* Reserve space for the JS-rendered board, keyboard and masthead state (CLS). */
body:not([data-mode]) #btn-new { display: none; }
#board:empty { min-height: 276px; }
#keyboard:empty { min-height: 202px; }
@media (min-width: 720px) {
  #board:empty { min-height: 236px; }
  #keyboard:empty { min-height: 98px; }
}
