/* ============================================================ Tomb of the Pharaoh */
:root {
  --bg: #0b2a3a;            /* minifantasy navy */
  --panel: #122b38;
  --panel2: #0d1f2a;
  --gold: #ffd75e;
  --sand: #e0a868;
  --ink: #e8e0cc;
  --dim: #8aa3ad;
  --hp: #e0564a;
  --mp: #4a90e0;
  --green: #7ef79a;
}

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

html, body {
  height: 100%;
  background: #06141d;
  color: var(--ink);
  font-family: 'Courier New', monospace;
  overflow: hidden;
}

#stage {
  position: relative;
  width: 100vw; height: 100vh;
  display: flex; align-items: center; justify-content: center;
}

#stage.shake { animation: shake 0.22s linear; }
@keyframes shake {
  0% { transform: translate(2px, 1px); } 25% { transform: translate(-2px, -1px); }
  50% { transform: translate(1px, -2px); } 75% { transform: translate(-1px, 2px); }
  100% { transform: translate(0, 0); }
}

canvas#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  background: #000;
}

.hidden { display: none !important; }

#loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; letter-spacing: 3px; color: var(--gold);
}

/* ------------------------------------------------ screens */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px;
  background:
    radial-gradient(ellipse at 50% -10%, #1d4458 0%, transparent 55%),
    radial-gradient(ellipse at 50% 115%, #3a2410 0%, transparent 50%),
    var(--bg);
  text-align: center;
  padding: 24px;
  z-index: 10;
}
.screen.overlay { background: rgba(6, 16, 24, 0.92); }

h1 {
  font-size: clamp(28px, 6vw, 56px);
  color: var(--gold);
  letter-spacing: 6px;
  text-shadow: 0 3px 0 #7a5410, 0 6px 12px #000;
}
h1 span { color: var(--sand); font-size: 0.5em; letter-spacing: 2px; }
h1.doom { color: var(--hp); text-shadow: 0 3px 0 #4a0d08, 0 6px 14px #000; }
h1.gilded { color: var(--gold); }
h2 { color: var(--gold); letter-spacing: 3px; font-size: clamp(16px, 3vw, 26px); }

.title-art { display: flex; gap: 14px; align-items: flex-end; filter: drop-shadow(0 4px 0 #061018); }
.title-art img { width: 84px; image-rendering: pixelated; }
.subtitle { color: var(--dim); letter-spacing: 2px; }
.footnote { position: absolute; bottom: 12px; color: var(--dim); font-size: 12px; }

/* ------------------------------------------------ menus */
.menu {
  display: grid;
  gap: 4px;
  min-width: min(420px, 80vw);
  max-height: 46vh;
  overflow-y: auto;
  background: var(--panel2);
  border: 2px solid #2a4a5c;
  box-shadow: 0 4px 0 #061018;
  padding: 6px;
}
.menu-item {
  padding: 7px 12px;
  text-align: left;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 1px;
  color: var(--ink);
  border-left: 4px solid transparent;
}
.menu-item .hint { font-size: 11px; color: var(--dim); }
.menu-item.sel {
  background: #1d4458;
  border-left-color: var(--gold);
  color: #fff;
}
.menu-item.disabled { opacity: 0.38; cursor: default; }

button {
  font-family: inherit;
  font-size: 15px;
  background: var(--panel);
  border: 2px solid #2a4a5c;
  color: var(--ink);
  padding: 9px 18px;
  cursor: pointer;
  letter-spacing: 1px;
}
button:hover { background: #1d4458; color: #fff; }
#party-start.ready { border-color: var(--gold); color: var(--gold); }
.row { display: flex; gap: 12px; }

/* ------------------------------------------------ party select */
#class-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 8px;
  width: min(900px, 92vw);
}
@media (max-width: 760px) { #class-grid { grid-template-columns: repeat(3, 1fr); } }
.class-card {
  background: var(--panel2);
  border: 2px solid #2a4a5c;
  padding: 8px 4px 6px;
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 1px;
}
.class-card img { width: 64px; height: auto; image-rendering: pixelated; }
.class-card:hover { border-color: var(--sand); background: #16374a; }
.class-card.picked { border-color: var(--gold); background: #243d18; }
#class-info {
  min-height: 86px;
  width: min(760px, 92vw);
  background: var(--panel2);
  border: 2px solid #2a4a5c;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.5;
}
#class-info .stats { color: var(--sand); }
#class-info .abil { color: var(--dim); font-size: 12px; }
#party-slots { display: flex; gap: 10px; }
.party-slot {
  width: 86px; height: 86px;
  background: var(--panel2);
  border: 2px dashed #2a4a5c;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-size: 11px; cursor: pointer;
}
.party-slot img { width: 52px; image-rendering: pixelated; }
.party-slot .empty { color: #27465a; font-size: 26px; }

/* ------------------------------------------------ HUD */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 8px 10px;
  pointer-events: none;
  z-index: 5;
}
#hud-party { display: flex; gap: 8px; flex-wrap: wrap; }
.hud-hero {
  display: flex; gap: 5px; align-items: center;
  background: rgba(6, 16, 24, 0.82);
  border: 1px solid #2a4a5c;
  padding: 3px 7px 3px 3px;
}
.hud-hero.dead { filter: grayscale(1); opacity: 0.6; }
.hud-hero img { width: 26px; image-rendering: pixelated; }
.hud-bars .nm { font-size: 10px; color: var(--ink); white-space: nowrap; }
.hud-bars .nm i { color: var(--gold); font-style: normal; }
.bar {
  width: 74px; height: 5px;
  background: #0a1620;
  margin-top: 2px;
  position: relative;
}
.bar i { display: block; height: 100%; }
.bar.hp i { background: var(--hp); }
.bar.mp i { background: var(--mp); }
#hud-gold {
  background: rgba(6, 16, 24, 0.82);
  border: 1px solid #2a4a5c;
  padding: 5px 10px;
  color: var(--gold);
  font-size: 13px;
}
#hud-keys {
  position: absolute; bottom: -100vh; /* repositioned below */
}
#hud::after { content: ''; }
#hud-keys {
  position: fixed; bottom: 6px; right: 10px;
  color: rgba(160, 190, 200, 0.55);
  font-size: 11px;
}

/* ------------------------------------------------ battle UI */
#battle-ui {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 6;
  display: flex; flex-direction: column; justify-content: space-between;
}
#battle-log {
  margin: 8px auto 0;
  width: min(640px, 90vw);
  font-size: 13px;
  color: var(--ink);
  text-shadow: 0 1px 0 #000;
  background: rgba(6, 16, 24, 0.72);
  border: 1px solid #2a4a5c;
  padding: 5px 10px;
  min-height: 24px;
}
#battle-hint {
  margin: 4px auto;
  color: var(--gold);
  font-size: 12px;
  text-shadow: 0 1px 0 #000;
}
#battle-bottom {
  display: flex; gap: 10px;
  align-items: flex-end; justify-content: center;
  padding: 0 10px 10px;
}
#battle-menu {
  pointer-events: auto;
  min-width: 300px;
  max-width: 46vw;
  max-height: 30vh;
}
#battle-party { display: flex; gap: 6px; }
.bp {
  background: rgba(6, 16, 24, 0.85);
  border: 1px solid #2a4a5c;
  padding: 4px 8px;
  width: 110px;
}
.bp.cur { border-color: var(--gold); box-shadow: 0 0 8px rgba(255, 215, 94, 0.4); }
.bp.dead { filter: grayscale(1); opacity: 0.55; }
.bp .nm { font-size: 11px; margin-bottom: 2px; }
.bp .bar { width: 100%; height: 7px; }
.bp .bar span {
  position: absolute; right: 2px; top: -3px;
  font-size: 9px; color: #fff; text-shadow: 0 1px 0 #000;
}
#battle-rewards {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px;
  background: rgba(4, 10, 16, 0.78);
  font-size: 15px;
  pointer-events: auto;
}
.reward-title { font-size: 34px; color: var(--gold); letter-spacing: 8px; text-shadow: 0 3px 0 #7a5410; }
.lvlup { color: var(--green); }
.dim { color: var(--dim); font-size: 12px; }

/* ------------------------------------------------ pause / shop */
#pause-party, .credits-body { width: min(640px, 90vw); }
#pause-party {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  font-size: 12px; text-align: left;
}
.pause-hero {
  display: flex; gap: 8px; align-items: center;
  background: var(--panel2); border: 1px solid #2a4a5c; padding: 6px;
}
.pause-hero img { width: 40px; image-rendering: pixelated; }
.pause-hero.dead { filter: grayscale(1); opacity: 0.65; }
.pause-gold { grid-column: span 2; color: var(--gold); padding: 2px 4px; }
.gold { color: var(--gold); }
.credits-body { line-height: 1.8; font-size: 14px; }

#gameover-msg, #ending-stats { font-size: 15px; line-height: 1.7; max-width: 640px; }

/* ------------------------------------------------ toast & fader */
#toast {
  position: absolute; left: 50%; bottom: 12vh;
  transform: translateX(-50%);
  background: rgba(6, 16, 24, 0.92);
  border: 2px solid var(--sand);
  color: var(--ink);
  padding: 8px 16px;
  max-width: min(620px, 86vw);
  font-size: 14px;
  z-index: 20;
  box-shadow: 0 4px 0 #061018;
}
#fader {
  position: absolute; inset: 0;
  background: #000;
  opacity: 0; pointer-events: none;
  transition: opacity 0.4s;
  z-index: 30;
}
#fader.on { opacity: 1; pointer-events: auto; }
