:root {
  --bg-0: #0a0b11;
  --bg-1: #101423;
  --bg-2: #1f162a;
  --ink: #f9f8f6;
  --muted: #b7b4c5;
  --cyan: #46d5ff;
  --gold: #ffcc47;
  --pink: #ff4f8a;
  --line: rgba(255, 255, 255, 0.14);
  --panel: rgba(11, 13, 21, 0.75);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% -10%, #1d355f 0%, transparent 30%),
    radial-gradient(circle at 80% 0%, #3f1647 0%, transparent 35%),
    linear-gradient(130deg, var(--bg-0), var(--bg-1) 45%, var(--bg-2));
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.bg-orb {
  position: fixed;
  width: 36vw;
  height: 36vw;
  border-radius: 50%;
  filter: blur(68px);
  opacity: 0.2;
  z-index: -1;
  pointer-events: none;
}

.orb-a { top: -12vw; left: -8vw; background: #2ab8ff; }
.orb-b { bottom: -14vw; right: -10vw; background: #ff4791; }

/* --- Navigation --- */

.top-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.88rem;
}

.nav-link {
  color: var(--cyan);
  text-decoration: none;
  font-weight: 600;
  transition: opacity 150ms;
}

.nav-link:hover { opacity: 0.8; }
.nav-sep { color: var(--muted); opacity: 0.4; }
.nav-current { color: var(--muted); }

/* --- Header --- */

.hero {
  width: min(1100px, 92vw);
  margin: 2rem auto 1.25rem;
  animation: rise 460ms ease-out both;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  color: var(--cyan);
  font-weight: 700;
}

h1, h2, h3 {
  font-family: "Bricolage Grotesque", sans-serif;
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4.7vw, 3.9rem);
  letter-spacing: -0.02em;
  line-height: 0.95;
  margin-top: 0.35rem;
}

.subhead {
  margin-top: 0.9rem;
  max-width: 70ch;
  color: var(--muted);
}

/* --- Layout --- */

.layout {
  width: min(1100px, 92vw);
  margin: 0 auto 2rem;
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  gap: 1rem;
}

.panel {
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1rem;
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.35);
}

.panel-controls {
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.44rem;
}

/* --- Forms --- */

label {
  font-weight: 600;
  color: #d2d0dc;
}

input, select, textarea, button {
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-family: inherit;
  font-size: 0.95rem;
}

input, select, textarea {
  background: rgba(5, 6, 12, 0.65);
  color: var(--ink);
  padding: 0.64rem 0.7rem;
  outline: none;
  transition: border-color 150ms ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(70, 213, 255, 0.15);
}

textarea {
  resize: vertical;
  min-height: 78px;
}

button {
  background: linear-gradient(130deg, #ff5f6d, #ffc371);
  color: #1a0f02;
  padding: 0.62rem 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 150ms ease, filter 150ms ease, box-shadow 150ms ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

button:active {
  transform: translateY(0);
}

button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

button.ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
}

button.ghost:hover {
  background: rgba(255, 255, 255, 0.12);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.inline-input, .button-row {
  display: flex;
  gap: 0.5rem;
}

.inline-input input { flex: 1; }
.button-row button { flex: 1; }

.tiny-copy {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

/* --- HUD inline (controls panel) --- */

.hud-inline {
  display: flex;
  gap: 0.5rem;
}

.hud-chip {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  border: 1px solid rgba(255, 204, 71, 0.25);
  border-radius: var(--radius-sm);
  background: rgba(255, 204, 71, 0.06);
  padding: 0.35rem 0.6rem;
  flex: 1;
}

.hud-chip .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
}

.hud-chip span:last-child {
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: 1.1rem;
  color: var(--gold);
}

/* --- Roster --- */

.roster-wrap, .story-wrap {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  padding: 0.65rem;
}

.roster {
  margin-top: 0.45rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  max-height: 215px;
  overflow: auto;
  padding-right: 0.2rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.roster-card {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  padding: 0.32rem;
  background: rgba(255, 255, 255, 0.02);
  transition: background 120ms ease;
}

.roster-card:hover {
  background: rgba(255, 255, 255, 0.05);
}

.roster-card img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 8px;
}

.roster-card span {
  flex: 1;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.roster-card button {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.3);
  color: #f5f5f7;
  border-radius: 7px;
  min-width: 28px;
  padding: 0.22rem 0.3rem;
  font-size: 0.72rem;
}

/* --- Story --- */

.story-beat {
  margin: 0.5rem 0 0;
  font-size: 0.84rem;
  line-height: 1.32;
  color: #f1f4fb;
}

#storyFeed {
  list-style: none;
  margin: 0.55rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
  max-height: 170px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}

#storyFeed li {
  font-size: 0.86rem;
  color: #d9d8e2;
  border-left: 2px solid var(--cyan);
  padding-left: 0.5rem;
  animation: fadeSlide 200ms ease-out;
}

/* --- Stage --- */

.panel-stage {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
}

.hud > div {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.03);
  padding: 0.46rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.hud .label {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.hud span:last-child {
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: 1.25rem;
}

#gameCanvas {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: #020305;
  touch-action: none;
  image-rendering: auto;
}

.touch-controls {
  display: none;
  gap: 0.5rem;
}

.touch-controls button { flex: 1; }

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.87rem;
}

/* --- Modal --- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1.5rem;
  width: min(440px, 90vw);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  transform: translateY(12px);
  transition: transform 250ms ease;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.modal-actions button {
  flex: 1;
  min-width: 100px;
}

/* --- Summary Grid --- */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.65rem;
  background: rgba(255, 255, 255, 0.03);
}

.stat-val {
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--cyan);
}

.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

/* --- Footer --- */

footer {
  width: min(1100px, 92vw);
  margin: 0 auto 1.25rem;
  color: var(--muted);
  text-align: center;
  font-size: 0.84rem;
}

/* --- Animations --- */

@keyframes rise {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeSlide {
  from { transform: translateX(-6px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* --- Responsive --- */

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .panel-stage { order: -1; }
  .roster { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .hero { margin-top: 1.25rem; }
  .panel { border-radius: 16px; padding: 0.75rem; }
  .button-row { flex-wrap: wrap; }
  .button-row button { flex: 1 1 calc(50% - 0.25rem); }
  .roster { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .touch-controls { display: flex; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 400px) {
  .summary-grid { grid-template-columns: 1fr; }
  .hud { grid-template-columns: repeat(2, 1fr); }
}
