:root {
  --bg: #0c1220;
  --panel: #152033ee;
  --ink: #f6f1e4;
  --muted: #c9c0ae;
  --gold: #e6c56a;
  --gold-2: #8c6a2e;
  --line: #e6c56a;
  --danger: #ff8b7a;
  --ok: #8ee0a8;
  --blue: #8eb7ff;
  color: var(--ink);
  font-family: Nunito, "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 500px at 10% -10%, #243864 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #3a2a14 0%, transparent 40%),
    var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { user-select: none; }
button, h1, h2, h3 { font-family: Cinzel, Palatino, serif; }
button { font-weight: 700; }
h1, h2, h3, p { margin: 0 0 0.4rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.fine { color: var(--muted); font-size: 12px; margin-top: 10px; }
.kicker { letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); font-size: 12px; font-weight: 800; }
.who { color: var(--gold); font-weight: 800; }
.stars { color: var(--gold); font-size: 22px; letter-spacing: 2px; }

button {
  font: inherit;
  color: var(--ink);
  background: linear-gradient(#31456f, #1c2c4c);
  border: 2px solid var(--gold);
  border-radius: 14px;
  padding: 10px 14px;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: default; filter: none; transform: none; }
button.big { font-size: 20px; padding: 12px 16px; width: 100%; }
button.ghost { background: transparent; }
button.small { padding: 6px 10px; border-radius: 10px; }
button:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.icon-btn {
  position: fixed;
  z-index: 20;
  top: 12px;
  right: 12px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 20px;
}

.screen { padding: 18px 18px 28px; max-width: 1180px; margin: 0 auto; }
#screen-play {
  max-width: none;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 8px;
  padding: 10px 68px 12px 12px;
}

.hero {
  position: relative;
  border-radius: 22px;
  overflow: hidden;
  border: 2px solid var(--gold);
  min-height: 220px;
  margin-bottom: 14px;
}
.hero img { width: 100%; height: 280px; object-fit: cover; display: block; }
.hero-copy {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 22px 22px 16px;
  background: linear-gradient(transparent, #0c1220ee 70%);
}
.hero h1 { font-size: 42px; text-shadow: 0 2px 0 #000; }

.menu-grid { display: grid; grid-template-columns: 320px 1fr; gap: 14px; }
.panel {
  background: var(--panel);
  border: 2px solid var(--gold-2);
  border-radius: 18px;
  padding: 14px;
  backdrop-filter: blur(6px);
}
.diffs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.diffs button { min-height: 64px; }
.diffs button small { display: block; color: var(--muted); font-family: Nunito, sans-serif; font-size: 12px; }
.diffs button.on { background: linear-gradient(#6a5424, #3c3116); box-shadow: 0 0 0 2px var(--gold) inset; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row .big { width: auto; flex: 1; }
.card-label { display: flex; flex-direction: column; min-width: 0; }
.row.spread { justify-content: space-between; align-items: center; }
.nodes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.node {
  min-height: 92px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
}
.node span, .node i { font-family: Nunito, sans-serif; font-style: normal; font-size: 12px; color: var(--gold); }
.node b { font-size: 14px; }
.node.locked { filter: grayscale(0.7); }
.shelf { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }
.shelf img {
  width: 92px; height: 92px; object-fit: cover;
  border-radius: 18px; border: 3px solid var(--gold);
  animation: bob 2.6s ease-in-out infinite;
}
.shelf img:nth-child(2) { animation-delay: 0.15s; }
.shelf img:nth-child(3) { animation-delay: 0.3s; }
.shelf img:nth-child(4) { animation-delay: 0.45s; }
.shelf img:nth-child(5) { animation-delay: 0.6s; }
@keyframes bob { 50% { transform: translateY(-7px); } }

.story { display: grid; grid-template-columns: 180px 1fr; gap: 16px; align-items: center; margin-top: 8vh; }
.story canvas {
  width: 180px; height: 200px; border-radius: 18px;
  background: #10192b; border: 2px solid var(--gold);
}
.story p { font-size: 18px; line-height: 1.45; }

.hud, .side, .shop { position: relative; z-index: 2; }
.hud {
  display: flex; gap: 14px; align-items: center; justify-content: space-between;
  background: #121b2ecc; border: 2px solid var(--gold-2); border-radius: 14px; padding: 8px 12px;
}
.pill { margin-left: 8px; color: var(--gold); font-size: 13px; }
.res { font-size: 20px; }
.coin {
  display: inline-block;
  width: 1.05em;
  height: 1.05em;
  margin: 0 0.16em;
  vertical-align: -0.16em;
  background: center / contain no-repeat url("../assets/icons/coins.svg");
}
.res .coin { width: 1.2em; height: 1.2em; margin: 0 0.28em 0 0; vertical-align: -0.18em; }
.heart { color: #ff6d7d; }
.play-main { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 10px; min-height: 0; overflow: hidden; }
.play-main.has-item { grid-template-columns: 240px minmax(0, 1fr) 280px; }
.stage { min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; gap: 8px; }
.frame { position: relative; }
#cv {
  display: block; background: #16351f; border-radius: 16px;
  border: 3px solid #e6c56a; touch-action: none; cursor: crosshair;
}
.side { display: flex; flex-direction: column; gap: 8px; min-height: 0; overflow: auto; }
.preview {
  background: #10192bcc; border-radius: 12px; padding: 8px 10px; min-height: 52px;
  border: 1px solid #31405c; font-size: 14px;
}
.horn { background: linear-gradient(#6d5420, #3a2c10); }
.horn em { display: block; font-style: normal; font-family: Nunito, sans-serif; font-size: 13px; color: var(--gold); }
.detail { background: #10192bcc; border-radius: 12px; padding: 8px 10px; border: 1px solid #31405c; }
.detail-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.detail-head h3 { font-size: 16px; margin: 0; }
.detail-head img {
  width: 48px; height: 48px; border-radius: 10px; object-fit: cover; flex: 0 0 auto;
  background: #0e1626; border: 2px solid var(--gold);
}
.detail-head img[hidden] { display: none !important; }
.shop {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px;
  max-height: 168px; overflow: auto; align-content: start;
}
.item-row {
  display: flex; align-items: center; gap: 8px;
  background: #10192bcc; border: 1px solid #31405c; border-radius: 12px; padding: 6px 8px;
}
.item-row[hidden] { display: none !important; }
.item-kicker { color: var(--gold); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; flex: 0 0 auto; }
.items { display: flex; gap: 6px; overflow-x: auto; flex: 1; min-width: 0; }
.item-btn {
  flex: 0 0 auto; display: flex; align-items: center; gap: 6px;
  min-height: 48px; padding: 4px 10px 4px 4px; font-size: 13px;
}
.item-btn img { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: #0e1626; }
.item-btn.on { box-shadow: 0 0 0 3px #fff1b8; }
.item-btn.poor { color: var(--danger); }
.item-card {
  display: flex; flex-direction: column; gap: 6px; min-height: 0; overflow: auto;
  background: #10192bcc; border: 1px solid #31405c; border-radius: 12px; padding: 10px;
}
.item-card[hidden] { display: none !important; }
.item-card img {
  width: 72px; height: 72px; border-radius: 12px; object-fit: cover;
  background: #0e1626; border: 2px solid var(--gold);
}
.item-card h3 { font-size: 18px; margin: 0; }
.item-card p { font-size: 14px; }
.item-card .stats { margin: 0; padding-left: 18px; font-size: 14px; }
.item-card .stats li { margin: 3px 0; }
.item-card .danger { color: var(--danger); }
#btn-equip { margin-top: auto; }
.card {
  display: flex; align-items: center; gap: 8px; text-align: left; min-height: 74px;
}
.face-wrap { position: relative; width: 58px; height: 58px; flex: 0 0 auto; }
.card img.portrait, .card canvas { width: 58px; height: 58px; border-radius: 8px; object-fit: cover; background: #0e1626; display: block; }
.skill-badge {
  position: absolute; right: -6px; bottom: -6px; width: 26px; height: 26px;
  border-radius: 6px; border: 2px solid #f0d78a; background: #0e1626;
  box-shadow: 0 2px 6px #000a;
}
.skill-line { display: flex; align-items: center; gap: 8px; margin: 6px 0 2px; }
.skill-line[hidden] { display: none !important; }
.skill-line img { width: 36px; height: 36px; border-radius: 8px; border: 1px solid #e6c56a; background: #0e1626; }
.skill-line b { font-family: Nunito, sans-serif; font-size: 14px; color: var(--gold); }
.card b { display: block; font-size: 14px; }
.card small { color: var(--gold); font-family: Nunito, sans-serif; }
.card.on { box-shadow: 0 0 0 3px #fff1b8; }
.card.poor small { color: var(--danger); }

#bossbar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 6px;
  width: 46px;
  box-sizing: border-box;
  padding: 8px 6px;
  background: #0e1524ee;
  border: 2px solid var(--gold);
  border-radius: 12px;
  overflow: hidden;
}
#bossbar-name {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  text-align: center;
  font-family: Cinzel, serif;
  font-size: 13px;
  line-height: 1;
}
#bossbar .track {
  position: relative;
  flex: 1 1 auto;
  width: 14px;
  min-height: 0;
  margin: 0;
  background: #2a3348;
  border-radius: 8px;
  overflow: hidden;
}
#bossbar-fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 100%;
  background: #8fd0ff;
}
#banner, #toast, #bossbar { pointer-events: none; }
#banner, #toast {
  position: absolute; left: 50%; transform: translateX(-50%);
  text-align: center;
}
#pause-veil[hidden], #banner[hidden], #toast[hidden], #bossbar[hidden] { display: none !important; }
#banner {
  top: 14px; background: #0e1524ee; border: 2px solid var(--gold);
  border-radius: 14px; padding: 8px 16px; min-width: 240px;
}
#banner strong { display: block; font-family: Cinzel, serif; font-size: 22px; }
#toast {
  bottom: 14px; background: #10192bee; border-radius: 999px;
  padding: 8px 14px; border: 1px solid var(--gold-2); max-width: 80%;
}
#pause-veil {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: #070b14aa; font-family: Cinzel, serif; font-size: 48px; border-radius: 16px;
}
.pulse, #btn-horn.ready { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse {
  50% { transform: translateY(-1px) scale(1.03); box-shadow: 0 0 0 4px rgba(255, 214, 120, 0.35); }
}
.node.pulse { animation: pulse 1.3s ease-in-out infinite; }

.modal {
  position: fixed; inset: 0; background: #070b14cc; z-index: 30;
  display: grid; place-items: center; padding: 18px;
}
.dialog {
  max-width: 640px; background: #152033; border: 2px solid var(--gold);
  border-radius: 18px; padding: 16px 18px;
}
.dialog ol { margin: 0 0 10px; padding-left: 18px; }
.dialog li { margin: 6px 0; }
.dialog.wide {
  max-width: 880px;
  width: min(880px, 100%);
  max-height: min(88vh, 860px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.dialog.wide > .big { flex: 0 0 auto; margin-top: 10px; }
#hero-book, #item-book { overflow: auto; min-height: 0; }
.roster { margin: 12px 0 4px; }
.roster h3 { margin: 0; font-size: 20px; }
.roster .lead { margin: 2px 0 8px; color: var(--muted); font-size: 14px; }
.roster h4 {
  margin: 10px 0 6px;
  font-family: Nunito, sans-serif;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
}
.roster-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hero-card {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 8px;
  background: #10192bcc;
  border: 1px solid #31405c;
  border-radius: 12px;
  padding: 8px;
}
.hero-card img.portrait {
  width: 64px; height: 64px; border-radius: 10px; object-fit: cover;
  background: #0e1626; border: 2px solid var(--gold);
}
.hero-card .top { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.hero-card b { font-size: 15px; }
.hero-card .phase {
  font-family: Nunito, sans-serif;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 1px 7px;
  white-space: nowrap;
}
.hero-card .phase.start { color: var(--ok); border: 1px solid #2e6a44; }
.hero-card .phase.mid { color: var(--gold); border: 1px solid var(--gold-2); }
.hero-card .phase.late { color: #ffb7a8; border: 1px solid #8a4a3a; }
.hero-card .skill { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.hero-card .skill img {
  width: 22px; height: 22px; border-radius: 5px;
  border: 1px solid var(--gold); background: #0e1626;
}
.hero-card .skill span { font-size: 13px; color: var(--gold); font-weight: 800; }
.hero-card p { font-size: 13px; line-height: 1.35; margin: 0; }
.hero-card .cost { color: var(--muted); font-size: 12px; margin-top: 3px; }
.hero-card .stat-line { color: var(--gold); font-size: 13px; font-weight: 800; margin: 1px 0; }

@media (max-width: 980px) {
  .menu-grid, .play-main, .play-main.has-item, .story { grid-template-columns: 1fr; }
  .nodes { grid-template-columns: repeat(2, 1fr); }
  .hero h1 { font-size: 30px; }
  #screen-play { height: auto; min-height: 100vh; }
  .shop { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: 148px; }
  .roster-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .shelf img, .pulse, #btn-horn.ready, .node.pulse { animation: none; }
}
