:root {
  --bg-0: #090b0d;
  --bg-1: #10161a;
  --bg-2: #172027;
  --panel: rgba(17, 24, 29, 0.94);
  --panel-strong: rgba(22, 31, 37, 0.98);
  --panel-soft: rgba(34, 44, 51, 0.88);
  --line: rgba(196, 186, 156, 0.16);
  --line-strong: rgba(214, 199, 154, 0.3);
  --text: #eef1e8;
  --muted: #a8b4ae;
  --gold: #d2b97a;
  --gold-deep: #8f7340;
  --teal: #7eb3aa;
  --shadow: 0 24px 48px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(179, 155, 86, 0.12), transparent 26%),
    radial-gradient(circle at 18% 18%, rgba(82, 113, 122, 0.18), transparent 24%),
    linear-gradient(180deg, #12171b 0%, #0c1114 48%, #07090b 100%);
  color: var(--text);
  font-family: Aptos, "Segoe UI", "Trebuchet MS", sans-serif;
  padding: 14px;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(180deg, rgba(255,255,255,0.55), transparent 88%);
  opacity: 0.28;
}

.app {
  position: relative;
  z-index: 1;
  width: min(1720px, 100%);
  height: calc(100vh - 28px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 286px;
  gap: 14px;
  align-items: stretch;
}

.panel {
  position: relative;
  min-height: 0;
  display: flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.045), rgba(255,255,255,0.012)),
    linear-gradient(180deg, rgba(20, 28, 34, 0.98), rgba(10, 14, 18, 0.98));
  box-shadow: var(--shadow);
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.24), transparent);
  opacity: 0.55;
}

.panel-inner {
  width: 100%;
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

h1, h2, h3, p { margin: 0; }

h2, .howto-copy h3, .splash-section h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--gold);
}

.subtle {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.small { font-size: 0.82rem; }
.stack { display: grid; gap: 14px; }
.row { display: flex; gap: 12px; align-items: center; }

.toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toolbar-compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.toolbar-glyph.active {
  border-color: rgba(214, 199, 154, 0.42);
  background: linear-gradient(180deg, rgba(86, 66, 31, 0.96), rgba(39, 29, 14, 0.98));
  color: #fff4d4;
}

button, select, input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(41, 52, 60, 0.92), rgba(19, 26, 31, 0.96));
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

button {
  cursor: pointer;
  font-weight: 500;
  letter-spacing: 0.01em;
}

button:hover,
select:hover,
input:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
canvas:focus-visible {
  outline: 2px solid rgba(126, 179, 170, 0.9);
  outline-offset: 2px;
}

button.primary {
  background: linear-gradient(180deg, #b89a5e, #816333);
  border-color: rgba(241, 221, 176, 0.38);
  color: #fff7e6;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.22);
}

.icon-btn {
  min-width: 42px;
  padding: 0;
  font-size: 1rem;
  text-align: center;
}

.toolbar-glyph {
  min-height: 38px;
  font-size: 1.05rem;
  font-weight: 400;
}

.label {
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  margin-bottom: 8px;
}

.value {
  font-size: 1rem;
  font-weight: 700;
  color: #f7f4ea;
}

.card {
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.015)),
    rgba(255,255,255,0.012);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.hud-strip {
  display: grid;
  gap: 10px;
}

.music-panel {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
}

.music-volume-value {
  font-family: "Aptos Mono", Consolas, monospace;
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  color: #f4ead2;
}

.music-toggle {
  min-width: 42px;
}

.music-toggle.active {
  border-color: rgba(214, 199, 154, 0.42);
  background: linear-gradient(180deg, rgba(86, 66, 31, 0.96), rgba(39, 29, 14, 0.98));
  color: #fff4d4;
}

.music-toggle:not(.active) {
  opacity: 0.62;
  color: rgba(238, 241, 232, 0.7);
}

.music-slider {
  width: 100%;
  min-height: 26px;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
}

.music-slider:hover,
.music-slider:focus-visible {
  transform: none;
  border: none;
}

.music-slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(212, 185, 122, 0.9), rgba(126, 179, 170, 0.9));
}

.music-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.28);
  background: #fff4da;
  box-shadow: 0 2px 10px rgba(0,0,0,0.28);
}

.music-slider::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(212, 185, 122, 0.9), rgba(126, 179, 170, 0.9));
}

.music-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.28);
  background: #fff4da;
  box-shadow: 0 2px 10px rgba(0,0,0,0.28);
}

.spotlight-card {
  background:
    radial-gradient(circle at top right, rgba(212, 185, 122, 0.16), transparent 38%),
    linear-gradient(180deg, rgba(37, 46, 54, 0.92), rgba(18, 25, 31, 0.94));
}

.turn-card {
  padding: 12px 14px;
}

.turn-line {
  font-size: 0.94rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #f7f4ea;
}

.turn-subline {
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  padding: 0;
  background: #0b1013;
}

.side-panel {
  min-width: 0;
}

.side-stack {
  grid-auto-rows: min-content;
}

.sidebar-brand {
  display: grid;
  gap: 4px;
}

.side-title {
  width: 100%;
  max-width: 254px;
  line-height: 0;
}

.side-version {
  font-family: "Aptos Mono", Consolas, monospace;
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(224, 214, 185, 0.76);
}

.brand-copy {
  margin-top: 4px;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 0;
  border: none;
  background: #0c1013;
  box-shadow: none;
  outline: none;
}

.battle-hud-overlay {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 2;
  display: none;
  grid-template-columns: 108px minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  min-height: 40px;
  padding: 6px 10px 5px;
  background: linear-gradient(180deg, rgba(6, 9, 12, 0.96), rgba(11, 15, 18, 0.88));
  border-bottom: 1px solid rgba(255,255,255,0.12);
  pointer-events: none;
}

.battle-hud-overlay.active {
  display: grid;
}

.battle-hud-tag,
.battle-hud-side {
  min-width: 0;
}

.battle-hud-title,
.battle-hud-terrain,
.battle-hud-name {
  font-family: "Aptos Mono", Consolas, monospace;
  line-height: 1;
  text-rendering: geometricPrecision;
}

.battle-hud-title {
  color: #f3e7cb;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.battle-hud-terrain {
  margin-top: 4px;
  color: #bac5c0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.battle-hud-side {
  display: grid;
  gap: 4px;
}

.battle-hud-track {
  position: relative;
  height: 8px;
  overflow: hidden;
  background: rgba(255,255,255,0.12);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
}

.battle-hud-fill {
  height: 100%;
}

.battle-hud-fill-left {
  background: linear-gradient(90deg, #dfe6e1, #9bb7ac);
}

.battle-hud-fill-right {
  margin-left: auto;
  background: linear-gradient(90deg, #d14c60, #7a2130);
}

.battle-hud-side-right .battle-hud-track {
  display: flex;
  justify-content: flex-end;
}

.battle-hud-name {
  color: #dbe4de;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.battle-hud-side-right .battle-hud-name {
  text-align: right;
}

.status-head {
  justify-content: space-between;
  align-items: flex-start;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  color: #d8dfda;
  font-size: 0.8rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.5;
}

.log {
  display: grid;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.log-entry {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.035);
  color: #e4eadf;
  line-height: 1.4;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(2, 5, 7, 0.76);
  backdrop-filter: blur(8px);
}

.modal.open { display: flex; }

.modal-card {
  width: min(920px, 100%);
  max-height: min(90vh, 960px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    radial-gradient(circle at top, rgba(214, 185, 117, 0.12), transparent 24%),
    linear-gradient(180deg, rgba(24, 31, 36, 0.98), rgba(12, 16, 20, 0.98));
  box-shadow: 0 36px 70px rgba(0, 0, 0, 0.5);
  padding: 26px;
}

.winner-modal {
  z-index: 24;
}

.winner-card {
  width: min(560px, 100%);
  max-height: none;
  display: grid;
  gap: 18px;
  justify-items: center;
  text-align: center;
  padding: 34px 30px;
  overflow: hidden;
}

.winner-card::before {
  content: "";
  position: absolute;
  inset: -20% auto auto 50%;
  width: 320px;
  height: 320px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.18), transparent 68%);
  pointer-events: none;
}

.winner-modal.winner-light .winner-card {
  background:
    radial-gradient(circle at top, rgba(255, 232, 180, 0.24), transparent 34%),
    linear-gradient(180deg, rgba(45, 55, 61, 0.98), rgba(18, 23, 27, 0.98));
}

.winner-modal.winner-dark .winner-card {
  background:
    radial-gradient(circle at top, rgba(255, 118, 154, 0.18), transparent 34%),
    linear-gradient(180deg, rgba(34, 19, 28, 0.98), rgba(16, 10, 16, 0.98));
}

.winner-badge {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
  color: #f6ead2;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.winner-title {
  position: relative;
  z-index: 1;
  font-size: 2.2rem;
  text-shadow: 0 8px 20px rgba(0,0,0,0.34);
}

.winner-copy {
  position: relative;
  z-index: 1;
  max-width: 420px;
  font-size: 1rem;
  line-height: 1.6;
}

.winner-actions {
  position: relative;
  z-index: 1;
  width: 100%;
  display: flex;
  justify-content: center;
}

.winner-actions button {
  width: min(220px, 100%);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.modal-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.5rem;
  color: #f7ecd2;
}

.modal-close {
  width: auto;
  min-width: 46px;
  font-size: 1.4rem;
  line-height: 1;
}

.howto-copy {
  display: grid;
  gap: 16px;
  font-size: 0.95rem;
}

.howto-copy p,
.howto-copy li {
  color: #dce3db;
}

.splash-card {
  width: min(1060px, 100%);
  max-height: min(92vh, 980px);
}

.splash-header {
  margin-bottom: 20px;
}

.splash-hero {
  display: grid;
  gap: 8px;
}

.splash-kicker {
  color: var(--teal);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.splash-title {
  width: min(940px, 100%);
  margin-top: 2px;
  line-height: 0;
}

.splash-lede {
  max-width: 720px;
  font-size: 1rem;
}

.brand-logo {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}

.brand-logo-splash {
  filter: drop-shadow(0 12px 28px rgba(0, 0, 0, 0.42));
}

.brand-logo-side {
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.36));
}

.splash-grid {
  display: grid;
  gap: 14px;
}

.splash-section {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 18px;
  background: rgba(255,255,255,0.025);
}

.splash-form-row,
.splash-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.compact-actions {
  align-items: center;
}

.compact-btn {
  width: auto;
  min-width: 132px;
  padding-inline: 16px;
}

.field {
  min-width: 180px;
  display: grid;
  gap: 6px;
}

.field.grow {
  min-width: 240px;
  flex: 1 1 260px;
}

#roomPlayersList {
  gap: 6px;
}

@media (max-width: 1240px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    grid-template-columns: 1fr;
  }

  .panel-inner {
    overflow: visible;
  }

  .canvas-wrap {
    min-height: 0;
  }

  canvas {
    height: auto;
    aspect-ratio: 1 / 1;
  }
}

@media (max-width: 720px) {
  body {
    padding: 10px;
  }

  .app {
    gap: 10px;
    height: auto;
  }

  .panel-inner,
  .canvas-wrap,
  .modal-card {
    padding: 8px;
  }

  .canvas-wrap {
    padding: 0;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .toolbar-compact {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .status-head {
    flex-direction: column;
    align-items: stretch;
  }

  .splash-actions button,
  .splash-form-row .field,
  .splash-form-row .field.grow {
    min-width: 100%;
    flex-basis: 100%;
  }

  .compact-btn {
    width: 100%;
    min-width: 100%;
  }
}
