:root {
  --bg: #071019;
  --bg-deep: #04080d;
  --panel: rgba(10, 18, 27, 0.86);
  --panel-strong: rgba(11, 20, 31, 0.94);
  --panel-border: rgba(196, 229, 244, 0.12);
  --text: #edf5ff;
  --muted: #99b2c8;
  --accent: #71f1d1;
  --accent-2: #ffd57c;
  --accent-3: #83b5ff;
  --shadow: 0 28px 72px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(113, 241, 209, 0.15), transparent 28%),
    radial-gradient(circle at top right, rgba(255, 213, 124, 0.14), transparent 32%),
    linear-gradient(180deg, rgba(5, 13, 20, 0.94), rgba(3, 8, 13, 0.98)),
    var(--bg);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at center, rgba(0, 0, 0, 0.76), transparent 92%);
  opacity: 0.18;
}

.page-shell {
  width: min(1680px, calc(100vw - 18px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar,
.topbar-status,
.layout,
.field-grid,
.action-row,
.invite-head,
.invite-row,
.board-header,
.score-strip,
.table-meta,
.board-footer,
.footer-actions,
.panel-head {
  display: flex;
  gap: 12px;
}

.topbar,
.invite-head,
.board-header,
.board-footer,
.panel-head {
  align-items: center;
  justify-content: space-between;
}

.topbar {
  position: sticky;
  top: 12px;
  z-index: 20;
  padding: 14px 18px;
  border-radius: 24px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, rgba(11, 19, 29, 0.92), rgba(7, 13, 20, 0.88));
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.back-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}

.brand-block strong,
h1,
h2 {
  font-family: "Space Grotesk", Inter, sans-serif;
}

.brand-block strong {
  display: block;
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar-status {
  justify-content: flex-end;
  flex-wrap: wrap;
  align-items: center;
}

.status-pill {
  padding: 0.55rem 0.82rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.status-pill.ghost {
  color: var(--muted);
}

.status-pill[data-tone="online"] {
  color: #041913;
  border-color: rgba(113, 241, 209, 0.52);
  background: linear-gradient(135deg, var(--accent), #ddfff4);
}

.status-pill[data-tone="connecting"] {
  color: #261301;
  border-color: rgba(255, 213, 124, 0.45);
  background: linear-gradient(135deg, rgba(255, 213, 124, 0.96), rgba(255, 241, 211, 0.95));
}

.status-pill[data-tone="offline"] {
  color: var(--muted);
}

.toolbar-btn {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 0.58rem 0.88rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.toolbar-btn[data-active="true"] {
  color: #041913;
  border-color: rgba(113, 241, 209, 0.5);
  background: linear-gradient(135deg, rgba(113, 241, 209, 0.96), rgba(220, 255, 243, 0.96));
  box-shadow: 0 10px 24px rgba(113, 241, 209, 0.16);
}

.layout {
  align-items: start;
  margin-top: 16px;
  display: grid;
  grid-template-columns: minmax(216px, 270px) minmax(0, 1fr) minmax(188px, 232px);
  transition: grid-template-columns 180ms ease;
}

.setup-column,
.board-column,
.sidebar {
  display: grid;
  gap: 14px;
  min-width: 0;
  transition: opacity 160ms ease, transform 160ms ease;
}

.layout.setup-collapsed {
  grid-template-columns: 0 minmax(0, 1fr) minmax(188px, 232px);
}

.layout.sidebar-collapsed {
  grid-template-columns: minmax(216px, 270px) minmax(0, 1fr) 0;
}

.layout.setup-collapsed.sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr) 0;
}

.layout.setup-collapsed .setup-column,
.layout.sidebar-collapsed .sidebar {
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  transform: translateY(8px);
}

.panel {
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  padding: 16px;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.04), transparent 34%),
    linear-gradient(180deg, var(--panel), var(--panel-strong));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.eyebrow,
.label {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

h1,
h2,
.lede,
.helper-text,
.status-text,
.metric-text,
.mini-status,
.footer-text,
.rule-card p,
.player-card p,
.event-item p {
  margin: 0;
}

h1 {
  margin-top: 12px;
  font-size: clamp(2.35rem, 5vw, 3.55rem);
  line-height: 0.98;
}

h2 {
  font-size: 1.26rem;
  line-height: 1.1;
}

.lede,
.helper-text,
.status-text,
.metric-text,
.mini-status,
.footer-text {
  color: var(--muted);
  line-height: 1.55;
}

.lede {
  margin-top: 10px;
}

.rule-strip {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

.rule-card,
.score-card,
.player-card,
.event-item {
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.03);
}

.rule-card {
  padding: 13px 14px;
}

.rule-card strong {
  display: block;
}

.rule-card p,
.player-card p,
.event-item p {
  margin-top: 5px;
  color: var(--muted);
  line-height: 1.45;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 7px;
  font-size: 0.88rem;
  color: var(--muted);
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  padding: 0.92rem 0.96rem;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  background: rgba(4, 10, 18, 0.76);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input:focus {
  border-color: rgba(113, 241, 209, 0.5);
  box-shadow: 0 0 0 4px rgba(113, 241, 209, 0.12);
  background: rgba(8, 14, 23, 0.9);
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, rgba(237, 245, 255, 0.82) 50%),
    linear-gradient(135deg, rgba(237, 245, 255, 0.82) 50%, transparent 50%);
  background-position:
    calc(100% - 22px) calc(50% - 3px),
    calc(100% - 16px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

select:focus {
  border-color: rgba(113, 241, 209, 0.5);
  box-shadow: 0 0 0 4px rgba(113, 241, 209, 0.12);
  background-color: rgba(8, 14, 23, 0.9);
}

input[readonly] {
  color: rgba(237, 245, 255, 0.8);
}

button {
  border: none;
  border-radius: 16px;
  padding: 0.92rem 1rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  cursor: pointer;
  font-weight: 700;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

button:hover,
button:focus-visible {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.11);
}

button.primary {
  color: #041611;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 18px 40px rgba(113, 241, 209, 0.14);
}

button.secondary {
  background: rgba(255, 255, 255, 0.05);
}

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

.action-row {
  flex-wrap: wrap;
  margin-top: 14px;
}

.action-row button {
  flex: 1 1 180px;
}

.invite-panel,
.variant-panel,
.advanced-panel,
.status-text {
  margin-top: 16px;
}

.invite-head {
  align-items: start;
}

.invite-row {
  margin-top: 10px;
  align-items: stretch;
  flex-wrap: wrap;
}

.invite-row input {
  flex: 1 1 260px;
}

.advanced-panel {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
}

.advanced-panel summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
}

.advanced-panel label {
  margin-top: 12px;
}

.board-panel {
  display: grid;
  gap: 12px;
}

.board-column {
  min-width: 0;
}

.board-header {
  gap: 10px 14px;
  flex-wrap: wrap;
}

.board-header > div {
  min-width: 0;
}

.metric-text {
  font-size: 1rem;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.score-card {
  padding: 12px 13px;
}

.score-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.7rem;
  line-height: 1;
  letter-spacing: 0.02em;
}

.score-card p:last-child {
  margin-top: 6px;
}

.score-card.white.active,
.score-card.black.active {
  border-color: rgba(113, 241, 209, 0.28);
  background: linear-gradient(135deg, rgba(113, 241, 209, 0.12), rgba(255, 255, 255, 0.04));
}

.table-stage {
  position: relative;
  min-height: 0;
  width: 100%;
  aspect-ratio: 16 / 9.6;
  border-radius: 30px;
  overflow: hidden;
  padding: 12px;
  background:
    radial-gradient(circle at top, rgba(255, 241, 222, 0.16), transparent 34%),
    linear-gradient(145deg, #3f2716, #1d1209 52%, #4d3421);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    inset 0 -12px 24px rgba(21, 9, 2, 0.38),
    0 24px 60px rgba(0, 0, 0, 0.34);
  border: 1px solid rgba(255, 235, 208, 0.08);
}

#poolTable {
  position: absolute;
  inset: 12px;
  width: calc(100% - 24px);
  height: calc(100% - 24px);
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.start-overlay {
  position: absolute;
  inset: 18px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  transition: opacity 180ms ease, transform 180ms ease;
}

.start-overlay[data-visible="false"] {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.985);
}

.start-overlay[data-visible="true"] {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.start-card {
  width: min(560px, 100%);
  padding: 24px 24px 18px;
  border-radius: 26px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background:
    radial-gradient(circle at top, rgba(113, 241, 209, 0.12), transparent 46%),
    linear-gradient(180deg, rgba(6, 14, 22, 0.82), rgba(7, 13, 20, 0.92));
  box-shadow:
    0 24px 52px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px);
  text-align: center;
}

.start-card h2,
.start-copy,
.start-note {
  margin: 0;
}

.start-card h2 {
  margin-top: 10px;
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  line-height: 1;
}

.start-copy,
.start-note {
  color: var(--muted);
  line-height: 1.55;
}

.start-copy {
  margin-top: 10px;
}

.start-actions,
.start-link-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.start-actions {
  margin-top: 18px;
}

.start-actions button {
  flex: 1 1 150px;
}

.start-primary {
  min-height: 58px;
  font-size: 1rem;
}

.start-link-row {
  margin-top: 12px;
}

.start-link {
  padding: 0;
  border: none;
  border-radius: 999px;
  color: var(--accent);
  background: transparent;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.start-link:hover,
.start-link:focus-visible {
  color: #d9fff5;
  background: transparent;
  transform: none;
  text-decoration: underline;
}

.start-note {
  margin-top: 12px;
  font-size: 0.88rem;
}

.table-meta {
  display: grid;
  grid-template-columns: minmax(280px, 1.35fr) minmax(220px, 0.9fr);
  align-items: stretch;
  gap: 10px;
}

.power-card {
  padding: 12px 14px;
  border-radius: 20px;
  background:
    linear-gradient(135deg, rgba(9, 17, 27, 0.88), rgba(12, 22, 34, 0.92));
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  min-height: 102px;
}

.power-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.power-title,
.tip-copy {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.power-title {
  color: rgba(237, 245, 255, 0.9);
  font-weight: 700;
}

.power-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.34rem 0.62rem;
  border-radius: 999px;
  color: #041611;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.power-meter {
  margin-top: 8px;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.power-meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 18px rgba(113, 241, 209, 0.34);
  transition: width 70ms linear;
}

#powerText {
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.45;
}

.tip-card {
  padding: 12px 14px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.03);
  min-height: 102px;
}

.board-footer {
  flex-wrap: wrap;
  align-items: start;
  gap: 10px;
}

.footer-actions {
  justify-content: flex-end;
}

.sidebar {
  gap: 14px;
}

.sidebar-panel,
.player-list,
.event-list {
  display: grid;
  gap: 12px;
}

.player-card,
.event-item {
  padding: 14px;
}

.player-card strong,
.event-item strong {
  display: block;
}

.player-card .chips {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.32rem 0.62rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.empty-state {
  padding: 18px;
  text-align: center;
  color: var(--muted);
  border-radius: 18px;
  border: 1px dashed rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.02);
}

@media (max-width: 1240px) {
  .layout {
    grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
  }

  .sidebar {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 920px) {
  .page-shell {
    width: min(100%, calc(100vw - 18px));
    padding-top: 10px;
  }

  .layout,
  .field-grid,
  .score-strip,
  .sidebar {
    grid-template-columns: 1fr;
  }

  .topbar {
    position: static;
    flex-wrap: wrap;
  }

  .brand-block {
    order: -1;
    width: 100%;
  }

  .table-meta {
    grid-template-columns: 1fr;
  }

  .start-card {
    padding: 20px 18px 16px;
  }

  .start-actions button {
    flex-basis: 100%;
  }
}
