/* Shared look for all pages: Christmas noir. A dark wooden desk, brass, wine and pine,
   and the navy ink of the case's official documents. */
:root {
  --bg: #0b0907;
  --bg-raise: #17120e;
  --panel: #1e1813;
  --line: rgba(236, 220, 186, 0.14);
  --text: #ede4d1;
  --muted: #a5987f;
  --brass: #c9a35b;
  --brass-hi: #f0d79c;
  --brass-lo: #6f5527;
  --wine: #7a1626;
  --wine-hi: #d0414f;
  --wine-lo: #3a0811;
  --pine: #1c3a2d;
  --pine-hi: #3f7a5f;
  /* The engine's "blood" accents are wine in this case: nobody bleeds, someone was poisoned. */
  --blood: #8e1a2b;
  --blood-hi: #d0414f;
  --paper: #efe6d0;
  --paper-dark: #ddcfae;
  --ink: #2a2119;
  --ok: #57c27a;
  --ink-blue: #1f2c78;
  --stamp-blue: #253a86;
  --navy: #1b2c63;
  --navy-band: #d8e6f4;
  /* Each edition loads the fonts it needs in its pages' <head>; these stacks use whichever is there. */
  --font-ui: 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-doc: 'Tinos', 'Times New Roman', Times, serif;
  --font-hand: 'Caveat', 'Segoe Script', cursive;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-card: 'Cormorant Garamond', 'Tinos', Georgia, serif;
  --font-type: 'Special Elite', 'Courier New', monospace;
  --font-lcd: 'Share Tech Mono', ui-monospace, monospace;
  --gutter: 16px;
  /* Patchy-ink mask for rubber stamps. */
  --grunge: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.09 .45' numOctaves='3' seed='4'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -3.4 2.6'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
}

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

html { -webkit-text-size-adjust: 100%; }
html.no-scroll, html.no-scroll body { overflow: hidden; }

body {
  margin: 0;
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.75;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* The detective's dark wooden desk under every page, lit from above. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(60, 38, 20, 0.35) 0%, rgba(8, 6, 4, 0) 60%),
    radial-gradient(140% 100% at 50% 40%, rgba(8, 6, 4, 0.55) 30%, rgba(5, 4, 3, 0.92) 100%),
    url('../assets/img/tex/wood.jpg') center / cover,
    var(--bg);
}

/* Film grain over everything (never blocks touches). */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2000;
  opacity: 0.06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, [tabindex]:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--brass-hi); outline-offset: 3px; }
img { max-width: 100%; }
[hidden], .hidden { display: none !important; }

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

/* ---------- Top strip ---------- */
.case-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) var(--gutter) 10px;
  font-size: 12.5px;
  color: var(--muted);
  position: relative;
  z-index: 900;
}
.case-bar .badge {
  flex: none;
  white-space: nowrap;
  border: 1px solid var(--brass-lo);
  color: var(--brass);
  border-radius: 4px;
  padding: 1px 9px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.case-bar > span:not(.badge) { margin-inline-start: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Desk button ---------- */
.desk-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(20, 15, 11, 0.6);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 700;
  text-decoration: none;
}
.desk-btn svg { width: 15px; height: 15px; fill: none; stroke: var(--brass); stroke-width: 1.6; }
.desk-btn:active { border-color: var(--brass-lo); }

/* The smallest phones: the case name and the desk button are enough in the top bar. */
@media (max-width: 359px) {
  .case-bar > span:not(.badge) { display: none; }
  .case-bar .desk-btn { margin-inline-start: auto; }
}

/* ---------- Section titles shared by the tool pages ---------- */
.scene-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(21px, 6vw, 26px);
  font-weight: 800;
  line-height: 1.25;
  color: var(--brass-hi);
  text-align: center;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.8);
}
.scene-sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; line-height: 1.6; text-align: center; }

/* ---------- Police form on paper (verdict sheet, detective's desk) ---------- */
.sheet {
  position: relative;
  width: min(100%, 540px);
  padding: 28px 22px 24px;
  border-radius: 4px;
  color: var(--ink);
  background: url('../assets/img/tex/paper.jpg') center / cover;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.6);
  animation: sheetIn 0.5s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes sheetIn { from { opacity: 0; transform: translateY(16px); } }

/* Letterhead: crest, office, unit, then the file line. */
.sheet-head { text-align: center; margin-bottom: 22px; }
.sh-crest { width: 70px; margin: 0 auto 4px; color: var(--navy); }
.sh-crest > svg, .sh-crest > img { display: block; width: 100%; height: auto; }
.sh-dept {
  margin: 0;
  font-family: var(--font-doc);
  font-size: clamp(13px, 3.8vw, 18px);
  font-weight: 700;
  line-height: 1.3;
  color: #111a3a;
  text-transform: uppercase;
}
.sh-unit { margin: 1px 0 0; font-family: var(--font-doc); font-size: 14.5px; font-style: italic; color: #2a2119; }
.sh-rule {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  padding-top: 5px;
  border-top: 1.5px solid var(--navy);
  font-family: var(--font-doc);
  font-size: 14px;
  color: #111;
}
.sheet-stamp { width: 92px; flex: none; }

/* ---------- Official-document parts (crest, ink stamp, signature) ---------- */
.ink-stamp { display: block; width: 100%; height: auto; color: var(--stamp-blue); opacity: 0.82; transform: rotate(-11deg); mix-blend-mode: multiply; overflow: visible; }
.ink-stamp.is-image { opacity: 0.92; transform: none; }
.ink-stamp-text { font: 700 17px var(--font-ui); }
.signature {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  color: var(--ink-blue);
  font-family: var(--font-hand);
  line-height: 1.2;
  transform: rotate(-6deg);
}
.signature svg { width: 2.4em; height: auto; margin-top: -0.35em; }
.signature.is-image { display: block; height: auto; transform: none; }

/* ---------- Buttons ---------- */
.btn-brass {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-height: 52px;
  padding: 0 30px;
  border-radius: 999px;
  background: linear-gradient(180deg, #f5dfa6 0%, #cfa95e 45%, #8f6d2f 100%);
  color: #22180c;
  font-weight: 800;
  font-size: 17px;
  text-decoration: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    inset 0 -2px 0 rgba(0, 0, 0, 0.25),
    0 10px 26px rgba(201, 163, 91, 0.22);
  transition: transform 0.12s ease, filter 0.2s;
}
.btn-brass:active { transform: translateY(1px) scale(0.98); filter: brightness(0.95); }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  min-height: 44px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
  font-size: 14.5px;
  font-weight: 700;
}
.btn-ghost:active { background: rgba(255, 255, 255, 0.08); }

/* ---------- Rubber stamp ---------- */
.stamp {
  display: inline-block;
  color: var(--blood-hi);
  border: 3px double currentColor;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 900;
  letter-spacing: 0.06em;
  transform: rotate(-7deg);
  opacity: 0.88;
  text-shadow: 0 0 1px currentColor;
}

/* ---------- Feedback ---------- */
.shake { animation: shake 0.45s cubic-bezier(.36, .07, .19, .97); }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 30px);
  opacity: 0;
  z-index: 1500;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(30, 24, 19, 0.96);
  border: 1px solid var(--brass-lo);
  color: var(--brass-hi);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  transition: transform 0.35s ease, opacity 0.35s ease;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- Viewer (documents & photos) ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  background: rgba(6, 5, 4, 0.96);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.viewer.open { opacity: 1; pointer-events: auto; }
.viewer-top, .viewer-bottom {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px var(--gutter);
  position: relative;
  z-index: 2;
}
.viewer-top { padding-top: max(10px, env(safe-area-inset-top)); }
.viewer-bottom { justify-content: center; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
.viewer-title { flex: 1; text-align: center; font-weight: 700; font-size: 15px; line-height: 1.4; }
.viewer-count { min-width: 44px; text-align: end; color: var(--muted); font-size: 14px; }
.viewer-tip { font-size: 12px; color: var(--muted); text-align: center; flex: 0 1 auto; }
.viewer-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.viewer-btn:disabled { opacity: 0.25; }
.viewer-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;
  display: grid;
  place-items: center;
}
/* No will-change here: drawn documents must re-render sharp once zoomed. */
.viewer-content { display: grid; place-items: center; transform-origin: center center; }
.viewer-content img {
  display: block;
  max-width: calc(100vw - 20px);
  max-height: calc(100svh - 150px);
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.6);
}
.viewer-content .doc {
  width: min(calc(100vw - 20px), calc((100svh - 150px) / var(--ratio, 1.414)), 640px);
}
.viewer-loading { color: var(--muted); font-size: 28px; }

/* ---------- Drawn documents (sized like a sheet of paper, text in cqw) ---------- */
.doc {
  --ratio: 1.414;
  position: relative;
  aspect-ratio: 1 / var(--ratio);
  container-type: inline-size;
  overflow: hidden;
  color: var(--ink);
  background: #fbfbf8;
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.6);
  user-select: none;
  -webkit-user-select: none;
}
/* Text lives in .doc-in so its cqw units measure the document itself. */
.doc > .doc-in { position: absolute; inset: 0; }

/* A ring left by a wine glass on paper. */
.wine-ring {
  position: absolute;
  pointer-events: none;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(closest-side, transparent 0 80%, rgba(110, 14, 34, 0.35) 86%, rgba(110, 14, 34, 0.12) 92%, transparent 100%);
  mix-blend-mode: multiply;
  -webkit-mask-image: var(--grunge);
  mask-image: var(--grunge);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
