:root {
  --bg: #0b0d12;
  --panel: #11151c;
  --ink: #e6e6e6;
  --muted: #9aa3b2;
  --accent: #ffd166;
  --accent-2: #84e1bc;
  --danger: #ef476f;
  --mana: #4cc9f0;
  --hp: #ef476f;
  --border: #1d2330;
  --touch-target-min: 44px;
  --touch-target-padding-y: 6px;
  --touch-target-padding-x: 10px;
  --mobile-thumb-safe-gap: 16px;
  --canvas-motion-brightness: brightness(1);
  --hud-font-size: 12px;
  --hud-label-font-size: 12px;
  --hud-panel-bg: rgba(8, 11, 17, 0.82);
  --hud-border-readable: #2a3142;
  --hud-bar-width: 140px;
  --hud-bar-height: 20px;
  --hud-top-unit: 1rem;
  --hud-top-gap: calc(var(--hud-top-unit) * 0.875);
  --hud-top-chip-gap: calc(var(--hud-top-unit) * 0.5);
  --hud-top-vitals-gap: calc(var(--hud-top-unit) * 0.1875);
  --hud-top-item-height: calc(var(--hud-top-unit) * 2.75);
  --hud-top-padding-y: calc(var(--hud-top-unit) * 0.375);
  --hud-top-padding-x: calc(var(--hud-top-unit) * 0.625);
  --hud-top-font-size: calc(var(--hud-top-unit) * 0.875);
  --hud-top-value-font-size: calc(var(--hud-top-unit) * 1.125);
  --hud-top-icon-font-size: calc(var(--hud-top-unit) * 1.375);
  --hud-top-book-icon-font-size: calc(var(--hud-top-unit) * 1.125);
  --hud-top-vitals-bar-width: calc(var(--hud-top-unit) * 8.75);
  --hud-top-level-bar-width: calc(var(--hud-top-unit) * 4.5);
  --hud-top-bar-height: calc(var(--hud-top-unit) * 0.875);
  --hud-top-icon-button-size: var(--hud-top-item-height);
  --hud-mobile-bar-width: 96px;
  --hud-mobile-bar-height: 20px;
  --wand-token-font-size: 12px;
  --mobile-wand-panel-gap: 158px;
  --mobile-ui-scale: 1;
  --menu-ui-scale: 1;
  --mobile-control-size: var(--touch-target-min);
  --mobile-joystick-size: 90px;
  --mobile-side-rail-width: 66px;
  --mobile-safe-edge-gap: 6px;
  --mobile-keyboard-inset: 0px;
  --mobile-visual-viewport-height: 100dvh;
  --mobile-visual-viewport-width: 100vw;
  --mobile-visual-viewport-offset-top: 0px;
}

body.high-contrast {
  --bg: #000000;
  --panel: #05070a;
  --ink: #ffffff;
  --muted: #d6deeb;
  --accent: #ffe66d;
  --accent-2: #9dffcf;
  --border: #8fb3ff;
}

body.colorblind-deuteranopia {
  --accent: #f6d55c;
  --accent-2: #64c2d1;
  --danger: #d95f02;
  --mana: #56b4e9;
  --hp: #e69f00;
}

body.colorblind-protanopia {
  --accent: #ffd166;
  --accent-2: #56b4e9;
  --danger: #cc79a7;
  --mana: #0072b2;
  --hp: #e69f00;
}

body.colorblind-tritanopia {
  --accent: #f0e442;
  --accent-2: #009e73;
  --danger: #d55e00;
  --mana: #cc79a7;
  --hp: #d55e00;
}

* {
  box-sizing: border-box;
}

.sr-only,
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans KR", ui-monospace, "SF Mono", Menlo, Consolas, "Apple SD Gothic Neo", "Malgun Gothic",
    "Noto Sans CJK KR", sans-serif;
  overscroll-behavior: none;
  overflow: hidden;
}

body.font-dyslexic {
  font-family: "OpenDyslexic", "Noto Sans KR", "Comic Sans MS", "Apple SD Gothic Neo", "Malgun Gothic", "Arial",
    sans-serif;
}

#app {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 700px at 50% 30%, #161c28 0%, #0b0d12 70%);
  overscroll-behavior: none;
}

.orientation-lock {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: none;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 50% 42%, rgba(132, 225, 188, 0.16), transparent 32%),
    rgba(3, 4, 7, 0.94);
  color: var(--ink);
  text-align: center;
  pointer-events: auto;
}

.orientation-lock__card {
  width: min(320px, 88vw);
  padding: 22px 20px;
  border: 1px solid rgba(132, 225, 188, 0.42);
  border-radius: 18px;
  background: rgba(13, 17, 24, 0.94);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.55), 0 0 34px rgba(132, 225, 188, 0.12);
}

.orientation-lock__icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 42px;
  margin: 0 auto 12px;
  border: 2px solid rgba(255, 209, 102, 0.74);
  border-radius: 12px;
  color: var(--accent);
  font-size: 28px;
  font-weight: 800;
}

.orientation-lock h2 {
  margin: 0 0 8px;
  color: #d5fbff;
  font-size: 20px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.orientation-lock p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

body[data-layout="mobile"][data-orientation="portrait"] .orientation-lock {
  display: none;
}

.mobile-install-hint {
  display: none;
}

.mobile-start-cta-hint {
  display: none;
}

#game-stage {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  line-height: 0;
  overscroll-behavior: none;
  touch-action: none;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100vh;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #050608;
  border: 1px solid var(--border);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), inset 0 0 80px rgba(0, 0, 0, 0.6);
  filter: var(--canvas-motion-brightness);
  -webkit-touch-callout: none;
  touch-action: none;
  user-select: none;
}

#game:focus,
#game:focus-visible {
  outline: none;
}

#game-transition-fade,
#hit-flash,
#biome-splash {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#game-transition-fade {
  z-index: 3;
  background: #030407;
  opacity: 0;
}

#game-transition-fade.show {
  animation: biome-transition-fade 400ms ease-in-out;
}

#hit-flash {
  z-index: 5;
  background: radial-gradient(circle at 50% 48%, rgba(255, 255, 255, 0.38), rgba(239, 71, 111, 0.28) 44%, rgba(239, 71, 111, 0) 76%);
  opacity: 0;
}

#hit-flash.show {
  animation: hit-flash-pop 180ms ease-out both;
  will-change: opacity;
}

#biome-splash {
  z-index: 4;
  display: grid;
  place-items: center;
  color: var(--accent);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: clamp(18px, 4vw, 34px);
  line-height: 1.2;
  text-shadow: 0 2px 10px #000, 0 0 28px rgba(255, 209, 102, 0.3);
  opacity: 0;
}

#biome-splash::before {
  content: "";
  position: absolute;
  width: min(580px, 82%);
  height: 82px;
  border: 1px solid rgba(255, 209, 102, 0.45);
  border-radius: 10px;
  background: linear-gradient(90deg, rgba(5, 6, 8, 0), rgba(5, 6, 8, 0.86), rgba(5, 6, 8, 0));
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  z-index: -1;
}

#biome-splash.show {
  animation: biome-title-splash 2s ease-in-out both;
  will-change: opacity, transform;
}

#biome-splash.hidden {
  display: none;
}

#captions-overlay {
  position: absolute;
  left: 50%; /* stylelint-disable-line csstools/use-logical -- rtl-skip: physical centering coordinate pairs with translateX */
  bottom: max(22px, 8%);
  z-index: 6;
  max-width: min(520px, 86%);
  padding: 8px 14px;
  border: 1px solid rgba(230, 230, 230, 0.22);
  border-radius: 8px;
  background: rgba(5, 6, 8, 0.86);
  color: #fff;
  font-size: clamp(12px, 2.4vw, 16px);
  line-height: 1.35;
  text-align: center;
  text-shadow: 0 1px 2px #000;
  transform: translateX(-50%);
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.38);
}

#captions-overlay.captions-hidden {
  display: none;
}

.tutorial-nudge {
  position: absolute;
  z-index: 24;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  max-width: min(320px, 86vw);
  padding: 7px 10px;
  border: 1px solid rgba(255, 209, 102, 0.75);
  border-radius: 999px;
  background: rgba(8, 12, 18, 0.92);
  color: #fff4c7;
  font: 700 12px/1.3 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  text-shadow: 0 1px 2px #000;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.42), 0 0 22px rgba(255, 209, 102, 0.12);
  pointer-events: auto;
  animation: tutorial-nudge-pop 160ms ease-out both;
}

.tutorial-nudge__dismiss {
  display: grid;
  place-items: center;
  min-width: 20px;
  min-height: 20px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font: 700 14px/1 ui-monospace, monospace;
  cursor: pointer;
}

.tutorial-nudge__dismiss:hover,
.tutorial-nudge__dismiss:focus-visible {
  border-color: var(--accent);
  outline: none;
  filter: brightness(1.2);
}

.tutorial-nudge--wand-empty {
  position: fixed;
  left: 50%;
  bottom: 132px;
  transform: translateX(-50%);
}

.tutorial-nudge--wand-empty::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 12px;
  height: 12px;
  border-right: 1px solid rgba(255, 209, 102, 0.75);
  border-bottom: 1px solid rgba(255, 209, 102, 0.75);
  background: rgba(8, 12, 18, 0.92);
  transform: translateX(-50%) rotate(45deg);
}

.tutorial-nudge--glyph-nearby {
  transform: translate(-50%, calc(-100% - 16px));
}

.tutorial-nudge--glyph-nearby::after {
  content: "↓";
  position: absolute;
  left: 50%;
  bottom: -18px;
  color: var(--accent);
  font-size: 16px;
  text-shadow: 0 1px 4px #000;
  transform: translateX(-50%);
}

.tutorial-nudge--cast-key {
  position: fixed;
  left: 50%;
  top: 72px;
  border-color: rgba(127, 214, 245, 0.8);
  background: rgba(8, 28, 42, 0.9);
  color: #d5fbff;
  transform: translateX(-50%);
}

.tutorial-nudge--idle-cast {
  position: fixed;
  left: 50%;
  bottom: 132px;
  border-color: rgba(255, 209, 102, 0.78);
  background: rgba(47, 35, 8, 0.9);
  color: #fff3bf;
  transform: translateX(-50%);
}

.tutorial-nudge--glyph-zero {
  border-color: rgba(132, 225, 188, 0.78);
  background: rgba(8, 42, 31, 0.9);
  color: #d7ffe9;
  transform: translate(-50%, calc(-100% - 16px));
}

.tutorial-nudge--glyph-zero::after {
  content: "↓";
  position: absolute;
  left: 50%;
  bottom: -18px;
  color: var(--accent-2);
  font-size: 16px;
  text-shadow: 0 1px 4px #000;
  transform: translateX(-50%);
}

.tutorial-nudge--death-loop {
  position: static;
  justify-content: center;
  width: fit-content;
  margin: 10px auto 12px;
  border-color: rgba(255, 209, 102, 0.75);
  background: rgba(47, 35, 8, 0.9);
  color: #fff3bf;
}

.joystick-base {
  position: fixed;
  inset-inline-start: max(20px, env(safe-area-inset-left));
  inset-block-end: calc(60px + env(safe-area-inset-bottom));
  inline-size: 90px;
  block-size: 90px;
  border: 2px solid rgba(230, 230, 230, 0.45);
  border-radius: 50%;
  background: rgba(10, 14, 22, 0.45);
  box-shadow: 0 0 22px rgba(0, 0, 0, 0.35), inset 0 0 18px rgba(255, 255, 255, 0.08);
  opacity: 0.72;
  touch-action: none;
  user-select: none;
  pointer-events: auto;
  z-index: 20;
}

body:has(#overlay.show) .joystick-base,
body:has(.modal.show) .joystick-base,
body:has(.win-screen.show) .joystick-base,
body:has(.mobile-death-recovery:not([hidden])) .joystick-base {
  display: none;
}

body[data-layout="mobile"]:has(#wand.open) .joystick-base,
body.mobile-layout:has(#wand.open) .joystick-base {
  display: none;
}

body[data-layout="mobile"]:has(.mobile-death-recovery:not([hidden])) #wand,
body.mobile-layout:has(.mobile-death-recovery:not([hidden])) #wand {
  display: none;
}

.joystick-knob {
  position: absolute;
  left: 50%; /* stylelint-disable-line csstools/use-logical -- rtl-skip: physical centering coordinate pairs with translateX */
  top: 50%;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(132, 225, 188, 0.45);
  border: 1px solid rgba(230, 230, 230, 0.55);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  touch-action: none;
  transform: translate(-50%, -50%);
}

.mobile-death-recovery {
  display: none;
}

.mobile-failure-recovery {
  display: none;
}

.mobile-cast-feedback {
  display: none;
}

.mobile-cast-ready-guidance {
  display: none;
}

.mobile-first-cast-cue {
  display: none;
}

.mobile-cast-aim-cue {
  display: none;
}

.mobile-overlay-escape-guard {
  display: none;
}

body[data-layout="mobile"] .mobile-death-recovery:not([hidden]),
body.mobile-layout .mobile-death-recovery:not([hidden]) {
  position: fixed;
  inset-inline: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right));
  inset-block-end: max(16px, calc(env(safe-area-inset-bottom) + 12px));
  z-index: 70;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 9px;
  align-items: stretch;
  max-block-size: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
  max-inline-size: min(420px, calc(100vw - 24px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  margin-inline: auto;
  padding: 14px;
  border: 1px solid rgba(255, 209, 102, 0.52);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(39, 29, 9, 0.96), rgba(9, 12, 18, 0.96)),
    rgba(9, 12, 18, 0.96);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.52), 0 0 22px rgba(255, 209, 102, 0.12);
  color: #f6e7c3;
  line-height: 1.25;
  overflow: auto;
  pointer-events: auto;
}

body[data-layout="mobile"] .mobile-failure-recovery:not([hidden]),
body.mobile-layout .mobile-failure-recovery:not([hidden]) {
  position: fixed;
  inset-inline: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right));
  inset-block-end: max(12px, calc(env(safe-area-inset-bottom) + 8px));
  z-index: 47;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
  padding: 12px;
  border: 1px solid rgba(239, 71, 111, 0.5);
  border-radius: 12px;
  background: rgba(9, 12, 18, 0.94);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  color: #ffe0e8;
  pointer-events: auto;
}

body[data-layout="mobile"]:has(#wand.open) .mobile-failure-recovery:not([hidden]),
body.mobile-layout:has(#wand.open) .mobile-failure-recovery:not([hidden]) {
  inset-block-start: max(76px, calc(env(safe-area-inset-top) + 12px));
  inset-block-end: auto;
  max-block-size: min(196px, calc(31dvh - env(safe-area-inset-top)));
  gap: 6px;
  padding: 10px;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

body[data-layout="mobile"]:has(#wand.open) .mobile-failure-recovery__actions,
body.mobile-layout:has(#wand.open) .mobile-failure-recovery__actions {
  gap: 6px;
}

body[data-layout="mobile"]:has(#wand.open) .mobile-failure-recovery button,
body.mobile-layout:has(#wand.open) .mobile-failure-recovery button {
  min-block-size: var(--touch-target-min);
  padding: 7px 10px;
  font-size: 12px;
}

body[data-layout="mobile"]:has(#wand.open) .mobile-failure-recovery:not([data-reason="first_cast_stall"]) #mobile-failure-restart-btn,
body.mobile-layout:has(#wand.open) .mobile-failure-recovery:not([data-reason="first_cast_stall"]) #mobile-failure-restart-btn {
  min-block-size: var(--touch-target-min);
  font-size: 13px;
}

body[data-layout="mobile"] .mobile-failure-recovery[data-reason="first_cast_stall"]:not([hidden]),
body.mobile-layout .mobile-failure-recovery[data-reason="first_cast_stall"]:not([hidden]) {
  inset-block-start: max(40px, calc(env(safe-area-inset-top) + 8px));
  inset-block-end: auto;
  max-inline-size: min(360px, calc(100vw - 24px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  margin-inline: auto;
  border-color: rgba(255, 209, 102, 0.58);
  color: #fff3bf;
}

body[data-layout="mobile"] .mobile-cast-feedback:not([hidden]),
body.mobile-layout .mobile-cast-feedback:not([hidden]) {
  position: fixed;
  inset-inline-start: 50%;
  inset-block-end: calc(92px + env(safe-area-inset-bottom));
  z-index: 35;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-inline-size: min(340px, calc(100vw - 32px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  padding: 8px 12px;
  border: 1px solid rgba(127, 214, 245, 0.55);
  border-radius: 999px;
  background: rgba(9, 12, 18, 0.9);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.38);
  color: #dff7ff;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
  overflow: hidden;
  pointer-events: none;
  text-align: center;
  text-overflow: ellipsis;
  transform: translateX(-50%);
  white-space: nowrap;
}

body[data-layout="mobile"] .mobile-cast-feedback--success:not([hidden]),
body.mobile-layout .mobile-cast-feedback--success:not([hidden]) {
  border-color: rgba(132, 225, 188, 0.65);
  color: #d8ffef;
}

body[data-layout="mobile"] .mobile-cast-feedback--fallback:not([hidden]),
body.mobile-layout .mobile-cast-feedback--fallback:not([hidden]) {
  border-color: rgba(255, 209, 102, 0.68);
  color: #fff3bf;
}

body[data-layout="mobile"] .mobile-cast-feedback--failure:not([hidden]),
body.mobile-layout .mobile-cast-feedback--failure:not([hidden]) {
  border-color: rgba(239, 71, 111, 0.58);
  color: #ffe2e9;
}

body[data-layout="mobile"] .mobile-first-cast-cue:not([hidden]),
body.mobile-layout .mobile-first-cast-cue:not([hidden]) {
  position: fixed;
  inset-inline-start: 50%;
  inset-block-end: calc(176px + env(safe-area-inset-bottom));
  z-index: 24;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-inline-size: min(340px, calc(100vw - 24px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  padding: 7px 8px 7px 12px;
  border: 1px solid rgba(255, 209, 102, 0.54);
  border-radius: 999px;
  background: rgba(9, 12, 18, 0.9);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.38), 0 0 18px rgba(255, 209, 102, 0.12);
  color: #fff3bf;
  font: 800 11px/1.25 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.02em;
  pointer-events: none;
  text-align: start;
  transform: translateX(-50%);
}

body[data-layout="mobile"]:has(#wand.open) .mobile-first-cast-cue:not([hidden]),
body.mobile-layout:has(#wand.open) .mobile-first-cast-cue:not([hidden]) {
  display: none;
}

body:has(#overlay.show) .mobile-first-cast-cue,
body:has(.mobile-death-recovery:not([hidden])) .mobile-first-cast-cue,
body:has(.mobile-failure-recovery:not([hidden])) .mobile-first-cast-cue,
body.mobile-keyboard-visible .mobile-first-cast-cue {
  display: none;
}

.mobile-first-cast-cue__copy {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  overflow-wrap: anywhere;
}

.mobile-first-cast-cue__close {
  appearance: none;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  min-inline-size: 32px;
  min-block-size: 32px;
  border: 1px solid rgba(255, 243, 191, 0.3);
  border-radius: 999px;
  background: rgba(255, 243, 191, 0.1);
  color: #fff8cf;
  font: 900 16px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

body[data-layout="mobile"] .mobile-cast-aim-cue:not([hidden]),
body.mobile-layout .mobile-cast-aim-cue:not([hidden]) {
  position: absolute;
  z-index: 34;
  display: grid;
  place-items: center;
  inline-size: 52px;
  block-size: 52px;
  border: 1px solid rgba(255, 209, 102, 0.72);
  border-radius: 999px;
  color: #ffd166;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.75));
  opacity: 0.94;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

body[data-layout="mobile"] .mobile-cast-aim-cue:not([hidden])::before,
body.mobile-layout .mobile-cast-aim-cue:not([hidden])::before {
  content: "";
  inline-size: 18px;
  block-size: 18px;
  border: 2px solid currentColor;
  border-radius: 999px;
  box-shadow: 0 0 18px rgba(255, 209, 102, 0.38);
}

body[data-layout="mobile"] .mobile-cast-aim-cue:not([hidden])::after,
body.mobile-layout .mobile-cast-aim-cue:not([hidden])::after {
  content: "TARGET";
  position: absolute;
  inset-block-start: calc(100% + 3px);
  inset-inline-start: 50%;
  padding: 2px 5px;
  border-radius: 999px;
  background: rgba(9, 12, 18, 0.82);
  color: #fff3bf;
  font: 800 9px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.1em;
  text-shadow: 0 1px 3px #000;
  transform: translateX(-50%);
}

body[data-layout="mobile"] .mobile-cast-aim-cue[data-state="fired"]:not([hidden]),
body.mobile-layout .mobile-cast-aim-cue[data-state="fired"]:not([hidden]) {
  border-color: rgba(132, 225, 188, 0.85);
  color: #84e1bc;
  box-shadow: 0 0 20px rgba(132, 225, 188, 0.18);
}

body[data-layout="mobile"] .mobile-cast-aim-cue[data-state="fired"]:not([hidden])::after,
body.mobile-layout .mobile-cast-aim-cue[data-state="fired"]:not([hidden])::after {
  content: "CAST";
  color: #d8ffef;
}

body[data-layout="mobile"]:has(#wand.open) .mobile-cast-feedback:not([hidden]),
body.mobile-layout:has(#wand.open) .mobile-cast-feedback:not([hidden]) {
  inset-block-start: max(58px, calc(env(safe-area-inset-top) + 10px));
  inset-block-end: auto;
}

body[data-layout="mobile"] .mobile-overlay-escape-guard:not([hidden]),
body.mobile-layout .mobile-overlay-escape-guard:not([hidden]) {
  position: fixed;
  inset-inline-end: max(10px, env(safe-area-inset-right));
  inset-block-start: 50%;
  z-index: 90;
  display: grid;
  gap: 6px;
  width: min(156px, calc(42vw - env(safe-area-inset-right)));
  padding: 7px;
  border: 1px solid rgba(132, 225, 188, 0.42);
  border-radius: 14px;
  background: rgba(8, 12, 18, 0.9);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
  transform: translateY(-50%);
}

body[data-layout="mobile"]:has(#wand.open):not(:has(.mobile-failure-recovery:not([hidden]))) .mobile-overlay-escape-guard:not([hidden]),
body.mobile-layout:has(#wand.open):not(:has(.mobile-failure-recovery:not([hidden]))) .mobile-overlay-escape-guard:not([hidden]) {
  inset-block-start: max(10px, env(safe-area-inset-top));
  transform: none;
}

body:has(.mobile-failure-recovery:not([hidden])) .mobile-overlay-escape-guard {
  display: none;
}

.mobile-overlay-escape-guard button {
  min-inline-size: var(--touch-target-min);
  min-block-size: var(--touch-target-min);
  border: none;
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--accent);
  color: #1a1300;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1.15;
  touch-action: manipulation;
}

.mobile-overlay-escape-guard button.secondary {
  background: #2a3142;
  color: #dfe6ef;
}

.mobile-death-recovery__copy {
  display: grid;
  gap: 3px;
  min-inline-size: 0;
  text-align: center;
}

.mobile-failure-recovery__copy {
  display: grid;
  gap: 3px;
  min-inline-size: 0;
}

.mobile-death-recovery__title {
  color: #ffd166;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  line-height: 1.15;
  text-transform: uppercase;
}

.mobile-failure-recovery__title {
  color: #ff9aa8;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  line-height: 1.15;
  text-transform: uppercase;
}

.mobile-failure-recovery[data-reason="first_cast_stall"] .mobile-failure-recovery__title {
  color: #ffd166;
}

.mobile-death-recovery__hint {
  color: #dfe6ef;
  font-size: 14px;
  line-height: 1.4;
}

.mobile-death-recovery__action-hint {
  display: block;
  padding: 5px 8px;
  border: 1px solid rgba(132, 225, 188, 0.34);
  border-radius: 999px;
  background: rgba(132, 225, 188, 0.08);
  color: #d8ffef;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.2;
  text-align: center;
}

.mobile-death-recovery__steps,
.post-run-recovery-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.mobile-death-recovery__steps li,
.post-run-recovery-steps li {
  min-inline-size: 0;
  border: 1px solid rgba(255, 209, 102, 0.32);
  border-radius: 999px;
  padding: 5px 4px;
  background: rgba(255, 209, 102, 0.08);
  color: #fff3bf;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.1;
  text-align: center;
}

.mobile-failure-recovery__hint {
  color: #dfe6ef;
  font-size: 13px;
  line-height: 1.35;
}

.mobile-failure-recovery__actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 132px), 1fr));
  gap: 8px;
  align-items: center;
}

.mobile-death-recovery button {
  box-sizing: border-box;
  inline-size: 100%;
  min-inline-size: 100%;
  min-block-size: 64px;
  border: none;
  border-radius: 12px;
  padding: 15px 18px;
  background: var(--accent);
  color: #1a1300;
  cursor: pointer;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.1em;
  line-height: 1.15;
  touch-action: manipulation;
}

.mobile-failure-recovery button {
  box-sizing: border-box;
  inline-size: 100%;
  min-inline-size: var(--touch-target-min);
  min-block-size: var(--touch-target-min);
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--accent);
  color: #1a1300;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.15;
  touch-action: manipulation;
}

.mobile-failure-recovery button.secondary {
  background: #2a3142;
  color: #dfe6ef;
}

.mobile-failure-recovery:not([data-reason="first_cast_stall"]) #mobile-failure-try-again-btn {
  order: 1;
}

.mobile-failure-recovery:not([data-reason="first_cast_stall"]) #mobile-failure-suggested-btn {
  order: 2;
}

.mobile-failure-recovery:not([data-reason="first_cast_stall"]) #mobile-failure-clear-btn {
  order: 3;
}

.mobile-failure-recovery:not([data-reason="first_cast_stall"]) #mobile-failure-dismiss-btn {
  order: 5;
}

.mobile-failure-recovery:not([data-reason="first_cast_stall"]) #mobile-failure-restart-btn {
  grid-column: 1 / -1;
  order: 4;
  min-block-size: 52px;
  font-size: 14px;
}

@media (max-width: 370px) {
  body[data-layout="mobile"] .mobile-death-recovery:not([hidden]),
  body.mobile-layout .mobile-death-recovery:not([hidden]) {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  body[data-layout="mobile"] .mobile-failure-recovery:not([hidden]),
  body.mobile-layout .mobile-failure-recovery:not([hidden]) {
    grid-template-columns: 1fr;
  }

  .mobile-failure-recovery button {
    inline-size: 100%;
  }
}

.quick-cast-bar {
  display: none;
}

body[data-layout="mobile"] #quick-cast-bar.has-favourites,
body.mobile-layout #quick-cast-bar.has-favourites {
  position: fixed;
  inset-inline-end: max(18px, env(safe-area-inset-right));
  inset-block-end: calc(148px + env(safe-area-inset-bottom));
  z-index: 22;
  display: flex;
  gap: 7px;
  align-items: center;
  max-inline-size: calc(100vw - 36px - env(safe-area-inset-left) - env(safe-area-inset-right));
  padding: 6px;
  overflow-x: auto;
  border: 1px solid rgba(255, 209, 102, 0.34);
  border-radius: 999px;
  background: rgba(8, 11, 17, 0.84);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4), 0 0 16px rgba(255, 209, 102, 0.12);
  pointer-events: auto;
  -webkit-overflow-scrolling: touch;
}

body[data-layout="mobile"]:has(.mobile-death-recovery:not([hidden])) #quick-cast-bar.has-favourites,
body.mobile-layout:has(.mobile-death-recovery:not([hidden])) #quick-cast-bar.has-favourites {
  display: none;
}

.quick-cast-chip {
  flex: 0 0 auto;
  min-inline-size: var(--mobile-control-size);
  min-block-size: var(--mobile-control-size);
  max-inline-size: 8ch;
  overflow: hidden;
  padding: 0 11px;
  border: 1px solid rgba(132, 225, 188, 0.48);
  border-radius: 999px;
  background: rgba(31, 111, 74, 0.76);
  color: #d7ffe9;
  font: 800 12px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
  text-overflow: ellipsis;
  text-transform: lowercase;
  white-space: nowrap;
  touch-action: manipulation;
}

.mobile-first-session-checklist {
  display: none;
}

body[data-layout="mobile"] .mobile-first-session-checklist:not([hidden]),
body.mobile-layout .mobile-first-session-checklist:not([hidden]) {
  position: fixed;
  inset-block-start: calc(max(8px, env(safe-area-inset-top)) + 74px);
  inset-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right));
  z-index: 21;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 8px;
  align-items: center;
  inline-size: min(500px, calc(100vw - 16px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  margin-inline: auto;
  padding: 7px 8px;
  border: 1px solid rgba(132, 225, 188, 0.38);
  border-radius: 14px;
  background: rgba(8, 11, 17, 0.82);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.36), inset 0 0 18px rgba(132, 225, 188, 0.08);
  color: #d7ffe9;
  font: 700 12px/1.25 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  pointer-events: none;
}

body:has(#overlay.show) .mobile-first-session-checklist {
  display: none;
}

body:has(.mobile-death-recovery:not([hidden])) .mobile-first-session-checklist {
  display: none;
}

body:has(.mobile-failure-recovery:not([hidden])) .mobile-first-session-checklist {
  display: none;
}

.mobile-first-session-checklist__summary {
  display: grid;
  min-inline-size: 0;
  gap: 2px;
}

.mobile-first-session-checklist__eyebrow {
  color: #ffd166;
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.mobile-first-session-checklist__steps {
  grid-column: 1 / -1;
  display: flex;
  gap: 5px;
  margin: 0;
  padding: 0;
  overflow-x: auto;
  list-style: none;
  overscroll-behavior-inline: contain;
  pointer-events: auto;
  -webkit-overflow-scrolling: touch;
}

.mobile-first-session-checklist__step {
  flex: 0 0 auto;
  padding: 3px 7px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(13, 17, 24, 0.78);
  color: rgba(215, 244, 255, 0.78);
  white-space: nowrap;
}

.mobile-first-session-checklist__step[data-done="true"] {
  border-color: rgba(132, 225, 188, 0.5);
  background: rgba(31, 111, 74, 0.62);
  color: #d7ffe9;
}

.mobile-first-session-checklist__step[aria-current="step"] {
  border-color: rgba(255, 209, 102, 0.58);
  color: #fff3bf;
}

.mobile-first-session-checklist__actions {
  display: flex;
  gap: 5px;
  align-items: center;
  pointer-events: auto;
}

.mobile-first-session-checklist__actions button {
  min-inline-size: var(--touch-target-min);
  min-block-size: var(--touch-target-min);
  padding: 4px 8px;
  border: 1px solid rgba(127, 214, 245, 0.32);
  border-radius: 999px;
  background: rgba(10, 14, 22, 0.86);
  color: #d7f4ff;
  font: 800 10px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.mobile-first-session-checklist.is-minimized {
  grid-template-columns: minmax(0, 1fr) auto;
  inline-size: min(360px, calc(100vw - 16px - env(safe-area-inset-left) - env(safe-area-inset-right)));
}

.mobile-first-session-checklist.is-minimized .mobile-first-session-checklist__steps {
  display: none;
}

.mobile-first-session-guidance {
  display: none;
}

.mobile-spellbook-affordance {
  display: none;
}

.mobile-restart-help-affordance {
  display: none;
}

.mobile-restart-help-panel {
  display: none;
}

body[data-layout="mobile"] .mobile-first-session-guidance:not([hidden]),
body.mobile-layout .mobile-first-session-guidance:not([hidden]) {
  position: fixed;
  inset-block-start: calc(max(8px, env(safe-area-inset-top)) + 154px);
  inset-inline: max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-right));
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  inline-size: min(520px, calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  margin-inline: auto;
  color: #d7f4ff;
  font: 800 9px/1.15 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  pointer-events: none;
}

body:has(#overlay.show) .mobile-first-session-guidance,
body:has(.mobile-death-recovery:not([hidden])) .mobile-first-session-guidance,
body:has(#wand.open) .mobile-first-session-guidance {
  display: none;
}

.mobile-first-session-guidance__item {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  max-inline-size: 100%;
  padding: 3px 6px;
  border: 1px solid rgba(127, 214, 245, 0.28);
  border-radius: 999px;
  background: rgba(8, 11, 17, 0.76);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
  white-space: nowrap;
}

.mobile-first-session-guidance__item b {
  color: #ffd166;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

body[data-layout="mobile"][data-orientation="portrait"] .mobile-spellbook-affordance,
body.mobile-layout[data-orientation="portrait"] .mobile-spellbook-affordance {
  position: fixed;
  inset-inline-start: 50%;
  inset-block-end: calc(82px + env(safe-area-inset-bottom));
  z-index: 22;
  display: grid;
  align-content: center;
  justify-items: center;
  min-inline-size: 96px;
  min-block-size: calc(var(--mobile-control-size) + 4px);
  padding: 8px 14px;
  border: 1px solid rgba(255, 209, 102, 0.76);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(41, 122, 96, 0.94), rgba(18, 71, 61, 0.94));
  box-shadow: 0 0 0 1px rgba(255, 209, 102, 0.18), 0 10px 24px rgba(0, 0, 0, 0.34);
  color: #fff7d4;
  font: 800 12px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  pointer-events: auto;
  text-transform: uppercase;
  touch-action: manipulation;
  transform: translateX(-50%);
}

body[data-layout="mobile"][data-orientation="portrait"] .mobile-restart-help-affordance:not([hidden]),
body.mobile-layout[data-orientation="portrait"] .mobile-restart-help-affordance:not([hidden]) {
  position: fixed;
  inset-inline-start: max(10px, env(safe-area-inset-left));
  inset-block-start: 50%;
  z-index: 23;
  display: grid;
  align-content: center;
  justify-items: center;
  min-inline-size: 68px;
  min-block-size: 52px;
  padding: 7px 10px;
  border: 1px solid rgba(127, 214, 245, 0.68);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(33, 52, 79, 0.94), rgba(10, 17, 28, 0.94));
  box-shadow: 0 0 0 1px rgba(127, 214, 245, 0.16), 0 10px 24px rgba(0, 0, 0, 0.34);
  color: #d7f4ff;
  font: 800 11px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  pointer-events: auto;
  text-transform: uppercase;
  touch-action: manipulation;
  transform: translateY(-50%);
}

.mobile-restart-help-affordance__label,
.mobile-restart-help-affordance__hint {
  pointer-events: none;
}

.mobile-restart-help-affordance__hint {
  margin-block-start: 3px;
  color: rgba(255, 243, 191, 0.94);
  font-size: 9px;
  letter-spacing: 0.04em;
  text-transform: none;
}

body[data-layout="mobile"] .mobile-restart-help-panel:not([hidden]),
body.mobile-layout .mobile-restart-help-panel:not([hidden]) {
  position: fixed;
  inset-block-start: calc(max(8px, env(safe-area-inset-top)) + 168px);
  inset-inline: max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-right));
  z-index: 44;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  inline-size: min(340px, calc(100vw - 28px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  margin-inline: auto;
  padding: 12px;
  border: 1px solid rgba(127, 214, 245, 0.56);
  border-radius: 14px;
  background: rgba(9, 12, 18, 0.95);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.48), 0 0 22px rgba(127, 214, 245, 0.12);
  color: #d7f4ff;
  pointer-events: auto;
}

.mobile-restart-help-panel__copy {
  display: grid;
  gap: 4px;
  min-inline-size: 0;
}

.mobile-restart-help-panel__title {
  color: #ffd166;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.2;
  text-transform: uppercase;
}

.mobile-restart-help-panel__hint {
  color: #dfe6ef;
  font-size: 13px;
  line-height: 1.35;
}

.mobile-restart-help-panel__actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(var(--touch-target-min), 1fr));
  gap: 8px;
}

.mobile-restart-help-panel button {
  box-sizing: border-box;
  min-inline-size: var(--touch-target-min);
  min-block-size: var(--touch-target-min);
  padding: 9px 10px;
  border: 1px solid rgba(127, 214, 245, 0.42);
  border-radius: 10px;
  background: #84e1bc;
  color: #08110d;
  font: 800 11px/1.1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  touch-action: manipulation;
}

.mobile-restart-help-panel button.secondary {
  background: #2a3142;
  color: #dfe6ef;
}

.mobile-spellbook-affordance__label,
.mobile-spellbook-affordance__hint {
  pointer-events: none;
}

.mobile-spellbook-affordance__hint {
  margin-block-start: 3px;
  color: rgba(215, 244, 255, 0.92);
  font-size: 9px;
  letter-spacing: 0.04em;
  text-transform: none;
}

body:has(#overlay.show) .mobile-spellbook-affordance,
body:has(.modal.show) .mobile-spellbook-affordance,
body:has(.win-screen.show) .mobile-spellbook-affordance,
body:has(.mobile-death-recovery:not([hidden])) .mobile-spellbook-affordance,
body:has(.mobile-failure-recovery:not([hidden])) .mobile-spellbook-affordance,
body:has(#wand.open) .mobile-spellbook-affordance {
  display: none;
}

body:has(#overlay.show) .mobile-restart-help-affordance,
body:has(.modal.show) .mobile-restart-help-affordance,
body:has(.win-screen.show) .mobile-restart-help-affordance,
body:has(.mobile-death-recovery:not([hidden])) .mobile-restart-help-affordance,
body:has(.mobile-failure-recovery:not([hidden])) .mobile-restart-help-affordance,
body:has(.mobile-restart-help-panel:not([hidden])) .mobile-restart-help-affordance,
body:has(#wand.open) .mobile-restart-help-affordance,
body.mobile-keyboard-visible .mobile-restart-help-affordance {
  display: none;
}

body:has(#overlay.show) .mobile-restart-help-panel,
body:has(.modal.show) .mobile-restart-help-panel,
body:has(.win-screen.show) .mobile-restart-help-panel,
body:has(.mobile-death-recovery:not([hidden])) .mobile-restart-help-panel,
body:has(.mobile-failure-recovery:not([hidden])) .mobile-restart-help-panel,
body:has(#wand.open) .mobile-restart-help-panel {
  display: none;
}

@media (max-width: 480px) {
  body[data-layout="mobile"] #wand {
    position: fixed;
    inset-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right));
    inset-block-end: max(52px, env(safe-area-inset-bottom));
    z-index: 30;
    display: grid;
    gap: 6px;
    box-sizing: border-box;
    width: auto;
    max-height: min(330px, calc(48dvh - max(20px, env(safe-area-inset-bottom))));
    padding: 8px;
    overflow: hidden;
    border-radius: 14px;
    transition: none;
  }

  body[data-layout="mobile"] #wand.closed {
    transform: translateY(calc(100% + 18px));
  }

  body[data-layout="mobile"] #wand.open,
  body[data-layout="mobile"] #tutorial-overlay,
  body[data-layout="mobile"] #overlay.show .panel:has(#pause-root) {
    opacity: 1;
    transform: translateY(0);
  }

  body[data-layout="mobile"] #wand.closing,
  body[data-layout="mobile"] #tutorial-overlay.closing,
  body[data-layout="mobile"] #pause-root.closing,
  body[data-layout="mobile"] #overlay.show .panel:has(#pause-root.closing),
  body[data-layout="mobile"] #overlay.show .panel:has(#pause-root[data-swipe-closing="true"]) {
    opacity: 0;
    transform: translateY(calc(100% + 24px));
  }

  body[data-layout="mobile"] #wand-header {
    margin-bottom: 0;
    gap: 6px;
  }

  body[data-layout="mobile"] #wand-header .hint {
    display: none;
  }

  body[data-layout="mobile"] #wand-mode,
  body[data-layout="mobile"] #wand-summon-name,
  body[data-layout="mobile"] #session-cost-display {
    min-height: 0;
    font-size: 11px;
  }

  body[data-layout="mobile"] #wand-slots {
    justify-content: flex-start;
    align-content: flex-start;
    flex-wrap: wrap;
    gap: 4px;
    min-height: 44px;
    max-height: 58px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  body[data-layout="mobile"] .slot {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    font-size: 18px;
  }

  body[data-layout="mobile"] .wand-empty-state {
    width: min(260px, 84%);
    min-height: 32px;
    padding: 4px 8px;
    font-size: 11px;
  }

  body[data-layout="mobile"] #wand.open .mobile-spell-input-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    margin-top: 0;
    touch-action: manipulation;
  }

  body[data-layout="mobile"] .mobile-spell-input {
    width: 100%;
    min-height: var(--mobile-control-size);
    box-sizing: border-box;
    touch-action: manipulation;
  }

  body[data-layout="mobile"] #cooldown-track,
  body[data-layout="mobile"] #spell-feedback {
    margin-top: 0;
  }

  body[data-layout="mobile"] #spell-feedback {
    min-height: 14px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 11px;
  }

  body[data-layout="mobile"] .wand-mobile-actions {
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr 1fr;
    gap: 6px;
  }

  body[data-layout="mobile"] .wand-mobile-actions button {
    min-width: var(--mobile-control-size);
    min-height: var(--mobile-control-size);
    padding: 8px 10px;
    border: 1px solid rgba(255, 209, 102, 0.5);
    border-radius: 10px;
    background: rgba(31, 111, 74, 0.72);
    color: var(--ink);
    font: 700 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  body[data-layout="mobile"] .wand-mobile-actions .secondary {
    border-color: rgba(127, 214, 245, 0.38);
    background: rgba(10, 14, 22, 0.82);
    color: #d7f4ff;
  }

body[data-layout="mobile"] #wand-mobile-clear-btn {
  border-color: rgba(255, 209, 102, 0.48);
  background: rgba(35, 26, 7, 0.82);
  color: #fff0b3;
}

  body[data-layout="mobile"] #wand-mobile-cast-btn {
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 2px;
    min-height: calc(var(--mobile-control-size) + 8px);
    border-color: rgba(255, 209, 102, 0.78);
    background: linear-gradient(180deg, rgba(44, 160, 106, 0.92), rgba(22, 117, 76, 0.9));
    box-shadow: 0 0 0 1px rgba(255, 209, 102, 0.16), 0 8px 22px rgba(0, 0, 0, 0.24);
    touch-action: manipulation;
  }

  body[data-layout="mobile"] #wand-mobile-cast-btn.is-ready {
    border-color: #ffe08a;
    background: linear-gradient(180deg, rgba(56, 197, 124, 0.98), rgba(24, 137, 87, 0.96));
    box-shadow: 0 0 0 2px rgba(255, 224, 138, 0.24), 0 0 22px rgba(56, 197, 124, 0.34), 0 10px 24px rgba(0, 0, 0, 0.28);
  }

  body[data-layout="mobile"] #wand-mobile-cast-btn.is-invalid {
    border-color: rgba(239, 71, 111, 0.78);
    background: linear-gradient(180deg, rgba(116, 38, 56, 0.94), rgba(72, 20, 35, 0.92));
  }

  body[data-layout="mobile"] .wand-mobile-cast-btn__status,
  body[data-layout="mobile"] .wand-mobile-cast-btn__label,
  body[data-layout="mobile"] .wand-mobile-cast-btn__hint {
    display: block;
    max-width: 100%;
    overflow: hidden;
    pointer-events: none;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body[data-layout="mobile"] .wand-mobile-cast-btn__status {
    min-inline-size: 42px;
    padding: 2px 7px;
    border-radius: 999px;
    background: rgba(10, 13, 19, 0.42);
    color: rgba(255, 243, 191, 0.88);
    font-size: clamp(8px, 1.1dvh, 10px);
    line-height: 1;
    letter-spacing: 0.12em;
  }

  body[data-layout="mobile"] #wand-mobile-cast-btn.is-ready .wand-mobile-cast-btn__status {
    background: rgba(255, 243, 191, 0.22);
    color: #fff8cf;
  }

  body[data-layout="mobile"] #wand-mobile-cast-btn.is-invalid .wand-mobile-cast-btn__status {
    background: rgba(239, 71, 111, 0.18);
    color: #ffd5df;
  }

  body[data-layout="mobile"] #wand-mobile-cast-btn.is-ready .wand-mobile-cast-btn__hint {
    color: #fff8cf;
  }

  body[data-layout="mobile"] #wand-mobile-cast-btn.is-invalid .wand-mobile-cast-btn__hint {
    color: #ffd5df;
  }

  body[data-layout="mobile"] .wand-mobile-cast-btn__label {
    font-size: clamp(11px, 1.65dvh, 13px);
    line-height: 1.05;
  }

  body[data-layout="mobile"] .wand-mobile-cast-btn__hint {
    color: rgba(255, 243, 191, 0.92);
    font-size: clamp(8px, 1.15dvh, 10px);
    letter-spacing: 0.03em;
    line-height: 1.05;
    text-transform: none;
  }

  body[data-layout="mobile"] #quick-cast-bar.has-favourites,
  body.mobile-layout #quick-cast-bar.has-favourites {
    inset-block-end: calc(35dvh + 88px + env(safe-area-inset-bottom));
  }

}

@media (max-width: 600px) {
  body[data-layout="mobile"] {
    --mobile-control-size: clamp(38px, 5.2dvh, 44px);
    --mobile-joystick-size: clamp(72px, 10.5dvh, 90px);
    --mobile-side-rail-width: clamp(54px, 8dvh, 66px);
    --mobile-safe-edge-gap: clamp(4px, 0.75dvh, 6px);
    --hud-font-size: clamp(10px, 1.45dvh, 12px);
    --hud-label-font-size: clamp(9px, 1.35dvh, 12px);
    --wand-token-font-size: clamp(10px, 1.45dvh, 12px);
  }

  body[data-layout="mobile"] #spell-history-toggle,
  body[data-layout="mobile"] #spell-history-drawer {
    display: block;
  }

  body[data-layout="mobile"] #app {
    padding-block-end: var(--mobile-wand-panel-gap);
    place-items: center;
  }

  body[data-layout="mobile"] #game-stage {
    width: min(100vw, calc((100dvh - var(--mobile-wand-panel-gap)) * 16 / 9));
  }

  body[data-layout="mobile"] .joystick-base {
    inline-size: min(var(--mobile-joystick-size), calc(50vw - var(--mobile-thumb-safe-gap)));
    block-size: min(var(--mobile-joystick-size), calc(50vw - var(--mobile-thumb-safe-gap)));
  }

  body[data-layout="mobile"] .joystick-knob {
    inline-size: clamp(32px, 4.8dvh, 40px);
    block-size: clamp(32px, 4.8dvh, 40px);
  }

}

@media (orientation: landscape) {
  body[data-layout="mobile"][data-orientation="landscape"] {
    --mobile-control-size: clamp(34px, 11dvh, 44px);
    --mobile-joystick-size: clamp(62px, 23dvh, 90px);
    --mobile-side-rail-width: clamp(46px, 17dvh, 66px);
    --mobile-safe-edge-gap: clamp(3px, 1.55dvh, 6px);
    --hud-mobile-bar-width: clamp(36px, 12.5dvh, 48px);
    --hud-mobile-bar-height: clamp(9px, 3.1dvh, 12px);
    --hud-font-size: clamp(8px, 2.55dvh, 10px);
    --hud-label-font-size: clamp(8px, 2.3dvh, 9px);
    --wand-token-font-size: clamp(9px, 3dvh, 12px);
  }

  body[data-layout="mobile"][data-orientation="landscape"] #app {
    padding-block-end: 0;
    place-items: center;
  }

  body[data-layout="mobile"][data-orientation="landscape"] #game-stage {
    width: min(100vw, calc(100dvh * 16 / 9));
  }

  body[data-layout="mobile"][data-orientation="landscape"] #hud {
    padding: var(--mobile-safe-edge-gap);
  }

  body[data-layout="mobile"][data-orientation="landscape"] #hud > .row {
    position: fixed;
    inset-block: max(var(--mobile-safe-edge-gap), env(safe-area-inset-top)) max(var(--mobile-safe-edge-gap), env(safe-area-inset-bottom));
    inset-inline-start: max(var(--mobile-safe-edge-gap), env(safe-area-inset-left));
    display: flex;
    flex-flow: column nowrap;
    align-items: stretch;
    width: var(--mobile-side-rail-width);
    gap: clamp(2px, 1dvh, 4px);
    overflow-y: auto;
    overscroll-behavior: contain;
    pointer-events: none;
    -webkit-overflow-scrolling: touch;
  }

  body[data-layout="mobile"][data-orientation="landscape"] #hp-wrap,
  body[data-layout="mobile"][data-orientation="landscape"] #mana-wrap,
  body[data-layout="mobile"][data-orientation="landscape"] #score-wrap,
  body[data-layout="mobile"][data-orientation="landscape"] #depth-wrap,
  body[data-layout="mobile"][data-orientation="landscape"] #gold-wrap,
  body[data-layout="mobile"][data-orientation="landscape"] #xp-wrap,
  body[data-layout="mobile"][data-orientation="landscape"] #timer-wrap,
  body[data-layout="mobile"][data-orientation="landscape"] #codex-btn,
  body[data-layout="mobile"][data-orientation="landscape"] #combat-stats-btn,
  body[data-layout="mobile"][data-orientation="landscape"] #letter-stats-btn,
  body[data-layout="mobile"][data-orientation="landscape"] #perks-btn,
  body[data-layout="mobile"][data-orientation="landscape"] #daily-hud-badge,
  body[data-layout="mobile"][data-orientation="landscape"] #settings-btn,
  body[data-layout="mobile"][data-orientation="landscape"] #audio-btn,
  body[data-layout="mobile"][data-orientation="landscape"] #debug-btn {
    justify-content: center;
    width: var(--mobile-side-rail-width);
    min-width: 0;
    min-height: var(--mobile-control-size);
    padding: clamp(2px, 1dvh, 4px);
    overflow: hidden;
    text-align: center;
    text-overflow: ellipsis;
    pointer-events: auto;
  }

  body[data-layout="mobile"][data-orientation="landscape"] #hp-wrap,
  body[data-layout="mobile"][data-orientation="landscape"] #mana-wrap,
  body[data-layout="mobile"][data-orientation="landscape"] #xp-wrap {
    flex-direction: column;
    gap: 3px;
  }

  body[data-layout="mobile"][data-orientation="landscape"] #settings-btn {
    margin-inline-start: 0;
  }

  body[data-layout="mobile"][data-orientation="landscape"] #wand {
    position: fixed;
    inset-block-start: max(var(--mobile-safe-edge-gap), env(safe-area-inset-top));
    inset-block-end: max(calc(var(--mobile-joystick-size) + var(--mobile-safe-edge-gap) + var(--mobile-safe-edge-gap)), env(safe-area-inset-bottom));
    inset-inline-start: auto;
    inset-inline-end: max(var(--mobile-safe-edge-gap), env(safe-area-inset-right));
    z-index: 30;
    grid-template-columns: 1fr;
    align-content: start;
    block-size: calc(100dvh - var(--mobile-joystick-size) - var(--mobile-safe-edge-gap) - var(--mobile-safe-edge-gap) - var(--mobile-safe-edge-gap));
    width: var(--mobile-side-rail-width);
    max-height: none;
    padding: var(--mobile-safe-edge-gap);
    overflow: hidden auto;
    border-radius: 14px;
  }

  body[data-layout="mobile"][data-orientation="landscape"] #wand.closed {
    transform: translateX(calc(100% + 12px));
  }

  body[data-layout="mobile"][data-orientation="landscape"] #wand.open {
    transform: translateX(0);
  }

  body[data-layout="mobile"][data-orientation="landscape"] #wand-header,
  body[data-layout="mobile"][data-orientation="landscape"] .mobile-spell-input-row,
  body[data-layout="mobile"][data-orientation="landscape"] #spell-suggestions,
  body[data-layout="mobile"][data-orientation="landscape"] #cooldown-track,
  body[data-layout="mobile"][data-orientation="landscape"] #spell-feedback,
  body[data-layout="mobile"][data-orientation="landscape"] .wand-mobile-actions {
    grid-column: 1;
  }

  body[data-layout="mobile"][data-orientation="landscape"] #wand-header {
    display: grid;
    gap: 4px;
  }

  body[data-layout="mobile"][data-orientation="landscape"] #wand-header > .lbl,
  body[data-layout="mobile"][data-orientation="landscape"] #wand-summon-name,
  body[data-layout="mobile"][data-orientation="landscape"] #session-cost-display {
    display: none;
  }

  body[data-layout="mobile"][data-orientation="landscape"] #wand-mode {
    padding: 3px 4px;
    text-align: center;
  }

  body[data-layout="mobile"][data-orientation="landscape"] #wand-slots {
    grid-column: 1;
    display: grid;
    grid-auto-rows: var(--mobile-control-size);
    max-height: calc(var(--mobile-control-size) + var(--mobile-control-size) + var(--mobile-control-size) + 6px);
    overflow-x: hidden;
    overflow-y: auto;
  }

  body[data-layout="mobile"][data-orientation="landscape"] .mobile-spell-input-row,
  body[data-layout="mobile"][data-orientation="landscape"] .wand-mobile-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
  }

  body[data-layout="mobile"][data-orientation="landscape"] .mobile-spell-input {
    min-inline-size: 0;
    padding-inline: 4px;
    font-size: 13px;
  }

  body[data-layout="mobile"][data-orientation="landscape"] .wand-mobile-actions button {
    padding-inline: clamp(2px, 1dvh, 4px);
    font-size: clamp(8px, 2.55dvh, 10px);
  }

  body[data-layout="mobile"][data-orientation="landscape"] #quick-cast-bar.has-favourites,
  body[data-layout="mobile"][data-orientation="landscape"].mobile-layout #quick-cast-bar.has-favourites {
    inset-inline-end: max(var(--mobile-safe-edge-gap), env(safe-area-inset-right));
    inset-block-end: max(var(--mobile-safe-edge-gap), env(safe-area-inset-bottom));
    flex-direction: column;
    width: 66px;
    max-inline-size: 66px;
    max-block-size: 72px;
    overflow-x: hidden;
    overflow-y: auto;
    border-radius: 16px;
  }

  body[data-layout="mobile"][data-orientation="landscape"] .quick-cast-chip {
    width: var(--mobile-control-size);
    max-inline-size: var(--mobile-control-size);
    padding-inline: clamp(2px, 1dvh, 4px);
  }

  body[data-layout="mobile"][data-orientation="landscape"] .mobile-first-session-checklist:not([hidden]) {
    inset-block-start: max(var(--mobile-safe-edge-gap), env(safe-area-inset-top));
    inset-inline-start: calc(var(--mobile-side-rail-width) + var(--mobile-safe-edge-gap) + var(--mobile-safe-edge-gap));
    inset-inline-end: calc(var(--mobile-side-rail-width) + var(--mobile-safe-edge-gap) + var(--mobile-safe-edge-gap));
    inline-size: auto;
    max-inline-size: none;
    padding: 4px 6px;
    font-size: clamp(8px, 2.55dvh, 10px);
  }

  body[data-layout="mobile"][data-orientation="landscape"] .mobile-first-session-checklist__steps {
    display: none;
  }

  body[data-layout="mobile"][data-orientation="landscape"] .mobile-first-session-guidance:not([hidden]) {
    inset-block-start: auto;
    inset-block-end: max(var(--mobile-safe-edge-gap), env(safe-area-inset-bottom));
    inset-inline-start: calc(var(--mobile-side-rail-width) + var(--mobile-safe-edge-gap) + var(--mobile-safe-edge-gap));
    inset-inline-end: calc(var(--mobile-side-rail-width) + var(--mobile-safe-edge-gap) + var(--mobile-safe-edge-gap));
    inline-size: auto;
    max-block-size: calc(var(--mobile-control-size) + 14px);
    overflow: hidden;
    font-size: clamp(8px, 2.55dvh, 10px);
  }

  body[data-layout="mobile"][data-orientation="landscape"] .joystick-base {
    inset-inline-start: max(
      calc(var(--mobile-side-rail-width) + var(--mobile-safe-edge-gap) + var(--mobile-safe-edge-gap)),
      calc(env(safe-area-inset-left) + var(--mobile-side-rail-width) + var(--mobile-safe-edge-gap) + var(--mobile-safe-edge-gap))
    );
    inset-block-end: max(var(--mobile-safe-edge-gap), env(safe-area-inset-bottom));
    inline-size: var(--mobile-joystick-size);
    block-size: var(--mobile-joystick-size);
  }

  body[data-layout="mobile"][data-orientation="landscape"] .joystick-knob {
    inline-size: clamp(28px, 10dvh, 40px);
    block-size: clamp(28px, 10dvh, 40px);
  }
}

@keyframes biome-transition-fade {
  0% { opacity: 0; }
  48% { opacity: 0.72; }
  100% { opacity: 0; }
}

@keyframes biome-title-splash {
  0% { opacity: 0; transform: translateY(6px) scale(0.98); }
  25% { opacity: 1; transform: translateY(0) scale(1); }
  75% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-4px) scale(1.01); }
}

@keyframes world-loading-shader {
  to { transform: rotate(1turn); }
}

@keyframes world-loading-scan {
  0%, 100% { transform: translateY(-42%); opacity: 0; }
  50% { transform: translateY(42%); opacity: 1; }
}

@keyframes world-loading-orbit {
  to { transform: rotate(-1turn); }
}

@keyframes world-loading-bar {
  0% { transform: translateX(-105%); }
  100% { transform: translateX(245%); }
}

@keyframes hud-feedback-pulse {
  0% { transform: scale(1); box-shadow: none; }
  24% { transform: scale(1.08); box-shadow: 0 0 18px rgba(255, 209, 102, 0.42); }
  100% { transform: scale(1); box-shadow: none; }
}

@keyframes hit-flash-pop {
  0% { opacity: 0; }
  18% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes tick-up {
  0% { transform: translateY(0) scale(1); color: var(--accent); }
  36% { transform: translateY(-3px) scale(1.16); color: #fff3bf; text-shadow: 0 0 12px rgba(255, 209, 102, 0.55); }
  100% { transform: translateY(0) scale(1); color: inherit; text-shadow: none; }
}

@keyframes cast-echo-pulse {
  0% { filter: brightness(1); transform: translateY(0); }
  38% { filter: brightness(1.32); transform: translateY(-1px); }
  100% { filter: brightness(1); transform: translateY(0); }
}

@keyframes wand-cast-error {
  0% { transform: translateX(0); border-color: var(--danger); box-shadow: 0 0 0 rgba(239, 71, 111, 0); }
  18% { transform: translateX(-6px); border-color: var(--danger); box-shadow: 0 0 18px rgba(239, 71, 111, 0.35); }
  38% { transform: translateX(5px); }
  58% { transform: translateX(-3px); }
  100% { transform: translateX(0); box-shadow: 0 0 0 rgba(239, 71, 111, 0); }
}

@keyframes wand-validation-shake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  42% { transform: translateX(4px); }
  64% { transform: translateX(-2px); }
  100% { transform: translateX(0); }
}

@keyframes wand-cast-ok {
  0% { border-color: var(--accent-2); box-shadow: 0 0 0 rgba(132, 225, 188, 0); }
  36% { border-color: var(--accent-2); box-shadow: 0 0 18px rgba(132, 225, 188, 0.34); }
  100% { box-shadow: 0 0 0 rgba(132, 225, 188, 0); }
}

@keyframes tutorial-nudge-pop {
  0% { opacity: 0; filter: brightness(0.8); }
  100% { opacity: 1; filter: brightness(1); }
}

@keyframes tutorial-nudge-fade {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --canvas-motion-brightness: brightness(0.75);
  }

  #game-transition-fade.show,
  #hit-flash.show,
  #biome-splash.show,
  #score-wrap.pulse,
  #depth-wrap.pulse,
  #depth-text.tick-up,
  .inventory-rail.pickup-pulse,
  #wand-slots.cast-echo,
  .tutorial-nudge,
  #wand.cast-error,
  #wand.cast-ok,
  #wand.validation-shake,
  #summoning::before,
  #hud-summoning::before,
  .world-loading-panel::before,
  .world-loading-panel::after,
  .world-loading-vortex,
  .world-loading-bar span,
  .reward-burst {
    animation: none;
  }

  .juice-hover {
    transform: none;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.08) inset;
  }

  .tutorial-nudge {
    animation: tutorial-nudge-fade 120ms ease-out both;
  }

  .slot,
  .chip,
  #hud button,
  #wand button,
  #hp-bar,
  #mana-bar,
  #wand,
  #wand.closing,
  #tutorial-overlay,
  #tutorial-overlay.closing,
  #pause-root,
  #pause-root.closing,
  #overlay.show .panel:has(#pause-root),
  #overlay.show .panel:has(#pause-root.closing),
  #wand-cooldown-bar,
  .pwa-install-cta {
    transition: none;
  }

  #game-transition-fade.show {
    opacity: 0;
  }

  #biome-splash.show {
    opacity: 1;
    transform: none;
  }

  #summoning::before,
  #hud-summoning::before,
  .reward-burst {
    opacity: 1;
    transform: none;
  }
}

body.high-contrast #game {
  border-color: #bcd2ff;
  box-shadow: 0 0 0 2px #000, 0 0 0 4px #bcd2ff;
}

body.photosensitive-safe #game {
  filter: saturate(0.9) contrast(0.95) var(--canvas-motion-brightness);
}

body.colorblind-deuteranopia #game {
  filter: saturate(0.95) hue-rotate(-8deg) contrast(1.06) var(--canvas-motion-brightness);
}

body.colorblind-protanopia #game {
  filter: saturate(0.9) hue-rotate(12deg) contrast(1.08) var(--canvas-motion-brightness);
}

body.colorblind-tritanopia #game {
  filter: saturate(0.92) hue-rotate(32deg) contrast(1.08) var(--canvas-motion-brightness);
}

body.photosensitive-safe.colorblind-deuteranopia #game,
body.photosensitive-safe.colorblind-protanopia #game,
body.photosensitive-safe.colorblind-tritanopia #game {
  filter: saturate(0.84) contrast(1.02) var(--canvas-motion-brightness);
}

/* HUD */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

body.large-hud #hud {
  padding: 18px;
}

.row {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

#vitals-wrap,
#hp-wrap,
#mana-wrap,
#score-wrap,
#depth-wrap,
#gold-wrap,
#xp-wrap,
#timer-wrap,
#codex-btn,
#letter-stats-btn,
#perks-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--hud-panel-bg);
  border: 1px solid var(--hud-border-readable);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: var(--hud-font-size);
  line-height: 1.2;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
}

#vitals-wrap {
  display: grid;
  gap: 4px;
}

#vitals-wrap #hp-wrap,
#vitals-wrap #mana-wrap {
  gap: 0;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

#score-wrap {
  display: none;
}

#hp-wrap .lbl,
#hp-text,
#mana-wrap .lbl,
#mana-text,
#xp-wrap .lbl,
#timer-wrap .lbl {
  display: none;
}

#gold-wrap .lbl {
  color: #ffd166;
  font-size: 1.15em;
  line-height: 1;
}

#depth-wrap .lbl {
  color: var(--accent-2);
  font-size: 1.15em;
  line-height: 1;
}

#depth-wrap,
#gold-wrap {
  min-block-size: 36px;
}

body.large-hud #hp-wrap,
body.large-hud #mana-wrap,
body.large-hud #score-wrap,
body.large-hud #depth-wrap,
body.large-hud #gold-wrap,
body.large-hud #xp-wrap,
body.large-hud #timer-wrap,
body.large-hud #codex-btn,
body.large-hud #letter-stats-btn,
body.large-hud #perks-btn {
  font-size: 14px;
  padding: 8px 12px;
}

#debug-btn,
#settings-btn,
#audio-btn,
#admin-btn,
#codex-btn,
#combat-stats-btn,
#letter-stats-btn,
#perks-btn {
  pointer-events: auto;
  background: rgba(8, 11, 17, 0.76);
  color: #cdd5e0;
  border: 1px solid rgba(42, 49, 66, 0.78);
  border-radius: 6px;
  padding: var(--touch-target-padding-y) var(--touch-target-padding-x);
  font: inherit;
  font-size: var(--hud-font-size);
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: transform 80ms ease-out, box-shadow 80ms ease-out, border-color 80ms ease-out;
}

#settings-btn,
#audio-btn,
#codex-btn,
#perks-btn,
#debug-btn {
  display: inline-grid;
  place-items: center;
  padding: 0;
  letter-spacing: 0;
  line-height: 1;
  text-align: center;
}

.hud-icon {
  display: inline-grid;
  place-items: center;
  inline-size: 1.35em;
  block-size: 1em;
  overflow: hidden;
  line-height: 1;
  transform-origin: center;
}

.hud-icon-rotated {
  transform: rotate(90deg);
}

#settings-btn,
#audio-btn,
#perks-btn,
#debug-btn {
  font-size: calc(var(--hud-font-size) + 10px);
}

#codex-btn {
  font-size: calc(var(--hud-font-size) + 6px);
}

#settings-btn .hud-icon,
#perks-btn .hud-icon {
  transform: scale(1.25);
}

#perks-btn .hud-icon {
  transform: translateY(-0.105em) scale(1.25);
}

#settings-btn .hud-icon-rotated {
  transform: rotate(90deg) scale(1.25);
}

#combat-stats-btn,
#letter-stats-btn {
  display: none;
}

#combat-stats-btn {
  left: max(14px, env(safe-area-inset-left));
}

#letter-stats-btn {
  right: max(14px, env(safe-area-inset-right));
}

#hud button,
#wand button,
.hud button,
.wand button,
.wand-chip,
.cast-btn,
.settings-btn,
.pause-btn {
  box-sizing: border-box;
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
}

#timer-text {
  color: #ffd166;
  font-variant-numeric: tabular-nums;
}

#timer-wrap {
  margin-inline-start: auto !important;
}

.speedrun-hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  inset-inline-end: max(10px, env(safe-area-inset-right));
  z-index: 5;
  display: grid;
  gap: 4px;
  min-width: 156px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 209, 102, 0.45);
  border-radius: 8px;
  background: rgba(5, 6, 8, 0.86);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.38);
  color: var(--ink);
  font: 700 12px/1.25 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.06em;
  pointer-events: auto;
}

.speedrun-hud[hidden] {
  display: none;
}

#debug-seed {
  position: absolute;
  inset-block-end: 8px;
  inset-inline-start: 8px;
  z-index: 12;
  padding: 2px 5px;
  border: 1px solid rgba(154, 214, 255, 0.22);
  border-radius: 4px;
  background: rgba(5, 8, 16, 0.46);
  color: rgba(213, 251, 255, 0.72);
  font: 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  pointer-events: none;
}

#debug-seed[hidden] {
  display: none;
}

.speedrun-hud__row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.speedrun-hud__row span {
  color: var(--muted);
  text-transform: uppercase;
}

.speedrun-hud__row b {
  color: #ffd166;
  font-variant-numeric: tabular-nums;
}

.speedrun-hud__challenge {
  padding: 2px 6px;
  border: 1px solid rgba(132, 225, 188, 0.55);
  border-radius: 999px;
  color: var(--accent-2);
  text-align: center;
  text-transform: uppercase;
}

.speedrun-hud__challenge[hidden] {
  display: none;
}

.speedrun-hud__toggle {
  min-height: 28px;
  margin-top: 2px;
  padding: 4px 6px;
  border: 1px solid rgba(132, 225, 188, 0.55);
  border-radius: 6px;
  background: rgba(10, 13, 19, 0.78);
  color: var(--accent-2);
  font: inherit;
  cursor: pointer;
}

.speedrun-timer {
  display: inline-block;
  min-width: 5ch;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.32);
  color: #ffd166;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

#settings-btn { margin-inline-start: 0 !important; }
#debug-btn:hover, #settings-btn:hover, #audio-btn:hover, #codex-btn:hover, #combat-stats-btn:hover, #letter-stats-btn:hover, #perks-btn:hover {
  color: var(--ink);
  border-color: var(--accent-2);
}
#debug-btn.on,
#combat-stats-btn.on,
#letter-stats-btn.on {
  color: #1a1300;
  background: var(--accent-2);
  border-color: var(--accent-2);
  border-style: solid;
}

#combat-stats {
  pointer-events: none;
  position: fixed;
  inset-inline-start: max(14px, env(safe-area-inset-left));
  inset-block-end: calc(max(14px, env(safe-area-inset-bottom)) + var(--touch-target-min) + 8px);
  z-index: 18;
  background: rgba(10, 13, 19, 0.78);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--ink);
  font-size: 11px;
  line-height: 1.5;
  min-width: 150px;
}

#combat-stats.hidden {
  display: none;
}

#heatmap-panel {
  pointer-events: auto;
  position: fixed;
  inset-inline-end: max(14px, env(safe-area-inset-right));
  inset-block-end: calc(max(14px, env(safe-area-inset-bottom)) + var(--touch-target-min) + 8px);
  z-index: 18;
  background: rgba(10, 13, 19, 0.82);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px 10px;
  color: var(--ink);
  font-size: 11px;
  line-height: 1.45;
  width: 270px;
}

#heatmap-panel.hidden {
  display: none;
}

.heatmap-title {
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.heatmap-note {
  color: var(--muted);
  margin: 2px 0 8px;
}

#letter-heatmap {
  display: block;
  width: 100%;
  height: auto;
}

#subtitle-overlay {
  pointer-events: none;
  align-self: center;
  margin-top: auto;
  margin-bottom: 96px;
  max-width: min(520px, 86vw);
  background: rgba(5, 6, 8, 0.82);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--ink);
  padding: 7px 12px;
  text-align: center;
  font-size: 12px;
  line-height: 1.35;
  text-shadow: 0 1px 2px #000;
}

#subtitle-overlay.hidden {
  display: none;
}

#boss-transition {
  pointer-events: none;
  align-self: center;
  justify-self: center;
  margin-top: 64px;
  background: rgba(5, 6, 8, 0.9);
  border: 1px solid #ffd166;
  border-radius: 6px;
  color: #ffd166;
  padding: 8px 14px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 12px;
  text-shadow: 0 1px 2px #000;
}

#boss-transition.hidden {
  display: none;
}

#hud-status,
#hud-summoning,
#material-reticle-label {
  pointer-events: none;
  align-self: center;
  margin-top: 8px;
  background: rgba(10, 13, 19, 0.82);
  border: 1px solid #c084ff;
  border-radius: 6px;
  color: #f3e8ff;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.35;
  max-width: min(560px, 86vw);
  text-align: center;
  text-shadow: 0 1px 2px #000;
}

#hud-status {
  position: fixed;
  top: 74px;
  left: 50%; /* stylelint-disable-line csstools/use-logical -- rtl-skip: physical centering coordinate pairs with translateX */
  z-index: 30;
  transform: translateX(-50%);
}

#hud-summoning {
  position: fixed;
  top: 112px;
  left: 50%; /* stylelint-disable-line csstools/use-logical -- rtl-skip: physical centering coordinate pairs with translateX */
  z-index: 31;
  display: flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  border-color: rgba(192, 132, 255, 0.85);
  background: rgba(29, 16, 48, 0.92);
  box-shadow: 0 0 24px rgba(192, 132, 255, 0.24);
  transform: translateX(-50%);
}

#hud-summoning::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c084ff;
  box-shadow: 0 0 12px rgba(192, 132, 255, 0.7);
  animation: empty-state-pulse 900ms ease-in-out infinite;
  will-change: opacity, transform;
}

#hud-status.hud-status--success {
  border-color: rgba(132, 225, 188, 0.9);
  color: #d7ffe9;
  background: rgba(8, 42, 31, 0.9);
  box-shadow: 0 0 22px rgba(132, 225, 188, 0.22);
}

#hud-status.hud-status--warning {
  border-color: rgba(239, 71, 111, 0.95);
  color: #ffd6df;
  background: rgba(48, 16, 24, 0.92);
  box-shadow: 0 0 22px rgba(239, 71, 111, 0.22);
}

#hud-status.hud-status--progress {
  border-color: rgba(255, 209, 102, 0.95);
  color: #fff3bf;
  background: rgba(47, 35, 8, 0.92);
  box-shadow: 0 0 22px rgba(255, 209, 102, 0.22);
}

#material-reticle-label {
  align-self: flex-start;
  border-color: #2a9db8;
  color: #d5fbff;
}

#hud-status.hidden,
#hud-summoning.hidden,
#material-reticle-label.hidden {
  display: none;
}

#score-wrap.pulse,
#depth-wrap.pulse,
.inventory-rail.pickup-pulse {
  animation: hud-feedback-pulse 700ms ease-out both;
  will-change: transform;
}

#depth-text {
  display: inline-block;
}

#depth-text.tick-up {
  animation: tick-up 420ms ease-out both;
  will-change: transform;
}

#material-tooltip,
.spell-detail-popover {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  max-width: 260px;
  background: rgba(8, 11, 17, 0.96);
  border: 1px solid #46556f;
  border-radius: 6px;
  color: var(--ink);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

#material-tooltip b,
.spell-detail-popover b {
  display: block;
  color: #84e1bc;
  margin-bottom: 2px;
}

#material-tooltip span,
.spell-detail-popover span {
  color: var(--muted);
}

#material-tooltip.hidden,
.spell-detail-popover.hidden {
  display: none;
}

body.large-hud #combat-stats {
  font-size: 13px;
  padding: 9px 12px;
}

body.large-hud #subtitle-overlay {
  font-size: 14px;
  padding: 9px 14px;
}
#settings-btn.on {
  color: #1a1300;
  background: #c084ff;
  border-color: #c084ff;
  border-style: solid;
}

.wand-title-block {
  display: grid;
  gap: 1px;
  min-width: 92px;
}

#wand-summon-name {
  color: #c084ff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.15;
  max-width: 190px;
  min-height: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#session-cost-display {
  color: #9ee7ff;
  font: 10px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.02em;
  background: rgba(8, 28, 42, 0.78);
  border: 1px solid rgba(127, 214, 245, 0.55);
  border-radius: 999px;
  padding: 1px 6px;
  white-space: nowrap;
}

#session-cost-display.cap-reached {
  color: #ffd6df;
  border-color: rgba(239, 71, 111, 0.75);
  background: rgba(48, 16, 24, 0.82);
}

#session-cost-display.hidden {
  display: none;
}

#wand #session-cost-display {
  display: none !important;
}

/* Summoning feedback */
#summoning,
#summon-toast {
  pointer-events: none;
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 5px auto 0;
  width: fit-content;
  max-width: min(440px, 88vw);
  border: 1px solid rgba(192, 132, 255, 0.75);
  border-radius: 999px;
  background: rgba(29, 16, 48, 0.86);
  color: #f3e8ff;
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
  text-shadow: 0 1px 2px #000;
}

#summoning::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c084ff;
  box-shadow: 0 0 12px rgba(192, 132, 255, 0.7);
  animation: empty-state-pulse 900ms ease-in-out infinite;
  will-change: opacity, transform;
}

#summon-toast {
  color: #d5fbff;
  border-color: rgba(127, 214, 245, 0.8);
  background: rgba(8, 28, 42, 0.88);
}

#summoning.hidden,
#summon-toast.hidden {
  display: none;
}

#spell-feedback.summon {
  color: #c084ff;
}

/* Settings modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 8, 0.85);
  display: none;
  place-items: center;
  z-index: 20;
  backdrop-filter: blur(4px);
  overflow: auto;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
.modal.show { display: grid; }

.error-overlay {
  z-index: 80;
  background: rgba(10, 0, 8, 0.88);
}

.error-overlay[hidden] {
  display: none;
}

.error-overlay-panel {
  border-color: var(--danger);
}

.modal-panel {
  pointer-events: auto;
  transform-origin: center top;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 26px;
  width: min(640px, 92vw);
  max-height: 92vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.modal-header h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.1em;
  color: #c084ff;
}
.modal-header .x {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  padding: 0 6px;
}
.modal-header .x:hover { color: var(--ink); }
.modal-tag {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  margin: 0 0 14px;
}
.modal-tag code {
  background: #1a2030;
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
}
.modal-panel .row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  font-size: 13px;
}
.modal-panel .row .lbl {
  width: 90px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.1em;
}
.modal-panel .audio-mixer-row .lbl {
  width: 112px;
}
.modal-panel .audio-mixer-row input[type="range"] {
  flex: 1;
  min-width: 180px;
  accent-color: #c084ff;
}
.settings-readonly-value {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid rgba(132, 211, 255, 0.2);
  border-radius: 6px;
  background: rgba(5, 8, 13, 0.72);
  color: var(--accent);
  font: 700 12px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.modal-panel input[type="text"],
.modal-panel input[type="search"],
.modal-panel input[type="password"],
.modal-panel select {
  flex: 1;
  background: #0d1118;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--ink);
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
}
.modal-panel input[type="checkbox"] {
  accent-color: #c084ff;
}
.modal-panel button {
  background: #c084ff;
  color: #1a0628;
  border: none;
  border-radius: 5px;
  padding: 6px 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.modal-panel button.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 500;
}
.modal-panel button:hover { filter: brightness(1.15); }
.modal-panel button:focus-visible,
.modal-panel input:focus-visible,
.modal-panel select:focus-visible,
.modal-panel textarea:focus-visible,
#overlay button:focus-visible,
.pause-checkpoint-actions button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.18);
}
.modal-panel .status {
  font-size: 11px;
  color: var(--muted);
}
.modal-panel .status.ok { color: var(--accent-2); }
.modal-panel .status.bad { color: var(--danger); }

.admin-modal-panel {
  width: min(1040px, 96vw);
  padding: 18px;
}

.admin-shell {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 16px;
  min-height: min(650px, 78vh);
}

.admin-sidebar {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(13, 24, 26, 0.96), rgba(6, 12, 15, 0.92));
}

.admin-brand {
  margin-bottom: 14px;
}

.admin-brand-title {
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.admin-brand-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.admin-nav {
  display: grid;
  gap: 4px;
}

.modal-panel .admin-tab {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-weight: 600;
}

.modal-panel .admin-tab:hover,
.modal-panel .admin-tab.active {
  border-color: var(--border);
  background: rgba(255, 209, 102, 0.08);
  color: var(--ink);
}

.admin-content {
  min-width: 0;
  overflow: auto;
  padding-right: 4px;
}

.admin-view {
  display: none;
}

.admin-view.active {
  display: block;
}

.admin-banner {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(132, 225, 188, 0.22);
  border-radius: 8px;
  background: rgba(132, 225, 188, 0.06);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.admin-banner strong {
  color: var(--accent-2);
}

.admin-section {
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(13, 17, 24, 0.58);
}

.admin-section h3,
.admin-section summary {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.admin-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.admin-section-head h3 {
  margin: 0;
}

.admin-actions-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 8px;
}

.admin-card {
  min-width: 0;
  padding: 8px;
  border: 1px solid rgba(42, 49, 66, 0.95);
  border-radius: 6px;
  background: #0d1118;
}

.admin-card span,
.admin-list span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.admin-card b {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  max-height: 180px;
  overflow: auto;
}

.admin-list > div,
.admin-list-row {
  padding: 7px 8px;
  border: 1px solid rgba(42, 49, 66, 0.85);
  border-radius: 6px;
  background: rgba(5, 6, 8, 0.38);
  color: var(--ink);
  font-size: 12px;
  text-align: left;
}

.modal-panel .admin-list-row {
  width: 100%;
  cursor: pointer;
}

.admin-list-row.selected,
.admin-list-row:hover {
  border-color: rgba(132, 225, 188, 0.55);
  background: rgba(132, 225, 188, 0.08);
}

.admin-list b {
  display: block;
  color: var(--ink);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-search {
  min-width: 180px;
  max-width: 280px;
}

.admin-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.modal-panel .admin-filter {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}

.modal-panel .admin-filter.active,
.modal-panel .admin-filter:hover {
  border-color: rgba(255, 209, 102, 0.55);
  background: rgba(255, 209, 102, 0.1);
  color: var(--accent);
}

.admin-filter span {
  margin-left: 5px;
  color: var(--ink);
}

.admin-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 8px;
}

.admin-action-row label {
  display: grid;
  gap: 4px;
}

.admin-action-row .lbl {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.admin-snapshot {
  max-height: 260px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #050608;
  color: #cdd5e0;
  font: 11px ui-monospace, monospace;
  white-space: pre-wrap;
}

@media (max-width: 760px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }

  .admin-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.perk-tree-panel {
  width: min(780px, 94vw);
  background: rgba(13, 17, 24, 0.96);
}

.perk-tree-tier {
  margin: 12px 0;
}

.perk-tree-tier h3 {
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.14em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.perk-tree-tier ul {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.perk-tree-node {
  background: rgba(5, 8, 13, 0.82);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  padding: 9px 10px;
}

.perk-tree-node.is-unlocked {
  border-color: rgba(132, 225, 188, 0.55);
}

.perk-tree-node__title {
  color: var(--ink);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.perk-tree-node__meta {
  color: #7d8798;
  font-size: 11px;
  margin-top: 4px;
}

.controller-bindings-list {
  margin: 6px 0 12px;
}

.modal-panel .controller-binding-row {
  align-items: center;
}

.controller-binding-value {
  flex: 1;
  color: var(--ink);
  font-size: 12px;
}

.controller-binding-row.is-capturing .controller-binding-value {
  color: var(--accent-2);
}

#pwa-install-btn,
[data-pwa-install-btn] {
  display: none;
}

.pwa-install-cta {
  background: linear-gradient(135deg, #6c63ff, #3ecfcf);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 8px;
  transition: opacity 0.2s;
}

.pwa-install-cta:hover {
  opacity: 0.85;
}

.sw-update-toast {
  position: fixed;
  inset-inline-end: 16px;
  bottom: 16px;
  z-index: 60;
  border: 1px solid rgba(127, 214, 245, 0.85);
  border-radius: 999px;
  background: rgba(8, 28, 42, 0.95);
  color: #d5fbff;
  cursor: pointer;
  font: 700 12px/1.3 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  padding: 8px 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.sw-update-toast.hidden,
.sw-update-toast[hidden] {
  display: none;
}

.sw-update-toast:hover {
  filter: brightness(1.15);
}

#pwa-install-btn {
  align-items: center;
  width: fit-content;
}

[data-pwa-install-btn] {
  align-items: center;
  border: none;
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 8px 12px;
}
.ng-plus-panel {
  border-color: rgba(255, 209, 102, 0.45);
  background: linear-gradient(180deg, rgba(23, 19, 11, 0.98), rgba(13, 15, 20, 0.98));
}
.ng-plus-panel .modal-header h2 {
  color: var(--accent);
}
.ng-plus-choices {
  display: flex;
  gap: 8px;
  margin: 14px 0 12px;
  flex-wrap: wrap;
}
.ng-plus-choices .perk-card {
  flex: 1;
  min-width: 150px;
  padding: 10px;
  background: #0d1118;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  text-align: start;
  cursor: pointer;
}
.ng-plus-choices .perk-card-name {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.06);
}
.ng-plus-choices .perk-card-desc {
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}
.ng-plus-skip {
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}
.ng-plus-skip:hover {
  color: var(--ink);
}
.cache-list {
  margin-top: 8px;
  max-height: 160px;
  overflow: auto;
  font-size: 11px;
  color: var(--muted);
  background: #0d1118;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px;
  font-family: ui-monospace, monospace;
}
.cache-list .row { margin: 0; padding: 0; font-size: 11px; }
.modal-footer {
  margin-top: 14px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.modal-footer code {
  background: #1a2030;
  border: 1px solid var(--border);
  padding: 1px 4px;
  border-radius: 3px;
}

/* Codex */
#codex-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(2, 4, 8, 0.66);
  backdrop-filter: blur(5px);
  pointer-events: auto;
  overflow: auto;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

#codex-overlay.hidden {
  display: none;
}

.codex-panel {
  width: min(920px, 92vw);
  max-height: min(760px, 88vh);
  transform-origin: center top;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 10px;
  background: linear-gradient(180deg, rgba(17, 21, 28, 0.98), rgba(7, 10, 16, 0.98));
  border: 1px solid rgba(132, 225, 188, 0.28);
  border-radius: 12px;
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.72), inset 0 0 50px rgba(132, 225, 188, 0.04);
  padding: 16px;
  color: var(--ink);
}

.codex-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.codex-header-actions {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.codex-header h2 {
  margin: 0;
  color: var(--accent);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.codex-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.codex-help {
  color: var(--muted);
  font-size: 11px;
  text-align: end;
  line-height: 1.4;
}

.codex-close {
  min-inline-size: var(--touch-target-min);
  min-block-size: var(--touch-target-min);
  border: 1px solid rgba(132, 225, 188, 0.36);
  border-radius: 10px;
  padding: 8px 12px;
  background: rgba(132, 225, 188, 0.14);
  color: var(--accent-2);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  touch-action: manipulation;
}

.codex-close:hover {
  border-color: var(--accent-2);
  color: var(--ink);
}

.codex-search {
  width: 100%;
  background: #070a10;
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font: inherit;
}

.codex-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.codex-tab {
  background: #0d1118;
  color: var(--muted);
  border: 1px solid #2a3142;
  border-radius: 999px;
  padding: 6px 10px;
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.codex-tab.active {
  color: #102017;
  background: var(--accent-2);
  border-color: var(--accent-2);
}

.codex-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
  padding-inline-end: 3px;
}

.codex-entry {
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: 10px;
  align-items: start;
  background: rgba(13, 17, 24, 0.9);
  border: 1px solid #242b3a;
  border-radius: 9px;
  padding: 10px;
  line-height: 1.35;
}

.codex-entry.locked {
  opacity: 0.62;
}

.codex-swatch {
  width: 12px;
  height: 12px;
  margin-top: 4px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.08);
}

.codex-entry-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.codex-entry h3 {
  margin: 0;
  font-size: 13px;
  color: #e7edf7;
}

.codex-entry-title span {
  color: var(--muted);
  font-size: 10px;
  text-align: end;
}

.codex-entry p {
  margin: 5px 0 0;
  color: #aeb8c8;
  font-size: 11px;
}

.codex-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}

.codex-pill {
  color: var(--accent-2);
  background: rgba(132, 225, 188, 0.08);
  border: 1px solid rgba(132, 225, 188, 0.18);
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.codex-empty {
  grid-column: 1 / -1;
}

/* Profile & achievements overlay */
#profile-overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  pointer-events: auto;
  background: rgba(5, 6, 8, 0.78);
  backdrop-filter: blur(4px);
}

.profile-card {
  width: min(880px, 90vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: linear-gradient(180deg, rgba(17, 21, 28, 0.98), rgba(10, 13, 19, 0.98));
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.68);
  padding: 20px 22px;
}

.profile-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.profile-header h2 {
  margin: 0;
  color: var(--accent);
  font-size: 22px;
  letter-spacing: 0.12em;
}

.profile-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.profile-close {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 5px 10px;
}

.profile-close:hover,
.profile-close:focus-visible {
  color: var(--ink);
  border-color: var(--accent);
}

.profile-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.profile-tab {
  background: #0d1118;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 7px 12px;
}

.profile-tab.active,
.profile-tab:hover,
.profile-tab:focus-visible {
  background: rgba(255, 209, 102, 0.13);
  border-color: rgba(255, 209, 102, 0.55);
  color: var(--accent);
}

.profile-tab-content {
  min-height: 360px;
  max-height: min(620px, 58vh);
  overflow: auto;
  padding-inline-end: 4px;
}

.profile-list {
  display: grid;
  gap: 8px;
}

.profile-entry {
  background: rgba(13, 17, 24, 0.9);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: #cdd5e0;
  padding: 10px 12px;
}

.profile-row-entry,
.material-entry {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.profile-row-entry > :first-child,
.material-entry > :first-child {
  flex: 1 1 auto;
  min-width: 0;
}

.profile-row-entry > b {
  flex: 0 0 auto;
  text-align: end;
  white-space: nowrap;
}

.profile-entry h3 {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0.04em;
}

.profile-entry p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.achievement-entry {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 12px;
}

.achievement-entry.locked {
  opacity: 0.62;
}

.profile-check {
  color: var(--accent);
  margin-inline-end: 6px;
}

.profile-progress-label {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.profile-progress {
  grid-column: 1 / -1;
  height: 6px;
  overflow: hidden;
  background: #111722;
  border: 1px solid #1d2330;
  border-radius: 999px;
}

.profile-progress span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.profile-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.profile-stat {
  background: rgba(13, 17, 24, 0.9);
  border: 1px solid var(--border);
  border-radius: 9px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 8px;
  align-items: center;
  padding: 12px;
}

.profile-stat span {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.12em;
  min-width: 0;
  overflow-wrap: anywhere;
  text-transform: uppercase;
}

.profile-stat b {
  color: var(--ink);
  font-size: 18px;
  text-align: end;
  white-space: nowrap;
}

.kind-badge,
.perfect-cast {
  display: inline-block;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 7px;
}

.kind-badge {
  background: rgba(132, 225, 188, 0.12);
  border: 1px solid rgba(132, 225, 188, 0.35);
  color: var(--accent-2);
}

.kind-math {
  background: rgba(76, 201, 240, 0.12);
  border-color: rgba(76, 201, 240, 0.35);
  color: #a2e9ff;
}

.kind-compound {
  background: rgba(192, 132, 255, 0.12);
  border-color: rgba(192, 132, 255, 0.35);
  color: #c084ff;
}

.perfect-cast {
  margin-inline-start: 6px;
  background: rgba(255, 209, 102, 0.12);
  border: 1px solid rgba(255, 209, 102, 0.45);
  color: var(--accent);
}

.profile-material-counts {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  min-width: 130px;
  text-align: end;
  white-space: nowrap;
}

.profile-material-counts b {
  color: var(--ink);
}

.profile-empty {
  display: grid;
  min-height: 260px;
  place-items: center;
  color: #586478;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: rgba(13, 17, 24, 0.55);
}

body.high-contrast #profile-overlay {
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: none;
}

body.high-contrast .profile-card {
  border-color: #bcd2ff;
  box-shadow: 0 0 0 2px #000, 0 0 0 3px #bcd2ff;
}

.lbl {
  color: var(--muted);
  letter-spacing: 0.1em;
  font-size: var(--hud-label-font-size);
}

.bar {
  width: var(--hud-bar-width);
  height: var(--hud-bar-height);
  background: #1a2030;
  border: 1px solid rgba(230, 230, 230, 0.16);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.42);
}

#hp-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ef476f, #ff8fa3);
  transition: width 0.15s ease;
}

#mana-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #4cc9f0, #b5ffff);
  transition: width 0.15s ease;
}

/* Wand */
#wand {
  pointer-events: none;
  box-sizing: border-box;
  background: rgba(10, 13, 19, 0.88);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  align-self: center;
  width: min(1170px, 97vw);
  font-size: 14px;
  backdrop-filter: blur(6px);
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
}

#wand.closed {
  opacity: 0;
  transform: scale(0.96);
  visibility: hidden;
  pointer-events: none;
}

#wand.open {
  opacity: 1;
  transform: scale(1);
  visibility: visible;
  pointer-events: auto;
}

#wand.closing {
  opacity: 0;
  transform: scale(0.96);
}

#wand.cast-error {
  animation: wand-cast-error 520ms ease-out both;
  will-change: transform;
}

#wand.cast-ok {
  animation: wand-cast-ok 520ms ease-out both;
}

#wand.validation-shake {
  animation: wand-validation-shake 420ms ease-out both;
  will-change: transform;
}

body.large-hud #wand {
  font-size: 16px;
  width: min(1290px, 98vw);
}

#wand-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

#wand-mode {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.15em;
  font-size: 12px;
  background: #1a2030;
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 4px;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  margin-inline-start: auto;
}

/* Wand slots */
#wand-slots {
  position: relative;
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: center;
  min-height: 42px;
}

.slot {
  width: 30px;
  height: 38px;
  border: 1px dashed #2a3142;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #2a3142;
  background: #0a0d14;
  letter-spacing: 0;
  transition: transform 80ms ease-out, box-shadow 80ms ease-out, border-color 80ms ease-out;
}

body.large-hud .slot {
  width: 34px;
  height: 42px;
  font-size: 22px;
}

.slot.filled {
  border-style: solid;
  background: #11161f;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.05) inset;
}

.slot[data-invalid="true"] {
  color: var(--danger) !important;
  border-color: var(--danger) !important;
  background: rgba(239, 71, 111, 0.12);
  box-shadow: 0 0 10px rgba(239, 71, 111, 0.22) inset;
}

.slot-empty-nudge {
  color: rgba(255, 209, 102, 0.32);
  border-color: rgba(255, 209, 102, 0.32);
  background: rgba(255, 209, 102, 0.04);
}

.empty-state {
  border: 1px dashed rgba(132, 225, 188, 0.45);
  border-radius: 8px;
  background: rgba(13, 17, 24, 0.78);
  color: #d7ffe9;
  box-shadow: inset 0 0 18px rgba(132, 225, 188, 0.04);
}

.wand-empty-state {
  position: absolute;
  left: 50%; /* stylelint-disable-line csstools/use-logical -- rtl-skip: physical centering coordinate pairs with translateX */
  top: 50%;
  z-index: 1;
  width: min(300px, 78%);
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  color: #fff3bf;
  border-color: rgba(255, 209, 102, 0.55);
  background: rgba(47, 35, 8, 0.72);
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
  transform: translate(-50%, -50%);
}

.first-cast-spell-hint {
  margin-block-start: 8px;
  padding: 10px;
  border: 1px solid rgba(127, 214, 245, 0.24);
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(8, 28, 42, 0.82), rgba(26, 20, 47, 0.72));
  color: #d9f7ff;
  box-shadow: inset 0 0 18px rgba(127, 214, 245, 0.06);
}

.first-cast-spell-hint.hidden {
  display: none;
}

.first-cast-spell-hint__eyebrow {
  margin-block-end: 3px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.first-cast-spell-hint__title {
  margin-block-end: 8px;
  color: #fff3bf;
  font-size: 12px;
}

.first-cast-spell-hint__examples {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.first-cast-spell-hint__example {
  appearance: none;
  display: grid;
  gap: 4px;
  min-block-size: 44px;
  padding: 7px 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(5, 8, 13, 0.46);
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  line-height: 1.25;
  text-align: start;
  touch-action: manipulation;
}

.first-cast-spell-hint__example code {
  color: #fff3bf;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.first-cast-spell-hint__example:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.last-cast-recall-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-block-start: 5px;
  border: 1px solid rgba(127, 214, 245, 0.32);
  border-radius: 999px;
  background: rgba(8, 28, 42, 0.54);
  color: rgba(213, 251, 255, 0.72);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  touch-action: manipulation;
}

.last-cast-recall-hint.hidden {
  display: none;
}

.juice-hover {
  transform: scale(1.04);
  box-shadow: 0 0 12px rgba(255, 209, 102, 0.36), 0 0 8px rgba(255, 255, 255, 0.08) inset;
  will-change: transform;
}

#wand-slots.cast-echo {
  animation: cast-echo-pulse 320ms ease-out both;
  will-change: transform;
}

.mobile-spell-input-row {
  display: none;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

#spell-suggestions {
  display: none;
  overflow-x: auto;
  gap: 6px;
  padding: 4px 8px;
  min-height: 40px;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

.mobile-spell-input {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid rgba(127, 214, 245, 0.45);
  border-radius: 8px;
  background: rgba(5, 8, 13, 0.96);
  color: var(--ink);
  font: 700 16px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.05em;
}

.mobile-spell-input:focus {
  border-color: #7fd6f5;
  outline: 2px solid rgba(127, 214, 245, 0.28);
}

.mobile-composer-help {
  display: none;
}

body[data-layout=mobile] #wand.open .mobile-spell-input-row,
#wand.open.touch-spell-input .mobile-spell-input-row {
  display: flex;
}

body[data-layout=mobile] #wand.open #spell-suggestions.has-suggestions,
#wand.open.touch-spell-input #spell-suggestions.has-suggestions {
  display: flex;
}

.suggestion-chip {
  flex: 0 0 auto;
  border-color: rgba(127, 214, 245, 0.5);
  background: rgba(8, 28, 42, 0.88);
  color: #d5fbff;
  cursor: pointer;
  font: 700 12px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.06em;
}

.starter-suggestion-chip {
  border-color: rgba(255, 209, 102, 0.62);
  background: linear-gradient(180deg, rgba(79, 54, 13, 0.9), rgba(34, 25, 10, 0.92));
  color: #fff3bf;
}

#spell-history-toggle,
#spell-history-drawer {
  display: none;
}

#wand-share-btn,
#wand-mobile-done-btn,
#spell-history-share-btn {
  display: none;
}

#spell-history-toggle {
  position: fixed;
  inset-inline-start: 50%;
  inset-block-end: calc(35dvh + 14px + env(safe-area-inset-bottom));
  z-index: 81;
  inline-size: var(--touch-target-min);
  block-size: var(--touch-target-min);
  border: 1px solid rgba(255, 209, 102, 0.55);
  border-radius: 999px;
  background: rgba(10, 14, 22, 0.9);
  color: #fff2c4;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.42), 0 0 14px rgba(255, 209, 102, 0.16);
  font: 700 18px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  pointer-events: auto;
  transform: translateX(-50%);
  touch-action: manipulation;
}

body[data-layout=mobile]:has(#wand.open) #spell-history-toggle {
  display: none;
}

#spell-history-drawer {
  position: fixed;
  inset-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right));
  inset-block-end: max(8px, env(safe-area-inset-bottom));
  z-index: 80;
  max-block-size: min(48dvh, 360px);
  padding: 10px;
  overflow: hidden auto;
  border: 1px solid rgba(127, 214, 245, 0.38);
  border-radius: 18px 18px 14px 14px;
  background: linear-gradient(180deg, rgba(16, 22, 32, 0.98), rgba(6, 9, 15, 0.96));
  box-shadow: 0 -18px 42px rgba(0, 0, 0, 0.55), 0 0 22px rgba(127, 214, 245, 0.12);
  pointer-events: auto;
  transform: translateY(calc(100% + 18px));
  transition: transform 180ms ease;
  touch-action: pan-y;
  will-change: transform;
}

#spell-history-drawer.is-open {
  transform: translateY(0);
}

.spell-history-drawer__handle {
  inline-size: 52px;
  block-size: 4px;
  margin: 0 auto 8px;
  border-radius: 999px;
  background: rgba(230, 230, 230, 0.32);
}

.spell-history-drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-block-end: 8px;
}

.spell-history-drawer__actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.spell-history-drawer__eyebrow,
.spell-history-section__title {
  color: var(--muted);
  font: 700 10px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.spell-history-drawer__title {
  margin-block-start: 2px;
  color: var(--ink);
  font: 700 14px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.spell-history-section {
  display: grid;
  gap: 6px;
  margin-block-start: 8px;
}

.spell-history-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--touch-target-min);
  gap: 6px;
  align-items: center;
}

.spell-history-entry__pattern,
.spell-history-entry__favourite,
#spell-history-share-btn,
#spell-history-close {
  min-inline-size: var(--touch-target-min);
  min-block-size: var(--touch-target-min);
  border: 1px solid rgba(127, 214, 245, 0.38);
  border-radius: 10px;
  background: rgba(8, 12, 18, 0.86);
  color: var(--ink);
  font: 700 13px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.spell-history-entry__pattern {
  overflow: hidden;
  padding-inline: 10px;
  text-align: start;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spell-history-entry__favourite {
  color: var(--accent);
  font-size: 18px;
}

#spell-history-share-btn {
  color: #d5fbff;
  border-color: rgba(132, 225, 188, 0.5);
  background: rgba(31, 111, 74, 0.68);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

@media (max-width: 600px) {
  body[data-layout="mobile"] #wand-share-btn,
  body[data-layout="mobile"] #spell-history-share-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

.spell-history-entry__favourite[aria-pressed="true"] {
  border-color: rgba(255, 209, 102, 0.75);
  background: rgba(80, 55, 10, 0.82);
}

.spell-history-empty {
  padding: 8px 10px;
  border: 1px dashed rgba(154, 163, 178, 0.28);
  border-radius: 10px;
  color: var(--muted);
  font: 12px/1.35 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (pointer: fine), (min-width: 768px) {
  #spell-suggestions,
  body[data-layout=mobile] #wand.open #spell-suggestions.has-suggestions,
  #wand.open.touch-spell-input #spell-suggestions.has-suggestions {
    display: none;
    min-height: 0;
    padding-block: 0;
  }
}

/* Cast-delay / recharge bar */
#cooldown-track {
  height: 3px;
  margin-top: 6px;
  background: #11161f;
  border-radius: 2px;
  overflow: hidden;
}
#wand-cooldown-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffd166, #ef476f);
  transition: width 0.05s linear;
}

#spell-feedback {
  margin-top: 4px;
  min-height: 16px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

#wand-error {
  margin-top: 4px;
  min-height: 14px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

#wand-error.hidden {
  display: none;
}

#spell-feedback.ok {
  color: var(--accent-2);
}

#spell-feedback.bad {
  color: var(--danger);
}

.spell-details {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(42, 49, 66, 0.9);
  border-radius: 8px;
  background: rgba(5, 8, 13, 0.72);
  color: #cdd5e0;
  text-align: start;
}

.spell-details.is-empty {
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
}

.spell-details__title {
  margin-bottom: 6px;
  color: var(--accent);
  font: 700 11px/1.3 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spell-details__layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
}

.spell-details__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  min-width: 0;
}

.spell-details__materials {
  display: grid;
  min-width: 0;
}

.spell-details__item {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.spell-details__item span {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.spell-details__item b {
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spell-details__item--materials b {
  white-space: normal;
  overflow-wrap: anywhere;
}

.wand-mobile-actions {
  display: none;
}

@media (max-width: 600px) {
  body[data-layout="mobile"] .wand-mobile-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(calc(var(--touch-target-min) * 1.35), 1.35fr) repeat(2, minmax(var(--touch-target-min), 1fr));
    gap: 6px;
  }

  body[data-layout="mobile"] .wand-mobile-actions button {
    overflow: hidden;
    padding-inline: 8px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.spell-category-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.4em;
  margin-inline-end: 4px;
  padding: 1px 5px;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: rgba(13, 17, 24, 0.78);
  font-size: var(--wand-token-font-size);
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.3;
  vertical-align: 1px;
}

.spell-category-chip--elemental {
  color: #7fd6f5;
}

.spell-category-chip--arcane {
  color: #c084fc;
}

.spell-category-chip--physical {
  color: #ffb86b;
}

.spell-category-chip--nature {
  color: #84e1bc;
}

.spell-category-chip--support {
  color: #a2e9ff;
}

.spell-category-chip--summon {
  color: #caa365;
}

.spell-category-chip--chemistry_equation {
  color: #9aff5a;
}

.daily-badge,
.daily-seed-pill {
  border: 1px solid rgba(255, 209, 102, 0.55);
  background: rgba(31, 111, 74, 0.78);
  color: #f2d481;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 5px 9px;
}

.daily-seed-pill {
  background: rgba(13, 17, 24, 0.88);
  color: #84e1bc;
}

.daily-result-panel {
  background: rgba(13, 17, 24, 0.9);
  border: 1px solid rgba(132, 225, 188, 0.42);
  border-radius: 8px;
  color: #cdd5e0;
  margin: 10px 0;
  padding: 10px;
  text-align: start;
}

.daily-result-title {
  color: #84e1bc;
  font-size: 10px;
  letter-spacing: 0.15em;
  margin-bottom: 6px;
  text-transform: uppercase;
}

/* Inventory */
#inventory-row {
  margin-top: 8px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

#inventory-row .lbl {
  margin-top: 4px;
}

#inventory {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  background: #0d1118;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  min-width: 24px;
  justify-content: center;
  transition: transform 80ms ease-out, box-shadow 80ms ease-out, border-color 80ms ease-out;
}

.chip.depleted {
  opacity: 0.35;
}

.chip-tok {
  font-weight: 700;
  font-size: 13px;
}

.inv-empty {
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
}

.inventory-rail {
  position: absolute;
  top: 118px;
  bottom: 158px;
  width: 104px;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  overflow: hidden;
  background: rgba(6, 9, 14, 0.56);
  border: 1px solid rgba(42, 49, 66, 0.82);
  border-radius: 8px;
  backdrop-filter: blur(4px);
}

.inventory-rail-left {
  inset-inline-start: 12px;
}

.inventory-rail-right {
  inset-inline-end: 12px;
}

.inventory-rail-title {
  display: none;
}

.inventory-rail-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow: hidden auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}

.inventory-rail .chip {
  width: 100%;
  min-width: 0;
  padding: 3px 5px;
  background: rgba(13, 17, 24, 0.9);
}

.inventory-rail .chip-tok {
  font-size: 14px;
}

.inventory-rail .inv-empty {
  display: block;
  width: 100%;
  padding: 7px 8px;
  color: #d7ffe9;
  font-size: 12px;
  line-height: 1.3;
}

@keyframes empty-state-pulse {
  0%, 100% { opacity: 0.45; transform: scale(0.82); }
  50% { opacity: 1; transform: scale(1.08); }
}

/* Overlay */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 8, 0.85);
  display: none;
  place-items: center;
  z-index: 10;
  backdrop-filter: blur(4px);
}

.win-screen {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 50% 35%, rgba(196, 154, 44, 0.22), transparent 38%),
    rgba(4, 4, 7, 0.92);
  display: none;
  place-items: center;
  z-index: 12;
  backdrop-filter: blur(5px);
}

body.high-contrast .modal,
body.high-contrast #overlay,
body.high-contrast .win-screen,
body.high-contrast .reward-overlay {
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: none;
}

#overlay.show {
  display: grid;
}

#overlay.title-overlay.show {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 100dvh;
  padding: max(14px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
}

#overlay.world-loading-overlay.show {
  display: grid;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 44%, rgba(132, 225, 188, 0.16), transparent 28%),
    radial-gradient(circle at 30% 70%, rgba(192, 132, 255, 0.12), transparent 24%),
    #030407;
  backdrop-filter: blur(2px);
}

.win-screen.show {
  display: grid;
}

.demo-upsell-overlay {
  z-index: 45;
  background:
    radial-gradient(circle at 50% 35%, rgba(255, 209, 102, 0.18), transparent 36%),
    rgba(4, 4, 7, 0.9);
}

.demo-upsell-panel {
  border-color: rgba(255, 209, 102, 0.45);
}

.demo-upsell-panel .modal-header h2 {
  color: var(--accent);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 32px;
  width: min(720px, 92vw);
  text-align: center;
  max-block-size: 92dvh;
  overflow: auto;
  transform-origin: center top;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

#tutorial-overlay,
#overlay.show .panel:has(#pause-root) {
  opacity: 1;
  transform: scale(1);
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
}

#pause-root {
  transition: opacity 180ms ease, transform 180ms ease;
}

#tutorial-overlay.closing,
#pause-root.closing,
#overlay.show .panel:has(#pause-root.closing),
#overlay.show .panel:has(#pause-root[data-swipe-closing="true"]) {
  opacity: 0;
  transform: scale(0.96);
}

.title-panel {
  width: min(720px, calc(100vw - 24px));
  padding: clamp(18px, 3vw, 28px) clamp(16px, 4vw, 32px);
}

body[data-layout="mobile"] .mobile-install-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin: 10px 0 2px;
  padding: 9px 10px;
  border: 1px solid rgba(132, 225, 188, 0.34);
  border-radius: 10px;
  background: rgba(13, 17, 24, 0.72);
  color: #cdd5e0;
  font-size: 12px;
  line-height: 1.35;
}

body[data-layout="mobile"] .mobile-install-hint b {
  color: #d5fbff;
}

body[data-layout="mobile"] .mobile-install-hint span {
  color: var(--muted);
}

body[data-layout="mobile"] .mobile-install-hint .pwa-install-cta {
  margin-inline-start: 0;
}

body[data-layout="mobile"] .mobile-start-cta-hint {
  display: grid;
  gap: 6px;
  margin: 8px 0 4px;
  padding: 8px;
  border: 1px solid rgba(255, 209, 102, 0.42);
  border-radius: 10px;
  background: rgba(35, 26, 7, 0.76);
  color: #f5ead0;
  font-size: 12px;
  line-height: 1.35;
  text-align: left;
}

body[data-layout="mobile"][data-orientation="portrait"] #overlay.title-overlay.show {
  padding-block-end: max(96px, calc(72px + env(safe-area-inset-bottom)));
}

body[data-layout="mobile"][data-orientation="portrait"] #overlay.title-overlay.show .title-panel {
  padding-block-end: max(104px, calc(86px + env(safe-area-inset-bottom)));
}

body[data-layout="mobile"][data-orientation="portrait"] #overlay.title-overlay.show .title-actions {
  margin-block: 8px;
}

body[data-layout="mobile"][data-orientation="portrait"] #overlay.title-overlay.show .title-actions #start-btn {
  position: fixed;
  inset-inline: max(18px, env(safe-area-inset-left)) max(18px, env(safe-area-inset-right));
  inset-block-end: max(18px, env(safe-area-inset-bottom));
  z-index: 13;
  min-block-size: 58px;
  padding: 14px 18px;
  border: 1px solid rgba(255, 231, 150, 0.78);
  border-radius: 16px;
  background: linear-gradient(180deg, #ffe08a, #ffd166);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 209, 102, 0.18);
  font-size: 16px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

body[data-layout="mobile"] .mobile-start-cta-hint b {
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

body[data-layout="mobile"] .mobile-start-cta-hint__header {
  display: grid;
  gap: 2px;
}

body[data-layout="mobile"] .mobile-start-cta-hint__header span,
body[data-layout="mobile"] .mobile-start-cta-hint__escape {
  color: #f5ead0;
}

body[data-layout="mobile"] .mobile-start-cta-hint__steps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

body[data-layout="mobile"] .mobile-start-cta-hint__steps li {
  display: grid;
  gap: 1px;
  min-block-size: 40px;
  align-content: center;
  padding: 5px 6px;
  border: 1px solid rgba(255, 209, 102, 0.24);
  border-radius: 9px;
  background: rgba(8, 11, 17, 0.54);
}

body[data-layout="mobile"] .mobile-start-cta-hint__steps span {
  color: #fff7dc;
  font-size: 10px;
  line-height: 1.2;
}

body[data-layout="mobile"] .mobile-start-cta-hint__escape {
  margin: 0;
  padding: 6px 8px;
  border: 1px solid rgba(132, 225, 188, 0.3);
  border-radius: 9px;
  background: rgba(12, 39, 32, 0.58);
}

.spellbook-panel {
  width: min(1320px, calc(100vw - 24px));
  max-block-size: min(92dvh, 980px);
  overflow: auto;
}

.world-loading-panel {
  position: relative;
  width: min(520px, calc(100vw - 32px));
  min-height: 310px;
  display: grid;
  place-items: center;
  gap: 10px;
  overflow: hidden;
  background:
    linear-gradient(rgba(13, 17, 24, 0.86), rgba(13, 17, 24, 0.94)),
    repeating-linear-gradient(135deg, rgba(132, 225, 188, 0.08) 0 2px, transparent 2px 10px);
  border-color: rgba(132, 225, 188, 0.32);
}

.world-loading-panel::before {
  content: "";
  position: absolute;
  inset: -45%;
  background:
    conic-gradient(from 0deg, transparent, rgba(132, 225, 188, 0.18), transparent, rgba(192, 132, 255, 0.16), transparent),
    repeating-radial-gradient(circle, rgba(255, 209, 102, 0.08) 0 1px, transparent 1px 11px);
  animation: world-loading-shader 2.6s linear infinite;
  opacity: 0.9;
}

.world-loading-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 0 45%, rgba(213, 251, 255, 0.08) 50%, transparent 56%);
  animation: world-loading-scan 1.4s ease-in-out infinite;
  mix-blend-mode: screen;
}

.world-loading-panel h1,
.world-loading-panel .tag,
.world-loading-bar,
.world-loading-vortex {
  position: relative;
  z-index: 1;
}

.world-loading-panel h1 {
  margin: 0;
  color: #d5fbff;
  font-size: clamp(24px, 5vw, 38px);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-shadow: 0 0 18px rgba(132, 225, 188, 0.55), 0 2px 8px #000;
}

.world-loading-vortex {
  width: 132px;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle, #030407 0 18%, rgba(132, 225, 188, 0.22) 19% 21%, transparent 22%),
    conic-gradient(from 90deg, #84e1bc, #c084ff, #ffd166, #84e1bc);
  box-shadow: 0 0 36px rgba(132, 225, 188, 0.35), inset 0 0 24px #030407;
  animation: world-loading-orbit 1.8s linear infinite;
}

.world-loading-vortex span {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffd166;
  box-shadow: 0 0 14px #ffd166;
}

.world-loading-vortex span:nth-child(1) { transform: translate(42px, -20px); }
.world-loading-vortex span:nth-child(2) { transform: translate(-36px, 24px); background: #84e1bc; box-shadow: 0 0 14px #84e1bc; }
.world-loading-vortex span:nth-child(3) { transform: translate(4px, 46px); background: #c084ff; box-shadow: 0 0 14px #c084ff; }

.world-loading-bar {
  width: min(300px, 76vw);
  height: 8px;
  overflow: hidden;
  border: 1px solid rgba(132, 225, 188, 0.45);
  border-radius: 999px;
  background: rgba(3, 4, 7, 0.72);
}

.world-loading-bar span {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, #84e1bc, #ffd166, transparent);
  animation: world-loading-bar 1s ease-in-out infinite;
}

body.high-contrast .panel,
body.high-contrast .modal-panel {
  border-color: #bcd2ff;
  box-shadow: 0 0 0 2px #000, 0 0 0 3px #bcd2ff;
}

.panel h1 {
  margin: 0 0 6px;
  letter-spacing: 0.3em;
  font-size: 36px;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(255, 209, 102, 0.3);
}

.title-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 12px 0 10px;
}

.title-actions button,
.title-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
  margin: 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--ink);
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-decoration: none;
}

.title-actions #start-btn {
  min-inline-size: 7.5rem;
  margin-top: 0;
}

.title-actions a,
#title-profile-btn,
#title-settings-btn,
#title-mods-btn {
  background: #243044;
  color: #f7fbff;
  border: 1px solid #3c4a62;
}

#sandbox-btn {
  background: #146c43;
  color: #ffffff;
  border: 1px solid #2d9864;
}

.title-mp-panel {
  margin: 12px 0;
  padding: 12px;
  border: 1px solid rgba(58, 79, 115, 0.85);
  border-radius: 12px;
  background: rgba(8, 13, 23, 0.66);
  text-align: start;
}

.title-identity-panel {
  margin: 12px 0;
  padding: 10px 12px;
  border: 1px solid rgba(45, 152, 100, 0.55);
  border-radius: 12px;
  background: rgba(10, 32, 24, 0.42);
  text-align: start;
}

.title-identity-panel label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.title-identity-panel input {
  min-height: 36px;
  border: 1px solid #2d9864;
  border-radius: 8px;
  background: rgba(7, 11, 18, 0.9);
  color: var(--ink);
  font: 700 13px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  padding: 8px 10px;
}

.title-mp-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.title-mp-header h3 {
  margin: 0 0 4px;
}

.alpha-tag {
  display: inline-grid;
  place-items: center;
  margin-inline-start: 0.45em;
  padding: 0.22em 0.5em;
  border: 1px solid rgba(255, 209, 102, 0.75);
  border-radius: 999px;
  background: rgba(255, 209, 102, 0.14);
  color: #ffd166;
  font: 900 0.52em/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  vertical-align: 0.16em;
}

.title-mp-header p,
.title-mp-status {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.mp-status-pill {
  padding: 4px 8px;
  border: 1px solid #3c4a62;
  border-radius: 999px;
  background: #182235;
  color: #cdd5e0;
  font: 800 10px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mp-status-pill[data-status="connected"] {
  border-color: #2d9864;
  background: rgba(20, 108, 67, 0.35);
  color: #9ef2c4;
}

.mp-status-pill[data-status="connecting"] {
  border-color: #c084fc;
  color: #e9d5ff;
}

.mp-status-pill[data-status="error"] {
  border-color: var(--danger);
  color: #fecdd3;
}

.title-mp-grid {
  display: grid;
  grid-template-columns: minmax(16rem, 2fr) minmax(10rem, 1fr);
  gap: 8px;
  margin-block: 10px;
}

.title-mp-grid label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.title-mp-grid input {
  min-height: 36px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: rgba(7, 11, 18, 0.9);
  color: var(--ink);
  font: 600 12px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  padding: 8px 10px;
}

.title-mp-help {
  color: var(--muted);
  font: 600 10px/1.35 system-ui, -apple-system, Segoe UI, sans-serif;
  letter-spacing: 0;
  text-transform: none;
}

.title-mp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-block-end: 8px;
}

.title-mp-actions button {
  min-height: var(--touch-target-min);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: inherit;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.title-mp-actions button.secondary {
  background: #243044;
  color: #f7fbff;
  border: 1px solid #3c4a62;
}

@media (max-width: 720px) {
  .title-mp-grid {
    grid-template-columns: 1fr;
  }
}

.win-panel {
  border-color: #c49a2c;
  background: linear-gradient(180deg, #17130b 0%, #0d0f14 100%);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.72), 0 0 40px rgba(196, 154, 44, 0.18);
}

.win-panel h1 {
  color: #c49a2c;
  text-shadow: 0 0 24px rgba(196, 154, 44, 0.45);
}

.win-eyebrow {
  margin-bottom: 8px;
  color: var(--accent-2);
  font: 800 11px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.win-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.win-actions button {
  min-height: var(--touch-target-min);
  padding: 10px 16px;
  border: 1px solid rgba(196, 154, 44, 0.55);
  border-radius: 9px;
  background: #c49a2c;
  color: #0b0d12;
  font-family: inherit;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.win-actions button.secondary {
  background: #243044;
  color: #f7fbff;
  border-color: #3c4a62;
}

.win-actions button:hover,
.win-actions button:focus-visible {
  filter: brightness(1.15);
  outline: 2px solid #fff3b0;
  outline-offset: 2px;
}

.reward-overlay {
  position: fixed;
  inset: 0;
  z-index: 46;
  display: none;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 36%, rgba(255, 209, 102, 0.22), transparent 34%),
    radial-gradient(circle at 50% 52%, rgba(132, 225, 188, 0.13), transparent 42%),
    rgba(4, 4, 7, 0.9);
  backdrop-filter: blur(5px);
}

.reward-overlay.show {
  display: grid;
}

.reward-panel {
  position: relative;
  width: min(560px, 92vw);
  padding: 26px 28px;
  overflow: hidden;
  text-align: center;
  background: linear-gradient(180deg, #17130b 0%, #0d1118 100%);
  border: 1px solid rgba(255, 209, 102, 0.55);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.72), 0 0 44px rgba(255, 209, 102, 0.18);
}

.reward-burst {
  color: var(--accent);
  font: 800 26px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.42em;
  text-shadow: 0 0 18px rgba(255, 209, 102, 0.72);
  animation: reward-burst-pop 700ms ease-out both;
  will-change: transform, opacity;
}

.reward-eyebrow {
  margin-top: 8px;
  color: var(--accent-2);
  font: 800 11px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.reward-panel h1 {
  margin: 8px 0 6px;
  color: var(--accent);
  font-size: clamp(30px, 6vw, 48px);
  letter-spacing: 0.08em;
  text-shadow: 0 0 26px rgba(255, 209, 102, 0.4);
}

.reward-summary {
  margin: 0 auto 14px;
  max-width: 38em;
  color: #cdd5e0;
  line-height: 1.45;
}

.reward-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 16px 0 18px;
  text-align: start;
}

.reward-stats div {
  padding: 10px;
  background: rgba(13, 17, 24, 0.88);
  border: 1px solid rgba(255, 209, 102, 0.32);
  border-radius: 9px;
}

.reward-stats span {
  display: block;
  color: #9aa3b2;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.reward-stats b {
  display: block;
  margin-top: 4px;
  color: #f2d481;
  font-size: 20px;
}

.reward-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.reward-actions button {
  min-height: var(--touch-target-min);
  padding: 10px 16px;
  border: 1px solid rgba(255, 209, 102, 0.55);
  border-radius: 9px;
  background: #c49a2c;
  color: #0b0d12;
  font-family: inherit;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.reward-actions button.secondary {
  background: #243044;
  color: #f7fbff;
  border-color: #3c4a62;
}

.reward-actions button:hover,
.reward-actions button:focus-visible {
  filter: brightness(1.15);
  outline: 2px solid #fff3b0;
  outline-offset: 2px;
}

@keyframes reward-burst-pop {
  0% {
    opacity: 0;
    transform: scale(0.65);
  }
  55% {
    opacity: 1;
    transform: scale(1.16);
  }
  100% {
    opacity: 0.92;
    transform: scale(1);
  }
}

.win-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 16px;
  text-align: start;
}

.win-stats div {
  background: rgba(13, 17, 24, 0.88);
  border: 1px solid rgba(196, 154, 44, 0.35);
  border-radius: 8px;
  padding: 9px 10px;
}

.win-stats span {
  display: block;
  color: #9aa3b2;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.win-stats b {
  color: #f2d481;
}

.post-run-stats {
  margin-bottom: 10px;
}

.settings-section-h {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-2, #84d3ff);
  margin: 14px 0 6px;
  border-bottom: 1px solid rgba(132, 211, 255, 0.18);
  padding-bottom: 4px;
}
.settings-section-h:first-of-type {
  margin-top: 4px;
}

.post-run-report-panel {
  margin-bottom: 10px;
}

.post-run-recovery {
  margin: 10px 0;
  padding: 10px;
  border: 1px solid rgba(132, 225, 188, 0.34);
  border-radius: 10px;
  background: rgba(13, 17, 24, 0.82);
}

.post-run-recovery-title {
  display: none;
  margin: 0 0 4px;
  color: #ffd166;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  line-height: 1.2;
  text-transform: uppercase;
}

.post-run-recovery-copy {
  margin: 0 0 8px;
  color: #cdd5e0;
  font-size: 12px;
  line-height: 1.4;
}

.post-run-recovery-action-hint {
  margin: 8px 0;
  padding: 5px 8px;
  border: 1px solid rgba(132, 225, 188, 0.34);
  border-radius: 999px;
  background: rgba(132, 225, 188, 0.08);
  color: #d8ffef;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.2;
  text-align: center;
}

.post-run-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.post-run-actions button#quick-restart-btn,
.post-run-actions .post-run-secondary-action {
  margin: 0;
}

.post-run-secondary-action {
  min-inline-size: var(--touch-target-min);
  min-block-size: var(--touch-target-min);
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  background: #2a3142;
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.08em;
}

.post-run-secondary-action:hover {
  filter: brightness(1.12);
}

.operator-log-panel {
  margin: 8px 0 10px;
}

.pause-mobile-recovery-copy {
  line-height: 1.45;
}

.pause-primary-actions,
.pause-secondary-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 10px 0;
}

.pause-resume-btn,
.pause-restart-btn,
.pause-secondary-actions button {
  min-inline-size: var(--touch-target-min);
  min-block-size: var(--touch-target-min);
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.pause-resume-btn {
  background: var(--accent);
  color: #1a1300;
}

.pause-restart-btn {
  background: #2a3142;
}

.pause-resume-btn:hover,
.pause-restart-btn:hover,
.pause-secondary-actions button:hover {
  filter: brightness(1.12);
}

body[data-layout=mobile] #overlay.show .panel:has(#resume-btn) {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  box-sizing: border-box;
  width: min(560px, calc(100vw - 24px));
  max-block-size: calc(100dvh - max(20px, env(safe-area-inset-top)) - max(20px, env(safe-area-inset-bottom)));
  padding: 18px 16px;
}

body[data-layout=mobile] #overlay.show:has(#resume-btn) {
  align-items: start;
  place-items: start center;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
}

body[data-layout=mobile] .pause-primary-actions {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  order: -1;
  margin: 0 0 10px;
  padding-block-end: 8px;
  background: linear-gradient(180deg, rgba(13, 17, 24, 0.98) 72%, rgba(13, 17, 24, 0));
}

body[data-layout=mobile] .pause-resume-btn {
  flex: 1 1 100%;
  min-block-size: calc(52px / var(--menu-ui-scale));
  padding-block: calc(12px / var(--menu-ui-scale));
  font-size: calc(15px / var(--menu-ui-scale));
}

body[data-layout=mobile] .pause-restart-btn {
  flex: 1 1 100%;
  min-block-size: calc(52px / var(--menu-ui-scale));
  padding-block: calc(12px / var(--menu-ui-scale));
  font-size: calc(15px / var(--menu-ui-scale));
}

body[data-layout=mobile] .pause-secondary-actions button {
  flex: 1 1 calc(50% - 6px);
}

.report-export-btn {
  margin-inline-start: 6px;
  background: #1f6f4a;
}

.report-export-btn:disabled {
  cursor: wait;
  filter: grayscale(0.4);
  opacity: 0.72;
}

.pause-checkpoint-actions {
  display: inline-flex;
  gap: 6px;
  margin: 10px 0 0 6px;
  vertical-align: middle;
}

.pause-checkpoint-actions button {
  background: #2a3142;
  border: none;
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 8px 12px;
}

.pause-checkpoint-actions #btn-save-checkpoint {
  background: #1f6f4a;
}

.pause-checkpoint-actions button.secondary {
  background: #2a3142;
  color: #cdd5e0;
}

.pause-checkpoint-actions button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.8);
  opacity: 0.45;
}

.pause-secondary-controls {
  margin-top: 10px;
  text-align: left;
}

.pause-secondary-controls summary {
  cursor: pointer;
  color: var(--accent-2);
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.pause-secondary-body {
  margin-top: 8px;
}

.post-run-detail {
  background: rgba(13, 17, 24, 0.88);
  border: 1px solid #2a3142;
  border-radius: 6px;
  color: #cdd5e0;
  margin: 6px 0;
  padding: 8px;
  text-align: start;
}

.post-run-detail-title {
  color: #9aa3b2;
  font-size: 10px;
  letter-spacing: 0.15em;
  margin-bottom: 5px;
  text-transform: uppercase;
}

.post-run-chip {
  display: inline-block;
  background: #111722;
  border: 1px solid #2a3142;
  border-radius: 999px;
  color: #cdd5e0;
  font-size: 11px;
  margin: 2px;
  padding: 2px 7px;
}

.win-achievement-banner {
  margin: -4px 0 14px;
  padding: 8px 10px;
  background: rgba(255, 209, 102, 0.12);
  border: 1px solid rgba(255, 209, 102, 0.45);
  border-radius: 8px;
  color: #f2d481;
  font-size: 12px;
}

.tag {
  color: var(--muted);
  margin-top: 0;
}

.cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  text-align: start;
  margin: 18px 0;
}

@media (max-width: 600px) {
  .cols {
    grid-template-columns: 1fr;
  }
}

.col {
  background: #0d1118;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}

.col h3 {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 13px;
  letter-spacing: 0.15em;
}

.col ul {
  margin: 0;
  padding-inline-start: 18px;
  font-size: 13px;
  color: var(--ink);
  line-height: 1.6;
}

.col code,
.col kbd {
  background: #1a2030;
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.difficulty-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 12px 0 8px;
  text-align: start;
}

.difficulty-picker h3 {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--accent-2);
  font-size: 12px;
  letter-spacing: 0.16em;
}

.difficulty-picker label {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 6px;
  align-items: start;
  background: #0d1118;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px;
  cursor: pointer;
  font-size: 11px;
}

.difficulty-picker input {
  margin-top: 2px;
}

.difficulty-picker span {
  grid-column: 2;
  color: var(--muted);
  font-size: 10px;
}

@media (max-width: 720px) {
  .difficulty-picker {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  #overlay.title-overlay.show {
    padding-block-start: max(12px, env(safe-area-inset-top));
  }

  .title-panel {
    padding: 16px 14px 18px;
  }

  .title-panel h1 {
    font-size: clamp(26px, 8vw, 32px);
    letter-spacing: 0.22em;
  }

  .title-panel .tag {
    margin-bottom: 0;
    font-size: 12px;
    line-height: 1.35;
  }

  .title-actions {
    margin: 10px 0 8px;
  }

  .title-actions button,
  .title-actions a {
    flex: 1 1 44%;
    padding: 9px 10px;
    font-size: 0.74rem;
    line-height: 1.15;
  }

  .title-actions #start-btn,
  .title-actions #sandbox-btn {
    flex-basis: calc(50% - 4px);
  }

  .title-panel .cols {
    gap: 8px;
    margin: 10px 0;
  }

  .title-panel .col {
    padding: 9px 10px;
  }

  .title-panel .col ul {
    font-size: 11px;
    line-height: 1.45;
  }

  .title-panel .difficulty-picker {
    margin-top: 8px;
  }
}

button#start-btn,
button#quick-restart-btn {
  pointer-events: auto;
  background: var(--accent);
  color: #1a1300;
  border: none;
  border-radius: 8px;
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.1em;
  cursor: pointer;
  margin-top: 6px;
  font-family: inherit;
}

button#start-btn:hover,
button#quick-restart-btn:hover {
  background: #ffe199;
}

.footer {
  color: var(--muted);
  font-size: 11px;
  margin-top: 12px;
}

body[data-layout=mobile] #hud,
body[data-layout=mobile] .hud {
  padding: 8px;
  font-size: var(--hud-font-size);
}

body[data-layout=mobile][data-orientation=portrait]:has(#wand.open) #hud {
  inset-block-end: auto;
  block-size: min(36dvh, 304px);
}

body[data-layout=mobile] #hud > .row,
body[data-layout=mobile] #stats,
body[data-layout=mobile] #wand-ui,
body[data-layout=mobile] #tutorial,
body[data-layout=mobile] #token-hint-row {
  gap: 6px;
  margin: 0;
}

body[data-layout=mobile] #hp-wrap,
body[data-layout=mobile] #mana-wrap,
body[data-layout=mobile] #score-wrap,
body[data-layout=mobile] #depth-wrap,
body[data-layout=mobile] #gold-wrap,
body[data-layout=mobile] #xp-wrap,
body[data-layout=mobile] #timer-wrap,
body[data-layout=mobile] #stats,
body[data-layout=mobile] #wand-ui,
body[data-layout=mobile] #tutorial,
body[data-layout=mobile] #token-hint-row {
  gap: 5px;
  padding: 5px 7px;
  margin: 0;
  font-size: var(--hud-font-size);
  line-height: 1.2;
}

body[data-layout=mobile] #debug-btn,
body[data-layout=mobile] #settings-btn,
body[data-layout=mobile] #audio-btn,
body[data-layout=mobile] #codex-btn,
body[data-layout=mobile] #combat-stats-btn,
body[data-layout=mobile] #letter-stats-btn,
body[data-layout=mobile] #perks-btn,
body[data-layout=mobile] #daily-hud-badge,
body[data-layout=mobile] button#start-btn,
body[data-layout=mobile] button#quick-restart-btn {
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
  padding: 4px 8px;
  font-size: var(--hud-font-size);
  line-height: 1.15;
}

body[data-layout=mobile] #overlay.show .panel:has(#quick-restart-btn) button#quick-restart-btn {
  min-inline-size: calc(44px / var(--menu-ui-scale));
  min-block-size: calc(44px / var(--menu-ui-scale));
  padding: calc(10px / var(--menu-ui-scale)) calc(16px / var(--menu-ui-scale));
  font-size: calc(14px / var(--menu-ui-scale));
}

body[data-layout=mobile] #overlay.show:has(#quick-restart-btn) {
  align-items: start;
  place-items: start center;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
}

body[data-layout=mobile] #overlay.show .panel:has(#quick-restart-btn) {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: min(560px, 100%);
  max-block-size: calc(100dvh - max(10px, env(safe-area-inset-top)) - max(10px, env(safe-area-inset-bottom)));
  padding: 16px 14px calc(166px / var(--menu-ui-scale));
}

body[data-layout=mobile] #overlay.show .panel:has(#quick-restart-btn) .post-run-recovery {
  position: fixed;
  inset-inline: max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-right));
  inset-block-end: max(10px, calc(env(safe-area-inset-bottom) + 8px));
  z-index: 60;
  box-sizing: border-box;
  width: min(560px, calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  margin: 0 auto;
  border-color: rgba(255, 209, 102, 0.44);
  background: rgba(9, 12, 18, 0.94);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.34);
}

body[data-layout=mobile] #overlay.show .panel:has(#quick-restart-btn) .post-run-recovery-copy {
  font-size: calc(13px / var(--menu-ui-scale));
}

body[data-layout=mobile] #overlay.show .panel:has(#quick-restart-btn) .post-run-recovery-title {
  display: block;
  font-size: calc(13px / var(--menu-ui-scale));
}

body[data-layout=mobile] #overlay.show .panel:has(#quick-restart-btn) .post-run-actions button#quick-restart-btn {
  flex: 1 1 100%;
  min-block-size: calc(56px / var(--menu-ui-scale));
  font-size: calc(16px / var(--menu-ui-scale));
}

body[data-layout=mobile] #overlay.show .panel:has(#quick-restart-btn) .post-run-actions .post-run-secondary-action {
  flex: 1 1 120px;
  min-block-size: calc(48px / var(--menu-ui-scale));
  padding: calc(10px / var(--menu-ui-scale)) calc(12px / var(--menu-ui-scale));
  font-size: calc(13px / var(--menu-ui-scale));
}

body[data-layout=mobile] .bar {
  width: var(--hud-mobile-bar-width);
  height: var(--hud-mobile-bar-height);
}

body[data-layout=mobile] #xp-wrap .bar {
  width: 44px !important;
}

body[data-layout=mobile] .lbl,
body[data-layout=mobile] .hint {
  font-size: var(--hud-label-font-size);
}

body[data-layout=mobile] #combat-stats,
body[data-layout=mobile] #heatmap-panel,
body[data-layout=mobile] #subtitle-overlay,
body[data-layout=mobile] #hud-status,
body[data-layout=mobile] #material-reticle-label {
  padding: 6px 8px;
  font-size: var(--hud-font-size);
  line-height: 1.3;
}

body[data-layout=mobile] #combat-stats {
  inset-inline-start: max(8px, env(safe-area-inset-left));
  inset-block-end: calc(max(8px, env(safe-area-inset-bottom)) + var(--touch-target-min) + 8px);
}

body[data-layout=mobile] #heatmap-panel {
  inset-inline-end: max(8px, env(safe-area-inset-right));
  inset-block-end: calc(max(8px, env(safe-area-inset-bottom)) + var(--touch-target-min) + 8px);
  max-width: min(270px, calc(100vw - 16px));
}

body[data-layout=mobile] #combat-stats-btn,
body[data-layout=mobile] #letter-stats-btn {
  bottom: max(8px, env(safe-area-inset-bottom));
}

body[data-layout=mobile] #combat-stats-btn {
  left: max(8px, env(safe-area-inset-left));
}

body[data-layout=mobile] #letter-stats-btn {
  right: max(8px, env(safe-area-inset-right));
}

body[data-layout=mobile] #wand {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(128px, 42%);
  gap: 4px 8px;
  align-items: center;
  width: min(640px, 94vw);
  padding: 8px 10px;
  font-size: var(--hud-font-size);
  max-height: min(40dvh, 340px);
  overflow: hidden auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

body[data-layout=mobile][data-orientation=portrait] #wand.open {
  padding-block-end: calc(8px + env(safe-area-inset-bottom));
  transform: none;
}

body[data-layout=mobile][data-orientation=portrait] #wand-header {
  order: 1;
}

body[data-layout=mobile][data-orientation=portrait] .mobile-spell-input-row {
  order: 2;
}

body[data-layout=mobile][data-orientation=portrait] .last-cast-recall-hint {
  order: 3;
}

body[data-layout=mobile][data-orientation=portrait] #wand-error {
  order: 4;
}

body[data-layout=mobile][data-orientation=portrait] .first-cast-spell-hint {
  order: 5;
}

body[data-layout=mobile][data-orientation=portrait] #wand-slots {
  order: 6;
}

body[data-layout=mobile][data-orientation=portrait] #spell-suggestions {
  order: 7;
}

body[data-layout=mobile][data-orientation=portrait] .mobile-composer-help {
  order: 8;
}

body[data-layout=mobile][data-orientation=portrait] #cooldown-track,
body[data-layout=mobile][data-orientation=portrait] #spell-feedback {
  order: 9;
}

body[data-layout=mobile][data-orientation=portrait] .spell-details {
  order: 10;
}

body[data-layout=mobile][data-orientation=portrait] .wand-mobile-actions {
  order: 20;
}

@media (max-height: 700px) and (orientation: portrait) {
  body[data-layout=mobile] #wand {
    max-height: min(330px, calc(52dvh - max(20px, env(safe-area-inset-bottom))));
  }
}

body[data-layout=mobile] #wand-header {
  grid-column: 1 / -1;
  gap: 6px;
  margin-bottom: 0;
}

body[data-layout=mobile] #input-hint {
  display: none;
}

body[data-layout=mobile] #wand-mode {
  padding: 2px 6px;
  font-size: var(--hud-font-size);
}

body[data-layout=mobile] #wand-mobile-done-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-inline-size: var(--touch-target-min);
  min-block-size: var(--touch-target-min);
  margin-inline-start: auto;
  padding-inline: 12px;
  border-color: rgba(127, 214, 245, 0.55);
  background: rgba(8, 28, 42, 0.88);
  color: #d7f4ff;
  font: 800 clamp(11px, 1.55dvh, 12px)/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  text-transform: uppercase;
}

body[data-layout=mobile] #wand-summon-name,
body[data-layout=mobile] #spell-feedback,
body[data-layout=mobile] .spell-details,
body[data-layout=mobile] #summoning,
body[data-layout=mobile] #summon-toast,
body[data-layout=mobile] .inv-empty,
body[data-layout=mobile] .chip {
  font-size: var(--hud-font-size);
}

body[data-layout=mobile] #wand-slots {
  grid-column: 1;
  gap: 4px;
}

body[data-layout=mobile] .first-cast-spell-hint {
  position: static;
  z-index: 2;
  grid-column: 1 / -1;
  margin-block-start: 0;
  max-block-size: min(110px, 20dvh);
  overflow: hidden auto;
  padding: 7px 8px;
  font-size: clamp(11px, 1.55dvh, 12px);
  overscroll-behavior: contain;
}

body[data-layout=mobile] .first-cast-spell-hint__eyebrow {
  font-size: 9px;
}

body[data-layout=mobile] .first-cast-spell-hint__title {
  margin-block-end: 6px;
  font-size: clamp(11px, 1.55dvh, 12px);
  line-height: 1.25;
}

body[data-layout=mobile] .first-cast-spell-hint__examples {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

body[data-layout=mobile] .first-cast-spell-hint__example {
  display: flex;
  align-items: center;
  justify-content: center;
  min-block-size: var(--touch-target-min);
  padding: 4px 6px;
  font-size: clamp(11px, 1.55dvh, 12px);
  line-height: 1.1;
  text-align: center;
}

body[data-layout=mobile] .first-cast-spell-hint__example > span {
  display: none;
}

body[data-layout=mobile] #wand:has(#wand-error:not(.hidden):not([hidden])) .first-cast-spell-hint {
  display: none;
}

body[data-layout=mobile] #wand-error {
  grid-column: 1 / -1;
  min-block-size: var(--touch-target-min);
  box-sizing: border-box;
  margin-top: 0;
  padding: 6px 8px;
  border: 1px solid rgba(239, 71, 111, 0.42);
  border-radius: 8px;
  background: rgba(45, 11, 22, 0.74);
  font-size: clamp(12px, 1.6dvh, 13px);
  line-height: 1.25;
}

body[data-layout=mobile] .slot {
  width: 24px;
  height: 30px;
  font-size: 1rem;
}

body[data-layout=mobile] #cooldown-track {
  grid-column: 1 / -1;
  height: 2px;
  margin-top: 0;
}

body[data-layout=mobile] #spell-feedback {
  grid-column: 1 / -1;
  min-height: 12px;
  margin-top: 0;
}

body[data-layout=mobile] .spell-details {
  grid-column: 1 / -1;
  margin-top: 0;
  padding: 6px 8px;
}

body[data-layout=mobile] .spell-details__grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

body[data-layout=mobile] .spell-details__layout {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

body[data-layout=mobile] #inventory-row {
  gap: 5px;
  margin-top: 4px;
  padding-top: 4px;
}

body[data-layout=mobile] #inventory {
  gap: 3px;
}

body[data-layout=mobile] .chip {
  min-width: 20px;
  padding: 2px 5px;
}

@media (pointer: coarse) {
  #hud button,
  #wand button,
  #wand input,
  .modal-panel button,
  .modal-panel select,
  .modal-panel input,
  .modal-header .x,
  #overlay button,
  .title-actions button,
  .title-actions a,
  .difficulty-picker label,
  .pause-checkpoint-actions button,
  .tutorial-nudge__dismiss,
  .speedrun-hud__toggle {
    min-inline-size: var(--touch-target-min);
    min-block-size: var(--touch-target-min);
  }

  .modal-panel button,
  .pause-checkpoint-actions button,
  .speedrun-hud__toggle {
    padding-block: var(--touch-target-padding-y);
    padding-inline: var(--touch-target-padding-x);
  }

  .slot,
  .chip {
    min-inline-size: var(--touch-target-min);
    min-block-size: var(--touch-target-min);
  }

  .slot {
    inline-size: var(--touch-target-min);
    block-size: var(--touch-target-min);
  }

  #wand-slots {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    min-block-size: var(--touch-target-min);
  }

  .chip {
    padding-block: 7px;
    padding-inline: 8px;
  }

  .inventory-rail .chip {
    inline-size: 100%;
  }

  .tutorial-nudge__dismiss {
    flex: 0 0 var(--touch-target-min);
  }

  .modal-panel input[type="checkbox"] {
    inline-size: var(--touch-target-min);
    block-size: var(--touch-target-min);
    margin-block: 0;
  }

  .modal-panel input[type="range"] {
    min-block-size: var(--touch-target-min);
  }
}

body[data-layout=mobile] #hud button,
body[data-layout=mobile] #wand button,
body[data-layout=mobile] #wand input,
body[data-layout=mobile] .modal-panel button,
body[data-layout=mobile] .modal-panel select,
body[data-layout=mobile] .modal-panel input,
body[data-layout=mobile] .modal-header .x,
body[data-layout=mobile] #overlay button,
body[data-layout=mobile] .title-actions button,
body[data-layout=mobile] .title-actions a,
body[data-layout=mobile] .difficulty-picker label,
body[data-layout=mobile] .pause-checkpoint-actions button,
body[data-layout=mobile] .tutorial-nudge__dismiss,
body[data-layout=mobile] .speedrun-hud__toggle,
body[data-layout=mobile] .slot,
body[data-layout=mobile] .chip {
  min-inline-size: var(--touch-target-min);
  min-block-size: var(--touch-target-min);
}

body[data-layout=mobile] .modal-panel button,
body[data-layout=mobile] .pause-checkpoint-actions button,
body[data-layout=mobile] .speedrun-hud__toggle {
  padding-block: var(--touch-target-padding-y);
  padding-inline: var(--touch-target-padding-x);
}

body[data-layout=mobile] .mobile-spell-input-row {
  position: relative;
  z-index: 3;
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  min-inline-size: 0;
  margin-block: 0;
}

body[data-layout=mobile][data-orientation=portrait] .wand-mobile-actions {
  position: sticky;
  inset-block-end: 0;
  z-index: 4;
  grid-template-columns: repeat(2, minmax(var(--touch-target-min), 1fr));
  padding-block-start: 4px;
  background: linear-gradient(180deg, rgba(10, 13, 19, 0), rgba(10, 13, 19, 0.94) 34%);
}

body[data-layout=mobile][data-orientation=portrait] #wand-mobile-cast-btn {
  grid-column: 1 / -1;
  min-block-size: calc(var(--touch-target-min) + 10px);
}

body[data-layout=mobile][data-orientation=portrait] .mobile-spell-input-row {
  grid-column: 1 / -1;
}

body[data-layout=mobile] .mobile-spell-input-row .lbl {
  display: none;
}

body[data-layout=mobile] .mobile-spell-input {
  inline-size: 100%;
  border: 1px solid rgba(132, 225, 188, 0.55);
  border-radius: 8px;
  background: rgba(13, 17, 24, 0.9);
  color: var(--ink);
  font: 700 16px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

body[data-layout=mobile] #spell-suggestions {
  grid-column: 2;
  min-inline-size: 0;
  margin-block: 0;
}

body[data-layout=mobile] #wand.open .mobile-composer-help {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-block-size: var(--touch-target-min);
  padding: 5px 8px;
  border: 1px solid rgba(255, 209, 102, 0.32);
  border-radius: 999px;
  background: rgba(35, 26, 7, 0.62);
  color: #f5ead0;
  font: 800 clamp(12px, 1.6dvh, 13px)/1.25 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  text-align: center;
  pointer-events: none;
}

body[data-layout=mobile][data-orientation=portrait] #wand.open[data-first-cast-hint-visible="true"] #wand-slots,
body[data-layout=mobile][data-orientation=portrait] #wand.open[data-first-cast-hint-visible="true"] #spell-suggestions,
body[data-layout=mobile][data-orientation=portrait] #wand.open[data-first-cast-hint-visible="true"] #spell-feedback,
body[data-layout=mobile][data-orientation=portrait] #wand.open[data-first-cast-hint-visible="true"] .spell-details,
body[data-layout=mobile][data-orientation=portrait] #wand.open[data-first-cast-hint-visible="true"] .mobile-composer-help {
  display: none;
}

body[data-layout=mobile][data-orientation=portrait] #wand.open:has(.last-cast-recall-hint:not(.hidden)) #wand-slots,
body[data-layout=mobile][data-orientation=portrait] #wand.open:has(.last-cast-recall-hint:not(.hidden)) #spell-suggestions,
body[data-layout=mobile][data-orientation=portrait] #wand.open:has(.last-cast-recall-hint:not(.hidden)) #spell-feedback,
body[data-layout=mobile][data-orientation=portrait] #wand.open:has(.last-cast-recall-hint:not(.hidden)) .spell-details {
  display: none;
}

body[data-layout=mobile][data-orientation=portrait] #wand.open[data-first-cast-hint-visible="true"] .wand-mobile-actions {
  position: static;
  padding-block-start: 0;
  background: transparent;
}

body[data-layout=mobile][data-orientation=portrait] #wand.open:has(#wand-error:not(.hidden):not([hidden])) #wand-slots,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open:has(#wand-error:not(.hidden):not([hidden])) #wand-slots,
body[data-layout=mobile][data-orientation=portrait] #wand.open:has(#wand-error:not(.hidden):not([hidden])) #spell-suggestions,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open:has(#wand-error:not(.hidden):not([hidden])) #spell-suggestions,
body[data-layout=mobile][data-orientation=portrait] #wand.open:has(#wand-error:not(.hidden):not([hidden])) #spell-feedback,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open:has(#wand-error:not(.hidden):not([hidden])) #spell-feedback,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open:has(#wand-error:not(.hidden):not([hidden])) .spell-details,
body[data-layout=mobile][data-orientation=portrait] #wand.open:has(#wand-error:not(.hidden):not([hidden])) .spell-details {
  display: none;
}

body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open:has(#wand-error:not(.hidden):not([hidden])) .mobile-composer-help,
body[data-layout=mobile][data-orientation=portrait] #wand.open:has(#wand-error:not(.hidden):not([hidden])) .mobile-composer-help {
  order: 5;
}

body[data-layout=mobile][data-orientation=portrait] #wand.open:has(#wand-error:not(.hidden):not([hidden])):has(.last-cast-recall-hint:not(.hidden)) .mobile-composer-help,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open:has(#wand-error:not(.hidden):not([hidden])):has(.last-cast-recall-hint:not(.hidden)) .mobile-composer-help {
  display: none;
}

body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open:has(#wand-error:not(.hidden):not([hidden])) .wand-mobile-actions,
body[data-layout=mobile][data-orientation=portrait] #wand.open:has(#wand-error:not(.hidden):not([hidden])) .wand-mobile-actions {
  order: 6;
  position: static;
  padding-block-start: 0;
  background: transparent;
}

body[data-layout=mobile] #wand.open:has(#wand-mobile-cast-btn[data-cast-ready="true"]) .mobile-composer-help {
  display: none;
}

body[data-layout=mobile] #wand.open .mobile-cast-ready-guidance:not([hidden]) {
  grid-column: 1 / -1;
  order: 19;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-block-size: 34px;
  padding: 5px 9px;
  border: 1px solid rgba(132, 225, 188, 0.42);
  border-radius: 999px;
  background: rgba(9, 39, 29, 0.68);
  color: #d8ffef;
  font: 800 clamp(11px, 1.45dvh, 12px)/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  pointer-events: none;
  text-align: center;
}

body[data-layout=mobile] #wand.open .mobile-cast-ready-guidance__eyebrow {
  flex: 0 0 auto;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 243, 191, 0.16);
  color: #fff8cf;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

body[data-layout=mobile] #wand.open .mobile-cast-ready-guidance__copy {
  min-inline-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body[data-layout=mobile].mobile-keyboard-visible #wand.open .mobile-cast-ready-guidance {
  display: none;
}

body[data-layout=mobile][data-orientation=portrait] #wand.open:has(#wand-mobile-cast-btn[data-cast-ready="true"]) .spell-details,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open:has(#wand-mobile-cast-btn[data-cast-ready="true"]) .spell-details {
  display: none;
}

body[data-layout=mobile]:not([data-orientation="landscape"]):not(.mobile-keyboard-visible) #wand.open:not(.keyboard-safe-focus):not(:has(#mobile-spell-input:focus))[data-first-cast-hint-visible="false"]:has(#wand-mobile-cast-btn[data-cast-ready="true"]) .wand-mobile-actions {
  position: sticky;
  inset-inline: auto;
  inset-block-end: 0;
  z-index: 4;
  padding-block-start: 6px;
  background: linear-gradient(180deg, rgba(10, 13, 19, 0), rgba(10, 13, 19, 0.94) 28%);
}

body[data-layout=mobile]:not([data-orientation="landscape"]):not(.mobile-keyboard-visible) #wand.open:not(.keyboard-safe-focus):not(:has(#mobile-spell-input:focus))[data-first-cast-hint-visible="false"]:has(#wand-mobile-cast-btn[data-cast-ready="true"]) #wand-mobile-cast-btn {
  order: 2;
}

body[data-layout=mobile]:not([data-orientation="landscape"]):not(.mobile-keyboard-visible) #wand.open:not(.keyboard-safe-focus):not(:has(#mobile-spell-input:focus))[data-first-cast-hint-visible="false"]:has(#wand-mobile-cast-btn[data-cast-ready="true"]) #wand-share-btn,
body[data-layout=mobile]:not([data-orientation="landscape"]):not(.mobile-keyboard-visible) #wand.open:not(.keyboard-safe-focus):not(:has(#mobile-spell-input:focus))[data-first-cast-hint-visible="false"]:has(#wand-mobile-cast-btn[data-cast-ready="true"]) #wand-mobile-done-btn {
  display: none;
}

body[data-layout=mobile]:not([data-orientation="landscape"]):not(.mobile-keyboard-visible) #wand.open:not(.keyboard-safe-focus):not(:has(#mobile-spell-input:focus))[data-first-cast-hint-visible="false"]:has(#wand-mobile-cast-btn[data-cast-ready="true"]) #wand-slots,
body[data-layout=mobile]:not([data-orientation="landscape"]):not(.mobile-keyboard-visible) #wand.open:not(.keyboard-safe-focus):not(:has(#mobile-spell-input:focus))[data-first-cast-hint-visible="false"]:has(#wand-mobile-cast-btn[data-cast-ready="true"]) #spell-suggestions {
  display: none;
}

body[data-layout=mobile] .last-cast-recall-hint {
  grid-column: 2;
  min-inline-size: var(--touch-target-min);
  min-block-size: var(--touch-target-min);
  box-sizing: border-box;
  margin-block-start: 0;
  padding: 6px 10px;
  border-color: rgba(132, 225, 188, 0.58);
  background: linear-gradient(180deg, rgba(15, 67, 53, 0.9), rgba(8, 31, 31, 0.88));
  color: #dfffee;
  font: 800 clamp(11px, 1.55dvh, 12px)/1.15 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  text-align: center;
  box-shadow: 0 0 0 1px rgba(132, 225, 188, 0.12), 0 8px 18px rgba(0, 0, 0, 0.24);
}

body[data-layout=mobile] .last-cast-recall-hint.hidden {
  display: none;
}

body[data-layout=mobile][data-orientation=portrait] #spell-suggestions,
body[data-layout=mobile][data-orientation=portrait] .last-cast-recall-hint {
  grid-column: 1 / -1;
}

body[data-layout=mobile] .suggestion-chip {
  padding-inline: 10px;
  white-space: nowrap;
}

body[data-layout=mobile] .slot {
  inline-size: var(--touch-target-min);
  block-size: var(--touch-target-min);
}

body[data-layout=mobile] #wand-slots {
  flex-wrap: nowrap;
  justify-content: flex-start;
  overflow-x: auto;
  min-block-size: var(--touch-target-min);
}

body[data-layout=mobile][data-orientation=portrait].mobile-keyboard-visible #wand.open,
body[data-layout=mobile]:not([data-orientation="landscape"]).mobile-keyboard-visible #wand.open,
body[data-layout=mobile][data-orientation=portrait] #wand.open.keyboard-safe-focus,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open.keyboard-safe-focus {
  inset-block-end: max(8px, calc(var(--mobile-keyboard-inset) + env(safe-area-inset-bottom) + 8px));
  max-block-size: min(320px, calc(var(--mobile-visual-viewport-height) - 76px));
  scroll-padding-block: 8px calc(var(--touch-target-min) + 14px);
}

body[data-layout=mobile][data-orientation=portrait].mobile-keyboard-visible #wand.open .spell-details,
body[data-layout=mobile]:not([data-orientation="landscape"]).mobile-keyboard-visible #wand.open .spell-details,
body[data-layout=mobile][data-orientation=portrait] #wand.open.keyboard-safe-focus .spell-details,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open.keyboard-safe-focus .spell-details {
  display: none;
}

body[data-layout=mobile][data-orientation=portrait].mobile-keyboard-visible #wand.open .first-cast-spell-hint,
body[data-layout=mobile]:not([data-orientation="landscape"]).mobile-keyboard-visible #wand.open .first-cast-spell-hint,
body[data-layout=mobile][data-orientation=portrait] #wand.open.keyboard-safe-focus .first-cast-spell-hint,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open.keyboard-safe-focus .first-cast-spell-hint,
body[data-layout=mobile][data-orientation=portrait] #wand.open:has(#wand-error:not(.hidden):not([hidden])) .first-cast-spell-hint {
  display: none;
}

body[data-layout=mobile][data-orientation=portrait].mobile-keyboard-visible #wand.open .mobile-composer-help,
body[data-layout=mobile]:not([data-orientation="landscape"]).mobile-keyboard-visible #wand.open .mobile-composer-help,
body[data-layout=mobile][data-orientation=portrait] #wand.open.keyboard-safe-focus .mobile-composer-help,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open.keyboard-safe-focus .mobile-composer-help {
  min-block-size: auto;
  padding-block: 4px;
}

body[data-layout=mobile][data-orientation=portrait].mobile-keyboard-visible #wand.open .wand-mobile-actions,
body[data-layout=mobile]:not([data-orientation="landscape"]).mobile-keyboard-visible #wand.open .wand-mobile-actions,
body[data-layout=mobile][data-orientation=portrait] #wand.open.keyboard-safe-focus .wand-mobile-actions,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open.keyboard-safe-focus .wand-mobile-actions,
body[data-layout=mobile][data-orientation=portrait] #wand.open:has(#wand-error:not(.hidden):not([hidden])) .wand-mobile-actions {
  position: static;
  padding-block-start: 0;
  background: transparent;
}

body[data-layout=mobile]:not([data-orientation="landscape"]).mobile-keyboard-visible #wand.open .wand-mobile-actions,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open.keyboard-safe-focus .wand-mobile-actions {
  grid-template-columns: minmax(0, 1.5fr) minmax(var(--touch-target-min), 0.85fr);
}

body[data-layout=mobile]:not([data-orientation="landscape"]).mobile-keyboard-visible #wand.open #wand-mobile-cast-btn,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open.keyboard-safe-focus #wand-mobile-cast-btn {
  grid-column: auto;
  min-block-size: var(--touch-target-min);
}

body[data-layout=mobile]:not([data-orientation="landscape"]).mobile-keyboard-visible #wand.open #wand-mobile-clear-btn,
body[data-layout=mobile]:not([data-orientation="landscape"]).mobile-keyboard-visible #wand.open #wand-share-btn,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open.keyboard-safe-focus #wand-mobile-clear-btn,
body[data-layout=mobile]:not([data-orientation="landscape"]) #wand.open.keyboard-safe-focus #wand-share-btn {
  display: none;
}

body[data-layout=mobile][data-orientation=portrait].mobile-keyboard-visible #quick-cast-bar.has-favourites {
  display: none;
}

body[data-layout=mobile].mobile-keyboard-visible .mobile-overlay-escape-guard:not([hidden]) {
  display: none;
}

body[data-layout=mobile].mobile-keyboard-visible:has(#wand.open) .mobile-failure-recovery:not([hidden]) {
  display: none;
}

body[data-layout=mobile] .chip {
  padding-block: 7px;
  padding-inline: 8px;
}

body[data-layout=mobile] .inventory-rail .chip {
  inline-size: 100%;
}

body[data-layout=mobile] .tutorial-nudge__dismiss {
  flex: 0 0 var(--touch-target-min);
}

body[data-layout=mobile] .modal-panel input[type="checkbox"] {
  inline-size: var(--touch-target-min);
  block-size: var(--touch-target-min);
  margin-block: 0;
}

body[data-layout=mobile] .modal-panel input[type="range"] {
  min-block-size: var(--touch-target-min);
}

.modal-panel input[type="checkbox"],
body[data-layout=mobile] .modal-panel input[type="checkbox"] {
  inline-size: 1.35em;
  block-size: 1.35em;
  min-inline-size: 1.35em;
  min-block-size: 1.35em;
}

body[data-layout=mobile] .modal-panel input[type="checkbox"] {
  inline-size: var(--touch-target-min);
  block-size: var(--touch-target-min);
  min-inline-size: var(--touch-target-min);
  min-block-size: var(--touch-target-min);
}

@media (orientation: landscape) and (pointer: coarse), (orientation: landscape) and (max-width: 900px) {
  .modal,
  #overlay,
  #codex-overlay,
  .win-screen {
    align-items: flex-start;
    place-items: start center;
    overflow: auto;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }

  #overlay.show,
  .modal.show,
  #codex-overlay:not(.hidden),
  .win-screen.show {
    display: grid;
  }

  #overlay.title-overlay.show {
    display: grid;
    align-items: start;
    justify-items: center;
  }

  .panel,
  .modal-panel,
  .codex-panel,
  .win-panel,
  .reward-panel {
    zoom: var(--menu-ui-scale);
    max-block-size: calc(100dvh / var(--menu-ui-scale) - 24px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .title-panel {
    width: min(720px, calc(100vw - 24px));
  }

  .codex-panel {
    width: min(920px, calc(100vw - 24px));
  }
}

/* Mobile landscape keeps the desktop HUD/wand layout with compact touch affordances. */
body[data-layout="mobile"][data-orientation="landscape"] {
  --hud-top-unit: 0.75rem;
  --menu-ui-scale: 0.75;
  --touch-target-min: 28px;
  --touch-target-padding-y: 2px;
  --touch-target-padding-x: 5px;
  --hud-font-size: 8px;
  --hud-label-font-size: 8px;
  --mobile-joystick-size: 72px;
}

@media (orientation: landscape) {
  body[data-layout="mobile"] {
    --hud-top-unit: 0.75rem;
    --menu-ui-scale: 0.75;
  }
}

@media (orientation: landscape) and (pointer: coarse), (orientation: landscape) and (max-width: 900px) {
  body {
    --hud-top-unit: 0.75rem;
    --menu-ui-scale: 0.75;
    --hud-top-gap: calc(var(--hud-top-unit) * 0.875);
    --hud-top-chip-gap: calc(var(--hud-top-unit) * 0.5);
    --hud-top-vitals-gap: calc(var(--hud-top-unit) * 0.1875);
    --hud-top-item-height: calc(var(--hud-top-unit) * 2.75);
    --hud-top-padding-y: calc(var(--hud-top-unit) * 0.375);
    --hud-top-padding-x: calc(var(--hud-top-unit) * 0.625);
    --hud-top-font-size: calc(var(--hud-top-unit) * 0.875);
    --hud-top-value-font-size: calc(var(--hud-top-unit) * 1.125);
    --hud-top-icon-font-size: calc(var(--hud-top-unit) * 1.375);
    --hud-top-book-icon-font-size: calc(var(--hud-top-unit) * 1.125);
    --hud-top-vitals-bar-width: calc(var(--hud-top-unit) * 8.75);
    --hud-top-level-bar-width: calc(var(--hud-top-unit) * 4.5);
    --hud-top-bar-height: calc(var(--hud-top-unit) * 0.875);
    --hud-top-icon-button-size: var(--hud-top-item-height);
  }
}

body[data-layout="mobile"][data-orientation="landscape"] #hud,
body[data-layout="mobile"][data-orientation="landscape"] .hud {
  padding: 7px;
  font-size: 9px;
}

body[data-layout="mobile"][data-orientation="landscape"] #hud > .row {
  position: static;
  inset: auto;
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  width: auto;
  gap: 5px;
  margin: 0;
  overflow: visible;
  pointer-events: none;
}

body[data-layout="mobile"][data-orientation="landscape"] #hp-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #mana-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #score-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #depth-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #gold-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #xp-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #timer-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #stats,
body[data-layout="mobile"][data-orientation="landscape"] #wand-ui,
body[data-layout="mobile"][data-orientation="landscape"] #tutorial,
body[data-layout="mobile"][data-orientation="landscape"] #token-hint-row {
  justify-content: flex-start;
  width: auto;
  min-width: 0;
  min-height: 0;
  gap: 4px;
  padding: 3px 5px;
  margin: 0;
  overflow: visible;
  text-align: start;
  font-size: var(--hud-font-size);
  line-height: 1.2;
}

body[data-layout="mobile"][data-orientation="landscape"] #hp-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #mana-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #xp-wrap {
  flex-direction: row;
}

body[data-layout="mobile"][data-orientation="landscape"] #settings-btn {
  margin-inline-start: 0 !important;
}

body[data-layout="mobile"][data-orientation="landscape"] .bar {
  width: 60px;
  height: 7px;
}

body[data-layout="mobile"][data-orientation="landscape"] #xp-wrap .bar {
  width: 38px !important;
}

body[data-layout="mobile"][data-orientation="landscape"] #depth-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #gold-wrap {
  min-block-size: 18px;
}

body[data-layout="mobile"][data-orientation="landscape"] #debug-btn,
body[data-layout="mobile"][data-orientation="landscape"] #settings-btn,
body[data-layout="mobile"][data-orientation="landscape"] #audio-btn,
body[data-layout="mobile"][data-orientation="landscape"] #codex-btn,
body[data-layout="mobile"][data-orientation="landscape"] #combat-stats-btn,
body[data-layout="mobile"][data-orientation="landscape"] #letter-stats-btn,
body[data-layout="mobile"][data-orientation="landscape"] #perks-btn,
body[data-layout="mobile"][data-orientation="landscape"] #daily-hud-badge {
  width: auto;
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
  padding: var(--touch-target-padding-y) var(--touch-target-padding-x);
  font-size: var(--hud-font-size);
  pointer-events: auto;
}

body[data-layout="mobile"][data-orientation="landscape"] #settings-btn,
body[data-layout="mobile"][data-orientation="landscape"] #audio-btn,
body[data-layout="mobile"][data-orientation="landscape"] #perks-btn,
body[data-layout="mobile"][data-orientation="landscape"] #debug-btn {
  font-size: calc(var(--hud-font-size) + 10px);
}

body[data-layout="mobile"][data-orientation="landscape"] #codex-btn {
  font-size: calc(var(--hud-font-size) + 6px);
}

body[data-layout="mobile"][data-orientation="landscape"] #wand {
  position: static;
  inset: auto;
  z-index: auto;
  display: block;
  align-self: center;
  width: min(1170px, 97vw);
  block-size: auto;
  max-block-size: min(29dvh, 112px);
  padding: 4px 6px;
  overflow: hidden auto;
  border-radius: 8px;
  font-size: 9px;
}

body[data-layout="mobile"][data-orientation="landscape"] #wand.closed {
  transform: scale(0.96);
}

body[data-layout="mobile"][data-orientation="landscape"] #wand.open {
  transform: scale(1);
}

body[data-layout="mobile"][data-orientation="landscape"] #wand-header {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 3px;
}

body[data-layout="mobile"][data-orientation="landscape"] #wand-header > .lbl,
body[data-layout="mobile"][data-orientation="landscape"] #wand-summon-name,
body[data-layout="mobile"][data-orientation="landscape"] #input-hint {
  display: inline;
}

body[data-layout="mobile"][data-orientation="landscape"] #wand-mode {
  padding: 1px 4px;
  font-size: 8px;
  text-align: start;
}

body[data-layout="mobile"][data-orientation="landscape"] #wand-slots {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  gap: 3px;
  min-block-size: 26px;
  max-height: none;
  overflow-x: auto;
  overflow-y: visible;
}

body[data-layout="mobile"][data-orientation="landscape"] .slot {
  inline-size: 20px;
  block-size: 25px;
  min-inline-size: 20px;
  min-block-size: 25px;
  font-size: 14px;
}

body[data-layout="mobile"][data-orientation="landscape"] .mobile-spell-input-row {
  display: flex;
  grid-column: auto;
  gap: 4px;
  margin-top: 3px;
}

body[data-layout="mobile"][data-orientation="landscape"] .mobile-spell-input-row .lbl {
  display: inline;
}

body[data-layout="mobile"][data-orientation="landscape"] .mobile-spell-input {
  min-height: 24px;
  padding: 3px 5px;
  font-size: 11px;
}

body[data-layout="mobile"][data-orientation="landscape"] #cooldown-track,
body[data-layout="mobile"][data-orientation="landscape"] #spell-feedback,
body[data-layout="mobile"][data-orientation="landscape"] .spell-details,
body[data-layout="mobile"][data-orientation="landscape"] #spell-suggestions {
  grid-column: auto;
}

body[data-layout="mobile"][data-orientation="landscape"] .wand-mobile-actions {
  display: grid;
  grid-template-columns: minmax(120px, 1.6fr) minmax(60px, 0.8fr);
  gap: 4px;
  margin-top: 3px;
}

body[data-layout="mobile"][data-orientation="landscape"] .wand-mobile-actions button {
  min-block-size: var(--touch-target-min);
  padding: 3px 6px;
  font-size: 9px;
}

body[data-layout="mobile"][data-orientation="landscape"] #wand-mobile-cast-btn {
  min-block-size: calc(var(--touch-target-min) + 4px);
}

body[data-layout="mobile"][data-orientation="landscape"] .inventory-rail {
  top: 64px;
  bottom: 90px;
  width: 62px;
  gap: 4px;
  padding: 5px;
}

body[data-layout="mobile"][data-orientation="landscape"] .inventory-rail-left {
  inset-inline-start: 12px;
}

body[data-layout="mobile"][data-orientation="landscape"] .inventory-rail-right {
  inset-inline-end: 12px;
}

body[data-layout="mobile"][data-orientation="landscape"] .inventory-rail-title {
  font-size: 7px;
  line-height: 1.15;
  letter-spacing: 0.06em;
}

body[data-layout="mobile"][data-orientation="landscape"] .inventory-rail .chip {
  inline-size: 100%;
  min-inline-size: 0;
  min-block-size: 16px;
  padding: 1px 3px;
  font-size: 8px;
  line-height: 1.2;
}

body[data-layout="mobile"][data-orientation="landscape"] .inventory-rail .chip-tok {
  font-size: 10px;
}

body[data-layout] #vitals-wrap {
  display: grid;
  gap: 3px;
}

body[data-layout] #vitals-wrap #hp-wrap,
body[data-layout] #vitals-wrap #mana-wrap {
  min-width: 0;
  min-height: 0;
  gap: 0;
  padding: 0;
  margin: 0;
  overflow: visible;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

body[data-layout="mobile"][data-orientation="landscape"] #vitals-wrap {
  gap: 2px;
  padding: 3px 5px;
}

body[data-layout="mobile"][data-orientation="landscape"] #vitals-wrap .bar {
  width: 60px;
}

body[data-layout="mobile"][data-orientation="landscape"] #vitals-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #xp-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #depth-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #gold-wrap {
  block-size: 42px;
  min-block-size: 42px;
  gap: 6px;
  padding: 5px 8px;
  font-size: 12px;
  align-items: center;
}

body[data-layout="mobile"][data-orientation="landscape"] #vitals-wrap {
  gap: 3px;
  align-content: center;
}

body[data-layout="mobile"][data-orientation="landscape"] #vitals-wrap .bar {
  width: 90px;
  height: 10px;
}

body[data-layout="mobile"][data-orientation="landscape"] #xp-wrap .bar {
  width: 57px !important;
  height: 10px;
}

body[data-layout="mobile"][data-orientation="landscape"] #depth-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #gold-wrap {
  min-block-size: 42px;
}

body[data-layout="mobile"][data-orientation="landscape"] #timer-wrap {
  block-size: 42px;
  min-block-size: 42px;
  padding: 5px 8px;
  font-size: 12px;
  align-items: center;
}

body[data-layout="mobile"][data-orientation="landscape"] #debug-btn,
body[data-layout="mobile"][data-orientation="landscape"] #settings-btn,
body[data-layout="mobile"][data-orientation="landscape"] #audio-btn,
body[data-layout="mobile"][data-orientation="landscape"] #codex-btn,
body[data-layout="mobile"][data-orientation="landscape"] #perks-btn {
  inline-size: 42px;
  block-size: 42px;
  min-inline-size: 42px;
  min-block-size: 42px;
  padding: 0;
  font-size: 27px;
}

/* Keep mobile landscape visually aligned with the desktop HUD; the joystick is the mobile-only addition. */
body[data-layout="mobile"][data-orientation="landscape"] #hud,
body[data-layout="mobile"][data-orientation="landscape"] .hud {
  padding: 14px;
}

body[data-layout="mobile"][data-orientation="landscape"] #hud > .row {
  gap: 14px;
}

body[data-layout="mobile"][data-orientation="landscape"] #vitals-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #xp-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #depth-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #gold-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #timer-wrap {
  gap: 8px;
  padding: 7px 10px;
  font-size: 12px;
}

body[data-layout="mobile"][data-orientation="landscape"] #vitals-wrap {
  block-size: 59px;
  min-block-size: 59px;
  gap: 3px;
}

body[data-layout="mobile"][data-orientation="landscape"] #xp-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #depth-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #gold-wrap {
  block-size: 36px;
  min-block-size: 36px;
}

body[data-layout="mobile"][data-orientation="landscape"] #timer-wrap {
  block-size: 32px;
  min-block-size: 32px;
}

body[data-layout="mobile"][data-orientation="landscape"] .bar,
body[data-layout="mobile"][data-orientation="landscape"] #vitals-wrap .bar {
  width: 140px;
  height: 20px;
}

body[data-layout="mobile"][data-orientation="landscape"] #xp-wrap .bar {
  width: 60px !important;
  height: 20px;
}

body[data-layout="mobile"][data-orientation="landscape"] #debug-btn,
body[data-layout="mobile"][data-orientation="landscape"] #settings-btn,
body[data-layout="mobile"][data-orientation="landscape"] #audio-btn,
body[data-layout="mobile"][data-orientation="landscape"] #codex-btn,
body[data-layout="mobile"][data-orientation="landscape"] #perks-btn {
  inline-size: 44px;
  block-size: 44px;
  min-inline-size: 44px;
  min-block-size: 44px;
  padding: 0;
}

body[data-layout="mobile"][data-orientation="landscape"] #settings-btn,
body[data-layout="mobile"][data-orientation="landscape"] #audio-btn,
body[data-layout="mobile"][data-orientation="landscape"] #perks-btn,
body[data-layout="mobile"][data-orientation="landscape"] #debug-btn {
  font-size: 22px;
}

body[data-layout="mobile"][data-orientation="landscape"] #codex-btn {
  font-size: 18px;
}

#vitals-wrap,
#xp-wrap,
#depth-wrap,
#gold-wrap,
#timer-wrap {
  block-size: var(--hud-top-item-height);
  min-block-size: var(--hud-top-item-height);
  align-items: center;
  gap: var(--hud-top-chip-gap);
  padding: var(--hud-top-padding-y) var(--hud-top-padding-x);
  font-size: var(--hud-top-font-size);
}

#vitals-wrap {
  align-content: center;
  gap: var(--hud-top-vitals-gap);
}

#vitals-wrap .bar {
  width: var(--hud-top-vitals-bar-width);
  height: var(--hud-top-bar-height);
}

#xp-wrap .bar {
  width: var(--hud-top-level-bar-width) !important;
  height: var(--hud-top-bar-height);
}

#xp-level,
#depth-text,
#gold-text,
#depth-wrap .lbl,
#gold-wrap .lbl {
  font-size: var(--hud-top-value-font-size);
  line-height: 1;
}

#settings-btn,
#audio-btn,
#codex-btn,
#perks-btn,
#debug-btn {
  inline-size: var(--hud-top-icon-button-size);
  block-size: var(--hud-top-icon-button-size);
  min-inline-size: var(--hud-top-icon-button-size);
  min-block-size: var(--hud-top-icon-button-size);
  padding: 0;
}

#hud > .row,
body[data-layout="mobile"][data-orientation="landscape"] #hud > .row {
  gap: var(--hud-top-gap);
}

#settings-btn,
#audio-btn,
#perks-btn,
#debug-btn {
  font-size: var(--hud-top-icon-font-size);
}

#codex-btn {
  font-size: var(--hud-top-book-icon-font-size);
}

body[data-layout="mobile"][data-orientation="landscape"] #vitals-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #xp-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #depth-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #gold-wrap,
body[data-layout="mobile"][data-orientation="landscape"] #timer-wrap {
  block-size: var(--hud-top-item-height);
  min-block-size: var(--hud-top-item-height);
  gap: var(--hud-top-chip-gap);
  padding: var(--hud-top-padding-y) var(--hud-top-padding-x);
  font-size: var(--hud-top-font-size);
}

body[data-layout="mobile"][data-orientation="landscape"] #vitals-wrap .bar {
  width: var(--hud-top-vitals-bar-width);
  height: var(--hud-top-bar-height);
}

body[data-layout="mobile"][data-orientation="landscape"] #vitals-wrap {
  gap: var(--hud-top-vitals-gap);
}

body[data-layout="mobile"][data-orientation="landscape"] #xp-wrap .bar {
  width: var(--hud-top-level-bar-width) !important;
  height: var(--hud-top-bar-height);
}

body[data-layout="mobile"][data-orientation="landscape"] #settings-btn,
body[data-layout="mobile"][data-orientation="landscape"] #audio-btn,
body[data-layout="mobile"][data-orientation="landscape"] #codex-btn,
body[data-layout="mobile"][data-orientation="landscape"] #perks-btn,
body[data-layout="mobile"][data-orientation="landscape"] #debug-btn {
  inline-size: var(--hud-top-icon-button-size);
  block-size: var(--hud-top-icon-button-size);
  min-inline-size: var(--hud-top-icon-button-size);
  min-block-size: var(--hud-top-icon-button-size);
  padding: 0;
}

body[data-layout="mobile"][data-orientation="landscape"] #settings-btn,
body[data-layout="mobile"][data-orientation="landscape"] #audio-btn,
body[data-layout="mobile"][data-orientation="landscape"] #perks-btn,
body[data-layout="mobile"][data-orientation="landscape"] #debug-btn {
  font-size: var(--hud-top-icon-font-size);
}

body[data-layout="mobile"][data-orientation="landscape"] #codex-btn {
  font-size: var(--hud-top-book-icon-font-size);
}

body[data-layout=mobile] .title-actions #start-btn,
body[data-layout="mobile"][data-orientation="landscape"] .title-actions #start-btn {
  min-inline-size: 7.5rem;
  min-block-size: var(--touch-target-min);
  padding: 10px 14px;
  margin-top: 0;
  font-size: 0.8333rem;
}
