:root {
  --bg: #0b0d12;
  --frame: #444b58;
  --text: #9aa3b2;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, Consolas, monospace;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#stage {
  position: relative;
  width: min(100vw, calc((100vh - 170px) * 1.6));
  aspect-ratio: 8 / 5;
  border: 2px solid var(--frame);
  background: #000;
  overflow: hidden;
}

#view {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(0,0,0,.3), transparent 25%, transparent 75%, rgba(0,0,0,.5)),
    radial-gradient(circle at center, transparent 40%, rgba(0,0,0,.75) 100%);
}

#minimap {
  position: absolute;
  top: 8px;
  right: 8px;
  image-rendering: pixelated;
  opacity: .85;
  max-width: 28%;
}

#hud {
  position: absolute;
  left: 8px;
  bottom: 6px;
  font-size: 12px;
  text-shadow: 0 1px 2px #000;
}

#help { margin: 0; font-size: 12px; }

#party {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: min(100vw, calc((100vh - 170px) * 1.6));
  padding: 0 4px;
}

.hero {
  --accent: #777;
  display: grid;
  grid-template-columns: 56px 1fr;
  grid-template-areas: "p n" "p s" "b b" "t g";
  column-gap: 8px;
  align-items: center;
  padding: 6px;
  background: #151821;
  border: 2px solid #2a303c;
  border-top-color: var(--accent);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.hero:hover { border-color: var(--accent); }
.hero.down { opacity: .45; filter: grayscale(1); }
.hero .portrait {
  grid-area: p;
  width: 56px; height: 56px;
  overflow: hidden;
  background: #0c0e13;
  border: 2px solid var(--accent);
  display: grid; place-items: center;
  font-size: 28px; color: var(--accent);
}
.hero .portrait img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero .name { grid-area: n; font-size: 14px; color: #e4e8f0; font-weight: bold; }
.hero .sub { grid-area: s; font-size: 11px; }
.hero .hpbar { grid-area: b; height: 8px; margin-top: 6px; background: #0c0e13; border: 1px solid #000; }
.hero .fill { height: 100%; background: #4aa860; transition: width .2s; }
.hero .fill[data-level="low"] { background: #d0a038; }
.hero .fill[data-level="crit"] { background: #c8403c; }
.hero .hptext { grid-area: t; font-size: 11px; margin-top: 2px; }
.hero .badges { grid-area: g; font-size: 10px; text-align: right; color: #d0a038; }

@media (max-width: 720px) {
  #party { grid-template-columns: repeat(2, 1fr); }
}

#log {
  width: min(100vw, calc((100vh - 170px) * 1.6));
  height: 3.6em;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0 8px;
  font-size: 12px;
  line-height: 1.2;
  color: #b9c1cf;
}
#log p { margin: 0; }
#log p:not(:last-child) { opacity: .55; }

#flash { position: absolute; inset: 0; pointer-events: none; background: #c8201c; opacity: 0; transition: opacity .3s; }
#flash.on { opacity: .35; transition: none; }

#over { position: absolute; inset: 0; display: grid; place-content: center; gap: 12px; text-align: center; background: rgba(0,0,0,.8); }
#over[hidden] { display: none; }
#over h1 { margin: 0; color: #c8403c; font-size: 28px; }
#over button { font: inherit; padding: 8px 16px; background: #2a303c; color: var(--text); border: 2px solid var(--frame); cursor: pointer; }
.hero.ready { box-shadow: 0 0 0 1px var(--accent) inset; }
.hero .cd { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); }
.hero { position: relative; }

#shop, #victory { position: absolute; inset: 0; display: grid; place-content: center; gap: 10px; text-align: center; background: rgba(0,0,0,.82); }
#shop[hidden], #victory[hidden] { display: none; }
#shop h2 { margin: 0; color: #d9cf9a; }
#shop-list { display: grid; gap: 6px; min-width: 280px; }
#shop button, #victory button { font: inherit; padding: 8px 14px; background: #1c212b; color: var(--text); border: 2px solid var(--frame); cursor: pointer; }
#shop button:hover:not(:disabled), #victory button:hover { border-color: #d9cf9a; }
#shop button:disabled { opacity: .45; cursor: default; }
#victory h1 { margin: 0; color: #d2b24a; font-size: 26px; }
#victory p { margin: 0; }

#title { position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px; overflow: auto; background: linear-gradient(rgba(11,13,18,.78), rgba(11,13,18,.93)), #0b0d12 url('assets/title.jpg') center / cover; text-align: center; }
#title[hidden] { display: none; }
#title h1 { margin: 0; font-size: 32px; letter-spacing: 3px; color: #d9cf9a; }
#title p { margin: 0; font-size: 13px; }
#title-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; width: 100%; }
.pick { display: grid; grid-template-columns: 52px 1fr; gap: 8px; align-items: center; padding: 6px; background: #151821; color: var(--text); border: 2px solid #2a303c; font: inherit; text-align: left; cursor: pointer; }
.pick img { width: 52px; height: 52px; object-fit: cover; border: 1px solid #000; background: #0c0e13; }
.pick strong { display: block; color: #e4e8f0; font-size: 13px; }
.pick span { display: block; font-size: 11px; }
.pick em { display: block; font-size: 10px; color: #d0a038; font-style: normal; min-height: 12px; }
.pick.on { border-color: #d9cf9a; background: #1b2030; }
#title .row { display: flex; gap: 10px; }
#title button:not(.pick) { font: inherit; padding: 10px 22px; background: #1c212b; color: var(--text); border: 2px solid var(--frame); cursor: pointer; }
#title button:not(.pick):hover:not(:disabled) { border-color: #d9cf9a; }
#title button:disabled { opacity: .5; cursor: default; }

#sheet { position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; gap: 8px; padding: 12px; overflow: auto; background: rgba(8,10,14,.96); font-size: 12px; }
#sheet[hidden] { display: none; }
#sheet h2 { margin: 0; color: #d9cf9a; font-size: 20px; }
#sheet h3 { margin: 10px 0 4px; color: #9aa3b2; font-size: 12px; letter-spacing: 1px; text-transform: uppercase; border-bottom: 1px solid #2a303c; }
#sheet .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
#sheet .abil { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; text-align: center; }
#sheet .abil div { background: #151821; border: 1px solid #2a303c; padding: 4px 0; }
#sheet .abil b { display: block; font-size: 16px; color: #e4e8f0; }
#sheet ul { margin: 0; padding-left: 16px; }
#sheet .row { display: flex; gap: 8px; }
#sheet button { font: inherit; padding: 6px 12px; background: #1c212b; color: var(--text); border: 2px solid var(--frame); cursor: pointer; }
#sheet .tabs button.on { border-color: #d9cf9a; }
.sk-p { color: #d9cf9a; }

#dpad { display: none; grid-template-columns: repeat(3, 64px); gap: 6px; margin: 4px 0 12px; }
#dpad button { height: 48px; font: inherit; font-size: 18px; background: #1c212b; color: var(--text); border: 2px solid var(--frame); touch-action: manipulation; }
#dpad button:active { background: #2a3142; }
@media (pointer: coarse) { #dpad { display: grid; } #help { display: none; } }

@keyframes hurt { 0% { transform: translateX(0); background: #5a1c1c; } 25% { transform: translateX(-4px); } 50% { transform: translateX(4px); } 100% { transform: translateX(0); background: #151821; } }
.hero.hurt { animation: hurt .3s ease-out; }
