/* ============================================================
   Blackmere Keep — core layout & UI
   Palette: midnight stone, torch amber, old gold, parchment
   ============================================================ */

:root {
  --bg-0: #070912;
  --bg-1: #0b0e1a;
  --bg-2: #131725;
  --stone-1: #2a2d3a;
  --stone-2: #1c1f2b;
  --torch: #ffa94d;
  --torch-deep: #e07b2a;
  --gold: #c9a227;
  --gold-bright: #e8c85a;
  --parchment: #e8d9b0;
  --ink: #2b2015;
  --danger: #e05252;
  --ok: #7bc47f;
  --text: #d8d3c8;
  --text-dim: #8b8878;
  --serif: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --hud-h: 60px;
  --inv-h: 84px;
  --narr-h: 74px;
  --radius: 14px;
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
}

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

#app { position: fixed; inset: 0; }

.screen { position: absolute; inset: 0; }
.hidden { display: none !important; }

/* ============ TITLE SCREEN ============ */

#title-screen {
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 700px at 50% 120%, #1a1430 0%, transparent 60%),
    radial-gradient(900px 500px at 80% -10%, #141a33 0%, transparent 55%),
    linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 55%, #100b18 100%);
  overflow: hidden;
}

#title-bg {
  position: absolute; inset: 0;
  pointer-events: none;
  background:
    radial-gradient(140px 140px at 72% 24%, rgba(232, 224, 200, 0.22) 0%, rgba(232, 224, 200, 0.06) 40%, transparent 70%);
}

/* castle silhouette drawn with clip-path */
#title-bg::after {
  content: "";
  position: absolute;
  left: 50%; bottom: 0;
  width: min(90vw, 1100px);
  height: 42vh;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #0a0812 0%, #05040a 100%);
  clip-path: polygon(
    0% 100%, 0% 78%, 4% 78%, 4% 70%, 7% 70%, 7% 78%, 11% 78%, 11% 55%,
    14% 55%, 14% 48%, 16% 48%, 16% 55%, 19% 55%, 19% 48%, 21% 48%, 21% 55%,
    24% 55%, 24% 78%, 33% 78%, 33% 62%, 36% 62%, 36% 56%, 38% 56%, 38% 62%,
    41% 62%, 41% 78%, 46% 78%, 46% 30%, 48% 30%, 48% 22%, 50% 16%, 52% 22%,
    52% 30%, 54% 30%, 54% 78%, 60% 78%, 60% 60%, 63% 60%, 63% 54%, 65% 54%,
    65% 60%, 68% 60%, 68% 78%, 76% 78%, 76% 50%, 79% 50%, 79% 43%, 81% 43%,
    81% 50%, 84% 50%, 84% 43%, 86% 43%, 86% 50%, 89% 50%, 89% 78%, 95% 78%,
    95% 70%, 98% 70%, 98% 78%, 100% 78%, 100% 100%
  );
}

#title-stars {
  position: absolute; inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 28% 34%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1.5px 1.5px at 41% 12%, rgba(255,255,255,0.7), transparent),
    radial-gradient(1px 1px at 55% 28%, rgba(255,255,255,0.45), transparent),
    radial-gradient(1.5px 1.5px at 63% 8%, rgba(255,255,255,0.75), transparent),
    radial-gradient(1px 1px at 84% 15%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1.2px 1.2px at 91% 38%, rgba(255,255,255,0.6), transparent),
    radial-gradient(1px 1px at 7% 44%, rgba(255,255,255,0.4), transparent);
  animation: starTwinkle 5s ease-in-out infinite alternate;
}

.title-content {
  position: relative;
  text-align: center;
  padding: 0 24px;
  animation: fadeUp 1.1s var(--ease-out) both;
}

.title-kicker {
  font-size: 15px;
  letter-spacing: 0.45em;
  text-transform: uppercase;
  color: var(--torch);
  margin-bottom: 18px;
  animation: kickerGlow 3.5s ease-in-out infinite alternate;
}

#game-title {
  font-size: clamp(52px, 9vw, 108px);
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1;
  background: linear-gradient(180deg, #f4e9c8 0%, var(--gold-bright) 45%, #8a6d1c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 30px rgba(201, 162, 39, 0.25));
}

.title-sub {
  margin-top: 18px;
  font-size: clamp(15px, 2vw, 19px);
  font-style: italic;
  color: var(--text-dim);
}

.title-buttons {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 44px;
  flex-wrap: wrap;
}

.title-foot {
  margin-top: 46px;
  font-size: 12.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(139, 136, 120, 0.65);
}

/* ============ BUTTONS ============ */

.btn {
  padding: 13px 30px;
  font-size: 16px;
  letter-spacing: 0.06em;
  color: var(--gold-bright);
  background: rgba(201, 162, 39, 0.06);
  border: 1px solid rgba(201, 162, 39, 0.45);
  border-radius: 10px;
  transition: transform 0.25s var(--ease-spring), background 0.25s, box-shadow 0.25s, border-color 0.25s;
}
.btn:hover {
  background: rgba(201, 162, 39, 0.14);
  border-color: var(--gold-bright);
  transform: translateY(-2px);
  box-shadow: 0 8px 26px rgba(201, 162, 39, 0.18);
}
.btn:active { transform: translateY(0) scale(0.98); }

.btn-primary {
  background: linear-gradient(180deg, rgba(201, 162, 39, 0.28), rgba(201, 162, 39, 0.12));
  border-color: var(--gold);
}

.btn-ghost {
  border-color: rgba(216, 211, 200, 0.2);
  color: var(--text-dim);
}
.btn-ghost:hover { color: var(--text); box-shadow: none; }

.btn-danger { border-color: rgba(224, 82, 82, 0.5); color: #eb8f8f; background: rgba(224, 82, 82, 0.07); }
.btn-danger:hover { background: rgba(224, 82, 82, 0.16); border-color: var(--danger); box-shadow: 0 8px 26px rgba(224, 82, 82, 0.15); }

/* ============ GAME SCREEN LAYOUT ============ */

#game-screen {
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1000px 600px at 50% -20%, #171b2c 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
}

/* ---- HUD ---- */

#hud {
  height: var(--hud-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(11, 14, 26, 0.72);
  border-bottom: 1px solid rgba(201, 162, 39, 0.14);
  backdrop-filter: blur(10px);
  z-index: 30;
}

.hud-left { display: flex; align-items: center; gap: 12px; min-width: 0; }

#room-badge {
  flex: 0 0 auto;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--bg-0);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
}

#room-title {
  font-size: 19px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-center { position: absolute; left: 50%; transform: translateX(-50%); }

#timer {
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.1em;
  color: var(--parchment);
  text-shadow: 0 0 18px rgba(232, 217, 176, 0.25);
  transition: color 0.5s;
}
#timer.warn { color: var(--torch); text-shadow: 0 0 18px rgba(255, 169, 77, 0.4); }
#timer.crit { color: var(--danger); animation: critPulse 1s ease-in-out infinite; }

.hud-right { display: flex; gap: 10px; }

.hud-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  font-size: 14px;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid rgba(216, 211, 200, 0.14);
  border-radius: 9px;
  transition: color 0.2s, border-color 0.2s, background 0.2s, transform 0.2s var(--ease-spring);
}
.hud-btn:hover {
  color: var(--gold-bright);
  border-color: rgba(201, 162, 39, 0.5);
  background: rgba(201, 162, 39, 0.07);
  transform: translateY(-1px);
}
.hud-btn-icon { font-size: 16px; }

/* ---- STAGE / SCENE ---- */

#stage {
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  padding: 16px 20px 10px;
  min-height: 0;
}

#scene-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  max-width: calc((100vh - var(--hud-h) - var(--inv-h) - var(--narr-h) - 40px) * 16 / 9);
  max-height: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(201, 162, 39, 0.12),
    inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  background: var(--bg-2);
}

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

#scene.scene-enter { animation: sceneEnter 0.9s var(--ease-out) both; }

#vignette {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 6;
  background: radial-gradient(ellipse 120% 100% at 50% 45%, transparent 55%, rgba(4, 3, 8, 0.55) 100%);
}

#embers { position: absolute; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }

.ember {
  position: absolute;
  bottom: -8px;
  width: var(--sz, 4px);
  height: var(--sz, 4px);
  border-radius: 50%;
  background: radial-gradient(circle, #ffd9a0 0%, var(--torch) 55%, transparent 75%);
  opacity: 0;
  animation: emberRise var(--dur, 7s) linear var(--delay, 0s) 1 both;
}

/* ---- HOTSPOTS ---- */

#hotspots { position: absolute; inset: 0; z-index: 8; }

.hotspot {
  position: absolute;
  border-radius: 10px;
  cursor: pointer;
  outline: none;
  border: 1px solid transparent;
  background: transparent;
  transition: background 0.25s, border-color 0.25s, box-shadow 0.25s;
}
.hotspot:hover, .hotspot:focus-visible {
  background: radial-gradient(ellipse at center, rgba(232, 200, 90, 0.10) 0%, transparent 70%);
  border-color: rgba(232, 200, 90, 0.35);
  box-shadow: 0 0 24px rgba(232, 200, 90, 0.12), inset 0 0 18px rgba(232, 200, 90, 0.07);
}

.hotspot::after {
  content: attr(data-label);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(4px);
  padding: 5px 12px;
  font-size: 13px;
  font-family: var(--serif);
  letter-spacing: 0.08em;
  white-space: nowrap;
  color: var(--parchment);
  background: rgba(9, 11, 20, 0.92);
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 7px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.25s var(--ease-out);
}
.hotspot:hover::after, .hotspot:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.hotspot.label-below::after { bottom: auto; top: calc(100% + 8px); }

/* ---- NARRATION BAR (reserved strip below the scene — NEVER covers it) ---- */

#narration-bar {
  height: var(--narr-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 24px;
  background: rgba(9, 11, 20, 0.6);
  border-top: 1px solid rgba(201, 162, 39, 0.1);
  z-index: 25;
}

#message-card {
  position: relative;
  width: min(100%, 900px);
  max-height: 100%;
  overflow-y: auto;
  padding: 8px 40px 8px 18px;
  background: linear-gradient(180deg, rgba(13, 16, 28, 0.85), rgba(9, 11, 20, 0.9));
  border: 1px solid rgba(201, 162, 39, 0.28);
  border-radius: 10px;
  cursor: pointer;
  animation: fadeUp 0.35s var(--ease-out) both;
}
#message-card::-webkit-scrollbar { width: 4px; }
#message-card::-webkit-scrollbar-thumb { background: rgba(201, 162, 39, 0.3); border-radius: 2px; }

#message-text {
  font-size: 15.5px;
  line-height: 1.5;
  color: var(--parchment);
  font-style: italic;
  min-height: 1.5em;
}
#message-text::after {
  content: "";
  display: inline-block;
  width: 8px; height: 1.1em;
  margin-left: 3px;
  vertical-align: text-bottom;
  background: rgba(232, 217, 176, 0.7);
  animation: caretBlink 0.9s steps(1) infinite;
}
#message-card.done #message-text::after { display: none; }

#message-more {
  position: absolute;
  right: 12px; bottom: 8px;
  font-size: 10px;
  color: var(--gold);
  opacity: 0;
  animation: bobHint 1.4s ease-in-out infinite;
}
#message-card.done #message-more { opacity: 0.8; }

/* ---- INVENTORY ---- */

#inventory {
  height: var(--inv-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 26px;
  background: rgba(11, 14, 26, 0.78);
  border-top: 1px solid rgba(201, 162, 39, 0.14);
  backdrop-filter: blur(10px);
  z-index: 30;
}

#inv-label {
  font-size: 11px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-dim);
}

#inv-slots { display: flex; gap: 12px; align-items: center; flex: 1; overflow-x: auto; padding: 4px 2px; }
#inv-slots::-webkit-scrollbar { height: 4px; }
#inv-slots::-webkit-scrollbar-thumb { background: rgba(201, 162, 39, 0.3); border-radius: 2px; }

.inv-item {
  position: relative;
  flex: 0 0 auto;
  width: 56px; height: 56px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, rgba(42, 45, 58, 0.6), rgba(28, 31, 43, 0.8));
  border: 1px solid rgba(216, 211, 200, 0.16);
  border-radius: 11px;
  cursor: pointer;
  transition: transform 0.25s var(--ease-spring), border-color 0.25s, box-shadow 0.25s;
}
.inv-item svg { width: 38px; height: 38px; pointer-events: none; }
.inv-item:hover {
  transform: translateY(-4px);
  border-color: rgba(201, 162, 39, 0.55);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
}
.inv-item.selected {
  border-color: var(--gold-bright);
  box-shadow: 0 0 0 2px rgba(232, 200, 90, 0.35), 0 0 22px rgba(232, 200, 90, 0.25);
  animation: selectedPulse 1.6s ease-in-out infinite;
}
.inv-item.just-added { animation: itemPop 0.6s var(--ease-spring) both; }

.inv-item::after {
  content: attr(data-name);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%) translateY(4px);
  padding: 5px 12px;
  font-size: 13px;
  white-space: nowrap;
  color: var(--parchment);
  background: rgba(9, 11, 20, 0.94);
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 7px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.25s var(--ease-out);
  z-index: 50;
}
.inv-item:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- FLY-TO-INVENTORY LAYER ---- */

#fly-layer { position: fixed; inset: 0; pointer-events: none; z-index: 200; }
.fly-item {
  position: absolute;
  width: 46px; height: 46px;
  will-change: transform, opacity;
}
.fly-item svg { width: 100%; height: 100%; }

/* ============ MODALS ============ */

#modal-root { position: fixed; inset: 0; z-index: 100; pointer-events: none; }

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(4, 5, 10, 0.65);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.35s;
  pointer-events: auto;
}
.modal-backdrop.show { opacity: 1; }

.modal-card {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  width: min(92vw, 620px);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(165deg, #171a28 0%, #10131f 100%);
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 16px;
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.7), 0 0 60px rgba(201, 162, 39, 0.06);
  opacity: 0;
  pointer-events: auto;
  transition: opacity 0.3s, transform 0.45s var(--ease-spring);
}
.modal-card.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.modal-card.wide { width: min(94vw, 900px); }
.modal-card.shake { animation: shakeX 0.5s both; }

.modal-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 14px;
  border-bottom: 1px solid rgba(201, 162, 39, 0.18);
}
.modal-title {
  font-size: 19px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-bright);
  font-weight: 500;
}
.modal-close {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-size: 18px;
  color: var(--text);
  background: rgba(216, 211, 200, 0.06);
  border: 1px solid rgba(216, 211, 200, 0.28);
  border-radius: 9px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s, transform 0.2s;
}
.modal-close:hover { color: #fff; background: rgba(224, 82, 82, 0.16); border-color: rgba(224, 82, 82, 0.6); transform: rotate(90deg); }

.modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 22px 26px;
  font-size: 16px;
  line-height: 1.6;
}
.modal-body::-webkit-scrollbar { width: 6px; }
.modal-body::-webkit-scrollbar-thumb { background: rgba(201, 162, 39, 0.3); border-radius: 3px; }

.modal-body p { margin-bottom: 12px; }
.modal-body p:last-child { margin-bottom: 0; }

.modal-foot {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 14px 24px 20px;
}

/* parchment note styling for documents found in the world */
.parchment-note {
  position: relative;
  margin: 6px auto;
  padding: 26px 30px;
  max-width: 480px;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(120, 90, 40, 0.16) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 90%, rgba(100, 70, 30, 0.2) 0%, transparent 50%),
    linear-gradient(170deg, #e8d9b0 0%, #d9c493 55%, #cbb37e 100%);
  color: var(--ink);
  border-radius: 4px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5), inset 0 0 40px rgba(107, 78, 34, 0.18);
  font-style: italic;
  line-height: 1.7;
  animation: fadeUp 0.5s var(--ease-out) both;
}
.parchment-note::before, .parchment-note::after {
  content: "";
  position: absolute;
  width: 100%; left: 0;
  height: 8px;
  background: inherit;
  filter: brightness(0.92);
}
.parchment-note .note-title {
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 13px;
  margin-bottom: 10px;
  color: #5a4218;
}
.parchment-note.aged { filter: sepia(0.2) brightness(0.94); }

/* ============ PUZZLE UI PRIMITIVES ============ */

/* Photoreal mechanism banner at the head of a puzzle modal. Per-puzzle art is
   set inline (background-image), resolved relative to the game page. */
.puzzle-hero {
  width: 100%; height: 132px; margin: -2px 0 18px; border-radius: 10px;
  background-size: cover; background-position: center 44%; background-repeat: no-repeat;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 -44px 48px rgba(0, 0, 0, 0.72), 0 6px 20px rgba(0, 0, 0, 0.5);
}

.puzzle-desc { color: var(--text-dim); font-size: 15px; margin-bottom: 18px; }

.puzzle-row { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; margin: 14px 0; }

.puzzle-input {
  padding: 12px 16px;
  font-family: var(--serif);
  font-size: 18px;
  letter-spacing: 0.2em;
  text-align: center;
  color: var(--parchment);
  background: rgba(7, 9, 18, 0.7);
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.puzzle-input:focus { border-color: var(--gold-bright); box-shadow: 0 0 0 3px rgba(232, 200, 90, 0.15); }

/* rotating dial / ring selector */
.dial {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  user-select: none;
}
.dial-btn {
  width: 40px; height: 26px;
  display: grid; place-items: center;
  color: var(--gold);
  background: rgba(201, 162, 39, 0.08);
  border: 1px solid rgba(201, 162, 39, 0.3);
  border-radius: 7px;
  font-size: 12px;
  transition: background 0.15s, transform 0.15s;
}
.dial-btn:hover { background: rgba(201, 162, 39, 0.2); }
.dial-btn:active { transform: scale(0.92); }
.dial-face {
  width: 58px; height: 64px;
  display: grid; place-items: center;
  font-size: 28px;
  color: var(--parchment);
  background: linear-gradient(180deg, #232738, #161927);
  border: 1px solid rgba(201, 162, 39, 0.4);
  border-radius: 12px;
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.6), 0 2px 0 rgba(255,255,255,0.04);
  transition: transform 0.22s var(--ease-spring), color 0.2s;
}
.dial-face.tick { animation: dialTick 0.25s var(--ease-spring); }

/* draggable / arrangeable tiles */
.tile {
  display: grid;
  place-items: center;
  min-width: 64px; min-height: 64px;
  padding: 8px;
  background: linear-gradient(180deg, #262a3b, #181b29);
  border: 1px solid rgba(216, 211, 200, 0.2);
  border-radius: 12px;
  cursor: grab;
  user-select: none;
  transition: transform 0.25s var(--ease-spring), border-color 0.2s, box-shadow 0.25s;
}
.tile:hover { border-color: rgba(201, 162, 39, 0.55); transform: translateY(-3px); }
.tile.dragging { opacity: 0.4; cursor: grabbing; }
.tile.slot-target { border-style: dashed; border-color: rgba(201, 162, 39, 0.5); background: rgba(201, 162, 39, 0.05); }
.tile.correct-flash { animation: correctFlash 0.7s both; }

/* lever */
.lever { display: inline-flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.lever-track {
  width: 26px; height: 78px;
  border-radius: 13px;
  background: linear-gradient(180deg, #10121d, #1e2231);
  border: 1px solid rgba(201, 162, 39, 0.3);
  box-shadow: inset 0 4px 12px rgba(0,0,0,0.7);
  position: relative;
}
.lever-knob {
  position: absolute;
  left: 50%; top: 6px;
  width: 34px; height: 34px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e8c85a, #8a6d1c 70%);
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
  transition: top 0.35s var(--ease-spring);
}
.lever.down .lever-knob { top: calc(100% - 40px); }
.lever-label { font-size: 12px; letter-spacing: 0.15em; color: var(--text-dim); text-transform: uppercase; }

/* feedback banner inside puzzles */
.puzzle-feedback {
  min-height: 22px;
  text-align: center;
  font-size: 14px;
  font-style: italic;
  color: var(--text-dim);
  transition: color 0.3s;
}
.puzzle-feedback.bad { color: var(--danger); }
.puzzle-feedback.good { color: var(--ok); }

/* ============ GUS, THE COMPANION ============ */

/* Gus ALWAYS docks top-left, clear of scene interactions (series rule).
   Room authors: keep the top-left ~190x210 scene-unit zone free of critical
   hotspots — see docs/ROOM_CONTRACT.md. */
#gus-dock {
  position: absolute;
  left: 14px;
  top: 14px;
  z-index: 14;
  width: 74px;
  height: 86px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  filter: drop-shadow(0 0 14px rgba(154, 196, 255, 0.35));
  animation: gusBob 4.5s ease-in-out infinite;
  transition: transform 0.3s var(--ease-spring), filter 0.3s;
}
#gus-dock:hover {
  transform: scale(1.12);
  filter: drop-shadow(0 0 24px rgba(154, 196, 255, 0.65));
}
#gus-dock svg { width: 100%; height: 100%; }
#gus-dock img.gus-img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }

#gus-dock::after {
  content: attr(data-label);
  position: absolute;
  left: 50%;
  top: calc(100% + 4px);
  transform: translateX(-50%) translateY(-4px);
  padding: 4px 11px;
  font-size: 12.5px;
  letter-spacing: 0.08em;
  white-space: nowrap;
  color: #cfe0ff;
  background: rgba(9, 11, 20, 0.92);
  border: 1px solid rgba(154, 196, 255, 0.4);
  border-radius: 7px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.25s var(--ease-out);
}
#gus-dock:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

@keyframes gusBob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}

.gus-dialog { display: flex; gap: 20px; align-items: flex-start; }
.gus-portrait { flex: 0 0 120px; filter: drop-shadow(0 0 18px rgba(154, 196, 255, 0.3)); animation: gusBob 5s ease-in-out infinite; }
.gus-portrait svg { width: 120px; height: 140px; }
.gus-portrait img.gus-img { width: 120px; height: auto; display: block; border-radius: 12px; }
.gus-right { flex: 1 1 auto; min-width: 0; }

.gus-speech {
  font-style: italic;
  font-size: 16px;
  line-height: 1.55;
  color: #cfe0ff;
  margin-bottom: 16px;
}

.gus-tiers { display: flex; flex-direction: column; gap: 10px; }

.gus-tier {
  padding: 12px 16px;
  border-radius: 11px;
  border: 1px solid rgba(216, 211, 200, 0.14);
  background: rgba(7, 9, 18, 0.5);
}
.gus-tier.unlocked { border-color: rgba(201, 162, 39, 0.4); animation: fadeUp 0.4s var(--ease-out) both; }
.gus-tier.next { border-color: rgba(154, 196, 255, 0.35); }
.gus-tier.locked { opacity: 0.45; }

.gus-tier-name {
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.gus-tier-paid {
  font-size: 10px;
  color: var(--bg-0);
  background: var(--gold);
  padding: 2px 7px;
  border-radius: 999px;
  letter-spacing: 0.1em;
}
.gus-tier-lock { font-size: 11px; }
.gus-tier-text { font-size: 15px; line-height: 1.5; color: var(--parchment); font-style: italic; }
.gus-tier-buy { padding: 9px 18px; font-size: 14px; }
.gus-cost { color: var(--danger); font-size: 13px; margin-left: 6px; }

@media (max-width: 640px) {
  .gus-dialog { flex-direction: column; align-items: center; }
}

/* ============ JOURNAL ============ */

#btn-journal.badge-pulse { animation: journalPulse 1.2s var(--ease-spring) 2; border-color: var(--gold-bright); color: var(--gold-bright); }

@keyframes journalPulse {
  0%, 100% { transform: scale(1); box-shadow: none; }
  40%      { transform: scale(1.1); box-shadow: 0 0 22px rgba(232, 200, 90, 0.5); }
}

.journal-section-title {
  font-size: 12px;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 18px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(201, 162, 39, 0.2);
}
.journal-section-title:first-child { margin-top: 0; }

.journal-suns { display: flex; flex-wrap: wrap; gap: 16px; }
.journal-sun {
  width: 96px;
  text-align: center;
  padding: 10px 6px 8px;
  background: rgba(7, 9, 18, 0.5);
  border: 1px solid rgba(201, 162, 39, 0.25);
  border-radius: 11px;
  animation: springIn 0.5s var(--ease-spring) both;
}
.journal-sun svg { width: 64px; height: 74px; }
.journal-sun-cap { font-size: 11px; color: var(--text-dim); margin-top: 4px; line-height: 1.35; }

.journal-entry {
  margin-bottom: 10px;
  border: 1px solid rgba(216, 211, 200, 0.12);
  border-radius: 10px;
  background: rgba(7, 9, 18, 0.4);
  overflow: hidden;
}
.journal-entry summary {
  padding: 12px 16px;
  cursor: pointer;
  font-size: 15px;
  color: var(--parchment);
  letter-spacing: 0.04em;
  list-style: none;
  transition: background 0.2s;
}
.journal-entry summary::before { content: "❧ "; color: var(--gold); }
.journal-entry summary:hover { background: rgba(201, 162, 39, 0.06); }
.journal-entry[open] summary { border-bottom: 1px solid rgba(216, 211, 200, 0.1); }
.journal-entry-body { padding: 14px 18px; font-size: 15px; }

/* ============ HINT TOAST ============ */

.toast {
  position: fixed;
  top: calc(var(--hud-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  max-width: min(92vw, 560px);
  padding: 14px 22px;
  font-size: 15px;
  color: var(--parchment);
  background: linear-gradient(180deg, rgba(23, 26, 40, 0.97), rgba(14, 17, 28, 0.97));
  border: 1px solid rgba(201, 162, 39, 0.4);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: toastIn 0.5s var(--ease-spring) both;
}
.toast.leaving { animation: toastOut 0.4s var(--ease-out) both; }
.toast .toast-cost { color: var(--danger); font-size: 13px; margin-left: 8px; }

/* ============ FADER ============ */

#fader {
  position: fixed; inset: 0;
  z-index: 300;
  background: #030308;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.55s ease;
}
#fader.active { opacity: 1; pointer-events: auto; }

/* ============ END SCREENS ============ */

.end-screen {
  text-align: center;
  padding: 10px 6px;
}
/* Cinematic win/lose stinger at the head of the end screen (video, poster-backed). */
.end-hero {
  width: 100%; height: 168px; margin: -2px 0 22px; border-radius: 12px; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 -52px 56px rgba(0, 0, 0, 0.72), 0 8px 24px rgba(0, 0, 0, 0.5);
  background: #05060a;
}
.end-hero video { width: 100%; height: 100%; object-fit: cover; display: block; }
.end-screen h2 {
  font-size: 40px;
  letter-spacing: 0.06em;
  margin-bottom: 14px;
  background: linear-gradient(180deg, #f4e9c8, var(--gold-bright), #8a6d1c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.end-screen.defeat h2 { background: linear-gradient(180deg, #f0b9b9, var(--danger), #6d1c1c); -webkit-background-clip: text; background-clip: text; }
.end-screen .end-story { font-style: italic; color: var(--text-dim); line-height: 1.7; max-width: 460px; margin: 0 auto 22px; }
.end-stats {
  display: flex;
  justify-content: center;
  gap: 34px;
  margin: 22px 0 6px;
}
.end-stat { text-align: center; }
.end-stat .num { font-size: 30px; color: var(--parchment); font-variant-numeric: tabular-nums; }
.end-stat .lbl { font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--text-dim); margin-top: 4px; }

/* ============ RESPONSIVE ============ */

@media (max-width: 860px) {
  #room-title { font-size: 15px; }
  #timer { font-size: 21px; }
  .hud-btn { padding: 7px 10px; font-size: 13px; }
  #stage { padding: 10px; }
  .title-buttons { flex-direction: column; align-items: center; }
}

/* At phone width the absolute-centred timer would sit on top of the buttons,
   so float it back into the flex row; drop the room title (the badge already
   shows progress and it truncates to nothing) and collapse Journal to its
   icon (its label is a bare text node, so zero the button font and restore
   the icon span). */
@media (max-width: 560px) {
  #room-title { display: none; }
  .hud-center { position: static; transform: none; }
  #btn-journal { font-size: 0; gap: 0; }
  #btn-journal .hud-btn-icon { font-size: 16px; }
  .hud { padding: 0 12px; }
  .hud-right { gap: 6px; }
  .hud-btn { padding: 7px 9px; }
}

/* ============ DEV ROOM-JUMPER (inspection tool, all games) ============ */
#dev-skip {
  position: fixed; left: 10px; bottom: 10px; z-index: 99999;
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px; border-radius: 9px;
  background: rgba(10, 12, 18, 0.72); border: 1px dashed rgba(255, 255, 255, 0.38);
  font: 600 11px/1 ui-monospace, "Consolas", monospace; color: #cfd6e0;
  opacity: 0.42; transition: opacity 0.2s; backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
#dev-skip:hover, #dev-skip:focus-within { opacity: 1; }
#dev-skip .dev-tag { color: #ffb45e; letter-spacing: 0.1em; }
#dev-skip .dev-btn {
  cursor: pointer; width: 24px; height: 22px; padding: 0; font-size: 12px; line-height: 1;
  color: #fff; background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 5px;
}
#dev-skip .dev-btn:hover { background: rgba(255, 255, 255, 0.22); }
#dev-skip select {
  max-width: 168px; padding: 3px 5px; font: inherit; color: #fff;
  background: rgba(0, 0, 0, 0.45); border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 5px; cursor: pointer;
}
@media (max-width: 860px) { #dev-skip select { max-width: 110px; } }
