/*
 * midnight.css — "The Midnight Reading": a candlelit room, a book, and the NOBEs.
 */

/* ---------- Entry points ---------- */
.boot-midnight {
  display: block; margin: 1.4rem auto 0;
  background: none; border: none; cursor: pointer;
  font-family: "Cormorant Garamond", serif; font-style: italic; font-size: 1.15rem;
  color: #c96a6a; text-decoration: underline; text-underline-offset: 4px;
}
.boot-midnight span { font-size: 0.85rem; color: #8a6a6a; font-style: normal; }
.boot-midnight:hover { color: #ff8a8a; }
.enter-midnight { color: #e08585; border-color: rgba(224,133,133,0.6); }
.enter-midnight:hover { background: rgba(224,133,133,0.12); }

body.in-midnight { overflow: hidden; }
body.in-midnight .topbar,
body.in-midnight main,
body.in-midnight .gideon { display: none; }

/* ---------- Room ---------- */
.midnight {
  --danger: 0;
  position: fixed; inset: 0; z-index: 55; overflow: hidden;
  color: #e8dcc4;
  background: radial-gradient(ellipse at 50% 62%, #2a1c10 0%, #120c08 35%, #050404 70%);
}
.mn-room { position: absolute; inset: 0; z-index: 0; }

.mn-window {
  position: absolute; left: 4vw; top: 14vh;
  width: 17vw; height: 42vh; max-width: 240px;
  background: linear-gradient(to bottom, #1d2740, #0c111d);
  border: 8px solid #1a120c;
  box-shadow: 0 0 60px rgba(120,150,220,0.15), inset 0 0 40px rgba(0,0,0,0.6);
}
.mn-window span { position: absolute; background: #1a120c; }
.mn-window span:first-child { left: 50%; top: 0; bottom: 0; width: 6px; transform: translateX(-50%); }
.mn-window span:last-child { top: 45%; left: 0; right: 0; height: 6px; }

.mn-door {
  position: absolute; right: 5vw; bottom: 0;
  width: 15vw; max-width: 210px; height: 66vh;
  background: linear-gradient(to bottom, #000, #080605);
  border: 10px solid #1d140d; border-bottom: none;
  box-shadow: inset 0 0 60px #000;
}

.mn-candle {
  position: absolute; bottom: 24vh;
  width: 16px; height: 46px;
  background: linear-gradient(to right, #d9ccb0, #f3ead6, #cbbd9f);
  border-radius: 3px;
}
.mn-candle.left { left: 25vw; }
.mn-candle.right { right: 25vw; }
.mn-candle .flame {
  position: absolute; left: 50%; bottom: 100%;
  width: 12px; height: 22px; transform: translateX(-50%);
  border-radius: 50% 50% 45% 45% / 65% 65% 35% 35%;
  background: radial-gradient(ellipse at 50% 70%, #fff6d0, #ffb347 55%, rgba(255,120,30,0) 75%);
  box-shadow: 0 0 30px 12px rgba(255,170,70,0.35);
  animation: mn-flicker 1.4s ease-in-out infinite;
}
.mn-candle.target .flame { box-shadow: 0 0 60px 30px rgba(255,190,90,0.7); animation-duration: 0.5s; }
@keyframes mn-flicker {
  0%, 100% { transform: translateX(-50%) scale(1); opacity: 1; }
  30% { transform: translateX(-52%) scale(1.06, 0.95); opacity: 0.9; }
  60% { transform: translateX(-48%) scale(0.96, 1.05); opacity: 1; }
}

/* ---------- Monsters ---------- */
.monster {
  --p: 0; --stare: 0;
  position: absolute; bottom: 0; z-index: 1;
  width: min(20vw, 220px); aspect-ratio: 1 / 2;
  opacity: 0; pointer-events: none;
  transform-origin: bottom center;
  transition: opacity 0.8s ease, transform 0.12s linear;
}
.monster svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 0 6px rgba(140,160,255,0.28)); }
.monster.left  { left: 4vw;  transform: translateX(calc(var(--p) * 9vw))  scale(calc(0.8 + var(--p) * 0.6)); }
.monster.right { right: 5vw; transform: translateX(calc(var(--p) * -9vw)) scale(calc(0.8 + var(--p) * 0.6)); }
.monster.present { opacity: calc(0.55 + var(--p) * 0.45); pointer-events: auto; }
.monster.banished { opacity: 0; transition: opacity 0.4s ease; }
.monster.watched svg { animation: mn-flinch 0.12s linear infinite; }
.monster.watched .eyes { opacity: calc(1 - var(--stare) * 0.8); }
.monster .mouth { display: none; }
.monster .nobe, .mn-scare .nobe {
  font-family: "Arial Black", Impact, sans-serif; font-size: 34px; letter-spacing: 1px; fill: #141414;
}
.monster .eyes { filter: drop-shadow(0 0 4px #fff7c0); }
.stare-bar {
  position: absolute; left: 20%; right: 20%; top: -14px; height: 4px;
  background: rgba(255,255,255,0.12); border-radius: 2px; overflow: hidden;
}
.stare-bar::after {
  content: ""; position: absolute; inset: 0;
  width: calc(var(--stare) * 100%);
  background: #ffd27a; box-shadow: 0 0 8px #ffd27a;
}
@keyframes mn-flinch {
  0% { transform: translateX(0); } 25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); } 100% { transform: translateX(0); }
}

/* darkness closes in as danger rises */
.mn-vignette {
  position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: radial-gradient(ellipse at 50% 55%, transparent 35%, rgba(60,0,0, calc(var(--danger) * 0.55)) 75%, rgba(0,0,0,0.85) 100%);
}

/* ---------- HUD ---------- */
.mn-hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 4;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 1rem 1.5rem;
  font-family: "Cinzel", serif; font-size: 0.85rem; letter-spacing: 0.08em;
}
.mn-page { color: #d9a441; }
.mn-gaze { color: #9a8b73; }
.mn-hud-actions { display: flex; gap: 0.5rem; }
.midnight .g-btn { color: #e8dcc4; border-color: rgba(217,164,65,0.4); }

/* ---------- The book ---------- */
.midnight.panel-open .mn-book { visibility: hidden; }
.mn-book {
  position: absolute; z-index: 3;
  left: 50%; top: 50%; transform: translate(-50%, -46%);
  width: min(560px, 92vw);
}
.mn-sheet {
  padding: 1.6rem 2rem 1.4rem;
  background: linear-gradient(to bottom, #efe3c8, #dccaa5);
  color: #2a1d10;
  border-radius: 4px 4px 10px 10px;
  box-shadow: 0 0 80px rgba(255,170,70,0.25), 0 20px 40px rgba(0,0,0,0.7), inset 0 0 40px rgba(120,80,30,0.25);
}
.mn-sheet.turn { animation: mn-turn 0.5s ease; }
@keyframes mn-turn {
  from { opacity: 0.2; transform: perspective(800px) rotateY(-14deg); }
  to   { opacity: 1;   transform: none; }
}
.mn-page-title {
  font-family: "Cinzel", serif; font-size: 0.9rem; letter-spacing: 0.2em;
  text-align: center; color: #7a5528; margin-bottom: 1rem; max-width: none;
}
.mn-lines p {
  font-family: "Cormorant Garamond", serif; font-size: 1.45rem; line-height: 1.45;
  margin-bottom: 0.7rem; padding: 0.15rem 0.4rem; border-radius: 3px; max-width: none;
  transition: background 0.3s, opacity 0.3s;
}
.mn-lines .todo { opacity: 0.35; }
.mn-lines .done { opacity: 0.55; }
.mn-lines .done::after { content: " ✓"; color: #6b8a3a; }
.mn-lines .current { background: rgba(255,190,90,0.45); box-shadow: 0 0 0 1px rgba(150,90,20,0.3); font-weight: 600; }

.mn-heard {
  min-height: 1.4em; margin: 0.8rem 0 0.4rem; max-width: none;
  text-align: center; font-style: italic; font-size: 0.9rem; color: #9a8b73;
}
.mn-type input {
  width: 100%; padding: 0.5rem 0.7rem;
  background: rgba(0,0,0,0.5); color: #e8dcc4;
  border: 1px solid rgba(217,164,65,0.3); border-radius: 6px; font: inherit; font-size: 0.85rem;
}

/* ---------- Webcam preview (mirrored, like a mirror) ---------- */
.mn-video {
  position: absolute; left: 1rem; bottom: 1rem; z-index: 4;
  width: 150px; height: 112px; object-fit: cover;
  transform: scaleX(-1);
  border: 1px solid rgba(217,164,65,0.35); border-radius: 6px;
  opacity: 0; transition: opacity 0.4s;
}
.mn-video.on { opacity: 0.65; }

/* ---------- Panels (intro, calibration, caught, dawn) ---------- */
.mn-panel {
  position: absolute; z-index: 5;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, 92vw); max-height: 88vh; overflow-y: auto;
  padding: 1.8rem 2rem;
  background: rgba(10,7,5,0.94);
  border: 1px solid rgba(217,164,65,0.45);
  box-shadow: 0 0 60px rgba(0,0,0,0.9);
}
.mn-panel h2 { font-family: "Cinzel", serif; color: #f0c66b; font-size: 1.6rem; margin-bottom: 1rem; }
.mn-panel p { font-family: "Cormorant Garamond", serif; font-size: 1.15rem; line-height: 1.5; max-width: none; }
.mn-panel a { color: #f0c66b; }
.mn-panel kbd { border-color: #d9a441; color: #f0c66b; }
.mn-warn { color: #e0a0a0; font-size: 1rem !important; }
.mn-check { display: flex; gap: 0.5rem; align-items: center; margin: 0.5rem 0 1.2rem; color: #c8b89a; cursor: pointer; }
.mn-buttons { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.mn-btn {
  font-family: "Cinzel", serif; letter-spacing: 0.06em; font-size: 0.9rem;
  color: #f0c66b; background: rgba(217,164,65,0.08);
  border: 1px solid #d9a441; padding: 0.65rem 1.2rem; cursor: pointer;
}
.mn-btn:hover { background: rgba(217,164,65,0.2); }
.mn-btn.ghost { color: #c8b89a; border-color: rgba(200,184,154,0.4); background: none; }

/* during calibration, get out of the way so the candles are visible */
.mn-panel.calibrating { top: 12vh; transform: translateX(-50%); background: rgba(10,7,5,0.6); text-align: center; }
.mn-panel.caught h2 { color: #ff8a8a; }

/* ---------- The jumpscare ---------- */
.mn-scare {
  position: absolute; inset: 0; z-index: 10;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 35%, #4a0d0d 0%, #160303 45%, #000 80%);
}
.mn-scare svg { filter: drop-shadow(0 0 18px rgba(255,80,80,0.35)); }
.mn-scare svg { height: 150vh; width: auto; }
.mn-scare .smile { display: none; }
.mn-scare .mouth { display: inline; }
.mn-scare .eyes { filter: drop-shadow(0 0 10px #fff) drop-shadow(0 0 30px #ff3b3b); }
.mn-scare.go { animation: mn-flash 0.18s steps(2) 2; }
.mn-scare.go svg { animation: mn-lunge 0.28s cubic-bezier(.2,1.6,.4,1) forwards, mn-shake 0.07s linear 0.28s 12; }
@keyframes mn-lunge { from { transform: scale(0.25); } to { transform: scale(1); } }
@keyframes mn-shake {
  0% { transform: translate(0,0); } 25% { transform: translate(-14px, 8px); }
  50% { transform: translate(12px, -10px); } 75% { transform: translate(-8px, -6px); } 100% { transform: translate(0,0); }
}
@keyframes mn-flash { 0% { background: #fff; } 100% { background: #160303; } }

/* ---------- Small screens ---------- */
@media (max-width: 700px) {
  .mn-window { width: 26vw; top: 18vh; height: 30vh; }
  .mn-door { width: 24vw; height: 50vh; }
  .monster { width: 28vw; }
  .mn-candle.left { left: 8vw; } .mn-candle.right { right: 8vw; }
  .mn-lines p { font-size: 1.2rem; }
  .mn-sheet { padding: 1.2rem 1.2rem 1rem; }
  .mn-video { width: 96px; height: 72px; }
  .mn-hud { padding: 0.7rem 1rem; font-size: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  .mn-candle .flame, .monster.watched svg { animation: none; }
  .mn-scare.go, .mn-scare.go svg { animation-duration: 0.01s; }
}
