/* Monster Legends · Retro — SNES chrome, layered so chrome never covers gameplay:
   HUD (top) / canvas (middle) / controls (bottom). Canvas fills the middle. */
:root {
  --ink: #241812;
  --cream: #f7e8c8;
  --panel: #3a2a1a;
  --gold: #e0b23c;
  --hp: #43b98a;
  --hp-bad: #d93a2b;
  --accent: #2ba8a0;
  --frame: #1a1209;
  --font: 'Press Start 2P', monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
html, body { height: 100%; margin: 0; background: #0d1520; overflow: hidden; }
body {
  font-family: var(--font);
  color: var(--cream);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- CRT overlay (CSS only; toggleable) ---------- */
#crt {
  position: fixed; inset: 0; pointer-events: none; z-index: 40;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.16) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 62%, rgba(0,0,0,.38) 100%);
  display: none;
}
body.crt-on #crt { display: block; }

/* ---------- stage: flex column, chrome outside the canvas ---------- */
#stage {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background:
    linear-gradient(180deg, #101a26 0%, #0d1520 100%);
}

/* HUD — top bar, its own row */
#hud {
  flex: 0 0 auto;
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; align-items: center;
  padding: max(8px, env(safe-area-inset-top)) 8px 8px;
}
.chip {
  display: flex; align-items: center; gap: 5px;
  background: rgba(26, 18, 9, .92); border: 2px solid var(--cream); border-radius: 2px;
  padding: 4px 7px; font-size: 9px; white-space: nowrap;
}
.chip canvas { width: 14px; height: 14px; image-rendering: pixelated; }
.chip.lvl { border-color: var(--gold); }

/* Canvas — gets ALL middle space; Phaser FIT letterboxes inside this box */
#canvas-wrap {
  flex: 1 1 auto; min-height: 0; position: relative;
  display: flex; align-items: center; justify-content: center;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.02) 0 6px, transparent 6px 12px),
    linear-gradient(180deg, #14202e 0%, #0d1520 100%);
}
#game {
  display: block;
  margin: 0 !important; /* Phaser NO_CENTER leaves margins alone; flexbox centers */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  box-shadow: 0 0 0 4px #000, 0 0 0 8px #3a2a1a, 0 0 0 10px #1a1209;
  max-width: 100%;
  max-height: 100%;
}

#loading {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  background: #101820; z-index: 30; text-align: center;
}
#loading.hidden { display: none; }
.load-title { font-size: clamp(16px, 4vw, 34px); color: var(--cream); letter-spacing: 2px; text-shadow: 0 4px 0 #000; }
.load-sub { font-size: clamp(9px, 2.2vw, 16px); color: var(--gold); }
.load-bar { width: min(280px, 70vw); height: 12px; border: 3px solid var(--cream); background: #000; }
.load-fill { height: 100%; width: 0%; background: var(--accent); transition: width .3s; }
.load-tip { font-size: 9px; color: #9aa2ab; }

/* ---------- footer: controls get their own rows below the canvas ---------- */
#footer {
  flex: 0 0 auto;
  display: flex; flex-direction: column; gap: 8px;
  padding: 8px max(8px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: linear-gradient(180deg, rgba(16,22,32,.0), rgba(16,22,32,.9) 30%);
  border-top: 3px solid #000;
}

.btn {
  font-family: var(--font);
  font-size: 11px;
  color: var(--cream);
  background: var(--panel);
  border: 3px solid var(--frame);
  outline: 2px solid var(--cream);
  padding: 10px 12px;
  border-radius: 2px;
  cursor: pointer;
  min-height: 44px;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.4);
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.primary { background: #24514b; }
.btn.gold { color: #241812; background: var(--gold); }
.btn.small { font-size: 9px; padding: 6px 8px; min-height: 36px; }
.btn:disabled { opacity: .45; }

/* Tabs (bottom) */
#tabs {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; max-width: 100%;
}

/* Battle controls — in the footer, below the canvas */
#battle-ui { display: flex; flex-direction: column; gap: 8px; }
#battle-ui.hidden { display: none; }
#battle-log {
  width: min(96vw, 760px); margin: 0 auto;
  max-height: 16vh; overflow-y: auto;
  background: rgba(26,18,9,.85); border: 2px solid var(--cream); border-radius: 2px;
  padding: 6px 8px; font-size: 9px; line-height: 1.7; word-wrap: anywhere;
  display: none;
}
#battle-log.visible { display: block; }
#battle-skills {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: min(96vw, 760px);
  margin: 0 auto;
}
#battle-skills .btn { min-height: 52px; font-size: 10px; text-align: left; line-height: 1.5; }
#battle-skills .btn .cd { color: var(--gold); }
.battle-row { display: flex; justify-content: center; }

/* Modals — overlay on top of everything (they are meant to cover) */
#modal-root { position: absolute; inset: 0; z-index: 50; pointer-events: none; }
#modal-root > * { pointer-events: auto; }
.modal-back {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, .62);
  display: flex; align-items: center; justify-content: 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));
}
.modal {
  background: var(--cream); color: var(--ink);
  border: 4px solid var(--frame);
  outline: 3px solid var(--panel);
  max-width: min(92vw, 560px);
  max-height: 88vh;
  width: 100%;
  display: flex; flex-direction: column;
  border-radius: 3px;
  overflow: hidden;
}
.modal-head {
  background: var(--panel); color: var(--cream);
  padding: 10px 12px; font-size: 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.modal-head .x { cursor: pointer; font-size: 14px; padding: 4px 8px; }
.modal-body { padding: 12px; overflow-y: auto; font-size: 10px; line-height: 1.8; }
.modal-foot { padding: 8px 12px; border-top: 3px solid var(--panel); display: flex; gap: 8px; flex-wrap: wrap; }

/* Lists & cards */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card {
  background: #fff8e6; border: 3px solid var(--ink); border-radius: 2px;
  padding: 8px; display: flex; flex-direction: column; gap: 4px; align-items: center;
  width: 96px; cursor: pointer; position: relative;
}
.card.locked { filter: grayscale(1) brightness(.65); }
.card canvas { width: 64px; height: 64px; image-rendering: pixelated; }
.card .nm { font-size: 8px; text-align: center; line-height: 1.5; min-height: 24px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; justify-items: center; }
.card.sel { outline: 4px solid var(--gold); }

.badge { font-size: 8px; padding: 2px 4px; border: 2px solid var(--ink); border-radius: 2px; }
.bar { height: 10px; border: 2px solid var(--ink); background: #000; width: 100%; }
.bar > i { display: block; height: 100%; background: var(--hp); }
.bar.bad > i { background: var(--hp-bad); }

table.stats { width: 100%; border-collapse: collapse; }
table.stats td { padding: 3px 4px; border-bottom: 2px dashed rgba(38,24,18,.35); font-size: 9px; }

/* Toasts */
#toast-root { position: absolute; top: 18%; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; z-index: 60; }
.toast {
  background: var(--panel); color: var(--cream); border: 3px solid var(--cream);
  padding: 10px 16px; font-size: 10px; border-radius: 3px; box-shadow: 0 4px 0 #000;
  animation: toast-in .25s ease-out;
}
@keyframes toast-in { from { transform: translateY(-10px); opacity: 0; } }

.result-banner { text-align: center; font-size: 18px; padding: 12px 0 4px; }

/* Landscape helpers */
@media (min-aspect-ratio: 4/3) {
  #battle-skills { grid-template-columns: repeat(4, 1fr); }
  .btn { font-size: 12px; }
}
/* Wide tablets: two-column grids, bigger cards */
@media (min-width: 900px) {
  .card { width: 116px; }
  .card canvas { width: 80px; height: 80px; }
  .modal { max-width: 720px; }
}

/* Mission chip (HUD) + battle bench */
.chip.mission {
  border-color: #e0b23c;
  width: 100%;
  max-width: min(94vw, 620px);
  flex-wrap: wrap;
  justify-content: center;
  row-gap: 6px;
}
.chip.mission .mt { font-size: 9px; line-height: 1.6; min-width: 0; flex: 1 1 auto; text-align: center; }
.chip.mission .mr { font-size: 9px; }
#battle-bench { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.bench-card {
  background: rgba(26,18,9,.9); border: 2px solid var(--cream); border-radius: 2px;
  padding: 4px 8px; font-size: 8px; text-align: center; min-width: 64px; cursor: pointer; line-height: 1.6;
}
.bench-card.active { border-color: var(--gold); color: var(--gold); }
.bench-card.dead { opacity: .35; }
