/* Kenspeck — "The Interlinear" visual direction (design_handoff_interlinear).
   The game is set like a bilingual dictionary: interlinear gloss pairs with the
   foreign original redacted during play, rubricated sense numbers, a blue gloss
   rule as the only structural accent. Palette and scale come from the handoff's
   token table; dark mode derives per its notes (contained sheet on a near-black
   ground). */

/* Self-hosted Newsreader (Latin subsets, wght 400–600, opsz pinned 22/13).
   The ext files cover romanisations (ō, ū, ś…) and download only when used.
   Non-Latin originals (火山, תפוז…) intentionally fall through to the system
   serif stack — standard bilingual-dictionary typography. */
@font-face {
  font-family: "Newsreader";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("fonts/newsreader-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+2013-2014, U+2018-201F, U+2026;
}
@font-face {
  font-family: "Newsreader";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("fonts/newsreader-ext.woff2") format("woff2");
  unicode-range: U+0100-024F;
}
@font-face {
  font-family: "Newsreader";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/newsreader-italic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+2013-2014, U+2018-201F, U+2026;
}
@font-face {
  font-family: "Newsreader";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/newsreader-italic-ext.woff2") format("woff2");
  unicode-range: U+0100-024F;
}

:root {
  --paper: #F4F1E8;
  --paper-input: #FCFBF6;
  --ink: #23201A;
  --ink-soft: #5A5344;
  --rubric: #B23A2E;
  --gloss-blue: #2C4A6E;
  --pencil: #8A7E68;
  --pending: #B9B0A0;
  --redact: #C9C1AE;
  --hairline: #D9D3C4;
  --hairline-soft: #E4DECF;
  --input-border: #C4BBA6;
  --wash: color-mix(in srgb, var(--pencil) 12%, transparent);
  --serif: "Newsreader", ui-serif, "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Theme is a user choice (header toggle), not an OS preference: light unless
   the html element carries data-theme="dark". A head script applies the stored
   choice before first paint; with no script the page is simply light. */
:root { color-scheme: light; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0E1116;        /* the ground */
  --sheet: #1B212B;        /* the play column sits on this as a contained card */
  --paper-input: #161C24;
  --ink: #F1EFE9;
  --ink-soft: #B8B0A2;
  --rubric: #E4754F;
  --gloss-blue: #8FAECE;
  --pencil: #98A2B3;
  --pending: #5A626E;
  --redact: #2A313C;
  --hairline: #2A313C;
  --hairline-soft: #232A34;
  --input-border: #3A4350;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win, even over display:flex/grid rules
   that would otherwise override the UA [hidden] default. */
[hidden] { display: none !important; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--gloss-blue);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ---------- the sheet ----------
   Light mode: invisible — the paper fills the viewport and the column floats
   on it. Dark mode: the column becomes a contained, bordered sheet on the
   ground so nothing floats unanchored (an explicit handoff requirement). */

.sheet { max-width: 33rem; margin: 0 auto; }

:root[data-theme="dark"] .sheet {
  background: var(--sheet);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  margin-top: 16px;
  margin-bottom: 8px;
}

@media (max-width: 34rem) {
  :root[data-theme="dark"] .sheet { margin: 8px 6px; }
}

/* ---------- header ---------- */

.site-header { padding: 20px 24px 0; }

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

/* A small tracked logotype — a running head, not a headline. It must never
   compete with the 30px glosses or the 44px answer headword. */
.wordmark {
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--rubric);
}

/* The wordmark is a button (opens the About/definition), styled as plain text. */
.wordmark-btn {
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
}

.wordmark-btn:hover { text-decoration: underline; text-underline-offset: 4px; }

.pron-line {
  margin: 4px 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 12px;
  color: var(--pencil);
}

.header-buttons { display: flex; gap: 14px; align-items: center; }

.header-buttons button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  padding: 4px;
  color: var(--pencil);
  cursor: pointer;
}

#help-btn { font-family: var(--serif); font-size: 18px; line-height: 1; }

.header-buttons button:hover { color: var(--gloss-blue); }

/* The theme toggle shows the mode you'd switch to: moon in light, sun in dark. */
#theme-btn .icon-sun { display: none; }
:root[data-theme="dark"] #theme-btn .icon-moon { display: none; }
:root[data-theme="dark"] #theme-btn .icon-sun { display: block; }

.header-rule { height: 2px; background: var(--ink); margin-top: 12px; }

/* ---------- layout ---------- */

main { padding: 8px 24px 24px; }

/* ---------- the interlinear entries ---------- */

.clue-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.entry {
  padding: 16px 0;
  border-bottom: 1px solid var(--hairline);
}

.entry-head {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

/* Rubricated sense numbers — the manuscript nod. */
.sense {
  font-family: var(--serif);
  font-size: 14px;
  color: var(--rubric);
}

.lang {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--pencil);
}

/* The redaction: the original word drawn as bars — present, but unreadable
   until the game ends. */
.redaction {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

.bar {
  display: inline-block;
  height: 16px;
  background: var(--redact);
  border-radius: 2px;
}

.bar-s { width: 34px; }
.bar-m { width: 52px; }
.bar-l { width: 72px; }

.gloss {
  margin: 6px 0 0;
  font-family: var(--serif);
  font-size: clamp(26px, 7vw, 30px);
  font-weight: 500;
  line-height: 1.05;
  color: var(--ink);
  text-wrap: balance;
}

/* Signature: the blue gloss rule beneath each revealed literal. */
.gloss-rule {
  width: 52px;
  height: 2px;
  margin-top: 9px;
  background: var(--gloss-blue);
}

/* Pending rounds keep the entry shape visible without shouting. */
.entry.pending {
  padding: 15px 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.entry.pending .sense { color: var(--pending); }

.pending-note {
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  color: var(--pending);
}

/* End state: the redaction lifts and each entry completes as a dictionary
   pair — original above, gloss beneath in the small italic. */
.clue-list.over { border-top: 1px solid var(--hairline); margin-top: 18px; }

.entry-over {
  padding: 12px 0;
  border-bottom: 1px solid var(--hairline-soft);
}

.entry-over .sense { font-size: 13px; }

.original {
  margin: 5px 0 0;
  font-family: var(--serif);
  font-size: 23px;
  color: var(--ink);
}

.entry-over .gloss-small {
  margin: 1px 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: var(--pencil);
}

/* The one orchestrated motion moment: the entry reveal. */
@keyframes entry-in {
  from { opacity: 0; transform: translateY(-14px); }
  to   { opacity: 1; transform: none; }
}

@keyframes gloss-in {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

@keyframes fade-in {
  from { opacity: 0; }
}

.just-revealed { animation: entry-in 0.45s cubic-bezier(0.2, 0.7, 0.25, 1); }

.just-revealed .gloss-rule {
  transform-origin: left;
  animation: gloss-in 0.5s 0.25s cubic-bezier(0.2, 0.7, 0.25, 1) backwards;
}

/* The redaction lift is a brief settle, not a production number. */
.entry-over { animation: fade-in 0.3s ease-out; }

/* ---------- input row ---------- */

#guess-form { margin-top: 20px; }

.inline-msg {
  margin: 0 0 6px;
  min-height: 1.4em;
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: var(--rubric);
}

.input-row { display: flex; gap: 8px; }

#guess-input {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  font: 16px var(--serif);
  color: var(--ink);
  background: var(--paper-input);
  border: 1.5px solid var(--input-border);
  border-radius: 3px;
}

#guess-input:focus-visible { outline-offset: 0; border-color: var(--gloss-blue); }

#guess-input::placeholder { color: var(--pencil); opacity: 0.8; }

@keyframes shake-kf {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-3px); }
  40%, 60% { transform: translateX(3px); }
}

.shake { animation: shake-kf 0.3s; }

button.primary, button.secondary {
  font: 600 15px var(--sans);
  border-radius: 3px;
  padding: 11px 18px;
  cursor: pointer;
}

/* Rubric red is the single warm accent — the primary act of the game. */
button.primary {
  background: var(--rubric);
  color: #F4F1E8;
  border: 1.5px solid var(--rubric);
}

:root[data-theme="dark"] button.primary { color: #0E1116; }

/* Blue is structure: the round-advancing secondary action. */
button.secondary {
  background: none;
  color: var(--gloss-blue);
  border: 1.5px solid var(--gloss-blue);
}

button.skip {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 13px;
}

.guess-history {
  margin: 12px 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: var(--pencil);
  overflow-wrap: anywhere;
}

/* ---------- end state: the finished dictionary entry ---------- */

#end-panel { padding-top: 16px; }

.headword {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(36px, 10vw, 44px);
  font-weight: 600;
  line-height: 1;
  color: var(--ink);
}

.headnote {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 17px;
  color: var(--pencil);
  margin-left: 10px;
  /* An atomic inline: the line may break before it (even with no literal
     space between the spans), never inside it — "solved first try" drops
     whole or not at all. */
  display: inline-block;
  white-space: nowrap;
}

.headnote.lost { color: var(--rubric); }

.fact {
  margin: 10px 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 15.5px;
  line-height: 1.5;
  color: var(--ink-soft);
}

/* Share is the primary act at end state — set in ink, not rubric. */
button.share {
  display: block;
  width: 100%;
  margin-top: 18px;
  background: var(--ink);
  color: var(--paper);
  border: 1.5px solid var(--ink);
}

.snapshot {
  margin: 12px 0 0;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: var(--pencil);
}

.countdown {
  margin: 2px 0 0;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--pencil);
}

#play-today { display: block; width: 100%; margin-top: 12px; }

/* ---------- banner, catch-up bar, screens ---------- */

.banner {
  border: 1.5px solid var(--gloss-blue);
  border-radius: 3px;
  padding: 14px 16px;
  margin: 14px 0;
}

.banner p { margin: 0 0 10px; font-family: var(--serif); font-weight: 500; font-size: 18px; }

.banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.catchup-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 0;
}

.link-btn {
  background: none;
  border: none;
  padding: 4px 0;
  font: 600 15px var(--sans);
  color: var(--gloss-blue);
  cursor: pointer;
}

.catchup-tag {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--pencil);
  border: 1px solid var(--hairline);
  border-radius: 2px;
  padding: 3px 8px;
}

.screen { text-align: center; padding: 44px 0; }

.screen h2 {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 10px;
}

.screen p {
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink-soft);
  margin: 0 0 18px;
}

.notify-form { max-width: 400px; margin: 0 auto; }

#notify-email {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  font: 16px var(--serif);
  color: var(--ink);
  background: var(--paper-input);
  border: 1.5px solid var(--input-border);
  border-radius: 3px;
}

#notify-email:focus-visible { outline-offset: 0; border-color: var(--gloss-blue); }

#notify-email::placeholder { color: var(--pencil); opacity: 0.8; }

.notify-form p {
  min-height: 1.3em;
  margin: 10px 0 0;
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink-soft);
}

/* ---------- dialogs ---------- */

dialog {
  width: min(26rem, calc(100vw - 32px));
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  padding: 22px 20px;
  box-shadow: 0 8px 40px rgba(10, 15, 25, 0.3);
}

:root[data-theme="dark"] dialog { background: var(--sheet); }

dialog::backdrop { background: rgba(14, 12, 8, 0.45); }

dialog h2 {
  margin: 0 0 10px;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
}

dialog p { margin: 0 0 16px; }

/* About / definition modal — set like the dictionary entry it quotes. */
.about-headword {
  margin: 0;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 600;
}

.about-pron {
  margin: 4px 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: var(--pencil);
}

.about-pos {
  margin: 10px 0 0;
  font-size: 13px;
  font-style: italic;
  color: var(--pencil);
}

.about-def {
  margin: 6px 0 0;
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.3;
}

.about-note {
  margin: 16px 0 18px;
  font-size: 14px;
  color: var(--pencil);
}

/* The colophon: who stands behind the corpus. */
.about-credit {
  margin: 0 0 18px;
  padding-top: 14px;
  border-top: 1px solid var(--hairline);
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  line-height: 1.5;
  color: var(--pencil);
}

/* The network's name sits upright inside the italic run, dictionary-style. */
.about-credit a { color: var(--gloss-blue); font-style: normal; }

/* The "Do you Kenspeck?" sign-off. */
.help-signoff {
  font-family: var(--serif);
  font-size: 19px;
  color: var(--rubric);
}
.help-signoff em { font-style: italic; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 16px;
  text-align: center;
}

.stat-grid strong {
  display: block;
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 600;
}

.stat-grid span { font-size: 12px; color: var(--pencil); }

.dist-title, .section-title {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--pencil);
}

.section-title { margin-bottom: 6px; }

.dist-list {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.dist-list li { display: flex; align-items: center; gap: 8px; }

.dist-label {
  width: 1.2em;
  font-family: var(--serif);
  font-weight: 600;
  color: var(--rubric);
  text-align: center;
}

.dist-bar {
  display: inline-block;
  background: var(--gloss-blue);
  color: var(--paper);
  font-size: 12px;
  font-weight: 600;
  border-radius: 2px;
  padding: 2px 7px;
  text-align: right;
  min-width: 1.4em;
}

:root[data-theme="dark"] .dist-bar { color: #0E1116; }

/* ---------- stats modal sections: catch-up + sync ---------- */

.modal-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
}

.section-note {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--pencil);
}

button.quiet {
  font: 600 13px var(--sans);
  color: var(--gloss-blue);
  background: none;
  border: 1px solid var(--gloss-blue);
  border-radius: 3px;
  padding: 5px 12px;
  cursor: pointer;
}

.catchup-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.catchup-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--wash);
  border-radius: 3px;
  padding: 7px 12px;
}

.catchup-num { font-family: var(--serif); font-size: 17px; min-width: 2.4em; }

.catchup-score {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--pencil);
  margin-left: auto;
}

.catchup-row .quiet { margin-left: auto; }
.catchup-row .catchup-score + .quiet { margin-left: 0; }

.code-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }

.code-row input {
  flex: 1;
  min-width: 0;
  text-transform: uppercase;
  padding: 8px 12px;
  font: 15px var(--sans);
  color: var(--ink);
  background: var(--paper-input);
  border: 1.5px solid var(--input-border);
  border-radius: 3px;
}

.sync-code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 20px;
  letter-spacing: 0.12em;
  color: var(--gloss-blue);
  background: var(--wash);
  border-radius: 3px;
  padding: 8px 12px;
  flex: 1;
}

.sync-msg { margin: 6px 0 0; font-size: 13px; color: var(--pencil); min-height: 1.2em; }

/* ---------- footer ---------- */

.site-footer {
  max-width: 33rem;
  margin: 0 auto;
  padding: 10px 24px 28px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  justify-content: center;
  font-size: 12px;
  color: var(--pencil);
}

.site-footer > * { white-space: nowrap; }

.site-footer a { color: var(--pencil); text-decoration: none; }
.site-footer a:hover { color: var(--gloss-blue); text-decoration: underline; }

/* "Get the app" — a button dressed as a footer link, slightly emphasised. */
.footer-link {
  font: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--gloss-blue);
  font-weight: 600;
}
.footer-link:hover { text-decoration: underline; }

.install-intro { margin: 0 0 10px; }

.install-steps {
  margin: 0 0 12px;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ios-share {
  vertical-align: -3px;
  margin: 0 2px;
  color: var(--gloss-blue);
}

/* ---------- legal pages (terms, privacy) ---------- */

.legal {
  max-width: 42rem;
  margin: 0 auto;
  padding: 24px;
  line-height: 1.6;
}

.legal h1 { font-family: var(--serif); font-size: 30px; font-weight: 600; margin: 8px 0 4px; }
.legal h2 { font-family: var(--serif); font-size: 19px; font-weight: 600; margin: 26px 0 6px; color: var(--ink); }
.legal p, .legal li { color: var(--ink); }
.legal .legal-meta { color: var(--pencil); font-size: 14px; margin-bottom: 20px; }
.legal .legal-back { font-size: 14px; }
.legal .legal-back a { color: var(--gloss-blue); text-decoration: none; }
.legal .legal-back a:hover { text-decoration: underline; }
.legal ul { padding-left: 20px; }
.legal li { margin-bottom: 6px; }
.legal a { color: var(--gloss-blue); }

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .just-revealed { animation: fade-in 0.3s; }
  .just-revealed .gloss-rule { animation: none; }
  .entry-over { animation: none; }
  .shake { animation: none; }
}
