@font-face { font-family: "Elite"; src: url("fonts/SpecialElite-Regular.ttf"); font-display: swap; }
@font-face { font-family: "Bebas"; src: url("fonts/BebasNeue-Regular.ttf"); font-display: swap; }
@font-face { font-family: "DMSerif"; src: url("fonts/DMSerifDisplay-Regular.ttf"); font-display: swap; }

:root {
  --night: #16130f;
  --night-2: #221d17;
  --paper: #efe6d2;
  --paper-2: #e3d6ba;
  --ink: #1d1a16;
  --ink-soft: #5b5246;
  --red: #b3261e;
  --brass: #c9a24a;
  --grid-max: 520px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--night); color: var(--paper); }
body {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px; line-height: 1.45;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
}

.masthead {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 14px 16px 10px; border-bottom: 1px solid #3a3229;
  max-width: 600px; margin: 0 auto;
}
.series { font-family: Bebas, Impact, sans-serif; letter-spacing: .12em; font-size: 20px; color: var(--brass); }
.case-tag { font-family: Elite, monospace; font-size: 13px; color: #a99b84; }

main { max-width: 600px; margin: 0 auto; padding: 12px 12px 40px; }
.screen[hidden] { display: none; }

.paper {
  background: var(--paper); color: var(--ink);
  border-radius: 3px; padding: 18px 18px 16px; position: relative;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  background-image: linear-gradient(transparent 96%, rgba(0,0,0,.03) 96%);
  background-size: 100% 24px;
}
.paper h1 { font-family: DMSerif, Georgia, serif; font-weight: normal; font-size: 28px; line-height: 1.1; margin: 6px 0 12px; }
.stamp {
  display: inline-block; font-family: Elite, monospace; color: var(--red);
  border: 2px solid var(--red); padding: 2px 8px; transform: rotate(-3deg);
  font-size: 14px; letter-spacing: .08em;
}
.stamp.big { font-size: 22px; padding: 4px 12px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 12px; font-size: 14px; }
.facts dt { font-family: Bebas, sans-serif; letter-spacing: .08em; color: var(--ink-soft); font-size: 15px; }
.facts dd { margin: 0; }
.brief { margin: 0 0 12px; }
.card-left { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; background: var(--paper-2); padding: 8px 10px; border-left: 3px solid var(--red); }
.star { color: var(--red); font-size: 18px; line-height: 1; }

.step { font-family: Bebas, Impact, sans-serif; font-weight: normal; letter-spacing: .06em; font-size: 26px; margin: 22px 0 4px; display: flex; align-items: center; gap: 10px; }
.step span { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--red); color: #fff; font-size: 18px; }
.hint { color: #b9ab93; margin: 0 0 12px; font-size: 14px; }

/* Suspect dossiers */
.suspects { display: grid; gap: 10px; }
.suspect {
  text-align: left; width: 100%; border: 2px solid transparent; cursor: pointer;
  background: var(--paper); color: var(--ink); border-radius: 3px; padding: 12px 14px;
  font: inherit; font-size: 14px; position: relative;
}
.suspect .name { font-family: DMSerif, Georgia, serif; font-size: 20px; }
.suspect .role { font-family: Bebas, sans-serif; letter-spacing: .08em; color: var(--ink-soft); font-size: 15px; margin-bottom: 6px; }
.suspect p { margin: 4px 0 0; }
.suspect b { font-family: Bebas, sans-serif; font-weight: normal; letter-spacing: .06em; font-size: 15px; color: var(--red); margin-right: 4px; }
.suspect[aria-pressed="true"] { border-color: var(--red); box-shadow: 0 0 0 3px rgba(179,38,30,.35); }
.suspect[aria-pressed="true"]::after {
  content: "CHOSEN"; position: absolute; top: 10px; right: 10px; font-family: Elite, monospace;
  color: var(--red); border: 2px solid var(--red); padding: 0 6px; transform: rotate(6deg); font-size: 12px;
}

.btn {
  display: block; width: 100%; margin-top: 14px; padding: 14px 16px; border-radius: 3px;
  font-family: Bebas, Impact, sans-serif; letter-spacing: .08em; font-size: 20px;
  border: 2px solid var(--paper); background: transparent; color: var(--paper); cursor: pointer;
}
.btn.primary { background: var(--brass); border-color: var(--brass); color: var(--night); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { border-color: #4a4035; color: #b9ab93; font-size: 17px; padding: 10px; }
.btn.small { width: auto; margin: 0; padding: 6px 12px; font-size: 16px; }
.btn:disabled { opacity: .35; cursor: default; }

.toolbar { display: flex; justify-content: space-between; align-items: center; }
.progress { font-family: Elite, monospace; color: var(--brass); }

/* The grid */
.grid-wrap {
  position: relative; width: min(100%, var(--grid-max)); margin: 0 auto;
  aspect-ratio: 1; background: var(--paper); border-radius: 3px;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  touch-action: none; user-select: none; -webkit-user-select: none;
  container-type: inline-size;
}
.grid, .marks { position: absolute; inset: 2%; width: 96%; height: 96%; }
.grid { display: grid; grid-template-columns: repeat(var(--cols), 1fr); grid-template-rows: repeat(var(--rows), 1fr); }
.cell {
  display: grid; place-items: center; color: var(--ink);
  font-family: "Courier New", Courier, monospace; font-weight: bold;
  font-size: 4.6cqw; transition: color .3s, opacity .3s;
}
.marks { pointer-events: none; overflow: visible; }
.marks line { stroke-linecap: round; }
.mark-found { opacity: .38; }
.mark-live { stroke: var(--red); opacity: .45; }
.mark-bad { stroke: #555; opacity: .4; }
.grid-wrap.decoding .cell { color: rgba(29,26,22,.22); }
.grid-wrap.decoding .cell.left { color: var(--red); }
.cell.left.lit { animation: pop .35s ease-out; }
@keyframes pop { 50% { transform: scale(1.5); } }

.toast { min-height: 24px; text-align: center; font-family: Elite, monospace; color: var(--brass); margin: 8px 0 2px; }

.words { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.words li {
  font-family: "Courier New", monospace; font-weight: bold; font-size: 13px; letter-spacing: .05em;
  padding: 4px 8px; border-radius: 2px; background: var(--night-2); border: 1px solid #3a3229; color: var(--paper);
}
.words li.found { text-decoration: line-through; text-decoration-color: var(--red); text-decoration-thickness: 2px; color: #7c705f; }

/* Decode */
.slots { display: flex; flex-wrap: wrap; gap: 10px 14px; justify-content: center; margin: 6px 0; }
.slot-word { display: flex; gap: 3px; }
.slot {
  width: 22px; height: 30px; border-bottom: 2px solid var(--brass);
  display: grid; place-items: end center; font-family: "Courier New", monospace; font-weight: bold; font-size: 20px; color: var(--paper);
}
.slot.filled { animation: drop .25s ease-out; }
@keyframes drop { from { transform: translateY(-10px); opacity: 0; } }

.evidence-card { background: var(--paper); color: var(--ink); padding: 14px 16px; border-radius: 3px; border-left: 4px solid var(--red); margin-bottom: 12px; }
.evidence-card .label { font-family: Bebas, sans-serif; letter-spacing: .1em; color: var(--ink-soft); }
.evidence { font-family: Elite, monospace; font-size: 22px; color: var(--red); }

.verdict h1 { margin-top: 14px; }
.deduction { background: var(--paper-2); padding: 10px 12px; border-left: 3px solid var(--ink); font-size: 15px; }
.score { font-family: Elite, monospace; font-size: 15px; }

dialog { border: none; padding: 0; background: var(--night); color: var(--paper); width: min(600px, 94vw); max-height: 88dvh; border-radius: 4px; }
dialog::backdrop { background: rgba(0,0,0,.7); }
.dialog-body { padding: 12px; overflow: auto; }
dialog form { padding: 0 12px 12px; position: sticky; bottom: 0; background: var(--night); }

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