:root {
  color-scheme: dark;
  --ink: #241b4a;
  --ink-deep: #16122f;
  --teal: #128f8a;
  --teal-bright: #3ecfc8;
  --gold: #f6c445;
  --cream: #fff8ee;
  --truth: #1fba6a;
  --paper: #f6f0dc;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background-color: var(--ink-deep);
  background-image:
    radial-gradient(circle at 12% 0%, rgba(246, 196, 69, 0.16), transparent 32%),
    radial-gradient(circle at 100% 8%, rgba(62, 207, 200, 0.22), transparent 36%);
  color: var(--cream);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  line-height: 1.35;
}

body.is-truth {
  background-color: #0c3b2e;
  background-image:
    radial-gradient(circle at 50% 18%, rgba(80, 255, 170, 0.38), transparent 46%),
    radial-gradient(circle at 8% 0%, rgba(246, 196, 69, 0.16), transparent 28%);
}

body.is-lie {
  background-color: #2a1848;
  background-image:
    radial-gradient(circle at 50% 12%, rgba(255, 214, 90, 0.22), transparent 42%),
    radial-gradient(circle at 100% 0%, rgba(62, 207, 200, 0.12), transparent 34%);
}

body.is-shake { animation: toy-shake 0.32s linear 1; }

button, input { font: inherit; }

#fx {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 3;
}

.star {
  position: absolute;
  overflow: visible;
  filter: drop-shadow(0 0 6px rgba(255, 225, 74, 0.85));
  animation: twinkle 1.4s ease-in-out infinite alternate;
}

@keyframes twinkle {
  from { transform: scale(0.92); opacity: 0.82; }
  to { transform: scale(1.08); opacity: 1; }
}

#flash {
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  opacity: 0;
  background: #fff4b0;
}

#flash.go { animation: one-flash 220ms ease-out forwards; }
#flash.calm { background: #ffe9a0; animation: calm-flash 420ms ease-out forwards; }

@keyframes one-flash {
  0% { opacity: 0.82; }
  100% { opacity: 0; }
}

@keyframes calm-flash {
  0% { opacity: 0.28; }
  100% { opacity: 0; }
}

@keyframes toy-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

#corner {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 5;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  background: transparent;
}

#corner::after {
  content: "";
  position: absolute;
  top: 10px;
  right: 10px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(246, 196, 69, 0.7);
}

main, .credit { position: relative; z-index: 1; }

main {
  width: min(440px, 100%);
  margin: 0 auto;
  padding: 12px 16px 4px;
}

.top {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 8px 10px;
  align-items: center;
}

#logo {
  width: 72px;
  height: 72px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#logo img { display: block; width: 72px; height: 72px; border-radius: 50%; }

h1, h2, .sub { font-family: Georgia, "Iowan Old Style", Palatino, serif; }

h1 {
  margin: 0;
  font-size: 1.28rem;
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sub { margin: 2px 0 0; font-size: 1rem; }

#mute {
  min-height: 44px;
  padding: 8px 12px;
  border: 2px solid var(--gold);
  border-radius: 999px;
  background: transparent;
  color: var(--cream);
  font-size: 0.85rem;
  font-weight: 800;
  white-space: nowrap;
}

#scan-screen, #result-screen { margin-top: 12px; }

#status {
  min-height: 2.7em;
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(246, 196, 69, 0.14);
  text-align: center;
  font-size: 1.02rem;
  font-weight: 800;
}

.meter-box {
  margin: 0 0 14px;
  overflow: hidden;
  border: 3px solid var(--gold);
  border-radius: 16px;
  background: #10241e;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
}

.meter-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  color: #b7ffd8;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.led {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #3a4a42;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.meter-box.is-live .led {
  background: #3dff9a;
  box-shadow: 0 0 8px #3dff9a;
}

.paper {
  height: 112px;
  margin: 0 8px 8px;
  overflow: hidden;
  border-radius: 10px;
  background: var(--paper);
}

#graph {
  display: block;
  width: 100%;
  height: 100%;
}

.pad-wrap { display: flex; justify-content: center; }

#pad {
  position: relative;
  width: min(62vw, 232px);
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border: 6px solid var(--gold);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, var(--teal-bright) 0%, var(--teal) 46%, #0b5c62 100%);
  box-shadow:
    0 0 0 8px rgba(246, 196, 69, 0.18),
    inset 0 0 24px rgba(0, 0, 0, 0.25);
  color: #fff6e4;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#pad .print {
  display: block;
  width: 68%;
  height: 78%;
  margin: 11% auto 0;
  pointer-events: none;
}

#pad .glass {
  position: absolute;
  left: 24%;
  top: 18%;
  width: 48%;
  height: 48%;
  opacity: 0;
  pointer-events: none;
  filter: drop-shadow(2px 4px 0 rgba(0, 0, 0, 0.18));
}

#pad.is-scanning {
  box-shadow:
    0 0 0 8px rgba(80, 255, 200, 0.35),
    0 0 28px rgba(80, 255, 200, 0.45),
    inset 0 0 24px rgba(0, 0, 0, 0.25);
}

#pad.is-scanning .glass {
  opacity: 1;
  animation: glass-sweep 1.15s ease-in-out infinite alternate;
}

@keyframes glass-sweep {
  from { transform: translate(-16%, -4%) rotate(-12deg); }
  to { transform: translate(18%, 14%) rotate(10deg); }
}

#bolt {
  position: absolute;
  left: 50%;
  top: 10%;
  z-index: 2;
  width: 34%;
  pointer-events: none;
  transform: translateX(-50%);
}

#bolt svg { display: block; width: 100%; height: auto; }

#bolt.strike { animation: strike 0.22s cubic-bezier(0.2, 1.2, 0.3, 1) both; }

@keyframes strike {
  0% { transform: translateX(-50%) translateY(-70%) scale(0.4) rotate(-8deg); opacity: 0; }
  100% { transform: translateX(-50%) translateY(0) scale(1) rotate(0); opacity: 1; }
}

.hint {
  margin: 12px 0 0;
  color: rgba(255, 248, 238, 0.84);
  text-align: center;
  font-size: 0.98rem;
}

#result-screen { text-align: center; }

.result-card {
  margin: 8px 0 0;
  padding: 22px 16px 18px;
  border: 4px solid var(--gold);
  border-radius: 24px;
  background: #fff8ee;
  color: var(--ink);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.28);
}

.result-card.is-truth {
  border-color: var(--truth);
  background: #e9fff4;
  box-shadow:
    0 0 0 6px rgba(31, 186, 106, 0.28),
    0 0 36px rgba(80, 255, 170, 0.55);
}

.result-card.is-lie {
  border-color: #f0b429;
  background: #fff8e8;
  box-shadow: 0 0 0 6px rgba(240, 180, 41, 0.22);
}

.dept {
  margin: 0;
  color: #0f6b62;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#result-title {
  margin: 8px 0 0;
  color: #1a1440;
  font-size: clamp(1.55rem, 7vw, 2.15rem);
  line-height: 1.12;
}

.result-card.is-truth #result-title { color: #0d6b3c; }

#result-extra {
  margin: 10px 0 0;
  color: #6b4a12;
  font-family: Georgia, "Iowan Old Style", Palatino, serif;
  font-size: 1.2rem;
  font-weight: 700;
}

#result-name {
  margin: 10px 0 0;
  color: #241b4a;
  font-size: 1.45rem;
  font-weight: 800;
}

.actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.big, #done {
  width: 100%;
  min-height: 64px;
  border-radius: 999px;
  font-size: 1.25rem;
  font-weight: 800;
}

.big {
  border: 3px solid var(--gold);
  background: var(--teal);
  color: var(--cream);
}

.credit {
  width: min(440px, 100%);
  margin: 8px auto 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  gap: 18px;
  font-size: 0.85rem;
}

.credit a { color: var(--gold); }

#parents {
  width: min(360px, calc(100vw - 28px));
  max-height: min(92vh, 640px);
  padding: 18px 16px 16px;
  overflow: auto;
  border: 4px solid var(--gold);
  border-radius: 24px;
  background: var(--cream);
  color: var(--ink);
}

#parents::backdrop { background: rgba(12, 10, 28, 0.72); }

#parents h2 {
  margin: 0 0 6px;
  font-size: 1.55rem;
  line-height: 1.1;
}

.parents-note { margin: 0 0 12px; font-size: 0.95rem; }

.modes {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}

.modes legend {
  margin-bottom: 8px;
  font-weight: 800;
}

.modes label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 12px;
  border: 2px solid #128f8a;
  border-radius: 14px;
  background: #fff;
  font-weight: 800;
}

.modes label:has(input:checked) {
  border-color: var(--gold);
  background: var(--ink);
  color: var(--cream);
}

.modes input {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--teal);
}

.name-field { display: grid; gap: 6px; margin-bottom: 14px; font-weight: 800; }

#kid-name {
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 2px solid #128f8a;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}

#done {
  border: 3px solid var(--ink);
  background: var(--ink);
  color: var(--cream);
}

button:focus-visible,
#kid-name:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

#parents button:focus-visible,
#parents input:focus-visible {
  outline-color: var(--ink);
}

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .star,
  #pad.is-scanning .glass,
  #bolt.strike,
  body.is-shake { animation: none !important; }

  #flash.go { animation: calm-flash 420ms ease-out forwards !important; }

  #pad.is-scanning .glass {
    opacity: 1;
    transform: translate(8%, 10%) rotate(-8deg);
  }
}
