/* Layout: a single dictionary column. The masthead is a headword entry; solved groups are
   highlighter swipes across the page, like a text marked up in four colours. */
:root {
  --paper: #f0eee8;
  --paper-2: #e4e1d8;
  --paper-3: #d6d2c6;
  --ink: #18191d;
  --ink-soft: #4a4a4e;
  --muted: #74726b;
  --rule: #cbc7bb;
  --focus: #2b59c3;
  --bad: #b3261e;
  --hl-1: #f6df63;
  --hl-2: #9ddb9a;
  --hl-3: #9ec8f2;
  --hl-4: #c8a8ef;
  --on-hl: #18191d;
  --shadow: 0 1px 0 rgba(24, 25, 29, .08), 0 8px 24px rgba(24, 25, 29, .08);
  --grain-op: .05;

  --f-display: "Gloock", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --f-ui: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --step--1: .8125rem;
  --step-0: 1rem;
  --step-1: 1.1875rem;
  --step-2: 1.5rem;
  --step-4: clamp(2.5rem, 9vw, 3.75rem);
  --col: 34rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #131418; --paper-2: #22242a; --paper-3: #2f323a; --ink: #eceae4; --ink-soft: #c2c0b9;
    --muted: #94928b; --rule: #34363d; --focus: #8fb0ff; --bad: #ff8a80;
    --hl-1: #e3cb52; --hl-2: #84c682; --hl-3: #86b5e3; --hl-4: #b393de; --on-hl: #131418;
    --shadow: 0 1px 0 rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .45); --grain-op: .07;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #131418; --paper-2: #22242a; --paper-3: #2f323a; --ink: #eceae4; --ink-soft: #c2c0b9;
  --muted: #94928b; --rule: #34363d; --focus: #8fb0ff; --bad: #ff8a80;
  --hl-1: #e3cb52; --hl-2: #84c682; --hl-3: #86b5e3; --hl-4: #b393de; --on-hl: #131418;
  --shadow: 0 1px 0 rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .45); --grain-op: .07;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-ui);
  font-size: var(--step-0);
  line-height: 1.5;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0;
  -webkit-tap-highlight-color: transparent;
}
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 50; opacity: var(--grain-op);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.page { max-width: var(--col); margin: 0 auto; padding-block: 12px 40px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- Masthead ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.edition { font-family: var(--f-mono); font-size: var(--step--1); color: var(--muted); letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.icons { display: flex; gap: 4px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; border: 0; background: none; border-radius: 50%;
  cursor: pointer; color: var(--ink);
}
.icon-btn:hover { background: var(--paper-2); }
.icon-btn svg { width: 21px; height: 21px; }

.entry { border-bottom: 1.5px solid var(--ink); padding-bottom: 14px; }
.headword {
  font-family: var(--f-display); font-weight: 400; font-size: var(--step-4); line-height: .95; margin: 0;
  letter-spacing: -.01em;
}
.headword .dot { color: var(--muted); }
.pron { font-family: var(--f-mono); font-size: var(--step--1); color: var(--ink-soft); margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.pron i { font-family: var(--f-display); font-style: italic; font-size: var(--step-0); }
.defn { margin: 6px 0 0; color: var(--ink-soft); max-width: 58ch; }
.defn b { font-weight: 600; color: var(--ink); }

.archive-banner {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  border: 1.5px dashed var(--rule); padding: 10px 12px; border-radius: 6px; font-size: var(--step--1);
}
.archive-banner strong { font-family: var(--f-mono); font-weight: 500; }

/* ---------- Board ---------- */
.board { display: flex; flex-direction: column; gap: 8px; container-type: inline-size; }
.solved { display: flex; flex-direction: column; gap: 8px; }

.found {
  position: relative; padding: 12px 14px 13px; color: var(--on-hl); isolation: isolate;
}
.found::before {
  content: ""; position: absolute; inset: 0; z-index: -1; background: var(--hl);
  border-radius: 3px 10px 4px 12px / 9px 4px 11px 5px;
  transform-origin: left center;
  animation: swipe .55s cubic-bezier(.2, .7, .2, 1) both;
}
.found[data-d="1"] { --hl: var(--hl-1); }
.found[data-d="2"] { --hl: var(--hl-2); }
.found[data-d="3"] { --hl: var(--hl-3); }
.found[data-d="4"] { --hl: var(--hl-4); }
.found.missed::before { opacity: .55; }
@keyframes swipe { from { transform: scaleX(.02); } to { transform: scaleX(1); } }
.found > * { animation: fadeUp .4s .25s both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.found-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.found-cat { font-family: var(--f-display); font-size: var(--step-1); line-height: 1.2; margin: 0; text-wrap: balance; }
.found-tier { font-family: var(--f-mono); font-size: .6875rem; letter-spacing: .1em; text-transform: uppercase; white-space: nowrap; }
.found-words { font-weight: 700; font-stretch: 80%; letter-spacing: .04em; font-size: var(--step--1); margin-top: 2px; }
.found-exp { margin: 8px 0 0; font-size: .9375rem; line-height: 1.5; padding-top: 8px; border-top: 1px solid rgba(24, 25, 29, .2); }

.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tile {
  height: clamp(64px, 19cqi, 88px); min-width: 0; padding: 4px; border: 0; border-radius: 6px;
  background: var(--paper-2); color: var(--ink); cursor: pointer;
  font-family: var(--f-ui); font-weight: 700; text-transform: uppercase; letter-spacing: .02em; line-height: 1.05;
  font-size: clamp(14px, 4.4cqi, 21px); font-stretch: 100%;
  display: grid; place-items: center; text-align: center; overflow-wrap: normal; word-break: normal;
  transition: background-color .15s, color .15s, transform .12s;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.tile[data-len="2"] { font-size: clamp(12px, 3.7cqi, 18px); font-stretch: 87.5%; }
.tile[data-len="3"] { font-size: clamp(11px, 3.1cqi, 16px); font-stretch: 75%; }
.tile[data-len="4"] { font-size: clamp(10px, 2.6cqi, 14px); font-stretch: 62.5%; }
.tile:hover { background: var(--paper-3); }
.tile:active { transform: scale(.97); }
.tile[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.tile.hint { box-shadow: inset 0 0 0 2px var(--ink); background: var(--paper-3); }
.tile.hint[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--paper); background: var(--ink); }
.tile.lift { animation: lift .5s ease both; }
@keyframes lift { 40% { transform: translateY(-6px); } 100% { transform: translateY(0); } }
.tile.shake { animation: shake .42s ease; }
@keyframes shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }

.status { display: flex; justify-content: center; align-items: center; gap: 10px; font-size: var(--step--1); color: var(--ink-soft); min-height: 24px; }
.pips { display: flex; gap: 6px; }
.pip { width: 11px; height: 11px; border-radius: 50%; background: var(--ink); transition: transform .25s, background-color .25s; }
.pip.spent { background: transparent; box-shadow: inset 0 0 0 1.5px var(--rule); transform: scale(.85); }

.controls { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }
.btn {
  border: 1.5px solid var(--ink); background: transparent; color: var(--ink); border-radius: 999px;
  padding: 10px 18px; font-weight: 600; font-size: .9375rem; cursor: pointer; min-height: 44px;
  transition: background-color .15s, color .15s, opacity .15s;
}
.btn:hover { background: var(--paper-2); }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { opacity: .85; background: var(--ink); }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn.primary:disabled:hover { opacity: .35; }

.done-panel { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding-block: 8px; }
.done-panel p { margin: 0; color: var(--ink-soft); }

.foot { border-top: 1px solid var(--rule); padding-top: 12px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-family: var(--f-mono); font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 72px); z-index: 60;
  transform: translate(-50%, -8px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 8px;
  font-weight: 600; font-size: .9375rem; box-shadow: var(--shadow); transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Dialogs ---------- */
dialog {
  border: 0; padding: 0; background: var(--paper); color: var(--ink); border-radius: 12px; box-shadow: var(--shadow);
  width: min(30rem, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
}
dialog::backdrop { background: rgba(10, 10, 12, .55); }
dialog[open] { animation: pop .22s ease both; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.dlg { padding: 22px 22px 24px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; max-height: calc(100dvh - 48px); }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.dlg h2 { font-family: var(--f-display); font-weight: 400; font-size: var(--step-2); line-height: 1.1; margin: 0; text-wrap: balance; }
.dlg h3 { font-family: var(--f-mono); font-weight: 500; font-size: .75rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 0; }
.dlg p, .dlg li { margin: 0; color: var(--ink-soft); }
.dlg ul { margin: 0; padding-left: 1.1em; display: flex; flex-direction: column; gap: 6px; }
.close { margin: -8px -8px 0 0; }

.tiers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.tier { padding: 6px 10px; border-radius: 3px 8px 3px 9px; color: var(--on-hl); font-size: var(--step--1); font-weight: 600; }

.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; text-align: center; }
.stat-num { font-family: var(--f-display); font-size: 2rem; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: .75rem; color: var(--muted); margin-top: 4px; }

.dist { display: flex; flex-direction: column; gap: 5px; }
.dist-row { display: grid; grid-template-columns: 1.6rem 1fr; align-items: center; gap: 8px; font-family: var(--f-mono); font-size: .8125rem; font-variant-numeric: tabular-nums; }
.dist-bar { height: 22px; background: var(--paper-3); border-radius: 3px; min-width: 26px; display: flex; justify-content: flex-end; align-items: center; padding-right: 7px; font-size: .75rem; }
.dist-bar.today { background: var(--ink); color: var(--paper); }

.share-grid { font-size: 1.6rem; line-height: 1.15; letter-spacing: .08em; text-align: center; white-space: pre; }
.share-box { width: 100%; min-height: 120px; font-family: var(--f-mono); font-size: .8125rem; background: var(--paper-2); color: var(--ink); border: 1px solid var(--rule); border-radius: 6px; padding: 8px; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.countdown { text-align: center; font-family: var(--f-mono); font-size: .875rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.countdown strong { display: block; font-size: 1.5rem; font-weight: 500; color: var(--ink); }

.arch-list { list-style: none; padding: 0 !important; margin: 0; display: flex; flex-direction: column; gap: 0 !important; }
.arch-list li { border-top: 1px solid var(--rule); }
.arch-item { width: 100%; display: grid; grid-template-columns: 3.2rem 1fr auto; gap: 10px; align-items: center; padding: 10px 4px; background: none; border: 0; cursor: pointer; text-align: left; font-variant-numeric: tabular-nums; }
.arch-item:hover { background: var(--paper-2); }
.arch-num { font-family: var(--f-mono); font-weight: 500; }
.arch-date { color: var(--ink-soft); font-size: .9375rem; }
.arch-state { font-family: var(--f-mono); font-size: .75rem; color: var(--muted); }

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

@media (max-width: 380px) {
  .grid, .board { gap: 6px; }
  .btn { padding: 9px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
}
