/* style.css - Match 3 Game Styles */
/* Mobile-first responsive design with PWA readiness */

/* ── Base ──────────────────────────────────────────────────────────────────── */

/* CSS Custom Properties for dynamic viewport handling + H3 UI tokens */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --viewport-width: 100vw;
  --viewport-height: 100vh;

  /* ── Dungeon/UI shared tokens (H3) ────────────────────────────────── */
  /* Fallback values; applyUiThemeToDocument() overrides these at runtime. */
  --dng-bg:              #0e0917;
  --dng-panel:           #18102e;
  --dng-border:          #3b2860;
  --dng-accent:          #b580ff;
  --dng-accent-glow:     #d0a8ff;
  --dng-text:            #e4daf5;
  --dng-text-dim:        #8a80b5;
  --dng-danger:          #cc3344;
  --dng-treasure:        #d8b463;
  --dng-monster:         #d96a44;

  --ui-bg:               #8030c0;
  --ui-bg-hover:         #9540d8;
  --ui-bg-active:        #6825a0;
  --ui-panel-bg:         #18102e;
  --ui-panel-border:     #5c3898;
  --ui-text:             #ddd4f2;
  --ui-text-dim:         #8a80b5;

  --dng-accent-subtle:   rgba(181,128,255,0.42);
  --dng-accent-strong:   rgba(181,128,255,0.90);
  --dng-panel-alpha:     rgba(24,16,46,0.72);
  --dng-bg-opaque:       rgba(14,9,23,0.92);
  --ui-nav-bg:           rgba(24,16,46,0.50);
  --ui-nav-border:       rgba(92,56,152,0.36);
  --ui-nav-text:         rgba(138,128,181,0.38);
  --ui-nav-open-bg:      rgba(80,40,160,0.68);
  --ui-nav-open-border:  rgba(181,128,255,0.78);
  --ui-nav-open-shadow:  rgba(104,37,160,0.30);
  --ui-gradient-start:   rgba(149,64,216,0.98);
  --ui-gradient-end:     rgba(104,37,160,0.98);
}

/* Prefer modern dynamic viewport units when available. */
@supports (height: 100dvh) {
  :root {
    --viewport-height: 100dvh;
  }
}

html {
  min-height: 100%;
  height: 100%;
  background: var(--dng-bg);
}

/* iOS Safari: use direct fill-available sizing instead of piping it through calc(),
   which can collapse flex layouts into a near-zero-height strip. */
@supports (-webkit-touch-callout: none) {
  html {
    height: -webkit-fill-available;
  }
}

/* Prevent text selection and callout on touch devices */
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

body {
  background: var(--dng-bg);
  margin: 0;
  font-family: 'Segoe UI', sans-serif;
  /* Prevent pull-to-refresh interfering with drag gestures */
  overscroll-behavior: none;
  /* Prevent text selection during swipes */
  user-select: none;
  -webkit-user-select: none;
  /* Ensure body takes full viewport on mobile */
  min-height: var(--viewport-height);
  box-sizing: border-box;
  /* Handle iOS safe areas */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

@supports (-webkit-touch-callout: none) {
  body {
    min-height: -webkit-fill-available;
  }
}

/* ── Container — mobile first ─────────────────────────────────────────────── */

.container {
  width: 100%;
  max-width: 410px;
  margin: 0 auto;
  background: var(--dng-bg);
  padding: 16px;
  border-radius: 18px;
  box-shadow: 0 4px 20px 0 rgba(0, 0, 0, .18);
  border: 1px solid rgba(95, 74, 51, 0.32);
  box-sizing: border-box;
  /* Smooth transitions for orientation changes */
  transition: max-width 0.3s ease, padding 0.3s ease;
}

/* Landscape on small screens: adjust layout */
@media (max-height: 500px) and (orientation: landscape) {
  .container {
    max-width: 100%;
    margin: 8px auto;
    padding: 12px;
    border-radius: 12px;
  }
  
  h1 {
    font-size: 1.4rem;
    margin-bottom: 8px;
  }
}

/* Tablet+ (480px+): restore original generous padding */
@media (min-width: 480px) {
  .container {
    margin: 24px auto;
    padding: 24px 28px 28px 28px;
  }
}

h1 {
  margin-top: 0;
  font-size: 1.8rem;
  color: var(--ui-bg);
  text-align: center;
  font-weight: 700;
}

@media (min-width: 480px) {
  h1 {
    font-size: 2.1rem;
  }
}

#game {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── H2: Dungeon full-height game view ────────────────────────────────── */
/* In dungeon mode: stretch the container to use the full viewport height,
   remove decorative padding/rounded corners so the room takes maximum space. */
body.dungeon-mode,
body.dungeon-encounter {
  background: var(--dng-bg);
  padding-left: 0;
  padding-right: 0;
  overflow-x: hidden;
}

body.dungeon-mode .container,
body.dungeon-encounter .container {
  min-height: calc(var(--viewport-height) - var(--sat) - var(--sab));
  height: calc(var(--viewport-height) - var(--sat) - var(--sab));
  width: 100%;
  max-width: none;
  margin: 0 auto;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  border: 0;
  background: var(--dng-bg);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

@supports (-webkit-touch-callout: none) {
  body.dungeon-mode .container,
  body.dungeon-encounter .container {
    min-height: -webkit-fill-available;
    height: -webkit-fill-available;
  }
  /* Reinforce the TV height on iOS so it never collapses to 0. */
  body.dungeon-encounter .dungeon-room-view {
    flex: 0 0 auto;
    height: max(calc(var(--viewport-height) * 0.44), min(calc(var(--viewport-height) * 0.48), calc(var(--viewport-height) - 380px)));
    min-height: 150px;
    max-height: none;
  }
}

body.dungeon-mode #game,
body.dungeon-encounter #game {
  flex: 1 1 0;
  align-items: stretch;
  min-height: 0;
  width: 100%;
  box-sizing: border-box;
}

/* Footer hidden in dungeon mode */
body.dungeon-mode #footer,
body.dungeon-encounter #footer { display: none !important; }

/* ── Pixi mount (canvas renderer) ─────────────────────────────────────────── */

/* Pixi renderer mount (Pixi-only; legacy DOM board renderer removed). */
#pixi-shell {
  display: block;
  width: 100%;
  /* Slightly taller than the raw 7×8 board so canvas HUD can sit above without covering top-row pieces. */
  aspect-ratio: 7 / 9;
  position: relative;
  margin-bottom: 14px;
  background: var(--puzzle-shell-bg, var(--ui-panel-bg));
  border-radius: 14px;
  overflow: hidden;
  /* Critical: prevent browser handling of touch gestures */
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  /* Smooth resize transition */
  transition: aspect-ratio 0.3s ease;
}

/* Landscape orientation: adjust aspect ratio for wider screens */
@media (max-height: 500px) and (orientation: landscape) {
  #pixi-shell {
    aspect-ratio: 16 / 9;
    margin-bottom: 10px;
    border-radius: 10px;
  }
}

@media (min-width: 480px) {
  #pixi-shell {
    margin-bottom: 18px;
    border-radius: 14px;
  }
}



#pixi-root {
  position: absolute;
  inset: 0;
  background: var(--puzzle-shell-bg, var(--ui-panel-bg));
}

#pixi-root canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* iOS Safari: keep the canvas path conservative. Forced GPU promotion has been
   causing black/blank output on some devices, so avoid transform hacks here. */
@supports (-webkit-touch-callout: none) {
  #pixi-root canvas {
    -webkit-transform: none;
    transform: none;
    -webkit-backface-visibility: visible;
    backface-visibility: visible;
    image-rendering: auto;
  }
}

/* Reserved for a future DOM-based accessibility mirror / intent bridge. */
#pixi-a11y-root {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#restart {
  display: none !important;
}

@media (min-width: 480px) {
  #restart {
    font-size: 1.1em;
    margin-top: 16px;
    padding: 14px 0;
  }
}

/* Hover only on devices that support it (no mobile hover ghosting) */
@media (hover: hover) and (pointer: fine) {
  #restart:hover {
    background: var(--ui-bg-hover);
  }
}

/* Active state for both touch and mouse */
#restart:active {
  background: var(--ui-bg-active);
  transform: scale(0.98);
}

/* ── Build / Version Footer ──────────────────────────────────────────────── */

.build-meta {
  margin-top: 14px;
  text-align: center;
  font-size: 11px;
  line-height: 1.25;
  color: var(--ui-text-dim);
  user-select: text;
}

@media (min-width: 480px) {
  .build-meta {
    font-size: 12px;
  }
}

/* ── Hidden utility ──────────────────────────────────────────────────────────── */

.hidden {
  display: none !important;
}

/* ── Goals Panel (DOM) removed ─────────────────────────────────────────────── */
/* Pixi HUD renders goals inside the canvas on the canvas branch. */

/* ── Boot/loading + debug log overlays ─────────────────────────────────────── */

.boot-loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(182, 144, 88, 0.12), transparent 38%),
    var(--dng-bg);
  z-index: 2000;
  cursor: wait;
}

.boot-loading__spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid rgba(217, 182, 124, 0.18);
  border-top-color: var(--dng-accent);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
  animation: boot-loading-spin 0.8s linear infinite;
}

@keyframes boot-loading-spin {
  to {
    transform: rotate(360deg);
  }
}

body.app-ready .boot-loading {
  display: none;
}

.mobile-console {
  position: fixed;
  inset: auto 10px calc(10px + var(--sab)) 10px;
  max-height: min(50vh, 360px);
  background: rgba(10, 8, 6, 0.96);
  border: 1px solid var(--dng-border);
  border-radius: 12px;
  z-index: 140;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
  overflow: hidden;
}

.mobile-console[hidden] {
  display: none !important;
}

.mobile-console__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  color: var(--dng-text);
  background: rgba(38, 28, 19, 0.96);
  border-bottom: 1px solid var(--dng-border);
}

.mobile-console__header button {
  background: rgba(72,55,35,0.88);
  border: 1px solid var(--dng-border);
  color: var(--dng-text);
  padding: 6px 10px;
  border-radius: 6px;
}

.mobile-console__output {
  margin: 0;
  padding: 10px 12px 14px;
  color: #d7d0c2;
  font-size: 11px;
  line-height: 1.45;
  overflow: auto;
  max-height: min(42vh, 300px);
  white-space: pre-wrap;
  word-break: break-word;
}

body.app-booting .container {
  visibility: hidden;
}

body.app-booting #restart {
  display: none !important;
}

/* ── End Overlay ─────────────────────────────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
  box-sizing: border-box;
}

.overlay-box {
  background: var(--ui-panel-bg);
  border-radius: 18px;
  padding: 32px 28px;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--ui-panel-border);
  text-align: center;
}

.overlay-title {
  font-size: 3rem;
  margin: 0 0 12px;
  line-height: 1;
}

.overlay-message {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ui-bg);
  margin: 0 0 24px;
}

.overlay-restart {
  width: 100%;
  min-height: 44px;
  padding: 12px 0;
  background: var(--ui-bg);
  color: #fffaf4;
  font-size: 1.1em;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  touch-action: manipulation;
}

@media (hover: hover) and (pointer: fine) {
  .overlay-restart:hover {
    background: var(--ui-bg-hover);
  }
}

.overlay-restart:active {
  background: var(--ui-bg-active);
  transform: scale(0.98);
}


/* Puzzle select row */
.puzzle-select-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.9em;
}

.puzzle-select-row label {
  color: var(--ui-text-dim);
  font-weight: 600;
}

#puzzleSelect {
  padding: 8px 12px;
  border-radius: 6px;
  border: 1.5px solid var(--ui-panel-border);
  background: var(--ui-panel-bg);
  color: var(--ui-text);
  font-size: 0.9em;
  cursor: pointer;
  /* Touch-friendly: minimum 44px height */
  min-height: 44px;
  touch-action: manipulation;
}

/* ── Renderer Badge (DOM/Pixi toggle indicator) ───────────────────────────── */

/* Renderer badge (DOM/Pixi toggle) removed on canvas branch (Pixi-only). */

/* ── Dungeon nav (legacy floating overlay hidden) ─────────────────────────────── */
#dungeon-nav-overlay { display: none !important; }

/* ── Dungeon board visibility rules ──────────────────────────────────────────── */

/* Default: hide everything until dungeon mode is ready */
.dungeon-room-view { display: none !important; }
#pixi-shell { display: none !important; }

/* Designer preview: show the puzzle board in freeplay layout, no dungeon UI */
body.designer-preview #pixi-shell { display: block !important; }

/* Navigating: show room view full-height, hide board + chrome. */
body.dungeon-mode #pixi-shell        { display: none !important; }
body.dungeon-mode .puzzle-select-row { display: none !important; }
body.dungeon-mode #restart           { display: none !important; }
body.dungeon-mode h1                 { display: none !important; }
body.dungeon-mode .dungeon-room-view {
  display: flex !important;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  aspect-ratio: unset !important;
  margin: 0 auto;
  border-radius: 0;
  /* Constrain width so portrait aspect ratio stays reasonable on wide/tall screens */
  width: min(100%, calc(var(--viewport-height) * 0.67));
  max-width: min(100%, calc(var(--viewport-height) * 0.67));
  box-sizing: border-box;
  position: relative;
}
body.dungeon-mode .drv-tv-stage {
  flex: 1 1 0;
  min-height: 0;
  aspect-ratio: unset;
  width: 100%;
  max-width: 100%;
  margin: 0;
  box-sizing: border-box;
  border-bottom: none;
}
body.dungeon-mode .drv-nav-bar {
  /* Overlay the bottom of the room view instead of sitting below it */
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 100%;
  margin: 0;
  background: var(--dng-bg-opaque);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--dng-border);
  z-index: 10;
  box-sizing: border-box;
}

body.dungeon-mode .drv-action-bar {
  z-index: 14;
}

/* Encounter: compact TV view, maximize puzzle space */
body.dungeon-encounter #game {
  position: relative;
}
body.dungeon-encounter .dungeon-room-view {
  display: flex !important;
  flex-direction: column;
  /* Use viewport-relative height so iOS Safari doesn't compute 0 for percentage
     flex-basis in a column container whose parent lacks an explicit px height.
     max(44%, min(48%, 100vh-380px)): short phones stay at 44%; taller phones
     grow up to 48% while always leaving ≥380px for the puzzle board. */
  flex: 0 0 auto;
  height: max(calc(var(--viewport-height) * 0.44), min(calc(var(--viewport-height) * 0.48), calc(var(--viewport-height) - 380px)));
  min-height: 150px;
  max-height: calc(var(--viewport-height) * 0.56);
  width: 100%;
  aspect-ratio: unset !important;
  margin-bottom: 0;
  border-radius: 0;
  align-items: stretch;
  justify-content: stretch;
  padding: 4px 0 0;
  box-sizing: border-box;
  position: relative;
  z-index: 1;
}
body.dungeon-encounter .drv-tv-stage {
  flex: 1 1 0;
  width: 100%;
  max-width: 100%;
  height: 100%;
  min-height: 0;
  aspect-ratio: unset !important;
  max-height: 100%;
  overflow: hidden;
  box-sizing: border-box;
}
body.dungeon-encounter #pixi-shell {
  display: block !important;
  /* Fullscreen overlay so Pixi HUD can render inside the TV corner area.
     Canvas is transparent, so the underlying compact TV room view remains visible. */
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  aspect-ratio: unset !important;
  margin: 0;
  border-radius: 0;
  background: transparent;
  z-index: 3;
}

body.dungeon-encounter .drv-room-canvas {
  min-height: 0;
  height: auto;
}

/* Ensure the Pixi mount itself doesn't paint an opaque panel over the TV. */
body.dungeon-encounter .pixi-root,
body.dungeon-encounter #pixi-root {
  background: transparent !important;
  width: 100% !important;
  height: 100% !important;
}
body.dungeon-encounter #pixi-a11y-root {
  display: none !important;
}
body.dungeon-encounter .puzzle-select-row { display: none !important; }
body.dungeon-encounter #restart           { display: none !important; }
body.dungeon-encounter h1                 { display: none !important; }
body.dungeon-encounter .drv-nav-bar       { display: none !important; }
body.dungeon-encounter .drv-action-bar    { display: none !important; }

body.dungeon-mode #game,
body.dungeon-encounter #game {
  position: relative;
  width: 100%;
  align-items: stretch;
  margin: 0 auto;
}

body.dungeon-mode #drv-debug-dock,
body.dungeon-encounter #drv-debug-dock {
  display: flex !important;
}

body:not(.dungeon-mode):not(.dungeon-encounter) #drv-debug-dock {
  display: none !important;
}

/* ── Dungeon room view shell ──────────────────────────────────────────────── */

.dungeon-room-view {
  width: 100%;
  aspect-ratio: 7 / 9;
  background: var(--dng-bg);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 14px;
  flex-shrink: 0;
  position: relative;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 4px 24px rgba(0,0,0,0.55);
}

.drv-tv-stage {
  display: flex;
  flex-direction: column;
  position: relative;
  width: 100%;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.03), rgba(0,0,0,0.12)),
    var(--dng-bg);
  border-bottom: 1px solid rgba(0,0,0,0.22);
}

/* ── HUD bar (lives · floor · minimap top right) ─────────────────────────── */

.drv-hud-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 6px;
  background: var(--dng-panel);
  border-bottom: 1px solid var(--dng-border);
  z-index: 2;
  width: 100%;
  box-sizing: border-box;
}

.drv-hud-bar .drv-minimap {
  margin-left: auto;
}

.drv-lives {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 1px;
  min-height: 18px;
  font-size: 15px;
  letter-spacing: 0;
  color: var(--dng-danger);
  line-height: 1;
}

.drv-heart {
  display: inline-block;
  transform-origin: center;
  transition: opacity 0.16s ease;
}

.drv-heart.is-empty {
  opacity: 0.45;
}

.drv-heart.is-lost {
  animation: drv-heart-loss 700ms ease-in forwards;
}

@keyframes drv-heart-loss {
  0%   { transform: translateY(0) scale(1); opacity: 1; filter: brightness(1); }
  35%  { transform: translateY(-2px) scale(1.12); opacity: 1; filter: brightness(1.35); }
  100% { transform: translateY(11px) scale(0.7); opacity: 0; filter: brightness(0.9); }
}

.drv-floor-label {
  flex: 0 0 auto;
  min-width: 34px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--dng-accent-subtle);
  background: var(--dng-panel-alpha);
  color: var(--dng-text);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  line-height: 1.1;
}

.drv-encounter-label {
  flex: 1 1 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--dng-monster);
  text-align: center;
  min-height: 18px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drv-minimap {
  flex: 0 0 auto;
  width: 68px;
  height: 68px;
  border-radius: 7px;
  border: 1.5px solid var(--dng-border);
  background: rgba(0,0,0,0.6);
  display: block;
  image-rendering: pixelated;
}

.drv-debug-dock {
  position: absolute;
  right: calc(10px + var(--sar));
  bottom: calc(10px + var(--sab));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 12;
}

.drv-debug-dock[hidden] {
  display: none !important;
}

.drv-debug-toggle {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--dng-border);
  background: var(--dng-bg-opaque);
  color: var(--dng-text);
  font-size: 18px;
  padding: 0;
  cursor: pointer;
  opacity: 0.96;
  box-shadow: 0 6px 18px rgba(0,0,0,0.28);
  touch-action: manipulation;
}

.drv-debug-toggle:active {
  opacity: 1;
  transform: scale(0.95);
}

.drv-debug-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  background: var(--dng-panel);
  border: 1px solid var(--dng-border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 13;
  min-width: 160px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.28);
}

.drv-debug-menu[hidden] {
  display: none !important;
}

.drv-debug-menu button,
.drv-debug-menu select {
  background: var(--dng-panel-alpha);
  border: 1px solid var(--dng-border);
  color: var(--dng-text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.drv-debug-menu button:active {
  background: var(--dng-accent);
}

/* ── Puzzle HUD overlay (during encounters) ──────────────────────────────── */

.drv-puzzle-hud {
  position: absolute;
  top: 85px;  /* Below the HUD bar (which is ~70px) */
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 5;
  pointer-events: none;
  width: auto;
  max-width: 90%;
}

.drv-puzzle-hud[hidden] {
  display: none !important;
}

.drv-hud-panel {
  background: rgba(20, 15, 10, 0.92);
  border: 1px solid var(--dng-border);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
}

.drv-goals-panel {
  flex: 1 1 0;
  min-width: 0;
}

.drv-moves-panel {
  flex: 0 0 auto;
  min-width: 70px;
}

.drv-hud-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--dng-monster);
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.drv-goals-container {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
}

.drv-goal-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--dng-text);
}

.drv-goal-chip img {
  width: 24px;
  height: 24px;
  border-radius: 4px;
}

.drv-moves-count {
  font-size: 28px;
  font-weight: 800;
  color: var(--dng-treasure);
  line-height: 1;
}

/* ── Room canvas ──────────────────────────────────────────────────────────── */

.drv-room-canvas {
  flex: 1 1 auto;
  align-self: stretch;
  display: block;
  width: 100%;
  max-width: 100%;
  height: 100%;
  min-height: 180px;
  background: var(--dng-bg);
  box-sizing: border-box;
}

@supports (-webkit-touch-callout: none) {
  .drv-room-canvas {
    min-height: 220px;
  }
}

/* ── Monster hit feedback (shake during dungeon encounter) ──────────────────── */

@keyframes monster-hit-shake {
  0%   { transform: translateX(0); }
  15%  { transform: translateX(-7px); }
  35%  { transform: translateX(7px); }
  55%  { transform: translateX(-5px); }
  75%  { transform: translateX(5px); }
  90%  { transform: translateX(-2px); }
  100% { transform: translateX(0); }
}

.drv-room-canvas.monster-hit-shake {
  animation: monster-hit-shake 0.32s ease-out forwards;
}

/* ── Fight button bar ─────────────────────────────────────────────────────── */

.drv-action-bar {
  position: absolute;
  left: 0;
  right: 0;
  top: 60%;
  bottom: auto;
  display: flex;
  justify-content: center;
  padding: 0 12px 12px;
  background: none;
  border-top: none;
  pointer-events: none;
  z-index: 8;
}

.drv-action-btn {
  min-width: 136px;
  min-height: 42px;
  padding: 10px 18px;
  border-radius: 999px;
  color: #fff6ef;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 10px 24px rgba(0,0,0,0.35), 0 0 0 1px rgba(255,243,230,0.08) inset;
  backdrop-filter: blur(3px);
  touch-action: manipulation;
  pointer-events: auto;
}

.drv-fight-btn {
  border: 1.5px solid rgba(217,106,68,0.82);
  background: linear-gradient(180deg, rgba(217,106,68,0.98), rgba(132,57,37,0.98));
}

.drv-descend-btn {
  min-width: 168px;
  border: 1.5px solid var(--dng-accent-strong);
  background: linear-gradient(180deg, var(--ui-gradient-start), var(--ui-gradient-end));
}

.drv-action-btn[hidden] {
  display: none !important;
}

.drv-action-btn:active {
  transform: scale(0.98);
}

/* ── Nav bar (compact row of directional buttons) ────────────────────────── */

.drv-nav-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px 9px;
  background: var(--dng-panel);
  border-top: 1px solid var(--dng-border);
}

.drv-nav-col {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.drv-nav-btn {
  width: 38px;
  height: 38px;
  background: var(--ui-nav-bg);
  border: 1.5px solid var(--ui-nav-border);
  border-radius: 9px;
  color: var(--ui-nav-text);
  font-size: 18px;
  cursor: default;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s, border-color 0.1s, transform 0.08s, box-shadow 0.1s;
  line-height: 1;
}

.drv-nav-btn.open {
  color: var(--dng-text);
  background: var(--ui-nav-open-bg);
  border-color: var(--ui-nav-open-border);
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 1px 8px var(--ui-nav-open-shadow);
}

@media (hover: hover) and (pointer: fine) {
  .drv-nav-btn.open:hover,
  .drv-action-btn:hover {
    filter: brightness(1.06);
  }
}

.drv-nav-btn.open:active {
  transform: scale(0.87);
}

.drv-nav-btn:disabled { pointer-events: none; }

/* ── Encounter result popup (win / loss) ─────────────────────────────────── */

.drv-result-popup {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 30;
  pointer-events: auto;
  animation: drv-popup-in 0.30s ease-out forwards;
}

.drv-result-popup.is-win {
  background: radial-gradient(ellipse at 50% 55%, rgba(128,48,192,0.55) 0%, rgba(14,9,23,0.80) 70%);
}

.drv-result-popup.is-loss {
  background: radial-gradient(ellipse at 50% 55%, rgba(180,0,40,0.45) 0%, rgba(14,9,23,0.80) 70%);
}

.drv-result-popup.is-dismissing {
  animation: drv-popup-out 0.32s ease-in forwards;
}

.drv-result-popup__title {
  font-size: clamp(2.4rem, 12vw, 4rem);
  font-weight: 900;
  letter-spacing: 0.05em;
  text-shadow: 0 0 48px currentColor, 0 2px 12px rgba(0,0,0,0.6);
  animation: drv-popup-title-in 0.45s 0.08s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.is-win  .drv-result-popup__title { color: var(--dng-accent-glow); }
.is-loss .drv-result-popup__title { color: #ff6680; }

.drv-result-popup__sub {
  margin-top: 0.5em;
  font-size: clamp(0.85rem, 3.5vw, 1.05rem);
  color: var(--dng-text-dim);
  animation: drv-popup-title-in 0.45s 0.2s both;
}

.drv-result-popup__particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

@keyframes drv-popup-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes drv-popup-out {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(1.04); }
}
@keyframes drv-popup-title-in {
  from { opacity: 0; transform: scale(0.65); }
  to   { opacity: 1; transform: scale(1); }
}
