/* ==============================================================
   BLOCK FIT — Industrial horror puzzle styling
   ============================================================== */

:root {
  --ink: #d8c4b4;
  --muted: #8a7468;
  --ground: #0b0709;
  --surface: #171014;
  --surface-2: #1f161b;
  --line: #3a2b30;
  --brand: #8c1f2c;
  --brand-hover: #6a1620;
  --accent: #8f9a2e;
  --btn-bg: #22181d;
  --btn-bg-hover: #2a1d23;
  --danger: #a04b42;
  --shadow: rgba(0, 0, 0, 0.55);

  /* Block-tray border color for the current hospital area (set by game.js).
     Used by the story caption so the caption chrome matches the tray. */
  --area-frame: #8f1d26;
  --area-frame-bg: rgba(140, 31, 44, 0.5);
  --area-frame-glow: rgba(140, 31, 44, 0.24);

  color-scheme: dark;
}

body.theme-horror {
  --ink: #d8c4b4;
  --muted: #8a7468;
  --ground: #0b0709;
  --surface: #171014;
  --surface-2: #1f161b;
  --line: #3a2b30;
  --brand: #8c1f2c;
  --brand-hover: #6a1620;
  --accent: #8f9a2e;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--ground);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game-container {
  position: fixed;
  inset: 0;
}

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  touch-action: none;
  cursor: grab;
}

#game-canvas.dragging {
  cursor: grabbing;
}

.screen-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.screen-layer > * {
  pointer-events: auto;
}

.hidden {
  display: none !important;
}

/* ==============================================================
   MENU — LEVEL MAP (candy-style road over the canvas)
   ============================================================== */

#screen-menu {
  padding: 0;
}

.map-ui {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.map-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 14px 0;
  pointer-events: auto;
}

.map-brand {
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.05em;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 16px;
  box-shadow: 0 3px 8px var(--shadow);
  white-space: nowrap;
}

.map-hud-buttons {
  display: flex;
  gap: 8px;
}

.map-body {
  flex: 1;
  min-height: 0;
  pointer-events: none;
}

.map-footer {
  display: flex;
  justify-content: center;
  padding: 0 20px max(16px, env(safe-area-inset-bottom));
  pointer-events: auto;
}

.map-footer .btn-industrial-primary {
  min-width: 200px;
}

/* ==============================================================
   BUTTONS (industrial)
   ============================================================== */

.btn-industrial-primary,
.btn-industrial-secondary {
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 15px 18px;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  box-shadow: 0 3px 10px var(--shadow);
}

.btn-industrial-primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.btn-industrial-primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}

.btn-industrial-primary:active {
  transform: translateY(1px) scale(0.99);
}

.btn-industrial-secondary {
  background: var(--btn-bg);
  color: var(--ink);
}

.btn-industrial-secondary:hover {
  background: var(--btn-bg-hover);
  border-color: var(--accent);
}

.btn-industrial-secondary:active {
  transform: translateY(1px) scale(0.99);
}

.btn-danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-icon {
  font-size: 15px;
  line-height: 1;
}

/* ==============================================================
   HUD
   ============================================================== */

#hud-in-game {
  display: flex;
  flex-direction: column;
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 14px 0;
}

.hud-actions {
  display: flex;
  gap: 8px;
}

.btn-hud-icon {
  cursor: pointer;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 8px var(--shadow);
  transition: background 0.15s ease, transform 0.08s ease;
}

.btn-hud-icon:hover {
  background: var(--surface-2);
}

.btn-hud-icon:active {
  transform: translateY(1px) scale(0.96);
}

.level-toast {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 3px 12px var(--shadow);
  opacity: 1;
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.level-toast.hidden {
  display: none;
}

.level-toast.toast-fadeout {
  opacity: 0;
  transform: translateY(-6px);
}

.level-tag {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.3em;
  color: var(--brand);
}

.level-toast-text {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

/* ==============================================================
   TUTORIAL HINT (level 1 training)
   ============================================================== */

#tutorial {
  position: fixed;
  left: 50%;
  top: max(122px, calc(110px + env(safe-area-inset-top)));
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(92vw, 520px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(9, 5, 7, 0.86);
  border: 1px solid #40272c;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: none;
}

.tutorial-tag {
  flex: none;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #c0393f;
  border: 1px solid #6a1620;
  background: rgba(140, 31, 44, 0.14);
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
}

#tutorial-text {
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.35;
}

#tutorial-countdown {
  flex: none;
  min-width: 18px;
  padding-left: 9px;
  border-left: 1px solid rgba(192, 57, 63, 0.42);
  color: rgba(216, 196, 180, 0.72);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.08em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ==============================================================
   STORY LINE (horror caption at the top of every level)
   ============================================================== */

#story-banner {
  flex: 1 1 auto;
  min-width: 0;
  align-self: center;
  margin: 0 10px;
  padding: 5px 14px;
  border-radius: 12px;
  /* Border/background/glow are defined once in the NEW GAMEPLAY INTERFACE
     section below (tinted with --dock-frame, the tray border color). Kept out
     of here on purpose so later rules can't silently override them. */
  pointer-events: none;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#story-text {
  display: block;
  max-width: 100%;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  font-family: "Times New Roman", "Times", Georgia, serif;
  font-style: italic;
  font-size: clamp(11px, 2.7vw, 14px);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.35;
  text-align: center;
  color: #f0ddce;
  text-shadow:
    0 0 4px rgba(190, 34, 44, 0.85),
    0 0 12px rgba(150, 22, 32, 0.5),
    0 1px 0 rgba(0, 0, 0, 0.95),
    0 0 3px rgba(0, 0, 0, 0.9);
  animation: story-flicker 7s ease-in-out infinite;
}

#story-banner.story-enter #story-text {
  animation: story-enter 0.7s ease-out, story-flicker 7s ease-in-out infinite;
}

@keyframes story-enter {
  0% { opacity: 0; transform: translateY(-3px); filter: blur(3px); }
  100% { opacity: 1; transform: translateY(0); filter: blur(0); }
}

@keyframes story-flicker {
  0%, 100% { opacity: 1; }
  46% { opacity: 1; }
  47% { opacity: 0.5; }
  48.5% { opacity: 1; }
  90% { opacity: 1; }
  91% { opacity: 0.68; }
  92.5% { opacity: 1; }
}

/* The level number floats just under the top bar so it never fights the
   story caption for the centre of the HUD row. */
#level-toast {
  position: absolute;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: fit-content;
  top: max(64px, calc(52px + env(safe-area-inset-top)));
  z-index: 5;
}

/* ==============================================================
   VICTORY (all 100 forms sealed)
   ============================================================== */

.victory-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 26px 24px 22px;
  box-shadow: 0 18px 60px var(--shadow);
  animation: modal-rise 0.25s ease;
  text-align: center;
}

.victory-seal {
  width: 84px;
  height: 84px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 35% 30%, #b3343c, var(--brand) 62%, #55121a);
  border: 2px solid var(--line);
  box-shadow: 0 0 0 6px rgba(140, 31, 44, 0.22), 0 8px 26px var(--shadow);
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.02em;
  color: #f3e2d2;
}

.victory-title {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--ink);
  text-transform: uppercase;
}

.victory-sub {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--muted);
  text-transform: uppercase;
}

.victory-name-label {
  margin-top: 20px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.3em;
  color: var(--muted);
}

.victory-name {
  margin-top: 4px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--brand);
}

.victory-actions {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.victory-actions .btn-industrial-primary,
.victory-actions .btn-industrial-secondary {
  width: 100%;
}

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

.screen-modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.55);
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 50;
}

.screen-modal > * {
  margin: auto;
}

.victory-card,
.modal-card {
  flex: 0 0 auto;
}

.modal-card {
  width: 100%;
  max-width: 340px;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  background: var(--surface);
  border: 1px solid var(--ui-line);
  border-radius: 3px;
  padding: 20px;
  box-shadow: 0 18px 60px var(--shadow);
  animation: modal-rise 0.2s ease;
}

.modal-card-large {
  max-width: 440px;
}

@keyframes modal-rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  margin-bottom: 16px;
}

.modal-header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}

.modal-kicker {
  font: 9px var(--ui-mono);
  font-weight: normal;
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  color: var(--ui-teal);
  text-transform: uppercase;
}

.modal-emblem {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-indent: 0.12em;
  color: #f3e2d2;
  background: radial-gradient(circle at 35% 30%, #b3343c, var(--brand) 62%, #55121a);
  border: 1px solid var(--line);
  box-shadow: 0 0 0 5px rgba(140, 31, 44, 0.16), 0 8px 24px var(--shadow);
}

.modal-title {
  margin: 0;
  font-family: var(--ui-sans);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0.18em;
  line-height: 1.05;
  color: var(--ui-cream);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.modal-confirm-card {
  max-width: 340px;
  text-align: center;
}

.confirm-message {
  margin: 0;
  color: var(--muted);
  font-family: var(--ui-sans);
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: 0.03em;
  overflow-wrap: break-word;
}

.modal-actions-stack {
  gap: 12px;
}

/* ==============================================================
   LEADERBOARD
   ============================================================== */

.leaderboard-user-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  margin-bottom: 14px;
}

.user-card-rank-box {
  flex: none;
  width: 74px;
  height: 74px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.rank-label {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.2em;
  opacity: 0.85;
}

.rank-num {
  font-size: 22px;
  font-weight: 900;
  line-height: 1.1;
}

.user-card-info {
  min-width: 0;
  flex: 1;
}

.user-card-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-name {
  font-weight: 800;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-micro-action {
  flex: none;
  cursor: pointer;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 4px 8px;
}

.btn-micro-action:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.user-card-score-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.score-val {
  color: var(--ink);
  font-weight: 700;
}

.leaderboard-table-container {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.leaderboard-table-header {
  display: flex;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--muted);
}

.leaderboard-entries-list {
  max-height: 300px;
  overflow-y: auto;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}

.leaderboard-row:last-child {
  border-bottom: none;
}

.leaderboard-row.is-current-user {
  background: rgba(255, 92, 43, 0.12);
}

.col-rank {
  flex: none;
  width: 34px;
  font-weight: 800;
}

.col-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col-score {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 24px;
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
}

.rank-01 { background: #e8b52a; }
.rank-02 { background: #9aa3af; }
.rank-03 { background: #b07a4a; }
.rank-other { background: var(--line); color: var(--muted); }

/* ==============================================================
   WIN BANNER
   ============================================================== */

#win-banner {
  position: absolute;
  left: var(--board-x, 0px);
  top: var(--board-y, 0px);
  width: var(--board-w, 320px);
  height: var(--board-h, 320px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  pointer-events: none;
}

#win-banner .win-box {
  display: inline-block;
  max-width: min(84vw, 460px);
  padding: 18px 28px;
  border-radius: 14px;
  border: 0;
  /* Matches the top level-text background (--dock-frame, the tray-frame color),
     borderless: a soft radial glow that fades out toward the margins. */
  background: radial-gradient(
    ellipse 130% 160% at 50% 50%,
    rgba(var(--dock-frame-rgb, 46, 111, 168), 0.34) 0%,
    rgba(var(--dock-frame-rgb, 46, 111, 168), 0.12) 58%,
    rgba(var(--dock-frame-rgb, 46, 111, 168), 0) 100%
  );
  box-shadow: none;
  animation: pulse-win 0.4s ease;
  text-align: center;
}

#win-banner .win-title {
  font-size: clamp(15px, 3.4vw, 21px);
  font-weight: 800;
  letter-spacing: 0.03em;
  line-height: 1.32;
  color: var(--ui-cream, #e9e8d6);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.9);
  text-wrap: balance;
}

#win-banner .win-sub {
  margin-top: 8px;
  font-size: 11px;
  color: var(--ui-cream, #e9e8d6);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.9);
  opacity: 0.82;
  letter-spacing: 0.18em;
}

@keyframes pulse-win {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* ==============================================================
   LANDSCAPE / SHORT-SCREEN OPTIMIZATIONS
   ============================================================== */

@media (orientation: landscape) and (max-height: 520px) {
  .btn-hud-icon {
    width: 36px;
    height: 36px;
    font-size: 17px;
  }

  .hud-top {
    padding: max(6px, env(safe-area-inset-top)) 12px 0;
    gap: 6px;
  }

  .level-toast {
    padding: 6px 14px;
  }

  .level-toast-text {
    font-size: 13px;
  }

  .level-tag {
    font-size: 9px;
  }

  #story-banner {
    margin: 0 6px;
    padding: 3px 10px;
  }

  #story-text {
    font-size: 10.5px;
    line-height: 1.2;
  }

  #level-toast {
    top: max(56px, calc(46px + env(safe-area-inset-top)));
  }

  #tutorial {
    top: max(96px, calc(86px + env(safe-area-inset-top)));
  }

  .btn-industrial-primary,
  .btn-industrial-secondary {
    padding: 12px 16px;
    font-size: 13px;
  }

  .map-brand {
    font-size: 13px;
    padding: 7px 12px;
  }
}

@media (orientation: landscape) and (max-height: 420px) {
  #hud-in-game .level-toast {
    display: none;
  }

  .btn-hud-icon {
    width: 32px;
    height: 32px;
    font-size: 15px;
  }
}

/* ==============================================================
   PORTRAIT / MOBILE — story caption wraps onto multiple lines so
   the horror text never truncates while staying readable.
   ============================================================== */

@media (orientation: portrait) {
  #story-banner {
    margin: 0 8px;
    padding: 8px 12px;
    border-radius: 12px;
  }

  #story-text {
    font-size: clamp(12px, 3.5vw, 15px);
    line-height: 1.4;
    letter-spacing: 0.01em;
  }
}

/* ==============================================================
   HOSPITAL ESCAPE — 3D layer, horror menu, credits, settings
   (Patient Zero: Escape)
   ============================================================== */

#hospital-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

#game-canvas {
  z-index: 10;
  /* Keep the 2D ritual readable, but let the moving hospital remain visible
     through the board so the player never fully leaves the scene. */
  opacity: 0.93;
  transition: opacity 0.65s ease;
}

#game-canvas.scene-breathe {
  opacity: 0;
  pointer-events: none;
}

.screen-layer {
  z-index: 40;
}

.screen-layer.scene-breathe,
#tutorial.scene-breathe {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.55s ease;
}

/* area-switch blackout veil (opacity toggled by game.js) */
#area-fade {
  position: absolute;
  inset: 0;
  z-index: 45;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.9s ease;
}

#screen-menu {
  padding: 0;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(8, 11, 13, 0) 0%, rgba(4, 7, 8, 0.55) 100%),
    rgba(8, 11, 13, 0.18);
}

/* ---- Menu — new interface theme (slate, mono labels, teal accent) ---- */
.menu-ui {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  justify-content: safe center;
  gap: clamp(12px, 2.2vh, 26px);
  padding: max(14px, env(safe-area-inset-top)) 18px max(14px, env(safe-area-inset-bottom));
  text-align: center;
  pointer-events: auto;
  touch-action: pan-y;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.menu-ui::-webkit-scrollbar {
  display: none;
}

.menu-panel {
  pointer-events: auto;
  flex: 0 0 auto;
  width: min(92vw, 400px);
  display: flex;
  flex-direction: column;
  gap: clamp(16px, 2.6vh, 26px);
  padding: clamp(22px, 4vh, 36px) clamp(20px, 5vw, 34px);
  background: linear-gradient(180deg, var(--ui-panel) 0%, var(--ui-panel-deep) 100%);
  border: 1px solid var(--ui-line);
  border-radius: 3px;
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%);
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(233, 232, 211, 0.06),
    0 0 60px rgba(75, 198, 196, 0.05);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.menu-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.menu-title {
  margin: 0;
  font-family: var(--ui-sans);
  font-size: clamp(28px, 7vw, 48px);
  font-weight: 600;
  letter-spacing: 0.14em;
  line-height: 1.02;
  color: var(--ui-cream);
  text-shadow: 0 0 26px rgba(75, 198, 196, 0.16), 0 4px 24px rgba(0, 0, 0, 0.8);
  text-wrap: balance;
}

.menu-title-accent {
  color: var(--ui-teal);
}

.menu-title .menu-title-accent {
  display: block;
}

.menu-rule {
  width: 100%;
  height: 1px;
  margin-top: 4px;
  background: linear-gradient(90deg, transparent, rgba(75, 198, 196, 0.65) 50%, transparent);
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 11px;
  width: 100%;
}

.menu-save-info {
  font: 9px var(--ui-mono);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ui-teal);
  text-align: center;
  padding: 7px 10px;
  border: 1px dashed rgba(75, 198, 196, 0.28);
  background: rgba(27, 62, 61, 0.22);
}

.btn-horror-primary,
.btn-horror-secondary {
  cursor: pointer;
  width: 100%;
  border-radius: 2px;
  font-family: var(--ui-sans);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding: 14px 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform 0.1s ease, background 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
  border: 1px solid var(--ui-line);
  background: rgba(27, 31, 30, 0.8);
  color: #cdccc0;
  box-shadow: 0 4px 14px var(--shadow);
}

.btn-horror-primary {
  background: rgba(27, 62, 61, 0.55);
  border-color: rgba(75, 198, 196, 0.55);
  color: var(--ui-cream);
}

.btn-horror-primary:hover {
  border-color: var(--ui-teal-dim);
  color: #fff;
  box-shadow: 0 0 22px rgba(75, 198, 196, 0.2);
  transform: translateY(-1px);
}

.btn-horror-secondary:hover {
  background: rgba(31, 36, 35, 0.95);
  border-color: var(--ui-teal-dim);
  color: var(--ui-teal);
  transform: translateY(-1px);
}

.btn-horror-primary:active,
.btn-horror-secondary:active {
  transform: translateY(1px) scale(0.99);
}

[data-gd-ad-action]:disabled {
  cursor: wait;
  opacity: 0.55;
  transform: none;
}

.level-complete-card {
  text-align: center;
}

.btn-horror-primary:focus-visible,
.btn-horror-secondary:focus-visible {
  outline: 2px solid var(--ui-teal);
  outline-offset: 3px;
}

.btn-industrial-primary:focus-visible,
.btn-industrial-secondary:focus-visible,
.btn-hud-icon:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-icon {
  font-size: 13px;
}

.menu-foot {
  pointer-events: auto;
  max-width: 420px;
  font: 9px var(--ui-mono);
  letter-spacing: 0.3em;
  color: rgba(157, 158, 147, 0.6);
  text-transform: uppercase;
  animation: foot-breathe 4.5s ease-in-out infinite;
}

@keyframes foot-breathe {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.95; }
}

/* ---- Settings body ---- */
.modal-settings-card {
  max-width: 360px;
}

.settings-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.settings-section-title {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.3em;
  color: var(--brand);
  text-transform: uppercase;
}

.setting-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.setting-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--muted);
  text-transform: uppercase;
}

.setting-buttons {
  display: flex;
  gap: 8px;
}

.setting-buttons .btn-industrial-secondary {
  flex: 1;
  padding: 11px 12px;
}

.seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.seg-item {
  flex: 1;
  cursor: pointer;
  border: none;
  background: var(--btn-bg);
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  padding: 11px 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-item + .seg-item {
  border-left: 1px solid var(--line);
}

.seg-item.active {
  background: var(--brand);
  color: #fff;
}

/* ---- Credits ---- */
.modal-credits-card {
  max-width: 380px;
}

.credits-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}

.credits-image {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.credits-block {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 11px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.credits-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--muted);
  text-transform: uppercase;
}

.credits-value {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--ink);
  text-transform: uppercase;
}

.credits-value-large {
  font-size: 16px;
  letter-spacing: 0.12em;
  color: #b3343c;
}

.credits-creep {
  margin: 8px 0 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: rgba(170, 90, 90, 0.85);
  text-transform: uppercase;
  animation: foot-breathe 4s ease-in-out infinite;
}

/* ---- Settings & Credits match the main menu (slate / teal) ---- */
#modal-settings .modal-card,
#modal-credits .modal-card,
#modal-confirm .modal-card {
  background: linear-gradient(180deg, var(--ui-panel) 0%, var(--ui-panel-deep) 100%);
  border-color: var(--ui-line);
  border-radius: 3px;
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(233, 232, 211, 0.06),
    0 0 60px rgba(75, 198, 196, 0.05);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#modal-settings .settings-section,
#modal-credits .credits-block {
  background: rgba(27, 31, 30, 0.8);
  border-color: var(--ui-line);
  border-radius: 2px;
}

#modal-settings .settings-section-title {
  color: var(--ui-teal);
}

#modal-settings .setting-label {
  color: var(--ui-muted);
}

#modal-settings .seg {
  border-color: var(--ui-line);
}

#modal-settings .seg-item {
  background: rgba(27, 31, 30, 0.8);
  color: #cdccc0;
  font-family: var(--ui-sans);
  font-weight: 600;
}

#modal-settings .seg-item.active {
  background: rgba(75, 198, 196, 0.18);
  color: var(--ui-teal);
}

#modal-settings .btn-industrial-secondary,
#modal-confirm .btn-industrial-secondary {
  background: rgba(27, 31, 30, 0.8);
  border-color: var(--ui-line);
  color: #cdccc0;
  font-family: var(--ui-sans);
  border-radius: 2px;
}

#modal-settings .btn-industrial-secondary:hover,
#modal-confirm .btn-industrial-secondary:hover {
  background: rgba(31, 36, 35, 0.95);
  border-color: var(--ui-teal-dim);
  color: var(--ui-teal);
}

#modal-settings .btn-industrial-primary,
#modal-credits .btn-industrial-primary,
#modal-confirm .btn-industrial-primary {
  background: rgba(27, 62, 61, 0.55);
  border-color: rgba(75, 198, 196, 0.55);
  color: var(--ui-cream);
  font-family: var(--ui-sans);
  border-radius: 2px;
}

#modal-settings .btn-industrial-primary:hover,
#modal-credits .btn-industrial-primary:hover,
#modal-confirm .btn-industrial-primary:hover {
  border-color: var(--ui-teal-dim);
  color: #fff;
  box-shadow: 0 0 22px rgba(75, 198, 196, 0.2);
}

#modal-confirm .btn-danger:hover {
  background: rgba(107, 39, 50, 0.6);
  border-color: rgba(201, 103, 106, 0.8);
  color: #fff;
}

#modal-credits .credits-label {
  color: var(--ui-muted);
}

#modal-credits .credits-value {
  color: var(--ui-cream);
}

#modal-credits .credits-value-large {
  color: var(--ui-teal);
}

#modal-credits .credits-image {
  border-color: var(--ui-line);
  background: rgba(27, 31, 30, 0.6);
}

/* ---- Developer level select (dev tool — safe to delete) ---- */
.dev-only {
  opacity: 0.72;
  border-style: dashed;
}

.dev-only:hover {
  opacity: 1;
}

.modal-dev-card {
  max-width: 460px;
}

.dev-level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 8px;
  max-height: min(56vh, 380px);
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.dev-level-btn {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--btn-bg);
  color: var(--ink);
  border-radius: 8px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 9px 0;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.08s ease;
}

.dev-level-btn:hover {
  background: var(--surface-2);
  border-color: var(--brand);
  color: #fff;
}

.dev-level-btn:active {
  transform: translateY(1px) scale(0.97);
}

.dev-level-btn.is-current {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  box-shadow: 0 0 14px rgba(140, 31, 44, 0.5);
}

/* ---- Pause menu — new interface theme ---- */
.modal-pause {
  background: rgba(4, 7, 8, 0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 60;
}

/* Settings opened from the pause menu keeps the same blurred backdrop so the
   playing field behind it stays soft instead of showing through transparent. */
#modal-settings {
  background: rgba(4, 7, 8, 0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

/* Confirm dialog sits above the popup it was opened from. */
#modal-confirm {
  background: rgba(4, 7, 8, 0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 70;
}

.modal-pause-card {
  max-width: 360px;
  background: linear-gradient(180deg, var(--ui-panel) 0%, var(--ui-panel-deep) 100%);
  border: 1px solid rgba(75, 198, 196, 0.45);
  border-radius: 3px;
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.6), 0 0 40px rgba(75, 198, 196, 0.1);
}

.modal-pause-card .modal-emblem {
  width: 44px;
  height: 44px;
  border-radius: 0;
  color: var(--ui-teal);
  background: rgba(75, 198, 196, 0.1);
  border: 1px solid var(--ui-teal-dim);
  font: 13px var(--ui-mono);
  letter-spacing: 0.06em;
  text-indent: 0.06em;
  clip-path: polygon(0 0, 100% 0, 100% 75%, 75% 100%, 0 100%);
  box-shadow: 0 0 0 4px rgba(75, 198, 196, 0.08), 0 8px 24px rgba(0, 0, 0, 0.4);
}

.modal-pause-card .modal-title {
  font-family: var(--ui-sans);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--ui-cream);
}

.pause-sub {
  font: 9px var(--ui-mono);
  font-weight: normal;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--ui-muted);
  text-transform: uppercase;
}

.modal-pause-card .btn-danger:hover {
  background: rgba(107, 39, 50, 0.6);
  border-color: rgba(201, 103, 106, 0.8);
  color: #fff;
}

.modal-actions-hint {
  margin-top: 14px;
  text-align: center;
  font: 9px var(--ui-mono);
  letter-spacing: 0.24em;
  color: rgba(157, 158, 147, 0.55);
  text-transform: uppercase;
}

/* ==============================================================
   RESPONSIVE FIT — keep every menu/modal item on screen
   ============================================================== */

@media (min-width: 560px) {
  .modal-settings-card {
    max-width: 560px;
  }

  .settings-body {
    grid-template-columns: 1fr 1fr;
  }

  .settings-section-game {
    grid-column: 1 / -1;
  }
}

@media (max-height: 680px) {
  .menu-ui {
    gap: clamp(10px, 1.8vh, 18px);
  }

  .menu-panel {
    gap: 16px;
    padding: 22px 22px 24px;
  }

  .menu-title {
    font-size: clamp(26px, 6vw, 40px);
  }

  .btn-horror-primary,
  .btn-horror-secondary {
    padding: 13px 16px;
    font-size: 13px;
  }

  .modal-card {
    padding: 18px;
  }
}

@media (max-height: 560px) {
  .menu-rule {
    display: none;
  }

  .menu-panel {
    gap: 12px;
    padding: 18px 20px 20px;
  }

  .menu-buttons {
    gap: 8px;
  }

  .menu-foot {
    display: none;
  }

  .modal-emblem {
    width: 44px;
    height: 44px;
    font-size: 13px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .menu-ui {
    gap: 10px;
  }

  .menu-panel {
    width: min(78vw, 460px);
    gap: 12px;
    padding: 16px 22px 18px;
  }

  .menu-title {
    font-size: clamp(22px, 4.2vw, 34px);
  }

  .menu-buttons {
    gap: 8px;
  }

  .menu-foot {
    display: none;
  }

  .btn-horror-primary,
  .btn-horror-secondary {
    padding: 11px 16px;
    font-size: 13px;
  }

  .modal-pause-card {
    max-width: 460px;
  }
}

@media (max-width: 360px) {
  .menu-panel {
    width: 94vw;
    padding-left: 16px;
    padding-right: 16px;
  }

  .menu-title {
    letter-spacing: 0.05em;
  }

  .credits-value {
    font-size: 12.5px;
  }
}

/* ==============================================================
   NEW GAMEPLAY INTERFACE — UI chrome only (frames the canvas)
   ==============================================================
   These panels are punctuation around the existing canvas board and
   dock. Everything here is pointer-events:none so the canvas keeps
   every drag-and-drop gesture exactly as before. */

:root {
  --ui-teal: #81f0df;
  --ui-teal-dim: #4bc6c4;
  --ui-mono: "Share Tech Mono", "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --ui-sans: "Barlow Condensed", "Arial Narrow", sans-serif;
  --ui-cream: #e9e8d6;
  --ui-muted: #9d9e93;
  --ui-line: rgba(220, 221, 203, 0.22);
  --ui-line-bright: rgba(233, 232, 211, 0.56);
  --ui-panel: rgba(29, 32, 32, 0.9);
  --ui-panel-deep: rgba(18, 21, 21, 0.95);
}

/* ---- topbar: logo ---- */

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

.hud-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  pointer-events: none;
}

.hud-logo-mark {
  flex: none;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: var(--ui-teal);
  border: 1px solid var(--ui-teal-dim);
  background: rgba(75, 198, 196, 0.08);
  font: 14px var(--ui-mono);
  letter-spacing: 0.03em;
  clip-path: polygon(0 0, 100% 0, 100% 75%, 75% 100%, 0 100%);
}

.hud-logo-text strong {
  display: block;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.13em;
  color: var(--ink);
  white-space: nowrap;
}

.hud-logo-text small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font: 8px var(--ui-mono);
  letter-spacing: 0.16em;
  white-space: nowrap;
}

/* ---- topbar: story banner (mockup .story treatment) ---- */

#story-banner {
  /* Same material as the loose-block tray border: the message chrome is tinted
     with the exact current tray-frame color (--dock-frame came from the same
     renderer.areaFrame value). */
  border: 1px solid var(--dock-frame, var(--area-frame, #2e6fa8));
  background: linear-gradient(
    90deg,
    rgba(var(--dock-frame-rgb, 46, 111, 168), 0.5),
    rgba(var(--dock-frame-rgb, 46, 111, 168), 0.34),
    rgba(var(--dock-frame-rgb, 46, 111, 168), 0.5)
  );
  clip-path: polygon(0 0, 99% 0, 100% 25%, 100% 75%, 99% 100%, 0 100%, 1% 75%, 1% 25%);
  box-shadow: inset 0 0 16px rgba(var(--dock-frame-rgb, 46, 111, 168), 0.22);
  padding: 6px 22px;
  overflow: visible;
}

#story-banner > div {
  min-width: 0;
}

#story-text {
  font-family: "Times New Roman", "Times", Georgia, serif;
  font-style: italic;
  font-weight: 700;
  font-size: clamp(11px, 2.2vw, 15px);
  letter-spacing: 0.04em;
  line-height: 1.2;
  color: #f1e9da;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.9);
}

.story-caption {
  display: block;
  margin-top: 2px;
  color: var(--ui-teal);
  font: 8px var(--ui-mono);
  letter-spacing: 0.17em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- chrome frames (sit exactly over canvas board / dock) ---- */

.ui-frame {
  position: absolute;
  z-index: 5;
  pointer-events: none;
}

#lock-frame {
  left: var(--frame-x, 0px);
  top: var(--frame-y, 0px);
  width: var(--frame-w, 320px);
  height: var(--frame-h, 320px);
  transform: translate(var(--ui-vx, 0px), var(--ui-vy, 0px));
  border: 1px solid rgba(232, 232, 211, 0.37);
  /* Same black-transparent fill as the fragment tray (#pieces-panel). */
  background: rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 0 26px rgba(0, 0, 0, 0.38), 0 0 0 1px rgba(0, 0, 0, 0.4);
}

#lock-frame::before,
#lock-frame::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-color: var(--ui-teal-dim);
  border-style: solid;
}

#lock-frame::before {
  left: -1px;
  top: -1px;
  border-width: 2px 0 0 2px;
}

#lock-frame::after {
  right: -1px;
  bottom: -1px;
  border-width: 0 2px 2px 0;
}

.frame-label {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 5px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  color: var(--muted);
  font: 11px var(--ui-mono);
  letter-spacing: 0.06em;
  white-space: nowrap;
}

/* Text may never leave the frame: shrink + ellipsize at the border inset so
   even the longest counter line stays fully inside the border. */
.frame-label,
.frame-footer {
  overflow: hidden;
}

.frame-label > *,
.frame-footer > * {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.frame-label b {
  color: var(--ui-teal);
  font-weight: normal;
}

.frame-footer {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 5px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  color: var(--muted);
  font: 11px var(--ui-mono);
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.frame-footer b {
  color: var(--ink);
  font-weight: normal;
}

.frame-online {
  color: var(--ui-teal);
}

/* Desktop landscape: the frame hugs the grid exactly, so the label/footer
   float just outside the border instead of squeezing between it and the
   cells. */
body.nui-frame-outside .frame-label {
  top: auto;
  bottom: calc(100% + 7px);
}

body.nui-frame-outside .frame-footer {
  bottom: auto;
  top: calc(100% + 7px);
}

/* --- TIGHT-EDGE MODE (mobile portrait) -----------------------------
   When the bottom/top frame pad has no room for the text row, drop it so
   the borders stay clear and nothing spills over the dock. */
body.nui-lock-tight-top .frame-label {
  display: none;
}

body.nui-lock-tight-bottom .frame-footer {
  display: none;
}

/* ---- FRAGMENT TRAY frame over the canvas dock ---- */

/* Safety net: none of the new UI chrome may ever intercept input — the
   canvas owns every pointer gesture. A plain text/decoration layer. */
#lock-frame,
#lock-frame *,
#pieces-panel,
#pieces-panel *,
#ui-preview,
#ui-preview * {
  pointer-events: none;
}

#pieces-panel {
  left: var(--dock-x, 0px);
  top: var(--dock-y, 0px);
  width: var(--dock-w, 0px);
  height: var(--dock-h, 0px);
  /* Exact same frame chrome as the FIT GRID frame (#lock-frame). */
  border: 1px solid rgba(232, 232, 211, 0.37);
  border-radius: 0;
  background: rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 0 26px rgba(0, 0, 0, 0.38), 0 0 0 1px rgba(0, 0, 0, 0.4);
}

#pieces-panel::before,
#pieces-panel::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-color: var(--ui-teal-dim);
  border-style: solid;
}

#pieces-panel::before {
  left: -1px;
  top: -1px;
  border-width: 2px 0 0 2px;
}

#pieces-panel::after {
  right: -1px;
  bottom: -1px;
  border-width: 0 2px 2px 0;
}

body.nui-no-dock #pieces-panel {
  display: none;
}

.pieces-head {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 4px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}

.pieces-head strong {
  color: var(--ink);
  font-family: var(--ui-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
}

.pieces-head span {
  color: var(--muted);
  font: 8px var(--ui-mono);
  letter-spacing: 0.1em;
}

.tray-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2px;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

/* ---- right preview panel (parked beside the board) ---- */

#ui-preview {
  position: absolute;
  top: 100px;
  right: var(--ui-right-x, 14px);
  width: 200px;
  z-index: 5;
  display: none;
  pointer-events: none;
}

body.nui-side-right #ui-preview {
  display: block;
}

/* The floating "Selected fragment" preview parks over the board in portrait
   (only the grid width is measured for free space, not the visible tray), so
   drop it entirely in portrait — it never shows in landscape anyway. */
@media (orientation: portrait) {
  #ui-preview {
    display: none !important;
  }
}

.panel {
  border: 1px solid var(--line);
  background: linear-gradient(150deg, rgba(30, 22, 17, 0.94), rgba(15, 11, 12, 0.92));
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}

.panel-head strong {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.eyebrow {
  color: var(--ui-teal);
  font: 8px var(--ui-mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.panel-body {
  padding: 11px 12px;
}

.briefing p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.briefing p em {
  color: var(--ink);
  font-style: normal;
}

.rule {
  height: 1px;
  margin: 13px 0;
  background: var(--line);
}

.step {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.02em;
}

.step b {
  width: 20px;
  height: 20px;
  flex: none;
  display: grid;
  place-items: center;
  color: var(--ui-teal);
  border: 1px solid var(--line);
  font: 9px var(--ui-mono);
  font-weight: 400;
}

.step.active {
  color: var(--ink);
}

.step.active b {
  border-color: var(--ui-teal-dim);
  background: rgba(75, 198, 196, 0.16);
  box-shadow: 0 0 10px rgba(75, 198, 196, 0.2);
}

.readout {
  padding: 12px;
}

.readout-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 9px;
  color: var(--muted);
  font: 9px var(--ui-mono);
  letter-spacing: 0.08em;
}

.readout-row strong {
  color: var(--ink);
  font-family: system-ui, sans-serif;
  font-size: 13px;
  font-weight: 700;
}

.readout-row strong.teal {
  color: var(--ui-teal);
}

.progress {
  height: 4px;
  background: rgba(216, 196, 180, 0.12);
}

.progress i {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--ui-teal-dim);
  box-shadow: 0 0 8px var(--ui-teal-dim);
  transition: width 0.3s ease;
}

.ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  color: var(--muted);
  font: 7px var(--ui-mono);
}

#ui-preview .preview-stage {
  margin: 10px 12px 0;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid rgba(232, 232, 211, 0.22);
  background: rgba(7, 6, 7, 0.5);
}

#preview-glyph {
  color: var(--ui-teal);
  font: 30px var(--ui-mono);
  text-shadow: 0 0 12px rgba(75, 198, 196, 0.4);
}

.preview-name {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin: 9px 12px 12px;
  font: 9px var(--ui-mono);
}

.preview-name strong {
  color: var(--ink);
  font-weight: 600;
  letter-spacing: 0.1em;
}

.preview-name span {
  color: var(--muted);
}

/* ---- shrink / hide on small screens ---- */

@media (max-width: 720px) {
  .hud-logo-text {
    display: none;
  }

  .hud-logo-mark {
    width: 32px;
    height: 32px;
    font-size: 12px;
  }

  #story-banner {
    padding: 4px 14px;
  }

  .frame-label {
    top: 5px;
    font-size: 8px;
  }

  .frame-footer {
    bottom: 5px;
    font-size: 8px;
  }
}

/* Mobile portrait: drop the PZ logo square — it crowds the top strip. */
@media (orientation: portrait) and (max-width: 720px) {
  .hud-logo-mark {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  #ui-preview {
    display: none !important;
  }

  .frame-label {
    top: 5px;
  }

  .frame-footer {
    bottom: 5px;
  }

  .pieces-head span {
    display: none;
  }
}