:root {
  --paper: #f3ecdd; --card: #fbf7ee; --ink: #2b2620; --muted: #7b7163; --line: #d6cbb6;
  --accent: #8a3324; --t4: #4f8a4b; --t3: #c9a227; --t2: #cf7a2c; --t1: #4f7ea8; --t0: #5b554c;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #1c1915; --card: #26221c; --ink: #ece4d3; --muted: #a2978a; --line: #413a30; --accent: #e08a6c; --t0: #6b655c; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--serif); min-height: 100vh; display: flex; flex-direction: column; align-items: center; }
header { width: 100%; max-width: 560px; display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; border-bottom: 3px double var(--line); }
.masthead { text-align: center; }
h1 { margin: 0; font-size: 30px; letter-spacing: .5px; font-weight: 700; }
h1 span { color: var(--accent); font-style: italic; }
#subtitle { margin: 0; font: 11px var(--mono); letter-spacing: 2px; text-transform: uppercase; color: var(--muted); }
main { width: 100%; max-width: 560px; padding: 16px; flex: 1; }
button, .button { font: inherit; cursor: pointer; border-radius: 4px; border: 1px solid var(--ink); padding: 9px 16px; text-decoration: none; display: inline-block; }
.primary { background: var(--ink); color: var(--paper); }
.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.icon { width: 38px; height: 38px; padding: 0; border-radius: 50%; background: transparent; color: var(--ink); border-color: var(--line); font-size: 17px; }
button:focus-visible, input:focus-visible, .button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.plate { margin: 0 0 14px; background: var(--card); border: 1px solid var(--line); padding: 10px 10px 6px; box-shadow: 0 1px 0 var(--line), 0 8px 24px rgba(0,0,0,.08); }
.frame { aspect-ratio: 4 / 3; overflow: hidden; background: #111; display: flex; align-items: center; justify-content: center; }
.frame img { width: 100%; height: 100%; object-fit: contain; transition: transform .7s cubic-bezier(.2,.7,.2,1); user-select: none; -webkit-user-drag: none; }
figcaption { font: 12px var(--mono); color: var(--muted); text-align: center; padding-top: 6px; letter-spacing: .5px; }

#guesses { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
#guesses li { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); background: var(--card); padding: 7px 10px; min-height: 40px; animation: pop .25s ease-out; }
#guesses li.empty { border-style: dashed; background: transparent; animation: none; }
#guesses li i, .legend i { flex: none; width: 18px; height: 18px; border-radius: 3px; display: inline-block; }
#guesses .name { font-weight: 600; }
#guesses .hint { margin-left: auto; font: 12px var(--mono); color: var(--muted); text-align: right; }
.t4 { background: var(--t4); } .t3 { background: var(--t3); } .t2 { background: var(--t2); } .t1 { background: var(--t1); } .t0 { background: var(--t0); }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }

#guess-form { display: flex; gap: 8px; }
.combo { position: relative; flex: 1; min-width: 0; }
#guess { width: 100%; font: inherit; padding: 9px 12px; border: 1px solid var(--ink); border-radius: 4px; background: var(--card); color: var(--ink); }
#guess.picked { border-color: var(--t4); box-shadow: inset 0 0 0 1px var(--t4); font-weight: 600; }
button:disabled { opacity: .4; cursor: not-allowed; }
#options { position: absolute; left: 0; right: 0; bottom: calc(100% + 4px); margin: 0; padding: 4px; list-style: none; background: var(--card); border: 1px solid var(--ink); border-radius: 4px; max-height: 232px; overflow-y: auto; z-index: 5; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
#options li { padding: 7px 10px; border-radius: 3px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
#options li small { color: var(--muted); font: 11px var(--mono); align-self: center; }
#options li[aria-selected="true"] { background: var(--ink); color: var(--paper); }
#options li[aria-selected="true"] small { color: inherit; opacity: .7; }
#options li.used { opacity: .4; text-decoration: line-through; }

#result { text-align: center; border-top: 3px double var(--line); margin-top: 14px; padding-top: 12px; }
#result h2 { margin: 0 0 4px; font-size: 24px; }
#result h2 em { color: var(--accent); }
#result-fact { margin: 0 auto 12px; max-width: 46ch; }
.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.next { font: 13px var(--mono); color: var(--muted); margin: 14px 0 4px; }
.credit { font-size: 11px; color: var(--muted); margin: 0; word-break: break-word; }
.credit a, footer a, #archive-nav a { color: inherit; }
#archive-nav { text-align: center; font: 12px var(--mono); color: var(--muted); margin-top: 16px; display: flex; gap: 14px; justify-content: center; }
footer { font-size: 11px; color: var(--muted); text-align: center; padding: 8px 16px 18px; max-width: 560px; }

dialog { background: var(--card); color: var(--ink); border: 1px solid var(--ink); border-radius: 6px; max-width: min(420px, calc(100vw - 32px)); padding: 20px 22px; }
dialog::backdrop { background: rgba(20,16,10,.6); }
dialog h2 { margin: 0 0 8px; }
dialog form { text-align: center; margin-top: 14px; }
.legend { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 5px; }
.legend li { display: flex; align-items: center; gap: 10px; }
.small { font-size: 13px; color: var(--muted); }
.statrow { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; margin: 8px 0 14px; }
.statrow b { display: block; font-size: 26px; }
.statrow span { font: 10px var(--mono); text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
#dist div { display: flex; align-items: center; gap: 8px; font: 13px var(--mono); margin: 3px 0; }
#dist u { text-decoration: none; background: var(--t0); color: #fff; padding: 1px 6px; min-width: 22px; text-align: right; border-radius: 2px; }
#dist u.me { background: var(--t4); }
#toast { position: fixed; top: 76px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: 4px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; }
#toast.show { opacity: 1; }
@media (max-width: 420px) { #guess-form { flex-wrap: wrap; } .combo { flex-basis: 100%; } #guess-form button { flex: 1; } #guesses .hint { font-size: 11px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.tiles { font: 20px/1.5 var(--mono); margin: 4px 0 12px; text-align: center; white-space: pre-wrap; user-select: all; letter-spacing: 2px; }
.tiles::first-line { font-size: 13px; letter-spacing: .5px; color: var(--muted); }
.share { background: var(--t4); border-color: var(--t4); color: #fff; font-weight: 600; padding: 10px 22px; }
#stats-share { text-align: center; border-top: 1px solid var(--line); margin-top: 14px; padding-top: 10px; }
dialog #toast { top: 24px; }
#archive-nav { flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 12px; }
#history { width: 420px; }
#history-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 52vh; overflow-y: auto; border-top: 1px solid var(--line); }
#history-list li { border-bottom: 1px solid var(--line); }
#history-list li.here { background: var(--paper); }
#history-list a { display: grid; grid-template-columns: auto auto 1fr; gap: 2px 10px; padding: 8px 6px; color: inherit; text-decoration: none; align-items: baseline; }
#history-list a:hover { background: var(--paper); }
#history-list .no { font: 12px var(--mono); letter-spacing: 1px; }
#history-list .when { font: 12px var(--mono); color: var(--muted); }
#history-list .tl { text-align: right; letter-spacing: 1px; }
#history-list .ans { grid-column: 1 / -1; font-size: 14px; }
#history-list .todo { text-align: right; font: 12px var(--mono); color: var(--accent); }
.byline { margin: 2px 0 0; font-size: 10.5px; color: var(--muted); text-align: center; }
.byline a { color: inherit; }
footer p { margin: 4px 0; }
.icon.button { display: inline-flex; align-items: center; justify-content: center; }
.icon-spacer { width: 38px; }
.doc main h2 { font-size: 20px; margin: 22px 0 6px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.doc main p, .doc main li { font-size: 15px; }
.doc main a { color: var(--accent); }
.doc main ul { padding-left: 20px; }
#credit-list { padding-left: 34px; font-size: 13px; }
#credit-list li { font-size: 13px; margin: 5px 0; }
.next { line-height: 1.7; }
#next-label { font: 15px var(--serif); color: var(--ink); }
#oops { width: 100%; background: var(--accent); color: #fff; text-align: center; padding: 10px 16px; font-size: 14px; }
#oops button { margin-left: 8px; padding: 4px 12px; background: #fff; color: #222; border: 0; }
dialog { width: min(420px, calc(100vw - 32px)); }
.statrow span { font-size: 9px; letter-spacing: .5px; }
