:root {
  --bg: #05070d;
  --bg-soft: #0b1018;
  --panel: rgba(12, 17, 27, 0.88);
  --panel-soft: rgba(255, 255, 255, 0.04);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.68);
  --azure: #1fd7ff;
  --azure-soft: rgba(31, 215, 255, 0.15);
  --yellow: #ffd447;
  --yellow-soft: rgba(255, 212, 71, 0.14);
  --red: #ff5963;
  --red-soft: rgba(255, 89, 99, 0.14);
  --radius-xl: 24px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--text);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(31, 215, 255, 0.08), transparent 24%),
    radial-gradient(circle at top right, rgba(255, 212, 71, 0.07), transparent 18%),
    linear-gradient(180deg, #04060b 0%, #080c14 52%, #05070d 100%);
}
button, input, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
.hidden { display: none !important; }

.shell-width {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
}
.app-shell {
  min-height: 100vh;
  position: relative;
  padding-bottom: 36px;
}
.ambient {
  position: fixed;
  border-radius: 999px;
  filter: blur(90px);
  pointer-events: none;
  opacity: 0.25;
}
.ambient-a { width: 220px; height: 220px; background: rgba(31, 215, 255, 0.18); top: -60px; left: -40px; }
.ambient-b { width: 240px; height: 240px; background: rgba(255, 212, 71, 0.15); right: -90px; top: 8%; }
.ambient-c { width: 220px; height: 220px; background: rgba(255, 89, 99, 0.14); bottom: -70px; left: 42%; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  backdrop-filter: blur(14px);
}
.brand {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 0;
}
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  color: #071018;
  font-weight: 700;
  background: linear-gradient(135deg, var(--azure), var(--yellow));
  box-shadow: 0 10px 28px rgba(31, 215, 255, 0.18);
}
.brand-copy { display: grid; gap: 2px; }
.brand-copy strong { font-size: 1rem; letter-spacing: 0.04em; text-transform: lowercase; }
.brand-copy small { color: var(--muted); }
.topbar-nav, .topbar-actions, .action-row, .compact-actions, .status-badges, .player-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.topbar-nav { justify-content: center; }
.topbar-actions { justify-content: flex-end; }

.page-root {
  display: grid;
  gap: 18px;
  padding-top: 6px;
}
.page-stack, .stack, .stack-sm, .stack-lg {
  display: grid;
}
.page-stack { gap: 18px; }
.stack { gap: 14px; }
.stack-sm { gap: 8px; }
.stack-lg { gap: 18px; }

.panel, .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}
.card, .panel {
  padding: 20px;
}
.subcard {
  padding: 16px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.page-title-bar,
.room-banner {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}
.solo-heading { align-items: center; }
.eyebrow {
  margin: 0 0 8px;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}
.hero-title {
  margin: 0;
  font-size: clamp(2.2rem, 5vw, 4rem);
  line-height: 0.96;
}
.hero-title span { color: var(--azure); }
.section-title-xl { margin: 0; font-size: clamp(1.7rem, 3.4vw, 2.5rem); }
.section-title-lg { margin: 0; font-size: clamp(1.18rem, 2vw, 1.55rem); }
.lead, .helper, .player-text small, .brand-copy small, .field span, .mini-label {
  color: var(--muted);
}
.lead { font-size: 1.02rem; line-height: 1.65; margin: 0; }
.helper { font-size: 0.92rem; line-height: 1.45; }
.mini-label {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.wrap-anywhere { word-break: break-word; }

.hero-grid,
.split-layout,
.room-layout,
.game-layout,
.summary-grid,
.kpi-grid,
.form-grid,
.results-grid {
  display: grid;
  gap: 18px;
}
.hero-grid {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
}
.split-layout {
  grid-template-columns: minmax(0, 1.1fr) minmax(300px, 0.9fr);
}
.split-layout-equal { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.split-layout-main { grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr); }
.room-layout {
  grid-template-columns: 320px minmax(0, 1fr);
  align-items: start;
}
.game-layout {
  grid-template-columns: minmax(0, 1fr) 320px;
  align-items: start;
}
.summary-grid,
.kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.results-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.two-column-grid { grid-template-columns: minmax(0, 1fr) minmax(220px, 0.8fr); align-items: end; }

.nav-chip,
.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.file-picker,
.icon-button,
.pill {
  border-radius: 999px;
  border: 1px solid transparent;
  transition: transform .16s ease, border-color .16s ease, background .16s ease, opacity .16s ease;
}
.nav-chip,
.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.file-picker {
  padding: 11px 15px;
  cursor: pointer;
}
.nav-chip,
.ghost-button,
.file-picker {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.08);
}
.nav-chip.active {
  background: rgba(31, 215, 255, 0.13);
  border-color: rgba(31, 215, 255, 0.3);
}
.primary-button {
  background: linear-gradient(135deg, var(--azure), #96ebff);
  color: #071018;
  font-weight: 700;
}
.secondary-button {
  background: linear-gradient(135deg, #ffd447, #fff1a5);
  color: #1c1404;
  font-weight: 700;
}
.danger-button {
  background: rgba(255, 89, 99, 0.12);
  color: #ffd7db;
  border-color: rgba(255, 89, 99, 0.28);
}
.nav-chip:hover,
.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.danger-button:hover,
.file-picker:hover,
.icon-button:hover {
  transform: translateY(-1px);
}
button:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

input[type='text'],
input[type='number'] {
  width: 100%;
  padding: 14px 15px;
  color: var(--text);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}
input:focus {
  border-color: rgba(31, 215, 255, 0.55);
  box-shadow: 0 0 0 4px rgba(31, 215, 255, 0.12);
}
.field {
  display: grid;
  gap: 10px;
}
.file-picker { display: inline-flex; align-items: center; justify-content: center; }
.file-picker input { display: none; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.08);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.pill-accent { background: var(--azure-soft); border-color: rgba(31, 215, 255, 0.24); }
.pill-warning { background: var(--yellow-soft); border-color: rgba(255, 212, 71, 0.26); color: #fff0bf; }
.pill-danger { background: var(--red-soft); border-color: rgba(255, 89, 99, 0.26); color: #ffd6d9; }

.hero-card { min-height: 100%; }
.profile-hero,
.player-meta,
.player-card-head,
.score-row,
.log-item-head,
.meta-row,
.info-row,
.timing-row,
.avatar-upload-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.profile-hero,
.avatar-upload-row { align-items: flex-start; }
.meta-list,
.info-list,
.roster-list,
.log-list,
.score-list,
.flow-list,
.timing-list {
  display: grid;
  gap: 12px;
}
.compact-list { gap: 10px; }
.info-row,
.meta-row,
.timing-row,
.score-row,
.result-player {
  justify-content: space-between;
}
.meta-row,
.info-row,
.timing-row,
.score-row,
.player-card,
.log-item,
.result-player,
.kpi-card,
.mini-panel,
.info-badge {
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-md);
}
.meta-row,
.info-row,
.timing-row,
.score-row,
.log-item,
.result-player,
.kpi-card,
.mini-panel,
.info-badge {
  padding: 13px 14px;
}
.kpi-card {
  display: grid;
  gap: 6px;
}
.kpi-card strong { font-size: 1.18rem; }
.compact-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.info-badge {
  min-width: 116px;
  display: grid;
  gap: 4px;
  text-align: center;
}
.info-badge strong { font-size: 1.25rem; }
.status-badges {
  justify-content: flex-end;
}

.flow-item {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  align-items: start;
}
.flow-index {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(31, 215, 255, 0.12);
  border: 1px solid rgba(31, 215, 255, 0.24);
  font-weight: 700;
}
.flow-item p { margin: 4px 0 0; }
.compact-flow { gap: 10px; }

.room-meta-card .action-row { margin-top: 6px; }
.room-code { letter-spacing: 0.12em; }
.player-card {
  display: grid;
  gap: 10px;
  padding: 14px;
}
.player-card-current { border-color: rgba(31, 215, 255, 0.3); box-shadow: inset 0 0 0 1px rgba(31, 215, 255, 0.14); }
.player-card-offline { border-color: rgba(255, 89, 99, 0.22); }
.player-card-waiting { border-color: rgba(255, 212, 71, 0.22); }
.player-text { display: grid; gap: 2px; }
.player-text strong { line-height: 1.2; }
.player-flags { justify-content: flex-end; }

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  overflow: hidden;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: linear-gradient(135deg, rgba(31, 215, 255, 0.18), rgba(255, 212, 71, 0.18));
  color: var(--text);
  font-weight: 700;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-xl { width: 64px; height: 64px; border-radius: 18px; }

.answer-shell { gap: 14px; }
.answer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}
.log-list { max-height: 520px; overflow: auto; padding-right: 4px; }
.log-city { font-size: 1.05rem; }
.score-list { gap: 10px; }
.score-row-current { border-color: rgba(31, 215, 255, 0.24); }
.score-values { text-align: right; display: grid; gap: 2px; }
.score-values strong { font-size: 1.25rem; }
.results-card { margin-top: 2px; }
.result-player {
  display: grid;
  gap: 14px;
}
.result-stats {
  display: grid;
  gap: 8px;
  color: var(--muted);
}
.result-stats span { display: flex; justify-content: space-between; gap: 10px; }

.empty-state {
  display: grid;
  gap: 8px;
  justify-items: start;
  padding: 22px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed rgba(255, 255, 255, 0.12);
}

.status-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 212, 71, 0.22);
  background: rgba(255, 212, 71, 0.08);
}
.timer {
  font-size: 1.05rem;
  font-weight: 700;
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  display: grid;
  gap: 10px;
}
.toast {
  min-width: 240px;
  max-width: 360px;
  padding: 13px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(12, 17, 27, 0.96);
  box-shadow: var(--shadow);
}
.toast.info { border-color: rgba(31, 215, 255, 0.2); }
.toast.warn { border-color: rgba(255, 212, 71, 0.24); }
.toast.error { border-color: rgba(255, 89, 99, 0.24); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 4, 8, 0.72);
  backdrop-filter: blur(10px);
}
.modal-card {
  position: relative;
  width: min(560px, calc(100vw - 28px));
  z-index: 1;
}
.modal-card-wide { width: min(860px, calc(100vw - 28px)); }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}
.modal-head h2 { margin: 0; }
.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}
.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,0.05);
  color: var(--text);
  border-color: rgba(255,255,255,0.08);
  cursor: pointer;
}
.modal-actions { margin-top: 16px; }

@media (max-width: 1080px) {
  .topbar { grid-template-columns: 1fr; justify-items: start; }
  .topbar-nav { justify-content: flex-start; }
  .topbar-actions { justify-content: flex-start; }
  .room-layout,
  .game-layout,
  .hero-grid,
  .split-layout,
  .split-layout-equal,
  .split-layout-main,
  .results-grid,
  .modal-grid,
  .summary-grid,
  .kpi-grid,
  .compact-kpis,
  .form-grid.two-column-grid {
    grid-template-columns: 1fr;
  }
  .status-badges { width: 100%; justify-content: flex-start; }
}

@media (max-width: 760px) {
  .shell-width { width: min(100vw - 18px, 100%); }
  .card, .panel { padding: 16px; }
  .topbar { padding: 12px 0; }
  .page-title-bar,
  .room-banner,
  .section-heading,
  .status-banner,
  .meta-row,
  .info-row,
  .timing-row,
  .score-row,
  .player-card-head,
  .log-item-head,
  .avatar-upload-row {
    flex-direction: column;
    align-items: stretch;
  }
  .answer-grid { grid-template-columns: 1fr; }
  .toast-stack { left: 10px; right: 10px; bottom: 10px; }
  .toast { min-width: 0; max-width: none; }
}

.field-inline {
  display: flex;
  gap: 12px;
  align-items: center;
}

.field-inline input {
  flex: 1 1 auto;
}

.compact-button {
  white-space: nowrap;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.history-card {
  min-height: 100%;
}
