/* =========================================================================
   Bones of the Realm — presentation shell
   SNES-era top-down Zelda-like styling. Pixel-friendly, Halloween palette.
   This file only styles the chrome/HUD/overlays. The game canvas is drawn by
   the engine module (see src/main.js wiring).
   ========================================================================= */

:root {
  --bg-deep: #0a0612;
  --bg-panel: #161028;
  --bg-panel-2: #221742;
  --ink: #f3e9c7;
  --ink-dim: #b9a96f;
  --bone: #e8e2c8;
  --pumpkin: #f2741a;
  --pumpkin-dim: #b85311;
  --poison: #7af542;
  --blood: #b21f1f;
  --gold: #f2c84b;
  --frame: #3a2a64;
  --frame-light: #5a3f99;
  --shadow: 0 0 0 4px #000, 0 0 0 6px var(--frame), 0 8px 24px rgba(0,0,0,0.6);
  --pixel-font: "Press Start 2P", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-deep);
  color: var(--ink);
  font-family: var(--pixel-font);
  -webkit-font-smoothing: none;
  font-smooth: never;
  image-rendering: pixelated;
  overflow: hidden;
}

body {
  background:
    radial-gradient(circle at 50% -10%, #2a0f3a 0%, transparent 60%),
    radial-gradient(circle at 50% 120%, #1a0a2a 0%, transparent 50%),
    var(--bg-deep);
}

button { font-family: var(--pixel-font); }

kbd {
  display: inline-block;
  background: var(--bg-panel-2);
  color: var(--ink);
  border: 2px solid var(--frame-light);
  border-radius: 3px;
  padding: 1px 5px;
  margin: 0 2px;
  font-size: 0.7em;
  box-shadow: 0 2px 0 #000;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  gap: 10px;
}

/* ---------- Title screen ---------- */
.title-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 40%, #2a0f3a 0%, transparent 65%),
    var(--bg-deep);
  z-index: 30;
  animation: flicker 4s infinite steps(60);
}
.title-card {
  text-align: center;
  padding: 28px 36px;
  background: linear-gradient(180deg, var(--bg-panel) 0%, var(--bg-panel-2) 100%);
  border: 4px solid var(--frame);
  box-shadow: var(--shadow);
  max-width: 640px;
  width: calc(100% - 24px);
}
.game-title {
  font-size: clamp(20px, 5vw, 44px);
  margin: 0 0 14px;
  color: var(--pumpkin);
  text-shadow:
    0 0 0 #000,
    3px 3px 0 #000,
    6px 6px 0 var(--blood),
    0 0 18px rgba(242,116,26,0.5);
  letter-spacing: 2px;
}
.game-subtitle {
  font-size: 11px;
  color: var(--ink-dim);
  margin: 0 0 18px;
  letter-spacing: 1px;
}
.title-flame {
  font-size: 26px;
  letter-spacing: 14px;
  margin: 6px 0 22px;
  animation: bob 1.2s ease-in-out infinite;
}
.title-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.title-hint {
  font-size: 9px;
  color: var(--ink-dim);
  line-height: 1.6;
}

/* ---------- Buttons ---------- */
.primary-btn, .ghost-btn, .mini-btn {
  font-size: 11px;
  color: var(--ink);
  padding: 10px 16px;
  cursor: pointer;
  border-radius: 0;
  letter-spacing: 1px;
  transition: transform 0.05s steps(2), background 0.1s;
  user-select: none;
}
.primary-btn {
  background: var(--pumpkin);
  color: #1a0a02;
  border: 3px solid #000;
  box-shadow: 0 4px 0 var(--pumpkin-dim), 0 4px 0 4px #000;
}
.primary-btn:hover { background: #ff8a2a; transform: translateY(-1px); }
.primary-btn:active { transform: translateY(3px); box-shadow: none; }

.ghost-btn {
  background: transparent;
  color: var(--ink);
  border: 3px solid var(--frame-light);
}
.ghost-btn:hover { background: var(--bg-panel-2); border-color: var(--pumpkin); }
.ghost-btn:active { transform: translateY(2px); }

.mini-btn {
  background: var(--bg-panel-2);
  color: var(--ink);
  border: 2px solid var(--frame-light);
  padding: 4px 8px;
  font-size: 13px;
  line-height: 1;
}
.mini-btn:hover { border-color: var(--pumpkin); color: var(--pumpkin); }

/* ---------- Stage / HUD ---------- */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 768px;
}

.hud {
  width: 100%;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  background: var(--bg-panel);
  border: 3px solid var(--frame);
  padding: 6px 10px;
}
.hud-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 8px;
  border-right: 2px solid var(--frame);
  min-width: 56px;
}
.hud-cell:last-child { border-right: none; }
.hud-label {
  font-size: 7px;
  color: var(--ink-dim);
  letter-spacing: 1px;
}
.hud-value {
  font-size: 11px;
  color: var(--ink);
}
.hud-actions {
  margin-left: auto;
  display: flex;
  flex-direction: row;
  gap: 6px;
  border-right: none;
  min-width: auto;
}

.hud-top .hud-hearts .hud-value { color: var(--blood); }
.hud-top .hud-rupees .hud-value { color: var(--bone); }
.hud-top .hud-keys .hud-value { color: var(--gold); }

/* ---------- Canvas frame ---------- */
.canvas-frame {
  position: relative;
  width: 100%;
  max-width: 768px;
  aspect-ratio: 256 / 224;
  background: #000;
  border: 4px solid var(--frame);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #05030a;
  outline: none;
}
.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0,
    rgba(0,0,0,0) 2px,
    rgba(0,0,0,0.18) 3px,
    rgba(0,0,0,0.18) 4px
  );
  mix-blend-mode: multiply;
  z-index: 5;
}

/* ---------- Overlay (in-game messages / fades) ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5,3,12,0.75);
  color: var(--ink);
  font-size: 12px;
  text-align: center;
  padding: 12px;
  z-index: 6;
}
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #05030a;
  color: var(--ink-dim);
  font-size: 11px;
  z-index: 7;
}
.loading-skull {
  font-size: 30px;
  animation: bob 1s ease-in-out infinite;
}
.loading.hidden { display: none; }

/* ---------- Bottom HUD ---------- */
.hud-bottom {
  justify-content: space-between;
  font-size: 9px;
}
.message-log {
  color: var(--poison);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-coords { color: var(--ink-dim); }

/* ---------- Map / Pause / Howto modals ---------- */
.map-screen, .pause-screen, .howto-screen, .fatal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5,3,12,0.85);
  z-index: 40;
  padding: 16px;
}
.map-card, .pause-card, .howto-card, .fatal-card {
  background: var(--bg-panel);
  border: 4px solid var(--frame);
  box-shadow: var(--shadow);
  padding: 18px 22px;
  text-align: center;
  max-width: 480px;
  width: 100%;
}
.map-title, .pause-title, .howto-title, .fatal-card h2 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--pumpkin);
}
.map-canvas {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 1 / 1;
  background: #05030a;
  border: 3px solid var(--frame-light);
  image-rendering: pixelated;
  margin-bottom: 10px;
}
.map-hint { font-size: 8px; color: var(--ink-dim); margin: 8px 0; }
.howto-list {
  text-align: left;
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
  font-size: 9px;
  line-height: 2.1;
  color: var(--ink);
}
.howto-tip {
  font-size: 8px;
  color: var(--ink-dim);
  margin: 0 0 14px;
  line-height: 1.8;
}
.fatal-card p { font-size: 9px; color: var(--ink-dim); line-height: 1.8; }
.fatal-card h2 { color: var(--blood); }

/* ---------- Credits ---------- */
.credits {
  font-size: 7px;
  color: var(--ink-dim);
  text-align: center;
  padding: 4px;
  opacity: 0.6;
}

/* ---------- Utilities ---------- */
.hidden { display: none !important; }

/* ---------- Animations ---------- */
@keyframes flicker {
  0%, 100% { opacity: 1; }
  92% { opacity: 1; }
  94% { opacity: 0.85; }
  96% { opacity: 1; }
  98% { opacity: 0.9; }
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .hud-cell { min-width: 44px; padding: 2px 4px; }
  .hud-label { font-size: 6px; }
  .hud-value { font-size: 10px; }
  .credits { font-size: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .title-screen, .title-flame, .loading-skull { animation: none; }
}
