:root {
  color-scheme: dark;
  --bg: #101218;
  --bg-2: #171a22;
  --bg-3: #1e222d;
  --bg-4: #12141c;
  --line: #313646;
  --text: #d7dbe6;
  --muted: #9aa3b8;
  --accent: #e4b15a;
  --accent-dim: #3a3120;
  --blue: #8eb6ff;
  --hp: #e15b64;
  --ok: #79d39a;
  --boss: #c58bff;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  font-size: 13px;
  line-height: 1.4;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button {
  background: #262b38;
  border: 1px solid var(--line);
  padding: 4px 10px;
  cursor: pointer;
}
button:hover { border-color: #8a7340; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent-dim); border-color: #8a6d32; color: #f3ddb0; }
button.danger { border-color: #7a3a40; color: #ffb4b8; }
button.ghost { background: transparent; color: var(--muted); }
button.active, .nav-btn.active { background: #2c2618; color: var(--accent); border-color: #8a6d32; }
button:focus-visible, textarea:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.muted, .fine { color: var(--muted); }
.fine { font-size: 12px; }
h2 { font-size: 16px; margin: 0 0 6px; font-weight: 650; }
h3 { font-size: 12px; margin: 14px 0 6px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 650; }
p { margin: 0 0 8px; }
.lede { color: var(--muted); margin: 0 0 10px; }

#app {
  height: 100%;
  display: grid;
  grid-template-columns: 188px minmax(0, 1fr) 280px;
  grid-template-rows: auto minmax(0, 1fr);
}
#sidebar {
  grid-column: 1;
  grid-row: 1 / span 2;
  background: #14171f;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.brand { padding: 14px 12px 10px; }
.brand strong { display: block; font-size: 18px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.brand span { color: var(--muted); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; }
#nav { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.nav-btn { text-align: left; background: transparent; border-color: transparent; padding: 7px 8px; }
.nav-btn:hover { background: #222633; }
.side-foot { margin-top: auto; padding: 12px; color: var(--muted); font-size: 12px; }

#topbar {
  grid-column: 2 / span 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.topbar-main {
  display: flex;
  gap: 14px;
  align-items: center;
  min-width: 0;
}
.action { display: flex; gap: 8px; align-items: center; flex: 1; min-width: 240px; }
.action-copy { flex: 1; min-width: 140px; }
.action-name { font-size: 13px; margin-bottom: 3px; }
.meters { width: 180px; display: flex; flex-direction: column; gap: 3px; }
.currencies { display: flex; flex-wrap: wrap; gap: 10px 12px; justify-content: flex-end; }
.cur b { display: block; color: var(--accent); font-size: 15px; }
.cur span { color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.speeds { display: flex; gap: 4px; }
.goal-hud {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid #2e3544;
  background: linear-gradient(90deg, #1a1e28, #151820);
}
.goal-copy {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 8px;
  align-items: baseline;
  overflow: hidden;
}
.goal-kicker {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.goal-copy strong {
  font-size: 13px;
  font-weight: 650;
  color: #e8edf7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.goal-eta {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
  align-items: baseline;
  color: var(--muted);
  font-size: 12px;
}
.goal-eta .num {
  color: var(--accent);
  font-size: 12px;
  font-weight: 650;
}
.goal-cta {
  flex-shrink: 0;
}
.goal-cta button {
  padding: 2px 8px;
  font-size: 12px;
  white-space: nowrap;
}

.bar {
  position: relative;
  height: 16px;
  background: #0d0f15;
  border: 1px solid var(--line);
  overflow: hidden;
}
.bar > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #8a6a2f, var(--accent)); }
.bar.xp > span { background: linear-gradient(90deg, #3d527a, var(--blue)); }
.bar.hp > span { background: linear-gradient(90deg, #7a3038, var(--hp)); }
.bar.boss > span { background: linear-gradient(90deg, #5a3d78, var(--boss)); }
.bar em {
  position: absolute;
  inset: 0;
  text-align: center;
  font-style: normal;
  font-size: 12px;
  line-height: 14px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 1px #000;
}

#main {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px;
  min-width: 0;
  min-height: 0;
}
#arena-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
#panel {
  flex: 1;
  min-height: 0;
  overflow: auto;
}
#sheet {
  grid-column: 3;
  grid-row: 2;
  overflow: auto;
  /* Extra bottom padding so Echo shop isn't flush with the viewport. */
  padding: 12px 12px 22px;
  background: #14171f;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.sheet-main { flex: 1 1 auto; min-height: 0; }
.sheet-panels {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}
.worn-panel {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: #10131a;
}
.worn-panel h3 {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.worn-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.worn-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
}
.worn-row.empty { opacity: 0.55; }
.worn-row .ico {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
}
.worn-empty {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border: 1px dashed var(--line);
  box-sizing: border-box;
  font-size: 12px;
}
.worn-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.worn-slot {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.worn-copy strong {
  font-size: 13px;
  font-weight: 650;
  line-height: 1.2;
}
.bonus-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
}
.bonus-rank {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--accent);
}
.bonus-toggle {
  flex: 0 0 auto;
  min-width: 44px;
  padding: 3px 8px;
  font-size: 12px;
}
.bonus-empty {
  list-style: none;
  font-size: 12px;
  padding: 2px 0;
}
.coach {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0 0 8px;
  padding: 8px 10px;
  border: 1px solid #3a4330;
  background: #1a2016;
  color: #d7e0c8;
  font-size: 12px;
  line-height: 1.35;
}
.coach.hidden { display: none; }
.coach-copy { flex: 1; min-width: 0; }
.coach-copy strong {
  display: block;
  margin-bottom: 2px;
  color: #e8f0d4;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.coach-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}
.coach-actions button {
  padding: 2px 8px;
  font-size: 12px;
  white-space: nowrap;
}
.arena-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 520px) minmax(220px, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  overflow: hidden;
}
.stage {
  align-self: start;
  background: #0c0e13;
  border: 1px solid var(--line);
}
#arena { display: block; width: 100%; background: #0c0e13; }
#pattern-list {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.boss-list {
  --boss-row: 66px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-x: hidden;
  overflow-y: auto;
  max-height: calc(10 * var(--boss-row) + 9 * 4px);
}
.stack { display: flex; flex-direction: column; gap: 8px; }
.card {
  background: var(--bg-3);
  border: 1px solid var(--line);
  padding: 8px;
}
.card.selected { border-color: #4e5870; }
.card.active { border-color: #8a6d32; }
.card.locked {
  opacity: 1;
  background: var(--bg-4);
}
.card.locked header strong { color: #c2c8d8; }
.card.locked .meta,
.card.locked .boss-status,
.card.locked p { color: #9aa3b8; }
.card header { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.card p { color: var(--muted); font-size: 12px; }
.card .meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.tier { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.diff {
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0 4px;
  border: 1px solid var(--line);
  color: var(--muted);
  flex-shrink: 0;
}
.diff-easy { color: #79d39a; border-color: #2f5a40; }
.diff-normal { color: #8eb6ff; border-color: #3a4f78; }
.diff-hard { color: #e4b15a; border-color: #8a6d32; }
.diff-lunatic { color: #ff9aa8; border-color: #7a3a40; }
.challenge-banner {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 0 8px;
  padding: 8px 10px;
  border: 1px solid #6a4a2a;
  background: linear-gradient(120deg, rgba(80, 48, 20, 0.45), rgba(30, 24, 18, 0.35));
  color: #f0d2a8;
  font-size: 12px;
}
.challenge-banner strong {
  font-size: 13px;
  letter-spacing: 0.02em;
}
.challenge-active {
  border-color: #6a4a2a;
}
.boss-card {
  padding: 5px 7px;
}
.boss-card header {
  align-items: center;
  margin-bottom: 2px;
}
.boss-card .boss-title {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.boss-portrait {
  width: 22px;
  height: 24px;
  flex-shrink: 0;
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.04);
  display: grid;
  place-items: center;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: #f4f7ff;
  overflow: hidden;
  background: #07090e;
}
.boss-portrait.has-sprite {
  display: block;
  place-items: unset;
}
/* Carapace sheets are 4×128×136 — clip to the first frame inside the frame.
   Intrinsic width/height attrs + aspect-ratio reserve layout before decode (CLS). */
.boss-portrait-strip {
  height: 100%;
  width: auto;
  max-width: none;
  aspect-ratio: 512 / 136;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
/* List uses dedicated first-frame thumbs (44×48 → 22×24 box). */
.boss-portrait-thumb {
  width: 100%;
  height: 100%;
  aspect-ratio: 44 / 48;
  display: block;
  object-fit: cover;
  object-position: left top;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.boss-card.locked .boss-portrait {
  filter: grayscale(0.85) brightness(0.55);
}
.boss-card.active .boss-portrait,
.boss-card.selected .boss-portrait {
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(228, 177, 90, 0.35);
}
.boss-card header strong {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.boss-card header button {
  padding: 2px 8px;
  font-size: 12px;
  flex-shrink: 0;
}
.boss-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.boss-card .meta {
  margin-bottom: 1px;
  font-size: 12px;
  gap: 8px;
}
.boss-card .meta:last-child { margin-bottom: 0; }
.boss-card .boss-status { color: var(--muted); }
.skill-list { --boss-row: 78px; }
.skill-card {
  padding: 6px 8px;
  cursor: pointer;
}
.skill-card header {
  align-items: center;
  margin-bottom: 2px;
}
.skill-card header strong {
  font-size: 13px;
}
.skill-card header button {
  padding: 2px 8px;
  font-size: 12px;
}
.skill-card .meta {
  margin-bottom: 2px;
  font-size: 12px;
}
.skill-card .skill-bar {
  height: 6px;
  margin-bottom: 4px;
}
.skill-card .skill-blurb {
  margin: 0;
  font-size: 12px;
  line-height: 1.3;
  color: var(--muted);
}
.shot-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 8px;
  padding: 6px 8px;
  background: var(--bg-3);
  border: 1px solid var(--line);
}
.shot-label {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.shot-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.shot-options button {
  font-size: 12px;
  padding: 3px 8px;
}
.battle-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.battle-toolbar .fine { flex: 1; min-width: 140px; }
.spell-boss { margin-bottom: 12px; }
.spell-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 6px;
}
.spell-card.special { border-color: #4a4258; }
.spell-badge {
  display: inline-block;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ok);
  margin-left: 4px;
}
.spell-badge.no-bomb { color: var(--blue); }
.card.row { display: grid; grid-template-columns: 32px 1fr auto; gap: 8px; align-items: center; }
.log {
  flex: 0 0 auto;
  margin-top: auto;
  height: 132px;
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--bg-4);
  padding: 6px 8px;
  font-size: 12px;
  color: var(--muted);
}
.log .log-rare {
  color: #c58bff;
}
.sheet .stat-bonus {
  color: #79d39a;
  font-weight: 500;
}
.bank { display: flex; flex-wrap: wrap; gap: 6px; }
.slot {
  width: 86px;
  min-height: 86px;
  background: var(--bg-4);
  border: 1px solid var(--line);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.slot b { font-size: 12px; font-weight: 600; }
.slot .count { margin-top: auto; text-align: right; color: var(--accent); }
.slot.empty { opacity: 0.45; }
.slot.rare { border-color: #c9a24a; box-shadow: inset 0 0 0 1px rgba(255, 208, 138, 0.25); }
.slot.rare b { color: #ffd08a; }
.equip { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.equip-slot {
  border: 1px solid var(--line);
  background: var(--bg-3);
  padding: 8px;
  min-height: 108px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.slot-name { color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.empty-mark { color: var(--muted); }
.sheet { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin: 0 0 8px; }
.sheet div { display: contents; }
.sheet dt { color: var(--muted); }
.sheet dd { margin: 0; text-align: right; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
table.grid th { color: var(--muted); font-size: 12px; font-weight: 650; }
ul.plain, ul.milestones { margin: 0; padding-left: 16px; }
ul.milestones { color: var(--muted); font-size: 12px; }
ul.milestones .done { color: var(--ok); }
textarea {
  width: 100%;
  margin-top: 8px;
  background: #0d0f15;
  border: 1px solid var(--line);
  padding: 8px;
  resize: vertical;
}
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.special-name { font-size: 12px; color: #f0d48a; }
.offline-hint { font-size: 12px; color: var(--muted); }
.offline-hint.ready { color: var(--ok); }
.offline-hint.waiting { color: var(--accent); }
.run-toast-host { margin: 0 0 10px; }
.run-toast {
  position: relative;
  padding: 10px 28px 10px 12px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  font-size: 12px;
  line-height: 1.4;
}
.run-toast.ok { border-color: #3d5a40; }
.run-toast.bad { border-color: #6a3535; }
.run-toast strong { display: block; margin-bottom: 4px; }
.run-toast .toast-x {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 16px;
}
.modal {
  width: min(460px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 14px;
  box-shadow: var(--shadow);
}
.modal-dialogue {
  width: min(520px, 100%);
}
.dialogue-modal {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  align-items: start;
}
.dialogue-art {
  width: 90px;
  height: 96px;
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  background: #07090e;
  object-fit: cover;
}
.dialogue-art.has-sprite {
  display: block;
}
.dialogue-art.svg {
  display: grid;
  place-items: center;
  overflow: hidden;
}
.dialogue-art.svg svg {
  width: 100%;
  height: 100%;
}
.dialogue-boss {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.dialogue-speaker {
  margin: 0 0 6px;
  font-weight: 700;
  color: #f0d48a;
}
.dialogue-text {
  margin: 0 0 10px;
  line-height: 1.45;
  font-size: 14px;
}
@media (max-width: 520px) {
  .dialogue-modal {
    grid-template-columns: 1fr;
  }
}
#tooltip {
  position: fixed;
  z-index: 40;
  max-width: 280px;
  background: #0c0e13;
  border: 1px solid #5c657c;
  padding: 7px 9px;
  font-size: 12px;
  white-space: pre-wrap;
  pointer-events: none;
  box-shadow: var(--shadow);
}

@media (max-width: 900px) {
  body { overflow: auto; }
  #app {
    height: auto;
    min-height: 100%;
    display: flex;
    flex-direction: column;
  }
  #sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  #sidebar .brand span, .side-foot { display: none; }
  #nav { flex-direction: row; overflow-x: auto; padding-bottom: 8px; }
  .nav-btn { white-space: nowrap; }
  #topbar { flex-wrap: wrap; }
  #main {
    overflow: visible;
    height: auto;
  }
  #arena-view {
    height: auto;
    overflow: visible;
  }
  #panel { overflow: visible; }
  #sheet { overflow: visible; border-left: 0; border-top: 1px solid var(--line); }
  .arena-layout {
    grid-template-columns: 1fr;
    overflow: visible;
    flex: none;
  }
  .boss-list { max-height: calc(10 * var(--boss-row) + 9 * 4px); }
  .log {
    position: sticky;
    bottom: 0;
    z-index: 3;
    margin-top: 12px;
    box-shadow: 0 -10px 18px rgba(0, 0, 0, 0.35);
  }
  .meters { width: 100%; }
}
