:root {
  --bg: #100e18;
  --ink: #f6f1e7;
  --muted: #b7adc4;
  --gold: #f2d27a;
  --gold-deep: #b8923e;
  --skin: #f3c2a4;
  --hair: #2b2642;
  --pajama: #3f4e88;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", "YuGothic", "Hiragino Sans", "Noto Sans JP", "WenQuanYi Micro Hei", "Droid Sans Fallback", sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

button, p, h1, h2, ul { margin: 0; font: inherit; }

button {
  font-family: inherit;
  cursor: pointer;
}

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

#app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  place-items: center;
}

#frame {
  position: relative;
  width: min(100vw, calc(100dvh * 9 / 16));
  height: min(100dvh, calc(100vw * 16 / 9));
  max-height: 100dvh;
  background: #161422;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  font-size: calc(min(100vw, calc(100dvh * 9 / 16)) / 23);
}

@media (max-aspect-ratio: 9/16) {
  #frame {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    box-shadow: none;
  }
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.screen[hidden] { display: none !important; }

/* ---------- title ---------- */

.title-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding:
    calc(1.1rem + env(safe-area-inset-top))
    calc(1.1rem + env(safe-area-inset-right))
    calc(1.2rem + env(safe-area-inset-bottom))
    calc(1.1rem + env(safe-area-inset-left));
  text-align: center;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(120, 140, 210, 0.22), transparent 55%),
    linear-gradient(#1a1830, #12101c 70%);
}

.eyebrow {
  letter-spacing: 0.22em;
  font-size: 0.62rem;
  color: #d7c7ef;
}

h1 {
  font-size: 2.15rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.15;
  text-shadow: 0 3px 0 #2a2040;
}

.subtitle {
  color: #eadfbf;
  font-size: 0.95rem;
}

.title-scene {
  position: relative;
  width: min(78%, 16rem);
  aspect-ratio: 4 / 3.1;
  margin: 0.35rem 0 0.2rem;
  border-radius: 1rem;
  overflow: hidden;
  background: linear-gradient(#232846, #1a1c30 60%, #3a2d28);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.06);
}

.ts-window {
  position: absolute;
  left: 8%;
  top: 10%;
  width: 24%;
  height: 28%;
  background: linear-gradient(#1b2a55, #31457a);
  border: 3px solid #c9bfa4;
  border-radius: 2px;
}

.ts-moon {
  position: absolute;
  width: 42%;
  aspect-ratio: 1;
  border-radius: 50%;
  right: 12%;
  top: 16%;
  background: #f6e7b4;
  box-shadow: 0 0 12px #f6e7b4;
}

.ts-door {
  position: absolute;
  left: 50%;
  top: 14%;
  width: 28%;
  height: 58%;
  transform: translateX(-50%);
  background: #4d3428;
  border-radius: 3px 3px 0 0;
}

.ts-panel {
  position: absolute;
  inset: 6px 6px 0;
  background: linear-gradient(90deg, #7a5138, #9a6a48 40%, #6d4934);
}

.ts-knob {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f0d48a;
  right: 10px;
  top: 54%;
}

.ts-parent {
  position: absolute;
  left: 58%;
  bottom: 22%;
  width: 18%;
  height: 36%;
  background: var(--pajama);
  border-radius: 40% 40% 8% 8%;
}

.ts-parent::before {
  content: "";
  position: absolute;
  width: 70%;
  height: 38%;
  left: 15%;
  top: -24%;
  background: var(--skin);
  border-radius: 50%;
  box-shadow: 0 -6px 0 2px var(--hair);
}

.ts-futon {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 28%;
  background:
    radial-gradient(circle at 20% 40%, rgba(255, 255, 255, 0.2) 0 2px, transparent 3px),
    linear-gradient(#7c68aa, #53447c);
  border-top: 4px solid #cbbfe4;
}

.ts-bang {
  position: absolute;
  right: 10%;
  top: 12%;
  color: #ffd15c;
  font-size: 1.8rem;
  font-weight: 900;
  animation: pop-idle 1.4s ease-in-out infinite;
}

.title-best {
  font-variant-numeric: tabular-nums;
  font-family: "DejaVu Sans Mono", "Noto Sans Mono", ui-monospace, monospace;
  font-size: 0.95rem;
  color: #f0e2b0;
}

.howto {
  list-style: none;
  padding: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.55;
}

.btn-main {
  appearance: none;
  border: 0;
  background: var(--gold);
  color: #2c2340;
  font-weight: 800;
  font-size: 1.15rem;
  border-radius: 999px;
  padding: 0.78rem 1.6rem;
  min-width: 11rem;
  box-shadow: 0 0.38rem 0 var(--gold-deep);
}

.btn-main:active {
  transform: translateY(0.22rem);
  box-shadow: 0 0.16rem 0 var(--gold-deep);
}

.btn-text {
  appearance: none;
  border: 0;
  background: transparent;
  color: #d9d0ea;
  font-size: 0.95rem;
  padding: 0.35rem 0.6rem;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.btn-sound {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  border-radius: 999px;
  min-width: 2.4rem;
  height: 2.4rem;
  padding: 0 0.55rem;
  font-weight: 700;
  position: relative;
}

.btn-sound.wide {
  height: auto;
  min-width: 0;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.btn-sound.is-off { color: #ffb0b8; }

.btn-sound.is-off::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  top: 50%;
  height: 2px;
  background: #ff8d98;
  transform: rotate(-32deg);
}

.btn-sound.wide.is-off::after { display: none; }

/* ---------- hud / dock ---------- */

.hud {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.6rem;
  padding:
    calc(0.55rem + env(safe-area-inset-top))
    calc(0.75rem + env(safe-area-inset-right))
    0.35rem
    calc(0.8rem + env(safe-area-inset-left));
  background: linear-gradient(#141226, rgba(20, 18, 38, 0.92));
  z-index: 2;
}

.hud-side {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
}

.hud-block { display: flex; flex-direction: column; gap: 0.05rem; }
.hud-block.right { align-items: flex-end; text-align: right; }

.hud-label {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.hud strong {
  font-family: "DejaVu Sans Mono", "Noto Sans Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #12101c;
}

.dock {
  flex: 0 0 auto;
  padding:
    0.45rem
    calc(0.85rem + env(safe-area-inset-right))
    calc(0.7rem + env(safe-area-inset-bottom))
    calc(0.85rem + env(safe-area-inset-left));
  background: linear-gradient(#141222, #0e0c16);
  z-index: 2;
}

#hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.35rem;
}

#gauge.lv-high ~ #hint { color: #ffb4bc; }

/* ---------- room ---------- */

#room { position: absolute; inset: 0; overflow: hidden; }

.wall {
  position: absolute;
  inset: 0 0 28% 0;
  background:
    radial-gradient(ellipse at 18% 0%, rgba(150, 170, 230, 0.16), transparent 42%),
    linear-gradient(#222848, #17192a 78%);
}

.moonlight {
  position: absolute;
  left: 8%;
  top: 18%;
  width: 28%;
  height: 70%;
  background: linear-gradient(180deg, rgba(190, 210, 255, 0.16), transparent 80%);
  transform: rotate(12deg);
  pointer-events: none;
  filter: blur(2px);
}

.window {
  position: absolute;
  left: 5%;
  top: 5%;
  width: 24%;
  height: 22%;
  background: linear-gradient(#152448, #2a3f72);
  border: 0.28rem solid #d9d0bc;
  border-radius: 2px;
  overflow: hidden;
  z-index: 2;
  box-shadow: 0 0 24px rgba(180, 200, 255, 0.18);
}

.moon {
  position: absolute;
  width: 32%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #f7e7b8;
  right: 14%;
  top: 18%;
  box-shadow: 0 0 16px 4px rgba(247, 231, 184, 0.7);
}

.stars {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 30%, #fff 0 1px, transparent 1.5px),
    radial-gradient(circle at 40% 70%, #fff 0 1px, transparent 1.5px),
    radial-gradient(circle at 70% 28%, #fff 0 1px, transparent 1.5px),
    radial-gradient(circle at 78% 62%, #fff 0 1px, transparent 1.5px);
}

.curtain {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 22%;
  background: linear-gradient(#6d3a52, #4a2438);
}
.curtain.left { left: 0; }
.curtain.right { right: 0; }

.sill {
  position: absolute;
  left: -6%;
  right: -6%;
  bottom: -8%;
  height: 14%;
  background: #d9d0bc;
}

.clock {
  position: absolute;
  right: 5%;
  top: 3.2%;
  width: 8%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #f4efe4;
  z-index: 3;
  box-shadow: inset 0 0 0 2px #c8bba4;
}

.clock i, .clock b {
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 2px;
  background: #2c2838;
  transform-origin: bottom center;
  border-radius: 2px;
}
.clock i { height: 28%; transform: translateX(-50%) rotate(20deg); }
.clock b { height: 38%; transform: translateX(-50%) rotate(120deg); }

.shelf {
  position: absolute;
  right: 3.5%;
  top: 14%;
  width: 22%;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.board {
  height: 2.15rem;
  background: linear-gradient(#6b4a34, #4e3424);
  border-radius: 2px;
  box-shadow: 0 4px 0 #3a2618;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  padding: 0 4px 3px;
}

.book {
  display: block;
  width: 0.48rem;
  height: 78%;
  border-radius: 1px;
}
.book.a { background: #d4546a; height: 86%; }
.book.b { background: #3d6ea8; height: 70%; }
.book.c { background: #e2b34a; height: 80%; }
.book.d { background: #4d9a72; }
.book.e { background: #8a4ea8; height: 74%; }
.book.f { background: #c46a3a; height: 88%; }
.book.g { background: #3a7c88; height: 80%; }

.bear {
  width: 1rem;
  height: 1rem;
  margin-bottom: 2px;
  border-radius: 50%;
  background: #c9844a;
  box-shadow: -5px -4px 0 -2px #c9844a, 5px -4px 0 -2px #c9844a;
  position: relative;
}
.bear::after {
  content: "";
  position: absolute;
  width: 40%;
  height: 28%;
  left: 30%;
  top: 42%;
  background: #f0c2a0;
  border-radius: 40%;
}

.ball {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  margin-bottom: 3px;
  background: radial-gradient(circle at 35% 35%, #fff, #e85d4c 45%, #b4382c);
}

.desk {
  position: absolute;
  left: 3%;
  top: 36%;
  width: 28%;
  height: 24%;
  z-index: 2;
}

.desk .top {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 22%;
  height: 14%;
  background: linear-gradient(#8d6244, #6d4a32);
  border-radius: 2px;
  z-index: 2;
}

.desk .leg {
  position: absolute;
  bottom: 0;
  width: 10%;
  height: 28%;
  background: #5a3c28;
}
.desk .leg.left { left: 8%; }
.desk .leg.right { right: 8%; }

.lamp { position: absolute; left: 18%; bottom: 32%; width: 30%; height: 70%; z-index: 3; }
.shade {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 32%;
  background: linear-gradient(#f0d59a, #e0b15a);
  clip-path: polygon(15% 0, 85% 0, 100% 100%, 0 100%);
}
.pole {
  position: absolute;
  left: 46%;
  top: 30%;
  width: 8%;
  bottom: 0;
  background: #d9c4a0;
}
.glow {
  position: absolute;
  left: 10%;
  top: -10%;
  width: 70%;
  height: 55%;
  background: radial-gradient(circle, rgba(255, 214, 140, 0.45), transparent 70%);
  filter: blur(2px);
  animation: lamp 3.2s ease-in-out infinite;
}

.door-frame {
  position: absolute;
  left: 50%;
  top: 6%;
  width: 34%;
  height: 54%;
  transform: translateX(-50%);
  background: #3a291e;
  border-radius: 4px 4px 0 0;
  z-index: 2;
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.18);
}

.hallway {
  position: absolute;
  inset: 0.45rem 0.45rem 0;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.15), transparent 30%),
    repeating-linear-gradient(90deg, #2a241e 0 18%, #332b24 18% 36%);
}

.door-glow {
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: 0;
  height: 5px;
  background: rgba(255, 214, 140, 0);
  filter: blur(2px);
  transition: background 0.3s linear;
}

#room.is-rattle .door-glow { background: rgba(255, 214, 140, 0.95); }

.door-swing {
  position: absolute;
  left: 50%;
  top: 6%;
  width: 34%;
  height: 54%;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
  perspective: 800px;
}

.door-panel {
  position: absolute;
  left: 0.45rem;
  right: 0.45rem;
  top: 0.45rem;
  bottom: 0;
  transform-origin: left center;
  transition: transform 0.5s cubic-bezier(.2, .7, .2, 1);
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.18), transparent 16%),
    repeating-linear-gradient(90deg, #7b533a 0 22%, #8d6244 22% 48%, #6e4a34 48% 100%);
  border-radius: 1px 4px 0 0;
  box-shadow: inset -10px 0 14px rgba(0, 0, 0, 0.18);
}

#room.is-open .door-panel { transform: rotateY(-68deg); }

#room.is-rattle .door-panel { animation: rattle 0.12s linear infinite; }

.panel-window {
  position: absolute;
  left: 22%;
  right: 22%;
  top: 10%;
  height: 22%;
  background: linear-gradient(#24365f, #1a2744);
  border: 2px solid #e6d7b5;
}

.knob {
  position: absolute;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  right: 12%;
  top: 54%;
  background: radial-gradient(circle at 35% 35%, #fff1c4, #c4963a 55%, #8a6420);
}

.floor {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 32%;
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.08) 0 2px, transparent 2px 2.4rem),
    linear-gradient(#4a382c, #2e241c);
  z-index: 1;
}

.rug {
  position: absolute;
  left: 28%;
  right: 28%;
  bottom: 20%;
  height: 8%;
  background: #6d3d4e;
  border-radius: 40%;
  z-index: 2;
  opacity: 0.85;
}

.futon {
  position: absolute;
  left: -4%;
  right: -4%;
  bottom: -6%;
  height: 24%;
  z-index: 6;
  pointer-events: none;
  transform-origin: center bottom;
  animation: breath 3.8s ease-in-out infinite;
}

.futon-body {
  position: absolute;
  inset: 18% 0 0 0;
  background:
    radial-gradient(circle at 12% 40%, rgba(255, 255, 255, 0.16) 0 2px, transparent 3px),
    radial-gradient(circle at 32% 70%, rgba(255, 255, 255, 0.12) 0 2px, transparent 3px),
    radial-gradient(circle at 58% 36%, rgba(255, 255, 255, 0.14) 0 2px, transparent 3px),
    radial-gradient(circle at 80% 64%, rgba(255, 255, 255, 0.12) 0 2px, transparent 3px),
    linear-gradient(180deg, #7460a4, #4c3d78 70%);
  border-radius: 46% 46% 0 0;
}

.futon-rim {
  position: absolute;
  left: 4%;
  right: 4%;
  top: 8%;
  height: 22%;
  border-radius: 40% 40% 0 0;
  background: linear-gradient(#d9cff0, #b7a6dc);
}

.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 7;
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.45);
}

/* ---------- parent ---------- */

.parent {
  position: absolute;
  left: 50%;
  bottom: 36%;
  width: 32%;
  height: 42%;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  transform-origin: center bottom;
  transform: translateX(-50%) scale(0.62);
  transition: transform 0.42s cubic-bezier(.2, .7, .2, 1), opacity 0.28s linear, bottom 0.42s cubic-bezier(.2, .7, .2, 1);
}

.parent.pose-doorway,
.parent.pose-back {
  opacity: 1;
  bottom: 38%;
  transform: translateX(-50%) scale(0.7);
}

.parent.pose-room {
  opacity: 1;
  bottom: 16%;
  transform: translateX(-50%) scale(1);
}

.parent.pose-left {
  opacity: 1;
  bottom: 17%;
  transform: translateX(-108%) scale(1) rotate(-4deg);
}

.parent.pose-right {
  opacity: 1;
  bottom: 17%;
  transform: translateX(8%) scale(1) rotate(4deg);
}

.parent.pose-closeup {
  opacity: 1;
  bottom: 8%;
  z-index: 8;
  transform: translateX(-50%) scale(1.55);
  transition-duration: 0.22s;
}

.parent.pose-hide { opacity: 0; }

.p-shadow {
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: -3%;
  height: 7%;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 50%;
  filter: blur(2px);
}

.p-leg {
  position: absolute;
  bottom: 0;
  width: 18%;
  height: 28%;
  background: #2c3358;
  border-radius: 0 0 6px 6px;
}
.p-leg.left { left: 30%; }
.p-leg.right { right: 30%; }

.p-torso {
  position: absolute;
  left: 18%;
  right: 18%;
  top: 32%;
  bottom: 18%;
  background:
    repeating-linear-gradient(90deg, #4a5a96 0 14%, #3c4c84 14% 22%);
  border-radius: 18% 18% 10% 10%;
  z-index: 1;
}

.collar {
  position: absolute;
  left: 30%;
  right: 30%;
  top: 0;
  height: 16%;
  background: #f4efe6;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.p-arm {
  position: absolute;
  top: 36%;
  width: 16%;
  height: 34%;
  background: #3c4c84;
  border-radius: 20px;
  z-index: 0;
}
.p-arm.left { left: 6%; transform: rotate(10deg); }
.p-arm.right { right: 6%; transform: rotate(-10deg); }
.p-arm i {
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: -6%;
  height: 22%;
  background: var(--skin);
  border-radius: 40%;
}

.p-head {
  position: absolute;
  left: 19%;
  width: 62%;
  height: 36%;
  top: 0;
  transition: transform 0.28s ease;
  z-index: 2;
}

.pose-left .p-head { transform: rotate(-18deg) translateX(-6%); }
.pose-right .p-head { transform: rotate(18deg) translateX(6%); }
.pose-back .p-face { opacity: 0; }
.pose-back .p-hair { height: 100%; border-radius: 46%; }

.p-face {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 22%;
  bottom: 0;
  background: var(--skin);
  border-radius: 46% 46% 42% 42%;
}

.p-hair {
  position: absolute;
  left: -2%;
  right: -2%;
  top: 8%;
  height: 52%;
  background: var(--hair);
  border-radius: 50% 50% 16% 16%;
  z-index: 3;
}

.p-ear {
  position: absolute;
  top: 42%;
  width: 16%;
  height: 18%;
  background: var(--skin);
  border-radius: 50%;
  z-index: 0;
}
.p-ear.left { left: 0; }
.p-ear.right { right: 0; }

.p-brow {
  position: absolute;
  top: 28%;
  width: 22%;
  height: 8%;
  background: #3a3058;
  border-radius: 4px;
}
.p-brow.left { left: 20%; transform: rotate(12deg); }
.p-brow.right { right: 20%; transform: rotate(-12deg); }

.p-eye {
  position: absolute;
  top: 40%;
  width: 22%;
  height: 18%;
  background: #fff;
  border-radius: 50%;
  overflow: hidden;
}
.p-eye.left { left: 20%; }
.p-eye.right { right: 20%; }
.p-eye b {
  display: block;
  width: 46%;
  height: 78%;
  margin: 12% auto 0;
  background: #241e36;
  border-radius: 50%;
  transition: transform 0.2s ease;
}
.pose-left .p-eye b { transform: translateX(-35%); }
.pose-right .p-eye b { transform: translateX(35%); }

.p-nose {
  position: absolute;
  left: 44%;
  top: 58%;
  width: 12%;
  height: 12%;
  background: #e4ae90;
  border-radius: 40%;
}

.p-mouth {
  position: absolute;
  left: 36%;
  top: 74%;
  width: 28%;
  height: 10%;
  border-bottom: 3px solid #c46b6e;
  border-radius: 0 0 40% 40%;
}

.p-cheek {
  position: absolute;
  top: 60%;
  width: 14%;
  height: 10%;
  background: rgba(232, 120, 130, 0.45);
  border-radius: 50%;
}
.p-cheek.left { left: 12%; }
.p-cheek.right { right: 12%; }

.pose-closeup .p-brow.left { transform: rotate(-18deg); }
.pose-closeup .p-brow.right { transform: rotate(18deg); }
.pose-closeup .p-eye { height: 22%; }
.pose-closeup .p-mouth {
  height: 16%;
  background: #6a3040;
  border: 0;
  border-radius: 40%;
  top: 70%;
}

/* ---------- eyes, warnings, drama ---------- */

#eyelids { position: absolute; inset: 0; z-index: 9; pointer-events: none; }

.lid {
  position: absolute;
  left: 0;
  right: 0;
  height: 58%;
  background: #07060c;
  transition: transform 0.15s ease-in-out;
}
.lid.top { top: 0; transform: translateY(-101%); }
.lid.bottom { bottom: 0; transform: translateY(101%); }

#frame.eyes-closed .lid.top,
#frame.eyes-closed .lid.bottom { transform: translateY(0); }

#frame.asleep .lid { transition-duration: 1.35s; }

#sleep-dark {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  z-index: 8;
  pointer-events: none;
  transition: opacity 1.35s linear;
}
#frame.asleep #sleep-dark { opacity: 0.55; }

.warn {
  position: absolute;
  top: 0.15rem;
  left: 0;
  right: 0;
  z-index: 10;
  text-align: center;
  font-size: 2.7rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1;
  pointer-events: none;
  opacity: 0;
  text-shadow:
    0 2px 0 #14121c,
    0 0 10px rgba(0, 0, 0, 0.85),
    0 0 2px #14121c;
}
.warn.show { opacity: 1; animation: warn-pop 0.28s ease-out; }
.warn.yellow { color: #ffd15c; }
.warn.red { color: #ff5b6a; }
.warn.blue { color: #8ec5ff; }
.warn.danger {
  color: #ff3348;
  font-size: 3.3rem;
  animation: warn-pop 0.28s ease-out, warn-pulse 0.55s ease-in-out 0.28s infinite;
}
.warn.show.yellow { animation: warn-pop 0.28s ease-out, warn-pulse 1s ease-in-out 0.28s infinite; }

#flash {
  position: absolute;
  inset: 0;
  z-index: 11;
  pointer-events: none;
  background: rgba(255, 30, 60, 0);
}
#frame.caught #flash { animation: redflash 0.5s ease-out; }
#frame.caught #room { animation: shake 0.42s linear; }

#drama { position: absolute; inset: 0; z-index: 12; pointer-events: none; }

#drama-zzz {
  display: none;
  position: absolute;
  left: 54%;
  top: 30%;
  font-size: 2rem;
  font-weight: 800;
  color: #f4f0ff;
}
#frame.asleep #drama-zzz { display: block; }
#drama-zzz span { display: inline-block; animation: floatz 1.5s ease-in-out infinite; }
#drama-zzz span:nth-child(2) { animation-delay: 0.15s; }
#drama-zzz span:nth-child(3) { animation-delay: 0.3s; }
#drama-zzz span:nth-child(4) { animation-delay: 0.45s; }

#drama-line {
  display: none;
  position: absolute;
  left: 50%;
  bottom: 18%;
  transform: translateX(-50%);
  background: #fff8ea;
  color: #2a1c22;
  font-weight: 800;
  font-size: 1.35rem;
  padding: 0.55rem 0.9rem;
  border-radius: 1rem;
  white-space: nowrap;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.18);
}
#drama-line::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -8px;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-bottom-color: #fff8ea;
  border-top: 0;
}
#frame.caught #drama-line,
#frame.asleep #drama-line { display: block; }

#frame.asleep #drama-line {
  top: 48%;
  bottom: auto;
  background: transparent;
  color: #f7f4ff;
  box-shadow: none;
  font-size: 1.25rem;
}
#frame.asleep #drama-line::after { display: none; }

/* ---------- gauge ---------- */

.gauge-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.gauge-track {
  height: 0.85rem;
  border-radius: 999px;
  background: #2a2638;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

#gauge-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(#7df0b4, #2fce86);
  transition: width 0.08s linear, background 0.2s linear;
}

#gauge.lv-mid #gauge-fill { background: linear-gradient(#ffe08a, #f0b429); }
#gauge.lv-high #gauge-fill {
  background: linear-gradient(#ff9aa4, #ff3148);
  animation: gblink 0.45s steps(2, end) infinite;
}
#gauge.lv-high .gauge-meta { color: #ffb4bc; }

/* ---------- result ---------- */

.result-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  text-align: center;
  padding:
    calc(1.4rem + env(safe-area-inset-top))
    1.2rem
    calc(1.4rem + env(safe-area-inset-bottom));
  background:
    radial-gradient(ellipse at 50% 0%, rgba(120, 100, 170, 0.25), transparent 50%),
    #14121f;
}

.result-mark {
  font-size: 2rem;
  font-weight: 800;
  min-height: 1.2em;
  color: #ffd0d6;
}

.result-reason {
  font-size: 1.35rem;
  font-weight: 800;
}

.result-card h2 {
  margin-top: 0.4rem;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.result-score {
  font-family: "DejaVu Sans Mono", "Noto Sans Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 2.6rem;
  font-weight: 700;
}

.result-new {
  background: var(--gold);
  color: #2c2340;
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  transform: rotate(-2deg);
}

.result-new[hidden] { display: none !important; }

.result-best {
  font-family: "DejaVu Sans Mono", "Noto Sans Mono", ui-monospace, monospace;
  color: #f0e2b0;
  font-size: 0.95rem;
}

.result-taunt {
  margin: 0.35rem 0 0.6rem;
  font-size: 1.05rem;
}

.result-card .btn-main { margin-top: 0.3rem; }

#pause {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: rgba(8, 7, 14, 0.72);
  font-size: 1.8rem;
  font-weight: 800;
}
#pause[hidden] { display: none !important; }
.pause-sub { font-size: 0.95rem; font-weight: 600; color: var(--muted); }

/* ---------- motion ---------- */

@keyframes warn-pop {
  0% { transform: scale(0.45); }
  70% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@keyframes warn-pulse {
  50% { transform: scale(1.08); }
}
@keyframes gblink {
  50% { opacity: 0.35; }
}
@keyframes redflash {
  0% { background: rgba(255, 36, 64, 0.86); }
  100% { background: rgba(255, 36, 64, 0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
@keyframes floatz {
  0%, 100% { transform: translateY(0); opacity: 0.45; }
  50% { transform: translateY(-10px); opacity: 1; }
}
@keyframes breath {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(1.018); }
}
@keyframes lamp {
  50% { opacity: 0.65; }
}
@keyframes rattle {
  0%, 100% { transform: rotateY(0deg); }
  50% { transform: rotateY(-5deg); }
}
@keyframes pop-idle {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

@media (prefers-reduced-motion: reduce) {
  .futon, .glow, .ts-bang { animation: none; }
}
