/* Pixelify Sans (SIL Open Font License, see fonts/OFL.txt), hosted with the game. */
@font-face {
  font-family: "Pixelify Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/pixelify-sans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Pixelify Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/pixelify-sans-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Pixelify Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/pixelify-sans-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

:root {
  --bg: #15120f;
  --panel: #241c17;
  --panel-2: #30251d;
  --text: #f8ead2;
  --muted: #c5a988;
  --line: #5b412d;
  --green: #4fb75c;
  --red: #d94d3f;
  --blue: #55aaff;
  --gold: #f6c85f;
  --shadow: rgba(0, 0, 0, 0.35);
  --display: "Pixelify Sans", "Trebuchet MS", system-ui, sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.03) 25%, transparent 25%) 0 0 / 28px 28px,
    linear-gradient(-45deg, rgba(0, 0, 0, 0.16) 25%, transparent 25%) 0 0 / 28px 28px,
    var(--bg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  width: min(1320px, calc(100vw - 24px));
  margin: 12px auto;
}

.game-shell,
.panel-card {
  border: 4px solid var(--line);
  background: var(--panel);
  box-shadow: 0 10px 0 var(--shadow);
}

.game-shell {
  padding: 14px;
  min-width: 0;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 12px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-wrap: balance;
}

h1 {
  margin-bottom: 4px;
  font-size: clamp(1.45rem, 2.4vw, 2.2rem);
  color: var(--gold);
  text-shadow: 3px 3px 0 #000;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.2rem;
}

p {
  color: var(--muted);
}

.stats {
  display: grid;
  gap: 8px;
  min-width: 290px;
}

.meter {
  display: grid;
  grid-template-columns: 64px 1fr 70px;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

.meter-track {
  height: 18px;
  border: 3px solid #110d0a;
  background: #100d0b;
}

.meter-fill {
  width: 100%;
  height: 100%;
  transition: width 120ms linear;
}

.meter-fill.hp {
  background: repeating-linear-gradient(90deg, #ef5b4b 0 14px, var(--red) 14px 28px);
}

.meter-fill.mana {
  background: repeating-linear-gradient(90deg, #6bc4ff 0 14px, var(--blue) 14px 28px);
}

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.coin-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
  padding: 4px 10px;
  border: 2px solid var(--line);
  background: #100d0b;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}

.coin-icon {
  width: 14px;
  height: 14px;
  display: inline-block;
  background: var(--gold);
  border: 2px solid #8a5f12;
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.2);
}

.chip-btn {
  padding: 6px 10px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: 600 0.85rem system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 3px 0 #0d0a08;
}

.chip-btn:hover {
  border-color: var(--gold);
}

.chip-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0d0a08;
}

.chip-btn:focus-visible,
.tbtn:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.canvas-wrap {
  position: relative;
  max-width: 960px;
  margin: 0 auto;
}

#gameCanvas {
  display: block;
  width: 100%;
  max-width: 960px;
  height: auto;
  margin: 0 auto;
  border: 5px solid #120e0a;
  background: #2c2015;
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Touch controls float over the canvas on tablets and sit under it on phones. */
.touch-controls {
  position: absolute;
  inset: auto 12px 12px 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}

.touch-controls[hidden] {
  display: none;
}

.stick,
.tbtn {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.stick {
  position: relative;
  width: 116px;
  height: 116px;
  border: 4px solid rgba(248, 234, 210, 0.45);
  background: rgba(16, 13, 11, 0.45);
  flex-shrink: 0;
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  background: rgba(246, 200, 95, 0.85);
  border: 3px solid #120e0a;
}

.touch-buttons {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  gap: 8px;
}

.tbtn {
  width: 52px;
  height: 52px;
  border: 3px solid #120e0a;
  background: rgba(48, 37, 29, 0.85);
  color: var(--text);
  font: 700 1rem var(--display);
  box-shadow: inset 0 -4px 0 var(--c, var(--line));
}

.tbtn.fire {
  background: rgba(246, 200, 95, 0.9);
  color: #241c17;
}

.tbtn.dash {
  background: rgba(85, 170, 255, 0.85);
  color: #0d1a2b;
  font-size: 0.85rem;
}

.tbtn.block {
  background: rgba(155, 231, 255, 0.85);
  color: #0d1a2b;
  font-size: 0.8rem;
}

.tbtn.flask {
  background: rgba(239, 91, 75, 0.85);
  color: #2b0d0a;
  font-size: 0.8rem;
}

.tbtn:active {
  transform: translateY(2px);
  filter: brightness(1.2);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

body.touch .controls {
  display: none;
}

.controls span {
  padding: 7px 9px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.85rem;
}

kbd {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  background: #100d0b;
  color: var(--text);
  font: 600 0.8rem ui-monospace, "SFMono-Regular", Menlo, monospace;
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  min-width: 0;
}

.panel-card {
  padding: 14px;
  min-width: 0;
}

.mini-map {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.map-cell {
  aspect-ratio: 1 / 1;
  border: 3px solid #100d0b;
  background: #18120e;
  position: relative;
}

.map-cell.seen {
  background: #57402c;
}

.map-cell.boss-alive::after {
  content: "";
  position: absolute;
  inset: 25%;
  background: var(--red);
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.25);
}

.map-cell.cleared {
  background: #315b37;
}

.map-cell.portal::after {
  content: "";
  position: absolute;
  inset: 22%;
  border: 3px solid var(--gold);
  background: #8b5cf6;
  animation: portal-pulse 0.9s steps(2) infinite;
}

@keyframes portal-pulse {
  50% { background: var(--gold); }
}

.map-cell.arena {
  background: #241a33;
  border-color: #3b2a52;
}

.map-cell.arena.locked::after {
  content: "";
  position: absolute;
  inset: 32%;
  background: #6b6f78;
}

.map-cell.arena.open {
  background: #4b2a6e;
}

.map-cell.arena.open::after {
  content: "";
  position: absolute;
  inset: 22%;
  background: #c084fc;
  animation: portal-pulse 0.9s steps(2) infinite;
}

.map-cell.arena.beaten {
  background: #8a6a1c;
}

.map-cell.arena.beaten::after {
  content: "";
  position: absolute;
  inset: 28%;
  background: var(--gold);
}

.map-cell.current {
  outline: 4px solid var(--gold);
  outline-offset: 1px;
}

.map-cell.current::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 3px solid #fff3b0;
}

.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.86rem;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-box {
  width: 16px;
  height: 16px;
  display: inline-block;
  border: 2px solid #100d0b;
}

.legend-box.current {
  background: var(--gold);
}

.legend-box.clear {
  background: #315b37;
}

.legend-box.danger {
  background: var(--red);
}

.legend-box.gate {
  background: #4b2a6e;
}

.legend-box.unknown {
  background: #18120e;
}

.tracker {
  display: grid;
  gap: 8px;
  margin: 0;
}

.tracker div {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 0;
  overflow-wrap: anywhere;
}

.spell-list {
  display: grid;
  gap: 10px;
}

.spell-card {
  display: grid;
  gap: 5px;
  padding: 10px;
  border: 2px solid var(--line);
  background: var(--panel-2);
}

.spell-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.spell-swatch {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  background: var(--c);
  border: 2px solid #100d0b;
}

.spell-card strong {
  color: var(--gold);
}

.spell-status {
  margin-left: auto;
  color: #9ee49c;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.spell-status.cooling {
  color: #ffcf7a;
}

.spell-status.empty {
  color: #ff8b7d;
}

.spell-card.locked {
  opacity: 0.6;
}

.spell-card.locked .spell-status {
  color: var(--muted);
}

.spell-card p,
.small-note {
  margin-bottom: 0;
  font-size: 0.9rem;
}

.small-note {
  margin-bottom: 10px;
}

.upgrade-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.upgrade-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  font-size: 0.9rem;
}

.upgrade-list li i {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  background: var(--c);
  border: 2px solid #100d0b;
}

.upgrade-list li b {
  margin-left: auto;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.upgrade-list li.empty {
  color: var(--muted);
  border-style: dashed;
}

.bestiary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.bestiary canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  border: 3px solid #100d0b;
  background: #18120e;
  image-rendering: pixelated;
}

.bestiary canvas.found {
  background: #3a2c20;
}

.p2-meters {
  display: grid;
  gap: 8px;
  padding-top: 8px;
  border-top: 2px dashed var(--line);
}

.p2-meters[hidden] {
  display: none;
}

.controls.coop {
  margin-top: 6px;
}

.controls.coop .who {
  font-family: var(--display);
  color: var(--gold);
}

.controls.coop b {
  color: var(--gold);
}

.combo-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.combo-list li {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border: 2px dashed var(--line);
  background: var(--panel-2);
  font-size: 0.9rem;
}

.combo-list li.found {
  border-style: solid;
  border-left: 6px solid var(--c);
}

.combo-list li strong {
  font-family: var(--display);
  color: var(--muted);
}

.combo-list li.found strong {
  color: var(--c);
}

.combo-list li span {
  color: var(--text);
  font-weight: 600;
}

.combo-list li p {
  margin: 0;
  font-size: 0.85rem;
}

.hat-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.hat-grid canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  border: 3px solid #100d0b;
  background: #18120e;
  image-rendering: pixelated;
}

.hat-grid canvas.found {
  background: #3a2c20;
  cursor: pointer;
}

.hat-grid canvas.found:hover {
  border-color: var(--muted);
}

.hat-grid canvas.worn {
  border-color: var(--gold);
}

@media (max-width: 1080px) {
  .app {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app {
    width: auto;
    margin: 8px 16px;
  }

  .game-shell {
    padding: 10px;
  }

  .top-bar,
  .side-panel {
    grid-template-columns: 1fr;
    display: grid;
  }

  .stats {
    min-width: 0;
  }

  .meter {
    grid-template-columns: 58px 1fr 62px;
  }

  /* On phones the canvas is too small to cover, so the pad sits below it. */
  .touch-controls {
    position: static;
    margin-top: 10px;
  }

  .stick {
    width: 104px;
    height: 104px;
  }

  .touch-buttons {
    grid-template-columns: repeat(3, 48px);
  }

  .tbtn {
    width: 48px;
    height: 48px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .map-cell.portal::after,
  .map-cell.arena.open::after {
    animation: none;
  }

  .meter-fill {
    transition: none;
  }
}
