:root {
  --bg: #120f14;
  --bg2: #1b1820;
  --panel: #ece4d6;
  --panel-2: #d7ccb9;
  --panel-3: #b9ab95;
  --ink: #241f22;
  --muted: #615755;
  --gold: #f0c868;
  --ember: #c96d59;
  --sage: #7fa17d;
  --pine: #345348;
  --sky: #c7d0df;
  --void: #0c0a10;
  --line: #201b1d;
  --pixel-shadow: 0 10px 0 rgba(0, 0, 0, 0.16);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Nunito", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(240, 200, 104, 0.18), transparent 18%),
    radial-gradient(circle at top right, rgba(127, 161, 125, 0.14), transparent 16%),
    linear-gradient(180deg, #15121a, #0d0c10 70%);
}

button {
  font: inherit;
}

.game-shell {
  width: min(100vw, 1440px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 1rem;
}

.hud-bar,
.pixel-panel,
.game-screen,
.battle-box {
  border: 4px solid var(--line);
  box-shadow: var(--pixel-shadow);
}

.hud-bar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1rem 1.25rem;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
}

.hud-brand h1,
.panel-header h3,
.pixel-panel h2,
.pixel-panel h3,
.screen-header h2,
.battle-name {
  margin: 0;
  font-family: "Press Start 2P", monospace;
  line-height: 1.3;
}

.hud-brand h1 {
  font-size: clamp(1rem, 1.6vw, 1.35rem);
}

.build-stamp {
  margin: 0.45rem 0 0;
  font-family: "Press Start 2P", monospace;
  font-size: 0.42rem;
  color: rgba(36, 31, 34, 0.56);
  letter-spacing: 0.06em;
}

.hud-label,
.panel-tag,
.hud-key {
  margin: 0 0 0.45rem;
  font-family: "Press Start 2P", monospace;
  font-size: 0.58rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--pine);
}

.hud-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  width: min(56rem, 100%);
}

.hud-pill {
  padding: 0.75rem;
  background: rgba(255, 249, 240, 0.72);
  border: 3px solid var(--line);
}

.hud-pill strong {
  display: block;
  font-size: 0.95rem;
}

.game-viewport {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 300px;
  gap: 1rem;
  margin-top: 1rem;
}

.viewport-column,
.game-screen-wrap {
  display: grid;
  gap: 1rem;
}

.pixel-panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  padding: 1rem;
}

.panel-copy,
.small-copy,
.room-story-box p,
.battle-status,
.battle-stats {
  margin: 0.55rem 0 0;
  line-height: 1.6;
  color: var(--muted);
}

.panel-actions,
.screen-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 0.8rem;
}

.screen-controls {
  width: fit-content;
  padding: 0.65rem;
  background: rgba(255, 249, 239, 0.9);
  border: 4px solid var(--line);
  box-shadow: var(--pixel-shadow);
  position: relative;
  z-index: 2;
}

.game-button,
.choice-button,
.nav-button,
.switch-button,
.map-tile,
.move-button {
  border: 3px solid var(--line);
  cursor: pointer;
  transition: transform 120ms steps(2);
}

.game-button:hover,
.choice-button:hover,
.nav-button:hover,
.switch-button:hover,
.map-tile:hover,
.move-button:hover {
  transform: translate(-2px, -2px);
}

.game-button {
  padding: 0.8rem 1rem;
  font-family: "Press Start 2P", monospace;
  font-size: 0.64rem;
  color: #fff7ef;
  background: var(--pine);
}

.game-button.gold {
  background: #b7892c;
}

.game-button.ember {
  background: var(--ember);
}

.game-button.slate {
  background: #716d74;
}

.panel-chip,
.screen-reward {
  display: inline-block;
  padding: 0.4rem 0.6rem;
  border: 3px solid var(--line);
  background: rgba(255, 248, 236, 0.8);
  font-size: 0.8rem;
}

.map-grid {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.9rem;
}

.building-stack {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.9rem;
}

.nav-shell {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 3px solid rgba(36, 31, 34, 0.18);
}

.nav-shell .panel-tag {
  margin-bottom: 0.65rem;
}

.floor-strip {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem 0.7rem;
  align-items: center;
  padding: 0.5rem;
  border: 3px solid var(--line);
  background: rgba(255, 248, 236, 0.82);
}

.floor-strip.is-current {
  background: rgba(240, 200, 104, 0.25);
}

.floor-strip.is-floor-locked {
  background: rgba(150, 140, 132, 0.28);
}

.floor-strip-label {
  font-family: "Press Start 2P", monospace;
  font-size: 0.58rem;
}

.floor-strip-grid {
  display: grid;
  gap: 0.2rem;
}

.mini-tile {
  min-width: 0.95rem;
  min-height: 0.95rem;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  background: #cfc4b1;
  font-family: "Press Start 2P", monospace;
  font-size: 0.38rem;
  cursor: pointer;
}

.mini-tile.is-visited {
  background: #d8d3b2;
}

.mini-tile.is-active {
  background: var(--gold);
}

.mini-tile.is-locked {
  background: #9a8f86;
  color: #f6efe3;
}

.mini-tile.is-empty {
  opacity: 0.15;
}

.mini-tile.is-neighbor,
.map-tile.is-neighbor {
  box-shadow: inset 0 0 0 3px rgba(183, 137, 44, 0.45);
}

.floor-strip-note {
  grid-column: 2;
  margin: 0;
  font-size: 0.76rem;
  color: var(--muted);
}

.map-tile {
  min-height: 3rem;
  background: #cfc4b1;
  font-family: "Press Start 2P", monospace;
  font-size: 0.72rem;
  cursor: pointer;
}

.map-tile.is-visited {
  background: #d8d3b2;
}

.map-tile.is-active {
  background: var(--gold);
}

.map-tile.is-locked {
  background: #9a8f86;
  color: #f6efe3;
}

.map-tile.is-empty,
.map-tile:disabled,
.mini-tile:disabled {
  cursor: default;
  transform: none;
}

.map-tile.is-empty {
  opacity: 0.2;
}

.nav-grid,
.switch-panel,
.move-grid {
  display: grid;
  gap: 0.6rem;
}

.screen-nav-grid {
  margin-top: 0.45rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.move-retreat-button {
  justify-self: end;
}

.switch-button {
  padding: 0.75rem;
  background: rgba(255, 248, 236, 0.84);
  text-align: left;
}

.switch-button.is-selected,
.choice-button.is-selected {
  background: linear-gradient(180deg, var(--gold), #d79f3d);
}

.game-screen-wrap {
  min-width: 0;
}

.screen-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: flex-start;
  padding: 1rem;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 4px solid var(--line);
  box-shadow: var(--pixel-shadow);
}

.screen-header h2 {
  font-size: clamp(1rem, 2vw, 1.55rem);
  line-height: 1.15;
  word-break: break-word;
}

.screen-meta {
  display: grid;
  gap: 0.5rem;
  justify-items: end;
  align-content: start;
}

.game-screen {
  position: relative;
  min-height: 42rem;
  overflow: hidden;
  background: linear-gradient(180deg, #f7efe1, #d8ccb9);
}

.screen-overlay {
  position: relative;
  z-index: 2;
  padding: 1rem;
  min-height: 42rem;
}

.screen-overworld {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: 100%;
}

.overworld-banner {
  padding: 0.85rem 1rem;
  background: rgba(255, 249, 239, 0.86);
  border: 4px solid var(--line);
}

.overworld-grid-shell {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 0.4rem;
  border: 4px solid var(--line);
  background:
    linear-gradient(180deg, #dde5f1 0 58%, #f1eadc 58% 100%);
}

.overworld-grid {
  width: 100%;
  max-width: 46rem;
  display: grid;
  gap: 0.2rem;
  aspect-ratio: 2 / 1;
  padding: 0.5rem;
  border: 4px solid var(--line);
  background: linear-gradient(180deg, #cabca8, #b3a28b);
}

.overworld-tile {
  position: relative;
  border: 1px solid rgba(32, 27, 29, 0.16);
  background: #e8decd;
}

.overworld-tile.is-floor,
.overworld-tile.is-path,
.overworld-tile.is-threshold {
  background: #efe6d8;
}

.overworld-tile.is-wall {
  background: #71635b;
}

.overworld-tile.is-obstacle {
  background: #9b8670;
}

.overworld-tile.is-stair,
.overworld-tile.is-lift {
  background: #d5c497;
}

.overworld-tile[class*="is-exit-"] {
  background: #e4c567;
}

.overworld-tile.has-player {
  display: grid;
  place-items: center;
}

.player-token {
  width: 60%;
  height: 60%;
  border: 2px solid var(--line);
  background: #241f22;
  clip-path: polygon(18% 20%, 34% 0, 46% 20%, 54% 20%, 66% 0, 82% 20%, 82% 80%, 18% 80%);
}

.player-token.is-xena {
  background: linear-gradient(135deg, #241f22 0 65%, #d1b07a 65% 100%);
}

.player-token.is-little-one {
  background: linear-gradient(135deg, #6e727d 0 62%, #f0ece5 62% 100%);
}

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

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 4.3rem);
  grid-template-rows: repeat(3, 3.4rem);
  gap: 0.35rem;
}

.move-pad {
  border: 3px solid var(--line);
  background: rgba(255, 248, 236, 0.92);
  font-family: "Press Start 2P", monospace;
  font-size: 0.56rem;
  cursor: pointer;
}

.move-up {
  grid-column: 2;
}

.move-left {
  grid-column: 1;
  grid-row: 2;
}

.move-down {
  grid-column: 2;
  grid-row: 2;
}

.move-right {
  grid-column: 3;
  grid-row: 2;
}

.overworld-hint {
  padding: 0.85rem 1rem;
  border: 4px solid var(--line);
  background: rgba(255, 249, 239, 0.9);
}

.battle-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: block;
  background:
    linear-gradient(180deg, rgba(245, 237, 222, 0.18), rgba(245, 237, 222, 0.06));
}

.battle-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, #dfe7f5 0 56%, #efe3c4 56% 100%);
}

.battle-stage::before {
  content: "";
  position: absolute;
  inset: 56% 0 0;
  background:
    radial-gradient(circle at 28% 22%, rgba(255, 255, 255, 0.34), transparent 16%),
    radial-gradient(circle at 78% 20%, rgba(255, 255, 255, 0.2), transparent 12%),
    linear-gradient(180deg, #e7d7ae, #d2bc8a);
}

.battle-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 20%),
    linear-gradient(0deg, rgba(50, 34, 19, 0.05), transparent 24%);
  pointer-events: none;
}

.battle-sprites {
  position: absolute;
  inset: 0;
}

.battle-platform {
  position: absolute;
  display: grid;
  place-items: center;
  aspect-ratio: 1.65;
  border-radius: 50%;
  border: 4px solid var(--line);
  background:
    radial-gradient(circle at 50% 40%, #faf4e8, #d9c6ab 78%);
}

.enemy-platform {
  top: 3.5rem;
  left: 4.5rem;
  width: 26%;
}

.player-platform {
  right: 4.5rem;
  bottom: 18rem;
  width: 34%;
}

.battle-sprite {
  --pixel-size: 6px;
  image-rendering: pixelated;
  transform-origin: center bottom;
}

.enemy-sprite {
  --pixel-size: 5px;
}

.player-sprite {
  --pixel-size: 8px;
  transform: scaleX(-1);
}

.pixel-sprite {
  position: relative;
  width: calc(var(--sprite-width) * var(--pixel-size));
  height: calc(var(--sprite-height) * var(--pixel-size));
}

.pixel {
  position: absolute;
  width: var(--pixel-size);
  height: var(--pixel-size);
}

.battle-hud-shell {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.battle-box {
  position: absolute;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  padding: 0.9rem 1rem;
  width: min(25rem, 44%);
  pointer-events: auto;
}

.enemy-box {
  top: 1.25rem;
  right: 1.25rem;
}

.player-box {
  left: 1.25rem;
  bottom: 0.35rem;
}

.battle-message-shell {
  position: absolute;
  left: 50%;
  bottom: 14.75rem;
  transform: translateX(-50%);
  width: min(35rem, calc(100% - 4rem));
  padding: 0.7rem 0.8rem;
  border: 4px solid var(--line);
  background: linear-gradient(180deg, rgba(245, 239, 226, 0.98), rgba(226, 214, 190, 0.98));
  box-shadow: var(--pixel-shadow);
  pointer-events: auto;
}

.battle-message-current {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--ink);
}

.battle-history {
  margin-top: 0.55rem;
  border-top: 2px solid rgba(32, 27, 29, 0.16);
  padding-top: 0.45rem;
}

.battle-history summary {
  cursor: pointer;
  font-family: "Press Start 2P", monospace;
  font-size: 0.52rem;
  color: var(--pine);
  list-style: none;
}

.battle-history summary::-webkit-details-marker {
  display: none;
}

.battle-history-log {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.45rem;
  max-height: 8rem;
  overflow: auto;
}

.battle-history-log p {
  margin: 0;
  padding: 0.55rem 0.65rem;
  border: 2px solid var(--line);
  background: rgba(255, 248, 236, 0.9);
  font-size: 0.82rem;
  line-height: 1.45;
}

.battle-box-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

.battle-name {
  font-size: 0.9rem;
}

.battle-meta {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.hp-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.55rem;
  align-items: center;
  margin-top: 0.7rem;
  font-family: "Press Start 2P", monospace;
  font-size: 0.58rem;
}

.hp-bar {
  height: 0.95rem;
  border: 3px solid var(--line);
  background: #cfc7b6;
}

.hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #7fba69, #d7e067);
}

.enemy-fill {
  background: linear-gradient(90deg, #c56a55, #efbb59);
}

.move-panel .move-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.move-button {
  display: grid;
  gap: 0.35rem;
  padding: 0.9rem;
  background: rgba(255, 249, 240, 0.95);
  text-align: left;
}

.move-button strong {
  font-family: "Press Start 2P", monospace;
  font-size: 0.62rem;
}

.move-button span,
.battle-note {
  font-size: 0.82rem;
  color: var(--muted);
}

.move-button:disabled {
  opacity: 0.6;
  cursor: default;
  transform: none;
}

.combat-log {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.combat-log p,
.battle-note,
.info-note {
  margin: 0;
  padding: 0.75rem;
  border: 3px solid var(--line);
  background: rgba(255, 248, 236, 0.84);
}

.pixel-list {
  margin: 0.7rem 0 0;
  padding-left: 1.2rem;
}

.pixel-list li + li {
  margin-top: 0.35rem;
}

.choice-buttons {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.8rem;
}

.choice-button {
  padding: 0.8rem;
  background: rgba(255, 249, 240, 0.95);
  text-align: left;
  font-family: "Press Start 2P", monospace;
  font-size: 0.58rem;
}

.subtag {
  margin-top: 1rem;
}

.is-attacking {
  animation: hop 220ms steps(2);
}

.is-hit {
  animation: shake 220ms steps(2), flash 220ms linear;
}

.is-miss {
  animation: miss 260ms steps(2);
}

.is-charge {
  animation: charge 320ms steps(2);
}

.is-defeat {
  animation: flash 340ms linear 2;
}

@keyframes hop {
  0% { transform: translateX(0) translateY(0); }
  50% { transform: translateX(8px) translateY(-10px); }
  100% { transform: translateX(0) translateY(0); }
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
  100% { transform: translateX(0); }
}

@keyframes miss {
  0% { transform: translateX(0); }
  30% { transform: translateX(8px); }
  65% { transform: translateX(-8px); }
  100% { transform: translateX(0); }
}

@keyframes charge {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  80% { transform: scale(0.97); }
  100% { transform: scale(1); }
}

@keyframes flash {
  0%, 100% { filter: brightness(1); opacity: 1; }
  50% { filter: brightness(1.85); opacity: 0.6; }
}

@media (max-width: 1200px) {
  .game-viewport {
    grid-template-columns: 1fr;
  }

  .hud-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .battle-hud-shell {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .game-shell {
    padding: 0.6rem;
  }

  .hud-bar,
  .screen-header {
    grid-template-columns: 1fr;
    display: grid;
  }

  .move-panel .move-grid {
    grid-template-columns: 1fr;
  }

  .battle-platform {
    width: 42%;
  }

  .battle-sprite {
    --pixel-size: 5px;
  }
}
