@import url("https://fonts.googleapis.com/css2?family=Lilita+One&family=Nunito:wght@700;800;900&display=swap");

:root {
  --ink: #1b1220;
  --paper: #fff6ea;
  --bg: #14081a;
  --pink: #ff4d73;
  --amber: #ffb703;
  --good: #b6f5c8;
  --bad: #ffc1cc;
  color: var(--paper);
  font-family: Nunito, "Trebuchet MS", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: #0c0610;
  overflow: hidden;
}

button { font: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

::selection { background: var(--pink); color: var(--paper); }

.app {
  width: min(100vw, 440px);
  height: 100dvh;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  color: var(--paper);
  display: flex;
  flex-direction: column;
}

.screen { min-height: 0; }

#game {
  flex: 1;
  display: grid;
  grid-template-rows: auto auto auto minmax(150px, 38vh) auto minmax(0, 1fr);
  min-height: 0;
  height: 100%;
}

#game[hidden],
#gate[hidden] { display: none !important; }

html.is-adult #gate { display: none !important; }

.gate {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(22px + env(safe-area-inset-bottom));
  background:
    radial-gradient(ellipse 80% 48% at 50% 16%, rgba(255, 183, 3, 0.42), transparent 60%),
    linear-gradient(180deg, #5a2048 0%, #14081a 62%);
}

.gate-art {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 160px;
}

.gate-art svg { width: min(250px, 72vw); height: auto; }

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--amber);
}

h1, h2, .situation {
  font-family: "Lilita One", "Arial Black", sans-serif;
  font-weight: 400;
  letter-spacing: 0.01em;
  margin: 0;
}

.gate h1 {
  font-size: clamp(2.6rem, 13vw, 3.6rem);
  line-height: 0.9;
  text-transform: uppercase;
  color: var(--paper);
  text-shadow: 4px 4px 0 var(--ink);
}

.gate h1 span,
.top h1 span { color: var(--pink); }

.lede {
  margin: 12px 0 0;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.35;
  max-width: 28ch;
}

.fine {
  margin: 8px 0 0;
  color: rgba(255, 246, 234, 0.78);
  font-weight: 700;
  line-height: 1.35;
}

.gate-actions,
.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.btn,
.choice {
  width: 100%;
  border: 3px solid var(--ink);
  border-radius: 16px;
  min-height: 52px;
  padding: 12px 14px;
  font-weight: 900;
  line-height: 1.25;
  box-shadow: 4px 4px 0 var(--ink);
  cursor: pointer;
}

.btn {
  background: var(--paper);
  color: var(--ink);
}

.choice {
  text-align: left;
  background: var(--paper);
  color: var(--ink);
  border-radius: 14px;
  text-wrap: pretty;
}

.btn.primary { background: var(--pink); color: #fff; }

.btn.ghost {
  background: transparent;
  color: var(--paper);
  box-shadow: none;
  border-color: rgba(255, 246, 234, 0.4);
}

.btn:active:not(:disabled),
.choice:active:not(:disabled),
.icon-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 var(--ink);
}

.choice:disabled { cursor: default; opacity: 1; color: var(--ink); }

.choice.is-win { background: var(--good); }

.choice.is-worse { background: var(--amber); }

.choice.is-bad { background: var(--bad); }

.choice.is-dim:disabled { opacity: 0.45; }

:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 0;
}

.top h1 {
  font-size: 1.45rem;
  text-transform: uppercase;
  color: var(--paper);
  text-shadow: 2px 2px 0 var(--ink);
}

.icon-btn {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font-weight: 900;
  font-size: 1.1rem;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 0;
  font-weight: 900;
  font-size: 0.92rem;
}

.pill {
  background: var(--amber);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 2px 10px;
}

.understood { margin-left: auto; }

.understood b {
  color: var(--amber);
  font-family: "Lilita One", "Arial Black", sans-serif;
  font-weight: 400;
  font-size: 1.15rem;
}

.meter {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  padding: 8px 14px 0;
}

.meter i {
  display: block;
  height: 10px;
  border-radius: 99px;
  background: rgba(255, 246, 234, 0.16);
  border: 1px solid rgba(255, 246, 234, 0.2);
  transition: background 0.25s ease, transform 0.25s ease;
}

.meter i.on {
  background: var(--pink);
  border-color: var(--pink);
  transform: scaleY(1.2);
}

.stage {
  position: relative;
  min-height: 0;
  margin-top: 4px;
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 58% at 50% 18%, rgba(255, 183, 3, 0.32), transparent 62%),
    linear-gradient(180deg, #3a1830 0%, #14081a 74%);
  transition: background 0.35s ease;
}

.stage[data-state="offended"],
.stage[data-state="fire"] {
  background:
    radial-gradient(ellipse 80% 58% at 50% 28%, rgba(255, 77, 115, 0.42), transparent 62%),
    linear-gradient(180deg, #4a1428 0%, #14081a 74%);
}

.stage[data-state="enlightened"] {
  background:
    radial-gradient(ellipse 80% 58% at 50% 24%, rgba(255, 183, 3, 0.55), transparent 60%),
    linear-gradient(180deg, #3d2a10 0%, #14081a 74%);
}

.stage[data-state="deceased"] {
  background:
    radial-gradient(ellipse 70% 50% at 50% 40%, rgba(190, 190, 210, 0.2), transparent 62%),
    linear-gradient(180deg, #1c1422 0%, #14081a 78%);
}

.stage[data-state="steaming"],
.stage[data-state="confused"] {
  background:
    radial-gradient(ellipse 80% 55% at 50% 20%, rgba(255, 226, 160, 0.28), transparent 62%),
    linear-gradient(180deg, #3a1830 0%, #14081a 74%);
}

.stage[data-state="melting"] {
  background:
    radial-gradient(ellipse 80% 55% at 50% 30%, rgba(255, 150, 90, 0.38), transparent 62%),
    linear-gradient(180deg, #4a2418 0%, #14081a 74%);
}

#machine {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.timer {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 52px;
  height: 52px;
  z-index: 4;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 50%;
  box-shadow: 3px 3px 0 var(--ink);
}

.timer svg { width: 100%; height: 100%; display: block; }

.timer span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: "Lilita One", "Arial Black", sans-serif;
  font-size: 1.15rem;
  color: var(--ink);
}

.ring-bg, .ring { fill: none; stroke-width: 4; }

.ring-bg { stroke: rgba(27, 18, 32, 0.15); }

.ring {
  stroke: var(--amber);
  stroke-linecap: round;
  stroke-dasharray: 113.1;
  stroke-dashoffset: calc(113.1 * (1 - var(--p, 1)));
  transform: rotate(-90deg);
  transform-origin: 22px 22px;
}

.timer.is-low { animation: pulse 0.45s ease-in-out infinite; }

.timer.is-low .ring { stroke: var(--pink); }

.timer.is-low span { color: var(--pink); }

.speech {
  position: relative;
  z-index: 3;
  margin: 8px 14px 0;
  flex: 0 0 auto;
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 16px 16px 16px 6px;
  box-shadow: 4px 4px 0 var(--ink);
  padding: 10px 12px;
  font-weight: 800;
  font-size: 0.98rem;
  line-height: 1.3;
}

.speech::before,
.speech::after {
  content: "";
  position: absolute;
  left: 36px;
  border-style: solid;
  border-left-color: transparent;
  border-right-color: transparent;
}

.speech::before {
  top: -12px;
  border-width: 0 10px 12px 10px;
  border-bottom-color: var(--ink);
}

.speech::after {
  top: -8px;
  left: 39px;
  border-width: 0 7px 10px 7px;
  border-bottom-color: var(--paper);
}

.speech[data-kind="understood"] { background: #e7ffe9; }
.speech[data-kind="understood"]::after { border-bottom-color: #e7ffe9; }

.speech[data-kind="worse"] { background: #fff1cc; }
.speech[data-kind="worse"]::after { border-bottom-color: #fff1cc; }

.speech[data-kind="disaster"],
.speech[data-kind="timeout"] { background: #ffe0ea; }
.speech[data-kind="disaster"]::after,
.speech[data-kind="timeout"]::after { border-bottom-color: #ffe0ea; }

.panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 8px 14px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 4px solid var(--ink);
  margin-top: 6px;
}

.situation {
  font-size: 1.45rem;
  line-height: 0.95;
  text-transform: uppercase;
  margin: 0 0 6px;
  color: var(--paper);
  text-shadow: 2px 2px 0 var(--ink);
}

.setup,
#intro p,
#result p {
  margin: 0 0 10px;
  font-weight: 800;
  line-height: 1.35;
  color: var(--paper);
}

.outcome {
  margin: 0 0 8px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.82rem;
}

.outcome[data-kind="understood"] { color: var(--good); }
.outcome[data-kind="worse"] { color: var(--amber); }
.outcome[data-kind="disaster"] { color: var(--pink); }

.answers {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#next { margin-top: 10px; }

#result h2 {
  font-size: clamp(1.8rem, 8vw, 2.3rem);
  text-transform: uppercase;
  line-height: 0.95;
  margin-bottom: 8px;
  text-shadow: 3px 3px 0 var(--ink);
}

.score-num {
  font-family: "Lilita One", "Arial Black", sans-serif;
  font-size: 2.6rem;
  color: var(--amber);
  margin: 0 0 4px;
}

.share-note {
  margin: 0;
  font-weight: 800;
  line-height: 1.35;
  color: var(--amber);
  user-select: text;
  word-break: break-word;
}

/* Machine face */

.mark { font-family: "Lilita One", "Arial Black", sans-serif; }

.screen { transition: fill 0.35s ease; }

#machine[data-state="calm"] .screen { fill: #d9fff2; }
#machine[data-state="confused"] .screen { fill: #ffe29a; }
#machine[data-state="offended"] .screen { fill: #ffd0dc; }
#machine[data-state="steaming"] .screen { fill: #eceaf0; }
#machine[data-state="melting"] .screen { fill: #ffc29a; }
#machine[data-state="fire"] .screen { fill: #ff7a4a; }
#machine[data-state="enlightened"] .screen { fill: #fff3b0; }
#machine[data-state="deceased"] .screen { fill: #c8c6d0; }

.rig {
  transform-origin: 200px 300px;
  transition: transform 0.45s ease;
}

#machine[data-state="calm"] .rig { animation: bob 3s ease-in-out infinite; }
#machine[data-state="confused"] .rig { animation: tilt 1.4s ease-in-out infinite; }
#machine[data-state="offended"] .rig { transform: rotate(-3.5deg); }
#machine[data-state="steaming"] .rig { animation: tremble 0.28s ease-in-out infinite; }
#machine[data-state="melting"] .rig { transform: translateY(12px) scaleY(0.94); }
#machine[data-state="fire"] .rig { animation: shake 0.12s linear infinite; }
#machine[data-state="enlightened"] .rig { animation: floaty 1.6s ease-in-out infinite; }
#machine[data-state="deceased"] .rig { transform: rotate(7deg) translateY(8px); }

.mouth,
.fx,
.blush,
.sweat,
.eyes-dead,
.eyes-spark { opacity: 0; transition: opacity 0.3s ease; }

#machine[data-state="calm"] .mouth-calm,
#machine[data-state="confused"] .mouth-confused,
#machine[data-state="offended"] .mouth-offended,
#machine[data-state="steaming"] .mouth-steaming,
#machine[data-state="melting"] .mouth-melting,
#machine[data-state="fire"] .mouth-fire,
#machine[data-state="enlightened"] .mouth-enlightened,
#machine[data-state="deceased"] .mouth-deceased { opacity: 1; }

#machine[data-state="steaming"] .fx-steam,
#machine[data-state="fire"] .fx-fire,
#machine[data-state="melting"] .fx-melt,
#machine[data-state="enlightened"] .fx-halo,
#machine[data-state="deceased"] .fx-crack,
#machine[data-state="deceased"] .eyes-dead,
#machine[data-state="enlightened"] .eyes-spark,
#machine[data-state="offended"] .blush,
#machine[data-state="fire"] .blush,
#machine[data-state="steaming"] .sweat,
#machine[data-state="melting"] .sweat,
#machine[data-state="fire"] .sweat { opacity: 1; }

#machine[data-state="deceased"] .eyes-live { opacity: 0; }
#machine[data-state="enlightened"] .pupil { opacity: 0; }

.blush { fill: #ff4d73; }

.brow,
.eye,
.pupil {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.35s ease;
}

#machine[data-state="confused"] .brow-l { transform: translateY(-6px) rotate(-14deg); }
#machine[data-state="confused"] .brow-r { transform: translateY(3px) rotate(12deg); }
#machine[data-state="confused"] .pupil-l { transform: translate(-5px, 3px); }
#machine[data-state="confused"] .pupil-r { transform: translate(5px, -3px); }

#machine[data-state="offended"] .brow-l { transform: translateY(5px) rotate(18deg); }
#machine[data-state="offended"] .brow-r { transform: translateY(5px) rotate(-18deg); }
#machine[data-state="offended"] .pupil { transform: scale(0.72); }

#machine[data-state="steaming"] .brow { transform: translateY(-5px); }
#machine[data-state="steaming"] .pupil { transform: scale(0.65); }

#machine[data-state="melting"] .eye { transform: translateY(10px) scaleY(0.62); }

#machine[data-state="fire"] .brow { transform: translateY(-7px); }
#machine[data-state="fire"] .pupil { transform: scale(0.45); fill: #ff4d73; }

#machine[data-state="enlightened"] .brow { transform: translateY(-4px); }

#machine[data-state="calm"] .eyes-live {
  transform-box: fill-box;
  transform-origin: center;
  animation: blink 4.8s infinite;
}

.lamp { fill: #ff4d73; transition: fill 0.3s ease; }

#machine[data-state="calm"] .lamp,
#machine[data-state="enlightened"] .lamp { fill: #7dffa8; }

#machine[data-state="fire"] .lamp,
#machine[data-state="steaming"] .lamp { animation: pulse 0.4s ease-in-out infinite; }

.flame {
  transform-box: fill-box;
  transform-origin: center bottom;
}

#machine[data-state="fire"] .flame { animation: flicker 0.28s ease-in-out infinite; }
#machine[data-state="fire"] .f2 { animation-delay: 0.08s; }
#machine[data-state="fire"] .f3 { animation-delay: 0.15s; }

#machine[data-state="steaming"] .fx-steam path { animation: puff 1.3s ease-in infinite; }
#machine[data-state="steaming"] .fx-steam path:nth-child(2) { animation-delay: 0.22s; }
#machine[data-state="steaming"] .fx-steam path:nth-child(3) { animation-delay: 0.45s; }

#machine[data-state="melting"] .fx-melt path {
  transform-box: fill-box;
  transform-origin: center top;
  animation: drip 1.15s ease-in infinite;
}
#machine[data-state="melting"] .fx-melt path:nth-child(2) { animation-delay: 0.2s; }
#machine[data-state="melting"] .fx-melt path:nth-child(3) { animation-delay: 0.4s; }

.led { animation: led 1s steps(2) infinite; }
.led.d2 { animation-delay: 0.45s; }

.eyes-dead path {
  fill: none;
  stroke: #1b1220;
  stroke-width: 5;
  stroke-linecap: round;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes tilt {
  0%, 100% { transform: rotate(-2.2deg); }
  50% { transform: rotate(2.6deg); }
}

@keyframes tremble {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(1.5px) rotate(-0.6deg); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px) rotate(-0.6deg); }
  75% { transform: translateX(4px) rotate(0.6deg); }
}

@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

@keyframes blink {
  0%, 88%, 100% { transform: scaleY(1); }
  94% { transform: scaleY(0.08); }
}

@keyframes flicker {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(0.8) translateY(3px); }
}

@keyframes puff {
  0% { transform: translateY(8px); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: translateY(-16px); opacity: 0; }
}

@keyframes drip {
  0% { transform: translateY(0); opacity: 1; }
  80% { transform: translateY(14px); opacity: 0; }
  100% { opacity: 0; }
}

@keyframes pulse {
  0%, 100% { opacity: 0.72; }
  50% { opacity: 1; }
}

@keyframes led {
  50% { opacity: 0.25; }
}

@media (max-height: 700px) {
  #game { grid-template-rows: auto auto auto minmax(132px, 34vh) auto minmax(0, 1fr); }
  .gate h1 { font-size: 2.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
