:root {
  --bg: #0b0c14;
  --ink: #e8e0d0;
  --muted: #8a8494;
  --gold: #f0c75e;
  --ice: #7ec8f0;
  --fire: #ff8a3a;
  --bolt: #f5e27a;
  --heal: #9be07a;
  --danger: #e25b5b;
  --panel: #16141f;
  --btn: #24202e;
  --btn-hi: #3a3448;
  --shadow: #05050a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

#app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#topbar {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 8px 14px 4px;
  flex: 0 0 auto;
}

.mute {
  margin-left: auto;
  padding: 4px 10px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 8px;
  flex: 0 0 auto;
}

.mute[aria-pressed="true"] {
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 700;
}

.hint {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

#stage {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 4px 8px;
}

#game {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #0b0c14;
  box-shadow: 0 0 0 2px #1c1a26, 0 8px 24px var(--shadow);
}

#controls {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 8px 12px 14px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.pad { position: relative; min-height: 132px; }

#pad-move {
  width: 132px;
  height: 132px;
  justify-self: start;
}

#pad-spells {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  justify-self: end;
  width: 168px;
  height: 132px;
}

#pad-move .dir[data-dir="up"]    { position: absolute; left: 44px; top: 0; }
#pad-move .dir[data-dir="left"]  { position: absolute; left: 0; top: 44px; }
#pad-move .dir[data-dir="down"]  { position: absolute; left: 44px; top: 88px; }
#pad-move .dir[data-dir="right"] { position: absolute; left: 88px; top: 44px; }

.btn {
  appearance: none;
  border: 2px solid #3d384c;
  background: var(--btn);
  color: var(--ink);
  font: inherit;
  border-radius: 10px;
  box-shadow: 0 3px 0 #0a0a10;
  cursor: pointer;
}

.btn:active, .btn.held {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0a0a10;
  background: var(--btn-hi);
}

.dir {
  width: 44px;
  height: 44px;
  font-size: 16px;
  padding: 0;
}

.spell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px;
  position: relative;
  overflow: hidden;
}

.spell span {
  font-size: 13px;
  font-weight: 700;
}

.spell[data-spell="frost"] { color: var(--ice); }
.spell[data-spell="fire"]  { color: var(--fire); }
.spell[data-spell="bolt"]  { color: var(--bolt); }
.spell[data-spell="heal"]  { color: var(--heal); }

.spell.cooling { opacity: 0.45; }
.spell .cd {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 0%;
  background: rgba(0,0,0,0.45);
  pointer-events: none;
}

#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 6, 12, 0.72);
  z-index: 10;
}

#overlay.hidden, #overlay[hidden] { display: none; }

.card {
  background: var(--panel);
  border: 2px solid #3d384c;
  padding: 22px 28px;
  text-align: center;
  min-width: 220px;
  box-shadow: 0 8px 0 #05050a;
}

.card h2 {
  margin: 0 0 8px;
  color: var(--danger);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

#final-score { color: var(--gold); margin: 0 0 16px; }

.card .btn { padding: 10px 22px; font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; }

@media (min-width: 900px) {
  #controls { padding-bottom: 20px; }
}
@media (max-width: 520px) {
  .desktop-hint { display: none; }
  h1 { font-size: 12px; }
  .mute { font-size: 10px; padding: 4px 8px; }
}
