/* styles.css — Page chrome + canvas scaling for NES tablet platformer. */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  font-family: monospace;
}

/* ── Canvas wrapper ─────────────────────────────────────────────────── */

#game-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#game-canvas {
  /* Internal resolution is 256×224 set in JS.
     Scale up to fill the screen while preserving aspect ratio. */
  image-rendering: pixelated;
  image-rendering: crisp-edges; /* Firefox */
  width: 100%;
  height: 100%;
  object-fit: contain;
  max-width: calc(100vh * (256 / 224));  /* letterbox: never exceed aspect ratio */
  max-height: calc(100vw * (224 / 256));
  display: block;
  touch-action: none; /* belt-and-suspenders: block pinch-zoom on the canvas */
}

/* ── HUD bar (Play/Edit toggle + edit tools) ────────────────────────── */

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: transparent;
  z-index: 10;
  pointer-events: none;
}

#hud-left,
#hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

#hud button {
  pointer-events: all;
  background: #222;
  color: #f8f8f8;
  border: 1px solid #555;
  border-radius: 6px;
  padding: 8px 16px;
  font-family: monospace;
  font-size: 16px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#hud button:active {
  background: #444;
}

#edit-tools {
  pointer-events: all;
  display: flex;
  gap: 6px;
  align-items: center;
}

/* Coin counter — absolutely centred in the HUD bar */
#hud-coins {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #F8F8F8;
  font-family: monospace;
  font-size: 20px;
  font-weight: bold;
  letter-spacing: 1px;
  pointer-events: none;
  white-space: nowrap;
}

#hud-coin-icon {
  color: #F8B800;  /* coin gold */
  font-size: 32px;
  line-height: 1;
}

/* ── Touch control overlay (Phase 3) ────────────────────────────────── */

#controls {
  position: absolute;
  bottom: env(safe-area-inset-bottom, 0px);
  left: 0;
  right: 0;
  height: 160px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 16px 12px;
  pointer-events: none;  /* children opt in */
  z-index: 10;
}

/* D-pad */
#dpad {
  pointer-events: all;
  position: relative;
  width: 132px;
  height: 132px;
  touch-action: none;
}

.dpad-btn {
  position: absolute;
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.dpad-btn:active,
.dpad-btn.pressed {
  background: rgba(255,255,255,0.35);
}

#btn-left  { width: 44px; height: 44px; left: 0;   top: 44px; }
#btn-right { width: 44px; height: 44px; left: 88px; top: 44px; }
#btn-up    { width: 44px; height: 44px; left: 44px; top: 0;    }
#btn-down  { width: 44px; height: 44px; left: 44px; top: 88px; }
#dpad-center {
  position: absolute;
  width: 44px; height: 44px;
  left: 44px; top: 44px;
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
}

/* Arrow icons on d-pad */
#btn-left::after  { content: '◀'; }
#btn-right::after { content: '▶'; }
#btn-up::after    { content: '▲'; }
#btn-down::after  { content: '▼'; }
.dpad-btn::after {
  display: flex;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.7);
  font-size: 18px;
}

/* A / B action buttons */
#action-buttons {
  pointer-events: all;
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.action-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: monospace;
  font-size: 20px;
  font-weight: bold;
  color: #fff;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  user-select: none;
}

.action-btn:active,
.action-btn.pressed {
  filter: brightness(1.4);
}

#btn-a {
  background: rgba(200, 72, 0, 0.7);
}

#btn-b {
  background: rgba(0, 100, 0, 0.7);
  width: 56px;
  height: 56px;
  margin-bottom: 8px;
}

/* ── Rotate-to-landscape overlay ─────────────────────────────────────── */

#rotate-overlay {
  display: none; /* shown via JS when portrait */
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #f8f8f8;
  font-family: monospace;
  font-size: 18px;
  text-align: center;
  gap: 16px;
}

#rotate-overlay .icon {
  font-size: 48px;
  transform: rotate(90deg);
}

/* ── Level Clear overlay ──────────────────────────────────────────────────── */

#level-clear-overlay {
  display: none; /* shown via JS when goal is touched */
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  z-index: 50;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#level-clear-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: #111;
  border: 3px solid #F8B800;
  border-radius: 8px;
  padding: 32px 48px;
}

#level-clear-title {
  font-family: monospace;
  font-size: 36px;
  font-weight: bold;
  color: #F8B800;
  letter-spacing: 3px;
  text-shadow: 0 0 12px rgba(248,184,0,0.6);
}

#level-clear-coins {
  font-family: monospace;
  font-size: 20px;
  color: #F8F8F8;
  letter-spacing: 1px;
}

#btn-play-again {
  margin-top: 8px;
  background: #C84800;
  color: #F8F8F8;
  border: 2px solid #F8B800;
  border-radius: 6px;
  padding: 12px 32px;
  font-family: monospace;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 1px;
}

#btn-play-again:active {
  background: #A03800;
}

#btn-clear-map {
  background: #222;
  color: #aaa;
  border: 1px solid #555;
  border-radius: 6px;
  padding: 8px 20px;
  font-family: monospace;
  font-size: 13px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 1px;
}

#btn-clear-map:active {
  background: #333;
  color: #fff;
}

/* ── Hero Select overlay ─────────────────────────────────────────── */

#hero-select-overlay {
  display: flex; /* visible by default; hidden via JS after PLAY! */
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 60;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#hero-select-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  background: #111;
  border: 3px solid #F8B800;
  border-radius: 8px;
  padding: 28px 40px;
}

#hero-select-title {
  font-family: monospace;
  font-size: 22px;
  font-weight: bold;
  color: #F8B800;
  letter-spacing: 3px;
  text-shadow: 0 0 10px rgba(248,184,0,0.5);
}

#hero-cards {
  display: flex;
  flex-direction: row;
  gap: 20px;
}

.hero-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border: 2px solid #444;
  border-radius: 6px;
  background: #1a1a1a;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.1s, background 0.1s;
}

.hero-card.selected {
  border-color: #F8B800;
  background: #2a2000;
}

.hero-card:active {
  background: #222;
}

.hero-preview {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hero-name {
  font-family: monospace;
  font-size: 16px;
  font-weight: bold;
  color: #F8F8F8;
  letter-spacing: 1px;
}

#btn-hero-play {
  margin-top: 4px;
  background: #C84800;
  color: #F8F8F8;
  border: 2px solid #F8B800;
  border-radius: 6px;
  padding: 12px 40px;
  font-family: monospace;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 2px;
}

#btn-hero-play:active {
  background: #A03800;
}

/* ── Hero Editor overlay ─────────────────────────────────────────── */

#hero-editor-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.90);
  z-index: 70;
  align-items: center;
  justify-content: center;
  font-family: monospace;
  color: #F8F8F8;
}

/* Modal box — list view and new-char flow */
#ced-box {
  background: #111128;
  border: 3px solid #6844FC;
  border-radius: 8px;
  padding: 16px 20px;
  max-width: 92vw;
  max-height: 92vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 340px;
}

/* Full-screen variant — pixel editor only, capped to game canvas width */
#ced-box.ced-fs {
  width: 100%; height: 100%;
  max-width: calc(100vh * (256 / 224));   /* matches game canvas letterbox */
  max-height: none;
  border: none; border-radius: 0;
  padding: 0; gap: 0;
  overflow: hidden;
  background: #0a0a18;
}

/* ── Shared title ─────────────────────────────────────────────────────── */

.ced-title {
  font-size: 18px; font-weight: bold;
  color: #F8B800; letter-spacing: 2px;
  text-align: center; padding-bottom: 4px;
}

/* ── List view ────────────────────────────────────────────────────────── */

.ced-list { display: flex; flex-direction: column; gap: 4px; min-height: 80px; }
.ced-section-hdr { color: #9878F8; font-size: 11px; letter-spacing: 1px; margin-top: 8px; text-transform: uppercase; }
.ced-list-row { display: flex; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.07); }
.ced-hero-name { flex: 1; font-size: 14px; }
.ced-readonly  { color: #484868; font-size: 11px; font-style: italic; }
.ced-empty     { color: #484868; font-size: 12px; padding: 8px 0; }
.ced-list-row button { font-size: 12px; padding: 4px 10px; background: #2a2a50; border: 1px solid #5050A0; color: #E8E8F8; border-radius: 4px; cursor: pointer; touch-action: manipulation; }
.ced-list-row button:active { background: #3a3a70; }

.ced-footer { display: flex; gap: 8px; justify-content: space-between; margin-top: 8px; }
.ced-footer button { background: #2a2a50; border: 1px solid #5050A0; color: #E8E8F8; border-radius: 5px; padding: 9px 18px; font-family: monospace; font-size: 14px; cursor: pointer; touch-action: manipulation; }
.ced-footer button:active { background: #3a3a70; }
.ced-new-btn { background: #1a4a1a !important; border-color: #4a9a4a !important; }

/* ── New-char form ────────────────────────────────────────────────────── */

.ced-new-form { display: flex; flex-direction: column; gap: 14px; padding: 8px 0; }
.ced-new-form label { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.ced-new-form select { background: #222248; color: #F8F8F8; border: 1px solid #6844FC; border-radius: 4px; padding: 6px 8px; font-family: monospace; font-size: 13px; flex: 1; }

/* ── Full-screen editor layout ────────────────────────────────────────── */

/* Top header bar */
.ced-editor-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; flex-shrink: 0;
  background: #151530;
  border-bottom: 1px solid #2a2a50;
}
#ced-name-input {
  flex: 1; background: #222248; color: #F8F8F8;
  border: 1px solid #5050A0; border-radius: 4px;
  padding: 6px 10px; font-family: monospace; font-size: 15px;
}
.ced-editor-header button {
  background: #2a2a50; border: 1px solid #5050A0; color: #E8E8F8;
  border-radius: 4px; padding: 7px 16px; font-family: monospace;
  font-size: 13px; cursor: pointer; touch-action: manipulation; white-space: nowrap;
}
.ced-editor-header button:active { background: #3a3a70; }
.ced-save-btn { background: #1a4a1a !important; border-color: #4a9a4a !important; }

/* Frame tabs row */
.ced-tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  padding: 7px 12px; flex-shrink: 0;
  background: #111128; border-bottom: 1px solid #222248;
}
.ced-tab {
  background: #222248; color: #8888B8; border: 1px solid #3a3a6e;
  border-radius: 4px; padding: 6px 14px; font-family: monospace; font-size: 13px;
  cursor: pointer; touch-action: manipulation;
}
.ced-tab.active { background: #4428BC; color: #F8F8F8; border-color: #9878F8; }
.ced-tab.locked { color: #484868; cursor: default; }

/* Main drawing area: grid left, controls right */
.ced-editor-main {
  flex: 1; display: flex; gap: 16px;
  padding: 12px; overflow: hidden; align-items: flex-start;
}

/* Grid canvas */
#ced-grid {
  image-rendering: pixelated; image-rendering: crisp-edges;
  cursor: crosshair; flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.15);
  background: #080814;
}

/* Right panel: preview + copy + palette */
.ced-right-panel {
  display: flex; flex-direction: column; gap: 14px;
  flex: 1; overflow-y: auto; max-height: 100%;
}

/* Copy-to row */
.ced-copy-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ced-copy-label { color: #9878F8; font-size: 12px; letter-spacing: 0.5px; flex-shrink: 0; }
.ced-copy-btn {
  background: #2a2a50; border: 1px solid #5050A0; color: #E8E8F8;
  border-radius: 4px; padding: 5px 12px; font-family: monospace; font-size: 12px;
  cursor: pointer; touch-action: manipulation;
}
.ced-copy-btn:active { background: #3a3a70; }

/* Palette swatches — larger for touch */
.ced-palette { display: flex; flex-wrap: wrap; gap: 4px; }
.ced-swatch {
  width: 26px; height: 26px;
  border: 2px solid transparent; border-radius: 3px;
  cursor: pointer; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; color: #888;
  touch-action: manipulation;
}
.ced-swatch:hover  { border-color: rgba(255,255,255,0.5); }
.ced-swatch.picked { border-color: #F8F8F8 !important; outline: 1px solid #000; }
.ced-eraser { background: repeating-linear-gradient(45deg, #2a2a2a 0, #2a2a2a 4px, #484848 4px, #484848 8px); }
