/* Silhouette — reading-room palette. The film on its backlit viewbox is the one bold element. */

:root {
  color-scheme: dark;
  --room: #161d27;
  --panel: #1f2834;
  --line: #33404f;
  --ink: #e3e8ee;
  --muted: #93a0af;
  --glow: #eef2f5;
  --match: #3fb68b;
  --match-ink: #06140e;
  --partial: #e7b53c;
  --partial-ink: #1d1503;
  --none: #46515f;
  --none-ink: #e3e8ee;
  --focus: #8cc8ff;
  --warn-text: var(--partial);
  --miss: #ff7b72;

  --font: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.75rem;
  --radius-s: 6px;
  --radius-m: 10px;
  --col: min(100% - 2rem, 34rem);

  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --room: #e9edf1;
    --panel: #f7f9fb;
    --line: #c9d1da;
    --ink: #18212b;
    --muted: #56616e;
    --glow: #ffffff;
    --match: #1d7556;
    --match-ink: #ffffff;
    --partial: #d9a422;
    --partial-ink: #1d1503;
    --none: #d3d9e0;
    --none-ink: #2a333d;
    --focus: #1769c2;
    --warn-text: #8a5a00;
    --miss: #c42b2b;
  }
}

*, *::before, *::after { box-sizing: inherit; }

html { scroll-padding-top: env(safe-area-inset-top, 0px); }

body {
  margin: 0;
  background: var(--room);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 1rem; top: 1rem; z-index: 20; background: var(--panel); padding: .5rem .75rem; }

/* ---------- Header ---------- */

.top {
  width: var(--col);
  margin: 0 auto;
  padding: 1rem 0 .75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand { display: flex; align-items: center; gap: .75rem; }
.wordmark {
  margin: 0;
  font-size: var(--step-2);
  font-weight: 800;
  font-stretch: 125%;
  font-variation-settings: "wdth" 125;
  letter-spacing: -0.02em;
  line-height: 1;
}

/* Lead side-marker tile, borrowed from the R/L markers burned into real films. */
.marker[hidden] { display: none; }
.marker {
  display: inline-grid;
  place-items: center;
  min-width: 2.1rem;
  height: 2.1rem;
  padding: 0 .4rem;
  border-radius: var(--radius-s);
  background: var(--glow);
  color: #161d27;
  font-weight: 800;
  font-size: var(--step--1);
  font-variation-settings: "wdth" 100;
  box-shadow: inset 0 0 0 2px rgba(22, 29, 39, .15);
}

.tools { display: flex; gap: .25rem; }
.icon-btn {
  width: 2.75rem; height: 2.75rem;
  display: grid; place-items: center;
  background: none; border: 0; border-radius: 50%;
  color: var(--muted);
}
.icon-btn:hover { color: var(--ink); background: var(--panel); }
.icon-btn svg { width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .dot { fill: currentColor; }

.dev-banner {
  width: var(--col); margin: 0 auto .75rem;
  padding: .5rem .75rem;
  border: 1px dashed var(--partial);
  border-radius: var(--radius-s);
  color: var(--muted);
  font-size: var(--step--1);
  display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center;
}
.dev-banner[hidden] { display: none; }
.dev-banner button { background: none; border: 1px solid var(--line); border-radius: var(--radius-s); padding: .15rem .5rem; }

/* ---------- Layout ---------- */

.app { width: var(--col); margin: 0 auto; display: grid; gap: 1.25rem; }

.section-title {
  margin: 0;
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .01em;
}

/* ---------- Film ---------- */

.viewer { display: grid; }
.film {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 0;
  border-radius: var(--radius-m);
  background: #000;
  overflow: hidden;
  /* The backlit viewbox: a pale glowing frame around the film. */
  box-shadow:
    0 0 0 6px var(--glow),
    0 0 0 7px var(--line),
    0 0 36px 6px color-mix(in srgb, var(--glow) 28%, transparent);
  cursor: zoom-in;
}
.film img { width: 100%; height: 100%; object-fit: contain; display: block; }
.film .overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.overlay rect {
  fill: none;
  stroke: var(--partial);
  stroke-width: 6;
  vector-effect: non-scaling-stroke;
  stroke-dasharray: 10 6;
}
.film:focus-visible { outline-offset: 10px; }

/* ---------- Hints ---------- */

.hints { display: grid; gap: .5rem; }
.hints-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.hints-head .text-btn { text-align: right; }
.text-btn {
  background: none; border: 0; padding: .25rem 0;
  color: var(--ink); font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
}
.text-btn:disabled { color: var(--muted); text-decoration: none; cursor: default; }
.hint-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.hint-list:empty { display: none; }
.hint {
  display: flex; gap: .75rem; align-items: center;
  padding: .6rem .75rem;
  background: var(--panel);
  border-radius: var(--radius-s);
}
.hint .marker { flex: none; }
.hint-zoom {
  flex: none;
  width: 6rem; height: 6rem;
  border-radius: var(--radius-s);
  background-color: #000;
  background-repeat: no-repeat;
}

/* ---------- Board ---------- */

.board-wrap { display: grid; gap: .4rem; }
.board-head, .row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) repeat(3, minmax(0, 1fr));
  gap: .35rem;
}
.board-head { font-size: var(--step--1); color: var(--muted); padding: 0 .1rem; }
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.row { min-height: 3.5rem; }
.row.empty {
  grid-template-columns: 1fr;
  border: 1px dashed var(--line);
  border-radius: var(--radius-s);
}
.row-guess {
  display: flex; align-items: center;
  padding: .35rem .5rem;
  font-weight: 650;
  font-size: .875rem;
  line-height: 1.2;
  hyphens: auto;
}
.row-label { min-width: 0; overflow-wrap: anywhere; hyphens: auto; }
.row.correct .row-guess { color: var(--match); }
.row.wrong .row-guess { color: var(--miss); }
.row-mark { margin-right: .25rem; font-weight: 800; flex: none; }

.chip {
  display: flex; flex-direction: column; justify-content: center; gap: .1rem;
  padding: .35rem .45rem;
  border-radius: var(--radius-s);
  font-size: .75rem;
  line-height: 1.15;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.chip .sym { font-size: 1rem; font-weight: 800; line-height: 1; }
.chip.match { background: var(--match); color: var(--match-ink); }
.chip.partial { background: var(--partial); color: var(--partial-ink); }
.chip.none { background: var(--none); color: var(--none-ink); }

.row.fresh .chip { animation: flip .45s ease both; }
.row.fresh .chip:nth-child(3) { animation-delay: .12s; }
.row.fresh .chip:nth-child(4) { animation-delay: .24s; }
@keyframes flip {
  from { transform: rotateX(90deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---------- Guess input ---------- */

.guess { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
.guess[hidden], .hints[hidden] { display: none; }
.combo { position: relative; }
.combo input {
  width: 100%;
  height: 3rem;
  padding: 0 .9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--panel);
  font-size: 1rem; /* 16px keeps iOS from zooming on focus */
}
.combo input::placeholder { color: var(--muted); }
.combo input:disabled { opacity: .5; }

.suggestions {
  position: absolute;
  left: 0; right: 0; bottom: calc(100% + .35rem);
  z-index: 5;
  margin: 0; padding: .25rem;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  max-height: 16rem;
  overflow-y: auto;
}
.suggestions li {
  padding: .6rem .7rem;
  border-radius: 4px;
  cursor: pointer;
  display: flex; justify-content: space-between; gap: .75rem;
}
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--line); }
.suggestions .matched { color: var(--muted); font-size: var(--step--1); white-space: nowrap; }

.primary-btn, .secondary-btn {
  min-height: 3rem;
  padding: 0 1.25rem;
  border-radius: var(--radius-s);
  font-weight: 700;
}
.primary-btn { background: var(--ink); color: var(--room); border: 0; }
.primary-btn:disabled { opacity: .4; cursor: default; }
.secondary-btn { background: none; color: var(--ink); border: 1px solid var(--line); }

.form-msg { grid-column: 1 / -1; margin: 0; min-height: 1.5em; font-size: var(--step--1); color: var(--warn-text); }

/* ---------- Result ---------- */

.result {
  display: grid; gap: .6rem;
  padding: 1.25rem;
  background: var(--panel);
  border-radius: var(--radius-m);
}
.result[hidden] { display: none; }
.verdict { margin: 0; color: var(--muted); font-weight: 600; }
.answer {
  margin: 0;
  font-size: var(--step-2);
  font-weight: 800;
  font-variation-settings: "wdth" 112;
  line-height: 1.1;
}
.draft-flag {
  justify-self: start;
  margin: 0;
  padding: .15rem .55rem;
  border: 1px solid var(--partial);
  border-radius: 999px;
  color: var(--partial);
  font-size: var(--step--1);
  font-weight: 600;
}
.secondary { margin: 0; color: var(--muted); }
.teaching { margin: 0 0 .25rem; max-width: 65ch; }
.signs { margin: 0; padding-left: 1.2rem; display: grid; gap: .25rem; }
.result-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.countdown { margin: .25rem 0 0; color: var(--muted); font-size: var(--step--1); }
#countdown { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }

/* ---------- Footer, toast ---------- */

.foot {
  width: var(--col);
  margin: 2rem auto 1.5rem;
  color: var(--muted);
  font-size: var(--step--1);
}
.toast {
  position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  padding: .6rem 1rem;
  background: var(--ink); color: var(--room);
  border-radius: var(--radius-s);
  font-weight: 600;
  z-index: 30;
}

/* ---------- Dialogs ---------- */

.sheet {
  width: min(100% - 1.5rem, 30rem);
  max-height: calc(100% - 2rem);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--panel);
  color: var(--ink);
}
.sheet::backdrop { background: rgba(5, 8, 12, .6); }
.sheet-body { padding: 1.5rem; display: grid; gap: .75rem; }
.sheet h2 { margin: 0; font-size: var(--step-1); font-weight: 800; }
.sheet p { margin: 0; }
.sheet form { margin-top: .5rem; }
.sheet form button { width: 100%; }
.fine { color: var(--muted); font-size: var(--step--1); }
.fine a { color: inherit; }

.traits { margin: 0; display: grid; gap: .15rem; }
.traits dd + dt { margin-top: .4rem; }
.traits dt { font-weight: 700; }
.traits dd { margin: 0; color: var(--muted); }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.legend li { display: flex; align-items: center; gap: .6rem; color: var(--muted); }
.legend .chip { flex-direction: row; gap: .35rem; align-items: center; min-width: 6.5rem; }

.stat-grid { margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; text-align: center; }
.stat-grid div { display: flex; flex-direction: column-reverse; }
.stat-grid dt { font-size: .75rem; color: var(--muted); line-height: 1.2; }
.stat-grid dd { margin: 0; font-size: var(--step-2); font-weight: 800; line-height: 1.1; }

.dist { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }
.dist li { display: grid; grid-template-columns: 1rem 1fr; gap: .5rem; align-items: center; font-size: var(--step--1); }
.dist .bar {
  min-width: 1.75rem;
  padding: .1rem .5rem;
  background: var(--none); color: var(--none-ink);
  border-radius: 4px;
  text-align: right;
  font-weight: 700;
}
.dist .bar.today { background: var(--match); color: var(--match-ink); }

.lightbox {
  width: 100%; height: 100%; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0;
  background: #000;
}
.lightbox::backdrop { background: #000; }
.lightbox img { width: 100%; height: 100%; object-fit: contain; display: block; }
.lightbox-close {
  position: fixed;
  top: calc(.75rem + env(safe-area-inset-top, 0px)); right: .75rem;
  width: 2.75rem; height: 2.75rem;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .15); color: #fff;
  font-size: 1.1rem;
}

/* ---------- Small screens, motion ---------- */

@media (max-width: 380px) {
  .chip { font-size: .6875rem; padding: .3rem; }
  .row-guess { font-size: .75rem; padding: .35rem .3rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
