:root {
  --ink: #16110e;
  --panel: #221811;
  --bark: #3a2a1c;
  --ember: #e85d3c;
  --gold: #e8c56a;
  --spirit: #3db8a0;
  --paper: #e6dcc8;
  --muted: #9a8770;
  --danger: #d64545;
  --mist: #c8b89a;
  --series-hero: #3db868;
  --series-slayer: #4a88a8;
  --series-aot: #c07050;
  --series-jjk: #a05070;
  --series-solo: #7ec8d8;
  --series-lane: #c0a070;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --rail-w: 0;
  --app-pad-x: max(0.15rem, var(--safe-left), var(--safe-right));
  --app-pad-top: max(0.1rem, var(--safe-top));
  --app-pad-bottom: max(0.1rem, var(--safe-bottom));
}

@font-face {
  font-family: "Press Start 2P";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/PressStart2P.woff2") format("woff2");
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  height: -webkit-fill-available;
}

html,
body {
  margin: 0;
  background:
    radial-gradient(ellipse 70% 45% at 30% -5%, rgba(90, 48, 28, 0.55) 0%, transparent 55%),
    radial-gradient(ellipse 50% 40% at 95% 85%, rgba(28, 72, 64, 0.35) 0%, transparent 45%),
    radial-gradient(ellipse 40% 30% at 10% 90%, rgba(80, 40, 60, 0.2) 0%, transparent 50%),
    linear-gradient(180deg, #1a1410 0%, #120e0b 45%, #0c0a08 100%);
  color: var(--paper);
  font-family: "Press Start 2P", "Courier New", Courier, monospace;
  letter-spacing: 0.02em;
}

body {
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding:
    var(--app-pad-top)
    var(--app-pad-x)
    var(--app-pad-bottom);
  overscroll-behavior: none;
  overflow: hidden;
}

#app {
  width: 100%;
  max-width: none;
  /* Prefer dvh, but keep vh fallbacks so Safari never collapses to 0 */
  height: calc(100vh - var(--app-pad-top) - var(--app-pad-bottom));
  height: calc(100dvh - var(--app-pad-top) - var(--app-pad-bottom));
  max-height: calc(100vh - var(--app-pad-top) - var(--app-pad-bottom));
  max-height: calc(100dvh - var(--app-pad-top) - var(--app-pad-bottom));
  min-height: 12rem;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
  visibility: visible;
  opacity: 1;
}

/* Full-bleed map stage — chrome floats over the board */
#playfield {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  align-items: stretch;
}

#stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  gap: 0.25rem;
}

#frame {
  position: relative;
  width: 100%;
  max-width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  aspect-ratio: 640 / 352;
  border: 3px solid #2a1c14;
  outline: 1px solid rgba(232, 93, 60, 0.55);
  box-shadow:
    0 0 0 4px rgba(18, 12, 8, 0.9),
    0 12px 36px rgba(0, 0, 0, 0.55),
    inset 0 0 40px rgba(0, 0, 0, 0.25);
  background: #0c0a08;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  overflow: hidden;
  animation: frame-in 0.55s ease-out both;
}

@keyframes frame-in {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  -ms-interpolation-mode: nearest-neighbor;
  cursor: crosshair;
  background: #14100c;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 0.3rem;
}

.overlay-chrome {
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

/* HUD sits above the map so it never covers tiles */
.hud-dock {
  position: relative;
  z-index: 8;
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 0.35rem;
  width: min(100%, 42rem);
  max-width: 100%;
  padding: 0 0.2rem;
  animation: hud-in 0.45s ease-out both;
}

.hud-bar {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.28rem 0.4rem 0.22rem;
  background:
    linear-gradient(180deg, rgba(48, 32, 20, 0.96), rgba(18, 12, 8, 0.94));
  border: 2px solid rgba(200, 160, 90, 0.55);
  box-shadow:
    0 4px 14px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(232, 197, 106, 0.18);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid;
  gap: 0.12rem;
}

@keyframes hud-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hud-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem 0.4rem;
  font-size: clamp(0.28rem, 1.35vh, 0.36rem);
  text-shadow: 1px 1px 0 #000;
}

.hud-brand {
  color: var(--gold);
  font-size: clamp(0.3rem, 1.4vh, 0.38rem);
  letter-spacing: 0.06em;
  text-shadow: 1px 1px 0 #000, 0 0 12px rgba(232, 197, 106, 0.25);
}

.hud-row .stat,
.hud-row .spirit-points {
  padding: 0.1rem 0.2rem;
  background: rgba(10, 8, 6, 0.45);
  border: 1px solid rgba(58, 42, 28, 0.7);
}

.hud-row .gold { color: var(--gold); }
.hud-row .lives { color: #ff7a6a; }
.hud-row .wave { color: var(--mist); }
.hud-row .income { color: var(--spirit); }

.spirit-points {
  color: var(--spirit);
  text-shadow: 1px 1px 0 #000;
}

.hint {
  margin: 0;
  font-size: clamp(0.22rem, 1.1vh, 0.28rem);
  line-height: 1.4;
  color: var(--muted);
  max-height: 1.5em;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.btn-fullscreen {
  flex: 0 0 auto;
  align-self: stretch;
  min-width: 2.6rem;
  padding: 0.25rem 0.4rem;
  font-family: inherit;
  font-size: clamp(0.26rem, 1.25vh, 0.34rem);
  letter-spacing: 0.04em;
  color: var(--gold);
  background: rgba(26, 18, 14, 0.96);
  border: 2px solid #5a4030;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.btn-fullscreen[aria-pressed="true"],
.btn-fullscreen.is-active {
  border-color: var(--spirit);
  color: var(--spirit);
}

html.is-fullscreen #app,
html:fullscreen #app,
html:-webkit-full-screen #app {
  max-width: none;
  height: 100%;
  max-height: none;
}

html.is-fullscreen body,
html:fullscreen body,
html:-webkit-full-screen body {
  padding: 0;
  background: #0c0a08;
}

html.is-fullscreen #stage,
html:fullscreen #stage,
html:-webkit-full-screen #stage {
  gap: 0.15rem;
}

/* Home Screen / standalone: already chrome-free */
html.is-standalone body {
  padding:
    max(0.1rem, env(safe-area-inset-top))
    max(0.1rem, env(safe-area-inset-right))
    max(0.1rem, env(safe-area-inset-bottom))
    max(0.1rem, env(safe-area-inset-left));
}

.rail {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 0.3rem;
  padding: 0.35rem;
  background: linear-gradient(180deg, #2a1c14, var(--panel));
  border: 3px solid var(--bark);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  align-content: start;
}

.meta-bar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.35rem;
  font-size: clamp(0.28rem, 1.3vh, 0.34rem);
}

.spirit-points {
  color: var(--spirit);
  text-shadow: 1px 1px 0 #000;
}

.meta-best {
  color: var(--muted);
}

.rail-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.2rem;
  position: relative;
  z-index: 2;
}

.rail-tab {
  font-family: inherit;
  font-size: clamp(0.28rem, 1.3vh, 0.34rem);
  padding: 0.4rem 0.25rem;
  min-height: 1.9rem;
  border: 2px solid var(--bark);
  background: #1a120e;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
  position: relative;
  z-index: 2;
}

.rail-tab.active {
  color: var(--gold);
  border-color: var(--spirit);
  box-shadow: inset 0 0 0 1px var(--spirit);
}

#tab-towers.active {
  color: #1a1008;
  background: var(--spirit);
  border-color: var(--spirit);
  box-shadow: none;
}

.rail-panel {
  min-height: 0;
  display: none !important;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0.25rem;
  overflow: hidden;
}

/* Only the active tab panel is shown. Do not rely on [hidden] alone —
   `.rail-panel { display: grid }` previously overrode it and both panels
   stayed in the rail, collapsing Shop to 0 height on phones. */
.rail-panel.is-open {
  display: grid !important;
}

.rail-panel[hidden] {
  display: none !important;
}

#panel-store {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.store-blurb {
  margin: 0;
  font-size: clamp(0.24rem, 1.1vh, 0.3rem);
  color: var(--muted);
  line-height: 1.4;
}

.meta-store {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: grid;
  gap: 0.2rem;
  align-content: start;
  touch-action: pan-y;
}

.meta-card {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "name buy"
    "desc buy"
    "lvl buy";
  column-gap: 0.35rem;
  row-gap: 0.08rem;
  align-items: center;
  padding: 0.35rem 0.4rem;
  border: 2px solid var(--bark);
  background: #1a120e;
  text-align: left;
  font-family: inherit;
  color: var(--paper);
  cursor: pointer;
  min-height: 2.4rem;
}

.meta-card:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.meta-card .name {
  grid-area: name;
  margin: 0;
  color: var(--gold);
  font-size: clamp(0.28rem, 1.25vh, 0.34rem);
}

.meta-card .desc {
  grid-area: desc;
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.24rem, 1.1vh, 0.3rem);
  line-height: 1.3;
}

.meta-card .lvl {
  grid-area: lvl;
  margin: 0;
  color: var(--spirit);
  font-size: clamp(0.24rem, 1.05vh, 0.28rem);
}

.meta-card .buy {
  grid-area: buy;
  margin: 0;
  color: var(--ember);
  font-size: clamp(0.26rem, 1.2vh, 0.32rem);
  white-space: nowrap;
}

.rail-label {
  font-size: clamp(0.3rem, 1.4vh, 0.38rem);
  color: var(--gold);
  text-shadow: 1px 1px 0 #000;
}

.map-picker {
  display: grid;
  gap: 0.25rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--bark);
}

.map-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.28rem;
  align-items: stretch;
}

#map-select {
  appearance: none;
  min-width: 0;
  border: 2px solid var(--bark);
  background: #1a120e;
  color: var(--paper);
  font-family: inherit;
  font-size: clamp(0.26rem, 1.2vh, 0.32rem);
  padding: 0.4rem 0.35rem;
  min-height: 2rem;
}

#map-select:disabled {
  opacity: 0.45;
}

#btn-map-random {
  min-height: 2rem;
  padding: 0.35rem 0.4rem;
  font-size: clamp(0.26rem, 1.2vh, 0.32rem);
}

.shop {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
  align-content: start;
  touch-action: pan-y;
  padding: 0.15rem 0;
}

.card {
  appearance: none;
  border: 2px solid var(--bark);
  border-left-width: 4px;
  border-left-color: var(--series-lane);
  background:
    linear-gradient(135deg, rgba(40, 28, 18, 0.5) 0%, transparent 42%),
    #1a120e;
  color: var(--paper);
  font-family: inherit;
  font-size: clamp(0.3rem, 1.4vh, 0.38rem);
  line-height: 1.35;
  text-align: left;
  padding: 0.4rem 0.45rem;
  cursor: pointer;
  min-height: 3.1rem;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas:
    "art name cost"
    "art blurb blurb";
  column-gap: 0.4rem;
  row-gap: 0.12rem;
  align-items: center;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}

.card[data-series="My Hero"] { border-left-color: var(--series-hero); }
.card[data-series="Demon Slayer"] { border-left-color: var(--series-slayer); }
.card[data-series="Attack on Titan"] { border-left-color: var(--series-aot); }
.card[data-series="Jujutsu Kaisen"] { border-left-color: var(--series-jjk); }
.card[data-series="Solo Leveling"] { border-left-color: var(--series-solo); }
.card[data-series="Lane Works"] { border-left-color: var(--series-lane); }

.card:hover,
.card:focus-visible {
  border-color: var(--gold);
  outline: none;
  transform: translateX(-2px);
}

.card.selected {
  border-color: var(--spirit);
  box-shadow:
    inset 0 0 0 1px var(--spirit),
    0 0 0 1px rgba(61, 184, 160, 0.25);
}

.card .art {
  grid-area: art;
  width: 36px;
  height: 36px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background:
    radial-gradient(circle at 40% 35%, rgba(232, 197, 106, 0.12), transparent 55%),
    #0c0a08;
  border: 1px solid var(--bark);
  flex-shrink: 0;
}

.card .art-endgame,
.card .art-model {
  width: 48px;
  height: 48px;
  object-fit: cover;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 0;
}

.card .art-model {
  object-fit: unset;
  background:
    linear-gradient(180deg, rgba(61, 184, 160, 0.08) 0%, transparent 42%),
    radial-gradient(circle at 50% 78%, rgba(232, 197, 106, 0.16), transparent 55%),
    #0c0a08;
}

.card .name {
  grid-area: name;
  color: var(--gold);
  margin: 0;
  display: block;
  align-self: end;
}

/* Hide series line; keep short blurb */
.card .meta:first-of-type {
  display: none;
}

.card .meta + .meta {
  grid-area: blurb;
  color: var(--muted);
  display: block;
  margin: 0;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  align-self: start;
}

.card .cost {
  grid-area: cost;
  color: var(--spirit);
  margin: 0;
  display: block;
  justify-self: end;
  align-self: end;
  font-size: 0.95em;
}

.sprite-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem;
  min-height: 1.4rem;
  padding-top: 0.2rem;
  border-top: 1px solid var(--bark);
}

.sprite-preview canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 28px;
  height: 28px;
  background: #120e0b;
  border: 1px solid var(--bark);
}

.sprite-preview .label {
  display: none;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.28rem;
}

button.primary,
button.ghost {
  font-family: inherit;
  font-size: clamp(0.28rem, 1.35vh, 0.36rem);
  padding: 0.45rem 0.35rem;
  border: 2px solid var(--bark);
  cursor: pointer;
  min-height: 2.1rem;
  -webkit-touch-callout: none;
}

button.primary {
  grid-column: 1 / -1;
  background: var(--ember);
  color: #1a1008;
  border-color: #ff8a60;
}

button.primary:disabled,
button.ghost:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.ghost {
  background: #1a120e;
  color: var(--paper);
}

button.ghost:not(:disabled):hover {
  border-color: var(--gold);
}

#btn-save-offline,
#btn-new-run {
  grid-column: 1 / -1;
}

#btn-save-offline {
  border-color: var(--spirit);
  color: var(--spirit);
}

#btn-new-run {
  border-color: var(--gold);
  color: var(--gold);
}

.offline-tip {
  margin: 0.35rem 0 0;
  font-size: clamp(0.26rem, 1.15vh, 0.32rem);
  color: var(--muted);
  line-height: 1.45;
}

.offline-tip.is-local {
  color: var(--spirit);
}

/* Edge arrows float on the map — do not steal layout width */
.edge-tabs {
  position: absolute;
  right: max(0.25rem, env(safe-area-inset-right));
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.35rem;
  z-index: 6;
  animation: tabs-in 0.5s ease-out 0.1s both;
}

@keyframes tabs-in {
  from {
    opacity: 0;
    transform: translateY(-50%) translateX(10px);
  }
  to {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
  }
}

.edge-tab {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.18rem;
  min-width: 2.7rem;
  min-height: 3.6rem;
  padding: 0.35rem 0.28rem;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: inherit;
  font-size: clamp(0.3rem, 1.4vh, 0.38rem);
  letter-spacing: 0.08em;
  color: var(--paper);
  background:
    linear-gradient(180deg, rgba(42, 28, 18, 0.96), rgba(18, 12, 8, 0.96));
  border: 2px solid #5a4030;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow:
    0 6px 16px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(232, 197, 106, 0.1);
  transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
}

.edge-tab .edge-glyph {
  writing-mode: horizontal-tb;
  color: var(--gold);
  font-size: 0.55rem;
  line-height: 1;
  opacity: 0.9;
}

.edge-tab .edge-arrow {
  writing-mode: horizontal-tb;
  transform: none;
  color: var(--spirit);
  font-size: 0.8rem;
  line-height: 1;
}

.edge-tab:hover,
.edge-tab:focus-visible {
  border-color: var(--gold);
  outline: none;
}

.edge-tab.is-open {
  border-color: var(--spirit);
  color: var(--gold);
  background:
    linear-gradient(180deg, rgba(48, 36, 22, 0.98), rgba(28, 20, 14, 0.98));
  box-shadow:
    0 6px 16px rgba(0, 0, 0, 0.45),
    inset 0 0 0 1px rgba(61, 184, 160, 0.35);
}

.edge-tab.is-open .edge-arrow,
.edge-tab.is-open .edge-glyph {
  color: var(--gold);
}

.float-ready {
  position: absolute;
  left: 50%;
  bottom: max(0.4rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 6;
  min-width: min(14rem, 70vw);
  min-height: 2.5rem;
  padding: 0.5rem 0.9rem;
  font-family: inherit;
  font-size: clamp(0.34rem, 1.55vh, 0.44rem);
  letter-spacing: 0.04em;
  border: 2px solid #ff9a70;
  background:
    linear-gradient(180deg, #ff7a52 0%, var(--ember) 55%, #c44028 100%);
  color: #1a1008;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow:
    0 8px 20px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  animation: ready-in 0.5s ease-out 0.15s both;
  transition: filter 0.12s ease, transform 0.12s ease;
}

@keyframes ready-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes ready-pulse {
  0%, 100% {
    box-shadow:
      0 8px 20px rgba(0, 0, 0, 0.45),
      inset 0 1px 0 rgba(255, 255, 255, 0.25),
      0 0 0 0 rgba(232, 93, 60, 0.45);
  }
  50% {
    box-shadow:
      0 8px 20px rgba(0, 0, 0, 0.45),
      inset 0 1px 0 rgba(255, 255, 255, 0.25),
      0 0 0 6px rgba(232, 93, 60, 0);
  }
}

.float-ready:not(:disabled) {
  animation: ready-in 0.5s ease-out 0.15s both, ready-pulse 2.2s ease-in-out 0.7s infinite;
}

.float-ready:not(:disabled):hover {
  filter: brightness(1.06);
}

.float-ready:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  animation: none;
  filter: grayscale(0.25);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(8, 6, 4, 0.58);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.drawer-backdrop.is-open {
  opacity: 1;
}

.drawer-backdrop[hidden] {
  display: none !important;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  width: min(22rem, 88vw);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding:
    max(0.75rem, env(safe-area-inset-top))
    max(0.75rem, env(safe-area-inset-right))
    max(0.75rem, env(safe-area-inset-bottom))
    0.75rem;
  background:
    linear-gradient(180deg, #322218 0%, #1c140e 38%, #120e0b 100%);
  border-left: 3px solid var(--spirit);
  box-shadow: -16px 0 48px rgba(0, 0, 0, 0.6);
  color: var(--paper);
  overflow: hidden;
  transform: translateX(104%);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.drawer.is-open {
  transform: translateX(0);
}

.drawer[hidden] {
  display: none !important;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.drawer-head h2 {
  margin: 0;
  font-size: clamp(0.55rem, 2.4vh, 0.7rem);
  color: var(--gold);
  letter-spacing: 0.04em;
}

.drawer-close {
  font-family: inherit;
  font-size: 1.1rem;
  line-height: 1;
  min-width: 2.4rem;
  min-height: 2.4rem;
  border: 2px solid var(--spirit);
  background: #120e0b;
  color: var(--spirit);
  cursor: pointer;
  touch-action: manipulation;
}

.drawer-blurb {
  margin: 0;
  font-size: clamp(0.3rem, 1.35vh, 0.38rem);
  color: var(--muted);
  line-height: 1.45;
}

.drawer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.drawer-actions-stack {
  grid-template-columns: 1fr;
}

.drawer-actions .ghost {
  min-height: 2.6rem;
}

#drawer-shop .meta-store {
  flex: 1 1 auto;
  min-height: 0;
}

#drawer-unit .shop {
  flex: 1 1 auto;
  min-height: 0;
}

#drawer-unit .drawer-actions {
  margin-top: 0.15rem;
}

.offline-sheet {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  background: rgba(8, 6, 4, 0.72);
}

.offline-sheet[hidden] {
  display: none !important;
}

.offline-sheet-card {
  width: min(26rem, 100%);
  background: #1a120e;
  border: 2px solid var(--spirit);
  color: var(--paper);
  padding: 0.85rem 0.9rem 0.75rem;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.45);
}

.offline-sheet-card h2 {
  margin: 0 0 0.45rem;
  font-size: clamp(0.42rem, 2.1vh, 0.55rem);
  color: var(--gold);
  line-height: 1.35;
}

.offline-sheet-card p,
.offline-steps {
  margin: 0 0 0.55rem;
  font-size: clamp(0.3rem, 1.35vh, 0.38rem);
  color: var(--muted);
  line-height: 1.45;
}

.offline-steps {
  padding-left: 1.1rem;
}

.offline-steps li + li {
  margin-top: 0.35rem;
}

.offline-steps strong,
.offline-steps em {
  color: var(--paper);
  font-style: normal;
}

.offline-sheet-card code {
  color: var(--spirit);
  font-family: inherit;
}

.offline-sheet-actions {
  display: grid;
  gap: 0.35rem;
}

.offline-sheet-actions .primary,
.offline-sheet-actions .ghost {
  width: 100%;
  min-height: 2.3rem;
}

/* Portrait: map still fills; edge tabs become a bottom strip */
@media (orientation: portrait) and (max-width: 900px) {
  .edge-tabs {
    top: auto;
    right: 0;
    left: 0;
    bottom: 3.4rem;
    transform: none;
    flex-direction: row;
    padding: 0 0.35rem;
    gap: 0.3rem;
    animation: none;
  }

  .edge-tab {
    writing-mode: horizontal-tb;
    transform: none;
    min-width: 0;
    min-height: 2.6rem;
    flex: 1;
    grid-template-columns: auto auto auto;
    justify-content: center;
  }

  .float-ready {
    bottom: max(0.25rem, env(safe-area-inset-bottom));
    min-width: min(16rem, 92vw);
  }

  .drawer {
    width: 100%;
    max-height: min(78vh, 34rem);
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    border-left: none;
    border-top: 3px solid var(--spirit);
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.55);
    transform: translateY(104%);
  }

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

  .shop {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 900px) {
  #frame {
    border-width: 3px;
  }
}
