:root {
  --bg: #14161a;
  --panel: #1d2026;
  --panel-2: #252931;
  --line: #343944;
  --text: #e8e6e1;
  --muted: #8d929c;
  --accent: #d9a441;
  --accent-2: #4f8ad6;
  --danger: #d65a4f;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  overflow: hidden;
}
button {
  font: inherit; color: var(--text); cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 12px;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Debug menu ---------- */
#debug {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 6px 10px; background: #2a1d1d; border-bottom: 1px solid #5a3333;
}
#debug button { padding: 3px 9px; font-size: 12px; background: #3a2626; border-color: #5a3333; }
.debug-label { font-weight: 700; font-size: 11px; letter-spacing: .12em; color: #ff8a7a; margin-right: 6px; }
.sep { width: 1px; height: 18px; background: #5a3333; margin: 0 4px; }
#debug-status { margin-left: auto; font-size: 12px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }

/* ---------- Tabs ---------- */
#tabs { display: flex; gap: 2px; padding: 8px 10px 0; border-bottom: 1px solid var(--line); }
.tab { border-radius: 8px 8px 0 0; border-bottom: none; background: transparent; color: var(--muted); padding: 8px 18px; }
.tab.active { background: var(--panel); color: var(--text); border-color: var(--line); }

main { flex: 1; min-height: 0; position: relative; }
.page { display: none; height: 100%; }
.page.active { display: grid; }

/* ---------- Character selection ---------- */
#page-select { grid-template-columns: 4fr 1fr; }

.select-left { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 12px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; }
.pager button { width: 40px; }
#page-label { min-width: 110px; text-align: center; color: var(--muted); }

.ring-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#ring { position: relative; }
.ring-bust {
  position: absolute; border-radius: 50%; overflow: hidden; padding: 0;
  background: radial-gradient(circle at 50% 35%, #3a3f4a, #1d2026);
  border: 2px solid var(--line);
  transform: translate(-50%, -50%);
  transition: transform .12s, border-color .12s;
}
.ring-bust img { width: 100%; height: 100%; display: block; pointer-events: none; }
.ring-bust:hover { transform: translate(-50%, -50%) scale(1.08); border-color: var(--accent); }
.ring-bust.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(217,164,65,.35); }
.ring-bust.in-party::after {
  content: "\2713"; position: absolute; right: 8%; bottom: 8%;
  width: 22%; height: 22%; border-radius: 50%; background: var(--accent-2);
  display: grid; place-items: center; font-size: 11px; color: #fff;
}

#featured {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 50%; height: 58%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
}
.featured-row { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; gap: 12px; }
#featured-img { max-height: 100%; max-width: 100%; object-fit: contain; cursor: grab; filter: drop-shadow(0 6px 14px rgba(0,0,0,.6)); }
#featured-img:not([src]) { display: none; }
.select-bottom { display: flex; justify-content: center; padding-top: 10px; }
#add-to-party { white-space: nowrap; background: #2b3a22; border-color: #4b6b3a; padding: 10px 28px; font-size: 16px; font-weight: 600; min-width: 220px; }
#featured-name { font-size: 18px; font-weight: 600; text-align: center; }

.select-right {
  display: flex; flex-direction: column; gap: 10px; min-height: 0;
  padding: 12px; background: var(--panel); border-left: 1px solid var(--line);
}
.select-right h2 { margin: 0; font-size: 15px; color: var(--muted); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
#slots { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.slot {
  flex: 1; min-height: 0; position: relative;
  display: flex; align-items: center; gap: 10px; padding: 8px;
  border: 2px dashed var(--line); border-radius: 10px; background: var(--panel-2);
}
.slot.drag-over { border-color: var(--accent); background: #2f2a1f; }
.slot.filled { border-style: solid; cursor: grab; }
.slot .slot-num { position: absolute; top: 4px; left: 8px; font-size: 11px; color: var(--muted); }
.slot img { height: 100%; max-height: 110px; aspect-ratio: 1; border-radius: 50%; object-fit: cover; background: #1d2026; pointer-events: none; }
.slot .slot-name { flex: 1; font-weight: 600; }
.slot .slot-empty { flex: 1; text-align: center; color: var(--muted); }
.slot .remove { padding: 2px 8px; font-size: 12px; }

#begin-msg { min-height: 1.2em; color: var(--danger); font-size: 13px; }
#begin { padding: 12px; font-size: 16px; font-weight: 700; background: #5a3c12; border-color: var(--accent); align-self: flex-end; width: 100%; }

/* ---------- Game ---------- */
#page-game { grid-template-rows: 1fr 1fr; }
.game-screen { display: grid; grid-template-rows: 1fr 1fr; min-height: 0; border-bottom: 1px solid var(--line); }
.viewport { display: grid; grid-template-columns: 1fr 1fr; min-height: 0; background: linear-gradient(#20242c, #171a1f); border-bottom: 1px solid var(--line); }
#party-lineup { display: flex; align-items: flex-end; justify-content: space-evenly; padding: 8px; min-height: 0; }
.hero { height: 100%; flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; cursor: pointer; }
.hero img { max-height: calc(100% - 20px); max-width: 100%; object-fit: contain; filter: drop-shadow(0 4px 8px rgba(0,0,0,.6)); }
.hero span { font-size: 12px; color: var(--muted); }
.hero.active span { color: var(--accent); }
.viewport-right { display: grid; place-items: center; }
.controls { display: grid; grid-template-columns: 1fr 1fr 1fr; min-height: 0; }
.panel { padding: 8px 12px; border-right: 1px solid var(--line); min-height: 0; overflow: auto; }
.panel:last-child { border-right: none; }
.panel h3, .diagnostics h3 { margin: 0 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.placeholder { color: var(--muted); }
#player-info img { width: 64px; height: 64px; border-radius: 50%; vertical-align: middle; margin-right: 10px; }
.diagnostics { display: flex; flex-direction: column; min-height: 0; padding: 8px 12px; background: #0f1013; }
#log { flex: 1; margin: 0; overflow: auto; font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: #9fd3a6; white-space: pre-wrap; }

/* ---------- Enemies ---------- */
#debug select { font: inherit; font-size: 12px; color: var(--text); background: #3a2626; border: 1px solid #5a3333; border-radius: 6px; padding: 3px 6px; }
#enemy-lineup { display: flex; align-items: flex-end; justify-content: space-evenly; padding: 8px; min-height: 0; border-left: 1px dashed var(--line); }
#enemy-lineup > .placeholder { align-self: center; }
.enemy { height: 100%; flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; cursor: pointer; }
.enemy img { max-height: calc(100% - 20px); max-width: 100%; object-fit: contain; filter: drop-shadow(0 4px 8px rgba(0,0,0,.6)); }
.enemy span { font-size: 12px; color: var(--muted); text-align: center; }
.enemy.active span { color: var(--danger); }
.enemy.active img { filter: drop-shadow(0 0 6px rgba(214,90,79,.8)); }
#target-info { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
#target-info img { width: 64px; height: 64px; border-radius: 8px; background: #1d2026; object-fit: contain; }
