:root {
  color-scheme: dark;
  --ink: #06111b;
  --navy: #153249;
  --wall: #3f6981;
  --paper: #fff1c7;
  --paper-deep: #dfc47e;
  --yellow: #ffda38;
  --red: #e64b46;
  --green: #34a66a;
  --blue: #63c6ef;
  --shadow: rgba(0, 0, 0, 0.55);
  font-family: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body, #game-shell {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
}

body { user-select: none; }

button, input, a { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
}

#scene.interactive { cursor: pointer; }

#game-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 42%, transparent 54%, rgba(0,0,0,.3) 100%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.008) 0 1px, transparent 1px 5px);
  z-index: 4;
}

.screen {
  position: absolute;
  z-index: 20;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .38s ease, visibility .38s ease;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

#loading {
  inset: 0;
  display: grid;
  place-content: center;
  gap: 1rem;
  text-align: center;
  background: #09121a;
  font: 700 .75rem/1 "Courier Prime", monospace;
  letter-spacing: .14em;
  color: #8da0ad;
}

.loading-mark { display: flex; justify-content: center; gap: .45rem; }
.loading-mark span { width: 9px; height: 9px; background: var(--yellow); animation: blink 1s infinite ease-in-out; }
.loading-mark span:nth-child(2) { animation-delay: .16s; }
.loading-mark span:nth-child(3) { animation-delay: .32s; }

@keyframes blink { 0%, 70%, 100% { opacity: .18; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-5px); } }

.intro-panel {
  top: 50%;
  left: clamp(1rem, 7vw, 7rem);
  width: min(28rem, calc(100vw - 2rem));
  transform: translateY(-50%) rotate(-.7deg);
  padding: 2rem 2rem 1.5rem;
  color: #1b1b19;
  background:
    linear-gradient(rgba(86, 68, 33, .08) 1px, transparent 1px) 0 0 / 100% 1.75rem,
    var(--paper);
  border: 1px solid #b29c6c;
  box-shadow: 0 2rem 6rem rgba(0,0,0,.55), inset 0 0 2.5rem rgba(92,57,22,.16);
}

.intro-panel::before {
  content: "";
  position: absolute;
  width: 78px;
  height: 20px;
  top: -8px;
  left: 50%;
  transform: translateX(-50%) rotate(2deg);
  background: rgba(190, 170, 119, .7);
  box-shadow: 0 2px 5px rgba(0,0,0,.2);
}

.case-label, .unofficial, .key-guide {
  font: 700 .7rem/1.3 "Courier Prime", monospace;
  letter-spacing: .08em;
}

.case-label { color: #725e32; }
.brand-logo { width: 9rem; height: auto; margin: .75rem 0 .15rem; filter: drop-shadow(0 2px 0 rgba(0,0,0,.22)); }

h1 {
  margin: 0;
  font: 400 clamp(2.6rem, 7vw, 4.7rem)/.9 "Chewy", cursive;
  letter-spacing: .02em;
  color: #182735;
  text-shadow: 2px 2px 0 rgba(255,255,255,.45);
}

.intro-copy {
  max-width: 25rem;
  margin: 1rem 0 1.25rem;
  font: 700 1rem/1.45 "Nunito", sans-serif;
}

.handle-field { display: grid; gap: .35rem; margin-bottom: 1rem; font: 900 .67rem/1 "Nunito", sans-serif; letter-spacing: .12em; }
.handle-input-wrap { display: flex; align-items: center; border-bottom: 2px solid #28343c; }
.handle-input-wrap b { font: 700 1rem "Courier Prime", monospace; }
.handle-input-wrap input { width: 100%; padding: .55rem .25rem; border: 0; outline: none; color: #1b262d; background: transparent; font: 700 1rem "Courier Prime", monospace; }
.handle-input-wrap input::placeholder { color: #877e69; }

.primary-button, .secondary-button, .official-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  border-radius: .35rem;
  font-weight: 900;
  letter-spacing: .04em;
  text-decoration: none;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}

.primary-button {
  width: 100%;
  border: 2px solid #1d2b34;
  color: #192733;
  background: var(--yellow);
  box-shadow: 0 4px 0 #8f6f10;
}

.primary-button:hover, .secondary-button:hover, .official-link:hover { filter: brightness(1.06); transform: translateY(-2px); }
.primary-button:active, .secondary-button:active { transform: translateY(2px); box-shadow: none; }

.key-guide { display: flex; align-items: center; justify-content: center; gap: .45rem; margin: 1rem 0 .75rem; color: #574f3f; }
kbd { padding: .2rem .35rem; border: 1px solid #766c58; border-radius: 3px; background: rgba(255,255,255,.28); box-shadow: 0 2px 0 #766c58; }
.unofficial { margin: 0; text-align: center; color: #766a53; }

.creator-credit {
  color: var(--yellow);
  font: 700 .68rem/1 "Courier Prime", monospace;
  letter-spacing: .08em;
  text-decoration: none;
}
.creator-credit:hover { color: white; }
.intro-credit { display: block; margin-top: .65rem; text-align: center; color: #68492a; }
.corner-credit { position: absolute; z-index: 12; left: 1rem; bottom: 1.15rem; display: none; text-shadow: 0 2px 8px #000; }
.playing .corner-credit { display: block; }

.hud {
  position: absolute;
  z-index: 7;
  top: max(.75rem, env(safe-area-inset-top));
  left: 50%;
  width: min(92vw, 64rem);
  transform: translateX(-50%);
  display: none;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  color: #e7e2cc;
  text-shadow: 0 2px 8px #000;
}

.playing .hud { display: grid; }
.hud-block { display: flex; align-items: baseline; gap: .6rem; font: 700 .7rem "Courier Prime", monospace; letter-spacing: .1em; }
.hud-block strong { font: 700 1.9rem/1 "Courier Prime", monospace; color: var(--yellow); }
.align-right { justify-content: flex-end; }
.hud-title { text-align: center; font: 900 .78rem/1.15 "Nunito", sans-serif; letter-spacing: .15em; }
.hud-title em { display: block; color: #8ea5b3; font: normal 700 .58rem "Courier Prime", monospace; letter-spacing: .24em; margin-top: .3rem; }

.combo {
  position: absolute;
  z-index: 8;
  right: clamp(1rem, 5vw, 4rem);
  top: 22%;
  display: none;
  text-align: right;
  color: var(--yellow);
  transform: rotate(2deg);
  text-shadow: 0 4px 14px #000;
}
.playing .combo { display: grid; }
.combo strong { font: 400 3.8rem/.8 "Chewy", cursive; }
.combo small { font: 900 .62rem "Nunito", sans-serif; letter-spacing: .12em; color: white; }
.combo.bump { animation: comboBump .25s ease; }
@keyframes comboBump { 50% { transform: rotate(-2deg) scale(1.25); } }

.case-file {
  position: absolute;
  z-index: 9;
  top: 49%;
  left: 50%;
  display: none;
  width: min(44vw, 34rem);
  min-height: 16.5rem;
  padding: 1.35rem 1.55rem 1.1rem;
  transform: translate(-50%, -50%);
  color: #192b37;
  background:
    linear-gradient(90deg, transparent 3.1rem, rgba(197,64,54,.22) 3.1rem 3.2rem, transparent 3.2rem),
    repeating-linear-gradient(0deg, transparent 0 2.18rem, rgba(47,102,133,.14) 2.18rem 2.25rem),
    var(--paper);
  border: 2px solid #b9964e;
  box-shadow: 0 1.35rem 3.5rem rgba(0,0,0,.42), inset 0 0 2rem rgba(126,75,15,.12);
  filter: drop-shadow(0 3px 0 rgba(0,0,0,.28));
}
.playing .case-file { display: grid; grid-template-rows: auto 1fr auto; animation: fileIn .38s cubic-bezier(.2,.9,.25,1); }
.case-file.incoming { animation: fileIn .38s cubic-bezier(.2,.9,.25,1); }
.case-file.out-approve { animation: fileOutLeft .34s ease-in forwards; }
.case-file.out-review { animation: fileOutDown .34s ease-in forwards; }
.case-file.out-reject { animation: fileOutRight .34s ease-in forwards; }
.case-file header { display: grid; gap: .2rem; padding-left: 2.5rem; }
.case-file header span { color: #a03a35; font: 700 .72rem/1.2 "Courier Prime", monospace; letter-spacing: .09em; }
.case-file header b { font: 700 clamp(1.35rem, 2.5vw, 2rem)/1.1 "Courier Prime", monospace; }
.case-file ol { display: grid; align-content: center; gap: .72rem; margin: .9rem 0 .7rem; padding: 0 0 0 4rem; font: 700 clamp(.95rem, 1.55vw, 1.12rem)/1.3 "Courier Prime", monospace; }
.case-file li { padding-left: .35rem; }
.case-file footer { padding-left: 2.5rem; color: #6d6044; font: 700 .69rem/1.2 "Courier Prime", monospace; letter-spacing: .07em; }

@keyframes fileIn {
  from { opacity: 0; transform: translate(30%, -48%) rotate(2deg) scale(.96); }
  to { opacity: 1; transform: translate(-50%, -50%) rotate(0) scale(1); }
}
@keyframes fileOutLeft { to { opacity: 0; transform: translate(-135%, -54%) rotate(-5deg) scale(.94); } }
@keyframes fileOutRight { to { opacity: 0; transform: translate(35%, -54%) rotate(5deg) scale(.94); } }
@keyframes fileOutDown { to { opacity: 0; transform: translate(-50%, 20%) scale(.94); } }

.decision-controls {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: max(1.05rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: none;
  grid-template-columns: repeat(3, 1fr);
  width: min(94vw, 41rem);
  gap: .7rem;
}
.decision-controls button {
  min-height: 3.9rem;
  border: 2px solid rgba(255,255,255,.54);
  border-radius: .55rem;
  color: white;
  box-shadow: 0 5px 0 rgba(0,0,0,.5), 0 10px 28px rgba(0,0,0,.32);
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
}
.decision-controls button:nth-child(1) { background: var(--green); }
.decision-controls button:nth-child(2) { color: #17222a; background: var(--yellow); border-color: #fff0a8; }
.decision-controls button:nth-child(3) { background: var(--red); }
.decision-controls button:hover { filter: brightness(1.12) saturate(1.1); transform: translateY(-2px); }
.decision-controls button:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.5); }
.decision-controls button span { display: block; margin-bottom: .1rem; color: currentColor; opacity: .72; font: 700 .7rem "Courier Prime", monospace; }
.decision-controls button strong { font-size: .9rem; letter-spacing: .08em; }

.desktop-hint {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: 1.25rem;
  display: none;
  transform: translateX(-50%);
  color: #d8ebf6;
  font: 700 .72rem/1 "Courier Prime", monospace;
  letter-spacing: .1em;
  text-shadow: 0 2px 7px #000;
}
.playing .desktop-hint { display: block; }

.sound-toggle {
  position: absolute;
  z-index: 12;
  right: max(.75rem, env(safe-area-inset-right));
  bottom: max(.75rem, env(safe-area-inset-bottom));
  padding: .45rem .6rem;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: .25rem;
  color: #aebbc3;
  background: rgba(8,16,24,.65);
  font: 700 .6rem "Courier Prime", monospace;
  cursor: pointer;
}
.sound-off { display: none; }
.sound-toggle[aria-pressed="true"] .sound-on { display: none; }
.sound-toggle[aria-pressed="true"] .sound-off { display: inline; }

.result-panel {
  inset: 0;
  display: grid;
  grid-template-columns: minmax(18rem, 31rem) minmax(12rem, 17rem);
  align-content: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 1rem;
  background: rgba(6, 15, 23, .92);
}

.report-card {
  position: relative;
  min-height: 34rem;
  padding: 2.2rem 2.4rem;
  overflow: hidden;
  transform: rotate(-.4deg);
  color: #26251f;
  background:
    linear-gradient(90deg, transparent 2.3rem, rgba(171,55,46,.22) 2.3rem 2.4rem, transparent 2.4rem),
    repeating-linear-gradient(0deg, transparent 0 1.8rem, rgba(54,88,110,.13) 1.8rem 1.86rem),
    #eee0b9;
  border: 1px solid #a48d5c;
  box-shadow: 0 2rem 6rem rgba(0,0,0,.62), inset 0 0 3rem rgba(108,67,20,.12);
}

.report-kicker { font: 700 .72rem "Courier Prime", monospace; letter-spacing: .16em; color: #8c2e2b; }
.report-card h2 { margin: .25rem 0 1rem; font: 400 2.35rem/1 "Chewy", cursive; color: #182a38; }
.report-rule { height: 4px; margin-bottom: 1.3rem; background: #263d4c; }
.report-card dl { display: grid; gap: .55rem; margin: 0; }
.report-card dl div { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px dashed rgba(45,43,33,.35); padding-bottom: .35rem; }
.report-card dt { font: 700 .7rem "Courier Prime", monospace; letter-spacing: .08em; }
.report-card dd { margin: 0; text-align: right; font: 700 .9rem "Courier Prime", monospace; }
.classification { display: grid; gap: .35rem; margin-top: 2rem; }
.classification span { font: 700 .65rem "Courier Prime", monospace; letter-spacing: .12em; }
.classification strong { max-width: 23rem; font: 400 2.2rem/.92 "Chewy", cursive; color: #9d332d; }
.report-stamp { position: absolute; right: 1.8rem; bottom: 2.2rem; padding: .45rem .8rem; transform: rotate(-11deg); border: 5px double #a4302d; color: #a4302d; font: 700 1.35rem "Courier Prime", monospace; opacity: .85; }
.report-code { position: absolute; left: 2.4rem; bottom: 1.25rem; font: 700 .65rem "Courier Prime", monospace; letter-spacing: .12em; color: #645b48; }

.result-actions { align-self: center; display: grid; gap: .75rem; }
.secondary-button { border: 1px solid #657986; color: #e8ecee; background: rgba(20,35,45,.9); box-shadow: 0 3px 0 #071017; }
.official-link { min-height: auto; padding: .65rem; border: 0; color: var(--yellow); background: transparent; text-align: center; font: 700 .7rem "Courier Prime", monospace; }
.asset-note { grid-column: 1 / -1; max-width: 46rem; margin: 0 auto; text-align: center; color: #8b9aa3; font: 400 .7rem/1.4 "Courier Prime", monospace; }
.asset-note a { color: var(--yellow); }

.toast {
  position: absolute;
  z-index: 30;
  top: 15%;
  left: 50%;
  min-width: 13rem;
  padding: .75rem 1rem;
  opacity: 0;
  transform: translate(-50%, -12px) rotate(-1deg);
  color: #1d281e;
  background: var(--yellow);
  border: 2px solid #161e23;
  text-align: center;
  font: 900 .78rem "Nunito", sans-serif;
  letter-spacing: .08em;
  box-shadow: 0 7px 20px rgba(0,0,0,.35);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0) rotate(1deg); }
.toast.bad { color: white; background: var(--red); }

@media (max-width: 720px) {
  .intro-panel { left: 50%; top: 52%; transform: translate(-50%, -50%) rotate(-.5deg); padding: 1.55rem 1.35rem 1.15rem; }
  .brand-logo { width: 7rem; }
  .intro-copy { margin: .7rem 0 1rem; font-size: .9rem; }
  .key-guide { display: none; }
  .unofficial { font-size: .56rem; margin-top: .8rem; }
  .hud { grid-template-columns: 1fr 1fr; width: calc(100vw - 1.25rem); }
  .hud-title { display: none; }
  .combo { top: 13%; right: .75rem; }
  .combo strong { font-size: 2.4rem; }
  .case-file { top: 49%; width: calc(100vw - 1.35rem); min-height: 18rem; padding: 1rem .95rem .85rem; background: repeating-linear-gradient(0deg, transparent 0 2.08rem, rgba(47,102,133,.14) 2.08rem 2.15rem), var(--paper); }
  .case-file header, .case-file footer { padding-left: 0; }
  .case-file header span { font-size: .64rem; }
  .case-file header b { font-size: 1.35rem; }
  .case-file ol { gap: .85rem; margin: .75rem 0; padding-left: 1.9rem; font-size: .96rem; line-height: 1.34; }
  .case-file footer { font-size: .61rem; }
  .decision-controls { width: calc(100vw - 1.1rem); gap: .4rem; }
  .playing .decision-controls { display: grid; }
  .decision-controls button { min-height: 3.6rem; padding: .3rem; }
  .decision-controls button strong { font-size: .78rem; letter-spacing: .04em; }
  .sound-toggle { bottom: 5.2rem; }
  .corner-credit { bottom: 5.45rem; left: .7rem; font-size: .58rem; }
  .desktop-hint { display: none !important; }
  .result-panel { grid-template-columns: minmax(0, 1fr); overflow-y: auto; align-content: start; padding: max(1rem, env(safe-area-inset-top)) .8rem max(1rem, env(safe-area-inset-bottom)); }
  .report-card { min-height: 30rem; padding: 1.65rem 1.4rem; }
  .report-card h2 { font-size: 1.95rem; }
  .classification strong { font-size: 1.8rem; }
  .report-stamp { right: 1rem; bottom: 2.2rem; }
  .report-code { left: 1.4rem; }
  .result-actions { grid-template-columns: 1fr 1fr; }
  .official-link { grid-column: 1 / -1; }
}

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