:root {
  --bg-page: #0f172a;
  --panel-bg: rgba(15, 23, 42, 0.88);
  --panel-border: #f8fafc;
  --accent: #f59e0b;
  --accent-pink: #f472b6;
  --accent-cyan: #38bdf8;
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --font-pixel: 'DotGothic16', 'Press Start 2P', 'Hiragino Kaku Gothic ProN', monospace;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #1e293b 0%, #0b1120 75%);
  color: var(--text-main);
  font-family: var(--font-pixel);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.app-shell {
  width: 100%;
  max-width: 980px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Top Toolbar */
.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(15, 23, 42, 0.82);
  border: 2px solid #334155;
  box-shadow: 0 4px 0 #020617;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  letter-spacing: 0.06em;
  color: #fde047;
  text-shadow: 2px 2px 0 #7c2d12;
}

.brand-sub {
  font-size: 11px;
  color: #94a3b8;
  text-shadow: none;
}

.toolbar-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-btn {
  font-family: var(--font-pixel);
  font-size: 12px;
  padding: 5px 10px;
  color: #f8fafc;
  background: #1e293b;
  border: 2px solid #64748b;
  box-shadow: 0 2px 0 #020617;
  cursor: pointer;
  transition: transform 0.06s, background 0.12s;
}

.mini-btn:hover {
  background: #334155;
}

.mini-btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

/* =====================================================
   GAME STAGE (Generated Image + SVG Layers + Pixel Canvas)
   ===================================================== */
.game-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #020617;
  border: 4px solid #f8fafc;
  box-shadow:
    0 0 0 4px #1e293b,
    0 12px 32px rgba(0, 0, 0, 0.65);
  overflow: hidden;
  touch-action: manipulation;
}

/* Layer 0: Generated Pixel-Art Distant Skyline Images */
.bg-sky-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg-sky-track {
  position: absolute;
  top: 0;
  left: 0;
  width: 300%;
  height: 86%;
  display: flex;
  will-change: transform, opacity;
  transition: opacity 0.25s linear;
}

.bg-sky-tile {
  width: calc(100% / 3);
  height: 100%;
  object-fit: cover;
  object-position: center bottom;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

.bg-sky-tile.mirrored {
  transform: scaleX(-1);
}

.bg-sky-sunset,
.bg-sky-night {
  opacity: 0;
}

/* Layer 1 & 2: Procedural Pixel-Art SVG City Parallax Layers */
.svg-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  shape-rendering: crispEdges;
}

/* Theme-reactive SVG palette: DAY */
.game-stage[data-theme='day'] .svg-viaduct { fill: #64748b; }
.game-stage[data-theme='day'] .svg-viaduct-rail { fill: #94a3b8; }
.game-stage[data-theme='day'] .svg-viaduct-pillar { fill: #475569; }
.game-stage[data-theme='day'] .svg-bldg-a { fill: #6b7fa3; }
.game-stage[data-theme='day'] .svg-bldg-a-shade { fill: #506385; }
.game-stage[data-theme='day'] .svg-bldg-b { fill: #8492b0; }
.game-stage[data-theme='day'] .svg-bldg-b-shade { fill: #657491; }
.game-stage[data-theme='day'] .svg-win-dark { fill: #3e4c66; }
.game-stage[data-theme='day'] .svg-win-lit-warm { fill: #bae6fd; }
.game-stage[data-theme='day'] .svg-win-lit-cool { fill: #e0f2fe; }
.game-stage[data-theme='day'] .svg-sign-frame { fill: #334155; }
.game-stage[data-theme='day'] .svg-neon-bg { opacity: 0.9; }
.game-stage[data-theme='day'] .svg-beacon { fill: #ef4444; }
.game-stage[data-theme='day'] .svg-train-body { fill: #f1f5f9; }
.game-stage[data-theme='day'] .svg-train-stripe { fill: #22c55e; }
.game-stage[data-theme='day'] .svg-train-win { fill: #38bdf8; }

.game-stage[data-theme='day'] .svg-shop-wall { fill: #f1e4d1; }
.game-stage[data-theme='day'] .svg-shop-roof { fill: #94a3b8; }
.game-stage[data-theme='day'] .svg-shop-window { fill: #7dd3fc; }
.game-stage[data-theme='day'] .svg-shop-door { fill: #78350f; }
.game-stage[data-theme='day'] .svg-vend-display { fill: #e0f2fe; }
.game-stage[data-theme='day'] .svg-tree-trunk { fill: #78350f; }
.game-stage[data-theme='day'] .svg-tree-leaf { fill: #15803d; }
.game-stage[data-theme='day'] .svg-tree-leaf-hi { fill: #22c55e; }
.game-stage[data-theme='day'] .svg-guardrail { fill: #f8fafc; }
.game-stage[data-theme='day'] .svg-guardrail-post { fill: #cbd5e1; }
.game-stage[data-theme='day'] .svg-pole { fill: #475569; }
.game-stage[data-theme='day'] .svg-pole-box { fill: #64748b; }
.game-stage[data-theme='day'] .svg-wire { stroke: #334155; opacity: 0.7; }
.game-stage[data-theme='day'] .svg-lamp-pole { fill: #475569; }
.game-stage[data-theme='day'] .svg-lamp-bulb { fill: #e2e8f0; }
.game-stage[data-theme='day'] .svg-lamp-glow { fill: #fef08a; opacity: 0; }

/* Theme-reactive SVG palette: SUNSET */
.game-stage[data-theme='sunset'] .svg-viaduct { fill: #4c2d4d; }
.game-stage[data-theme='sunset'] .svg-viaduct-rail { fill: #7c4565; }
.game-stage[data-theme='sunset'] .svg-viaduct-pillar { fill: #361e38; }
.game-stage[data-theme='sunset'] .svg-bldg-a { fill: #533154; }
.game-stage[data-theme='sunset'] .svg-bldg-a-shade { fill: #381e3b; }
.game-stage[data-theme='sunset'] .svg-bldg-b { fill: #6b3b5d; }
.game-stage[data-theme='sunset'] .svg-bldg-b-shade { fill: #4a2645; }
.game-stage[data-theme='sunset'] .svg-win-dark { fill: #2b172e; }
.game-stage[data-theme='sunset'] .svg-win-lit-warm { fill: #fde047; }
.game-stage[data-theme='sunset'] .svg-win-lit-cool { fill: #fdba74; }
.game-stage[data-theme='sunset'] .svg-sign-frame { fill: #29132c; }
.game-stage[data-theme='sunset'] .svg-neon-bg { opacity: 1; }
.game-stage[data-theme='sunset'] .svg-beacon { fill: #ff4d6d; }
.game-stage[data-theme='sunset'] .svg-train-body { fill: #6b3b5d; }
.game-stage[data-theme='sunset'] .svg-train-stripe { fill: #fb923c; }
.game-stage[data-theme='sunset'] .svg-train-win { fill: #fef08a; }

.game-stage[data-theme='sunset'] .svg-shop-wall { fill: #7c4a58; }
.game-stage[data-theme='sunset'] .svg-shop-roof { fill: #4a2638; }
.game-stage[data-theme='sunset'] .svg-shop-window { fill: #fde68a; }
.game-stage[data-theme='sunset'] .svg-shop-door { fill: #431c28; }
.game-stage[data-theme='sunset'] .svg-vend-display { fill: #fef3c7; }
.game-stage[data-theme='sunset'] .svg-tree-trunk { fill: #451a2b; }
.game-stage[data-theme='sunset'] .svg-tree-leaf { fill: #36493d; }
.game-stage[data-theme='sunset'] .svg-tree-leaf-hi { fill: #526e48; }
.game-stage[data-theme='sunset'] .svg-guardrail { fill: #d6a49c; }
.game-stage[data-theme='sunset'] .svg-guardrail-post { fill: #8c5a60; }
.game-stage[data-theme='sunset'] .svg-pole { fill: #2d1832; }
.game-stage[data-theme='sunset'] .svg-pole-box { fill: #43244a; }
.game-stage[data-theme='sunset'] .svg-wire { stroke: #241229; opacity: 0.85; }
.game-stage[data-theme='sunset'] .svg-lamp-pole { fill: #2d1832; }
.game-stage[data-theme='sunset'] .svg-lamp-bulb { fill: #fef08a; }
.game-stage[data-theme='sunset'] .svg-lamp-glow { fill: #fde047; opacity: 0.16; }

/* Theme-reactive SVG palette: NIGHT */
.game-stage[data-theme='night'] .svg-viaduct { fill: #182238; }
.game-stage[data-theme='night'] .svg-viaduct-rail { fill: #2c3e61; }
.game-stage[data-theme='night'] .svg-viaduct-pillar { fill: #0f172a; }
.game-stage[data-theme='night'] .svg-bldg-a { fill: #172038; }
.game-stage[data-theme='night'] .svg-bldg-a-shade { fill: #0e1526; }
.game-stage[data-theme='night'] .svg-bldg-b { fill: #1e2a4a; }
.game-stage[data-theme='night'] .svg-bldg-b-shade { fill: #131b33; }
.game-stage[data-theme='night'] .svg-win-dark { fill: #0c1222; }
.game-stage[data-theme='night'] .svg-win-lit-warm { fill: #fde047; }
.game-stage[data-theme='night'] .svg-win-lit-cool { fill: #67e8f9; }
.game-stage[data-theme='night'] .svg-sign-frame { fill: #090d1a; }
.game-stage[data-theme='night'] .svg-neon-bg { opacity: 1; }
.game-stage[data-theme='night'] .svg-beacon { fill: #ff3b5c; }
.game-stage[data-theme='night'] .svg-train-body { fill: #1e293b; }
.game-stage[data-theme='night'] .svg-train-stripe { fill: #38bdf8; }
.game-stage[data-theme='night'] .svg-train-win { fill: #fef08a; }

.game-stage[data-theme='night'] .svg-shop-wall { fill: #24304a; }
.game-stage[data-theme='night'] .svg-shop-roof { fill: #111827; }
.game-stage[data-theme='night'] .svg-shop-window { fill: #fde047; }
.game-stage[data-theme='night'] .svg-shop-door { fill: #0f172a; }
.game-stage[data-theme='night'] .svg-vend-display { fill: #e0f2fe; }
.game-stage[data-theme='night'] .svg-tree-trunk { fill: #1e1b2e; }
.game-stage[data-theme='night'] .svg-tree-leaf { fill: #143633; }
.game-stage[data-theme='night'] .svg-tree-leaf-hi { fill: #1e4d45; }
.game-stage[data-theme='night'] .svg-guardrail { fill: #64748b; }
.game-stage[data-theme='night'] .svg-guardrail-post { fill: #334155; }
.game-stage[data-theme='night'] .svg-pole { fill: #0f172a; }
.game-stage[data-theme='night'] .svg-pole-box { fill: #1e293b; }
.game-stage[data-theme='night'] .svg-wire { stroke: #090d18; opacity: 0.9; }
.game-stage[data-theme='night'] .svg-lamp-pole { fill: #0f172a; }
.game-stage[data-theme='night'] .svg-lamp-bulb { fill: #fef08a; }
.game-stage[data-theme='night'] .svg-lamp-glow { fill: #fef08a; opacity: 0.25; }

/* Layer 3: Pixel Art Gameplay Canvas */
#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
}

/* =====================================================
   HUD & TOUCH CONTROLS
   ===================================================== */
.hud-bar {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 10;
}

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

.hud-pill {
  background: rgba(15, 23, 42, 0.78);
  border: 2px solid #f8fafc;
  padding: 4px 10px;
  font-size: 14px;
  letter-spacing: 0.05em;
  box-shadow: 0 3px 0 rgba(2, 6, 23, 0.8);
}

.hud-pill .label {
  font-size: 10px;
  color: #94a3b8;
  margin-right: 5px;
}

.hud-pill.fish-pill {
  color: #7dd3fc;
  border-color: #38bdf8;
}

.hud-pill.hp-pill {
  border-color: #fb7185;
  letter-spacing: 0.12em;
  display: flex;
  align-items: center;
  gap: 2px;
}

.heart-full {
  color: #fb7185;
  text-shadow: 0 2px 0 #881337;
}

.heart-empty {
  color: #475569;
}

@keyframes hpShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.hp-pill.hp-hit {
  animation: hpShake 0.22s ease-in-out;
}

.hud-combo {
  background: #f59e0b;
  color: #0f172a;
  border: 2px solid #fef08a;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: bold;
  box-shadow: 0 3px 0 #78350f;
}

.hud-powerups {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pwr-badge {
  padding: 4px 8px;
  font-size: 12px;
  border: 2px solid #fff;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.7);
}
.pwr-star { background: #db2777; color: #fff; }
.pwr-magnet { background: #e11d48; color: #fff; }
.pwr-shield { background: #0284c7; color: #fff; }

.touch-controls {
  position: absolute;
  bottom: 12px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 10;
}

.touch-btn {
  pointer-events: auto;
  font-family: var(--font-pixel);
  font-size: 13px;
  padding: 9px 16px;
  color: #ffffff;
  background: rgba(15, 23, 42, 0.65);
  border: 2px solid rgba(248, 250, 252, 0.85);
  box-shadow: 0 3px 0 rgba(2, 6, 23, 0.8);
  cursor: pointer;
}

.touch-btn:active {
  transform: translateY(2px);
  background: rgba(56, 189, 248, 0.55);
}

/* =====================================================
   OVERLAYS (TITLE & GAME OVER)
   ===================================================== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.34);
  z-index: 20;
  padding: 16px;
}

.overlay-card {
  background: var(--panel-bg);
  border: 3px solid var(--panel-border);
  box-shadow:
    0 0 0 3px #0f172a,
    0 8px 0 rgba(2, 6, 23, 0.85);
  padding: 18px 24px;
  text-align: center;
  max-width: 500px;
  width: 100%;
}

.title-logo {
  margin: 0 0 4px;
  font-size: clamp(22px, 3.8vw, 32px);
  color: #fde047;
  text-shadow: 3px 3px 0 #b45309, -1px -1px 0 #0f172a;
  letter-spacing: 0.08em;
}

.title-jp {
  margin: 0 0 12px;
  font-size: 13px;
  color: #bae6fd;
}

.stats-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 14px;
  font-size: 13px;
}

.stat-chip {
  background: #1e293b;
  border: 2px solid #475569;
  padding: 4px 10px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
}

.pixel-btn {
  font-family: var(--font-pixel);
  font-size: 15px;
  padding: 10px 18px;
  border: 3px solid #ffffff;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 4px 0 #020617;
  transition: transform 0.06s, filter 0.1s;
}

.pixel-btn:hover {
  filter: brightness(1.1);
}

.pixel-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #020617;
}

.btn-primary {
  background: #ea580c;
  border-color: #fef08a;
}

.btn-closet {
  background: #db2777;
  border-color: #fbcfe8;
}

.btn-secondary {
  background: #334155;
  border-color: #cbd5e1;
}

.controls-hint {
  margin-top: 12px;
  font-size: 12px;
  color: #cbd5e1;
  line-height: 1.6;
}

.new-best-banner {
  display: inline-block;
  margin-bottom: 8px;
  padding: 3px 10px;
  background: #facc15;
  color: #0f172a;
  font-size: 12px;
  border: 2px solid #fff;
}

.go-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
  text-align: left;
}

.go-cell {
  background: #1e293b;
  border: 2px solid #475569;
  padding: 6px 10px;
  font-size: 12px;
}

.go-cell strong {
  display: block;
  font-size: 16px;
  color: #fde047;
  margin-top: 2px;
}

/* =====================================================
   DRESS-UP CLOSET MODAL
   ===================================================== */
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 12px;
}

.closet-window {
  width: 100%;
  max-width: 780px;
  max-height: 100%;
  background: #0f172a;
  border: 3px solid #f8fafc;
  box-shadow: 0 0 0 3px #1e293b, 0 10px 24px rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.closet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: #1e293b;
  border-bottom: 2px solid #475569;
}

.closet-title {
  font-size: 16px;
  color: #fbcfe8;
}

.closet-fish-wallet {
  background: #0f172a;
  border: 2px solid #38bdf8;
  color: #7dd3fc;
  padding: 3px 10px;
  font-size: 14px;
}

.closet-body {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 12px;
  padding: 12px;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.closet-preview-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#closet-preview-canvas {
  width: 152px;
  height: 120px;
  border: 3px solid #64748b;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #1e293b;
}

.closet-feedback {
  font-size: 11px;
  color: #fde047;
  text-align: center;
  min-height: 28px;
  line-height: 1.4;
}

.closet-shop-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.closet-tabs {
  display: flex;
  gap: 6px;
}

.tab-btn {
  flex: 1;
  font-family: var(--font-pixel);
  font-size: 13px;
  padding: 6px 4px;
  background: #1e293b;
  color: #cbd5e1;
  border: 2px solid #475569;
  cursor: pointer;
}

.tab-btn.active {
  background: #db2777;
  color: #ffffff;
  border-color: #fbcfe8;
}

.closet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  overflow-y: auto;
  padding-right: 4px;
  max-height: 250px;
}

.closet-card {
  font-family: var(--font-pixel);
  text-align: left;
  background: #1e293b;
  color: #f8fafc;
  border: 2px solid #475569;
  padding: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.1s, background 0.1s;
}

.closet-card:hover {
  border-color: #94a3b8;
  background: #283548;
}

.closet-card.is-equipped {
  border-color: #fde047;
  background: #3b2f1e;
}

.closet-card.cannot-afford {
  opacity: 0.72;
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
}

.card-name {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.fur-swatch {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 2px solid #000;
}

.item-badge {
  font-size: 10px;
  padding: 2px 5px;
  white-space: nowrap;
}

.badge-eq { background: #facc15; color: #0f172a; }
.badge-own { background: #334155; color: #e2e8f0; }
.badge-price { background: #0284c7; color: #fff; }

.card-desc {
  font-size: 11px;
  color: #cbd5e1;
  line-height: 1.35;
}

.item-bonus {
  font-size: 10px;
  color: #f9a8d4;
}

/* Legend bar below game stage */
.info-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(15, 23, 42, 0.75);
  border: 2px solid #334155;
  font-size: 12px;
  color: #cbd5e1;
}

.item-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.hidden {
  display: none !important;
}

@media (max-width: 700px) {
  .closet-body {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  .closet-preview-col {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }
  .hud-pill {
    font-size: 12px;
    padding: 3px 7px;
  }
  .overlay-card {
    padding: 12px 14px;
  }
}
