:root {
  --bg: #050a0f;
  --bg-elevated: #0b141d;
  --bg-panel: #070e15;
  --border: rgba(255, 255, 255, 0.12);
  --border-soft: rgba(255, 255, 255, 0.09);
  --text: #ffffff;
  --text-dim: rgba(255, 255, 255, 0.8);
  --text-muted: rgba(255, 255, 255, 0.5);
  --accent: #0089ff;
  --accent-strong: #006ef5;
  --accent-hover: #33a1ff;
  --accent-soft: rgba(0, 137, 255, 0.12);
  --active-bg: rgba(255, 255, 255, 0.12);
  --active-bg-subtle: rgba(255, 255, 255, 0.07);
  --active-border: rgba(255, 255, 255, 0.3);
  --active-text: #ffffff;
  --active-text-dim: rgba(255, 255, 255, 0.8);
  --nav-hover-bg: rgba(255, 255, 255, 0.05);
  --bg-subtle: rgba(255, 255, 255, 0.05);
  --nav-transition: 0.2s ease;
  --nav-rail-width: 56px;
  --nav-icon-slot: 40px;
  --black-stone: #1a1a1a;
  --white-stone: #f5f0e6;
  --danger: #e05c5c;
  --success: #5cb87a;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro', 'Segoe UI', system-ui, sans-serif;
  --font-go: 'Noto Serif SC', serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  container-type: inline-size;
  container-name: root;
  width: 100%;
  margin: 0 auto;
}

html,
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(0, 110, 245, 0.07) 0%, transparent 55%);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}

#app {
  min-height: 100vh;
}

.screen {
  display: none;
  min-height: 100vh;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* Loading / auto-join */
#screen-loading {
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.join-card {
  width: 100%;
  max-width: 420px;
  padding: 2.5rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.5);
  box-shadow: var(--shadow);
  text-align: center;
}

.logo {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.logo-stone {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.logo-stone.black {
  background: radial-gradient(circle at 30% 30%, #444, var(--black-stone));
}

.logo-stone.white {
  background: radial-gradient(circle at 30% 30%, #fff, var(--white-stone));
}

.join-card h1 {
  font-family: var(--font-go);
  font-size: 2.25rem;
  margin: 0 0 0.5rem;
  letter-spacing: 0.02em;
}

.tagline {
  color: var(--text-muted);
  margin: 0 0 2rem;
}

.loading-status {
  color: var(--text-muted);
  font-size: 0.9375rem;
  margin: 0 0 1rem;
  min-height: 1.25rem;
}

.loading-status.error {
  color: var(--danger);
}

.error {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: 0.75rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  width: 100%;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--accent);
}

.btn-danger {
  background: rgba(224, 92, 92, 0.15);
  color: var(--danger);
  border: 1px solid rgba(224, 92, 92, 0.3);
}

.btn-danger:hover {
  background: rgba(224, 92, 92, 0.25);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--bg-elevated);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-toggle {
  flex: 1;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-toggle.active {
  background: var(--active-bg);
  color: var(--active-text);
  border-color: var(--active-border);
}

.btn-group {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.select {
  width: 100%;
  padding: 0.65rem 1rem;
  margin-bottom: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(26, 34, 45, 0.8);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-mini {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #444, var(--black-stone));
  border: 2px solid var(--white-stone);
}

.player-badge {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 1rem;
  background: var(--bg-panel);
  border-radius: 999px;
  border: 1px solid var(--border);
}

.rank {
  font-size: 0.8125rem;
  padding: 0.15rem 0.5rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-weight: 600;
}

/* Lobby app shell */
#screen-lobby.active {
  height: 100vh;
  overflow: hidden;
}

.top-nav .player-badge {
  margin-left: auto;
}

.lobby-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
}

.side-nav {
  width: 226px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 17px 8px 16px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width var(--nav-transition);
}

/* Collapsed: narrow icon rail (Figma default) */
#screen-lobby.nav-collapsed .side-nav {
  width: var(--nav-rail-width);
}

#screen-lobby.nav-collapsed .nav-item__label {
  max-width: 0;
  opacity: 0;
  padding-right: 0;
}

.side-nav__items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
}

.tables-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 24px 32px;
  background: var(--bg);
}

.tables-header__title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 590;
  color: #fff;
}

.tables-header__sub {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}

.btn-new-table {
  flex-shrink: 0;
  width: auto;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 590;
  border-radius: 90px;
  white-space: nowrap;
}

.tables-head,
.tables-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px 180px;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
}

.tables-head {
  height: auto;
  min-height: 48px;
  padding-top: 14px;
  padding-bottom: 14px;
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-soft);
}

.tables-col {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 15px;
  font-weight: 590;
  color: #fff;
  white-space: nowrap;
}

.tables-sort {
  width: 12px;
  height: 12px;
  color: var(--text-muted);
  transition: transform 0.15s ease, color 0.15s ease;
}

.tables-col[data-sort],
.watch-head .watch-col[data-sort] {
  cursor: pointer;
  user-select: none;
}

.tables-col[data-sort]:hover .tables-sort,
.watch-head .watch-col[data-sort]:hover .tables-sort {
  color: #fff;
}

.tables-col.sort-active .tables-sort,
.watch-head .watch-col.sort-active .tables-sort {
  color: var(--active-text);
}

.tables-col.sort-asc .tables-sort,
.watch-head .watch-col.sort-asc .tables-sort {
  transform: rotate(180deg);
}

.tables-list {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.tables-row {
  padding-top: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background 0.15s;
}

.tables-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

.tables-players {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tables-player {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tables-player__stone {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 1.2px 3.6px rgba(0, 0, 0, 0.6);
}

.tables-player__stone.white {
  background: radial-gradient(circle at 32% 30%, #fff 0%, #c8c4bc 100%);
}

.tables-player__stone.black {
  background: radial-gradient(circle at 32% 30%, #555 0%, #303030 50%, #0a0a0a 100%);
}

.tables-player__rank {
  color: var(--text-muted);
}

.tables-empty {
  padding: 3rem 24px;
  color: var(--text-muted);
  text-align: center;
}

.tables-cell {
  font-size: 14px;
  font-weight: 510;
  color: #fff;
}

.lobby-side-panel {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg);
  border-left: 1px solid var(--border-soft);
  padding: 32px 24px;
  overflow-y: auto;
}

.lobby-side-panel__title {
  margin: 0 0 12px;
  padding: 0 8px;
  font-size: 15px;
  font-weight: 590;
  color: #fff;
}

.challenge-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.challenge-row {
  display: flex;
  align-items: center;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.challenge-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

.challenge-row.self {
  opacity: 0.5;
  cursor: default;
}

.challenge-row__name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 510;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.challenge-row__rank {
  color: var(--text-muted);
}

.challenge-empty {
  color: var(--text-muted);
  font-size: 14px;
  padding: 12px 8px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal__card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.modal__card--create {
  max-width: 400px;
  padding: 0;
  background: #1c2025;
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  box-shadow:
    0 1px 6px rgba(0, 0, 0, 0.16),
    0 1px 9px 6px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal__head--center {
  position: relative;
  justify-content: center;
  margin-bottom: 0;
  padding: 16px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.modal__head--center h2 {
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}

.modal__head--center .modal__close {
  position: absolute;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  padding: 0;
  font-size: 0;
  color: rgba(255, 255, 255, 0.8);
}

.modal__head--center .modal__close svg {
  width: 20px;
  height: 20px;
}

.modal__body {
  padding: 21px 24px 22px;
}

.modal__foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.modal__link {
  border: none;
  background: none;
  padding: 0;
  font-family: inherit;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
}

.modal__link:hover {
  color: rgba(255, 255, 255, 0.8);
}

.modal__link--back {
  margin-top: 16px;
}

.create-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.create-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.create-field__label {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.8);
  line-height: 1.45;
}

.size-pills {
  display: flex;
  gap: 8px;
  width: 100%;
}

.size-pill {
  flex: 1 1 0;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  border-radius: 9999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.size-pill.active {
  background: #fff;
  border-color: #fff;
  color: #050a0f;
  font-weight: 600;
}

.clock-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
}

.clock-field {
  flex: 1;
  min-width: 0;
}

.clock-plus {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 40px;
  flex-shrink: 0;
  color: rgba(255, 255, 255, 0.5);
}

.clock-plus svg {
  width: 16px;
  height: 16px;
}

.clock-select {
  width: 100%;
  height: 40px;
  padding: 0 24px 0 10px;
  border: none;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.09);
  color: rgba(255, 255, 255, 0.9);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6l4 4 4-4' stroke='rgba(255,255,255,0.5)' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.clock-select--full {
  max-width: none;
}

.clock-select option {
  background: #1c2025;
  color: #fff;
}

.btn-start {
  height: 38px;
  padding: 0 18px;
  border: none;
  border-radius: 9999px;
  background: #006ef5;
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow:
    inset 0 1.5px 2px rgba(255, 255, 255, 0.12),
    inset 0 7px 26.5px rgba(255, 255, 255, 0.12);
  transition: background 0.15s ease;
}

.btn-start:hover {
  background: #1a7dff;
}

.btn-start--full {
  width: 100%;
}

.modal__head h2 {
  margin: 0;
  font-size: 1.25rem;
}

.modal__close {
  font-size: 1.5rem;
  line-height: 1;
}

.modal__tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.modal__tab {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}

.modal__tab.active {
  background: var(--active-bg);
  border-color: var(--active-border);
  color: var(--active-text);
}

.modal__body.hidden,
.modal__foot.hidden {
  display: none;
}

.modal__panel.hidden {
  display: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0;
  width: 100%;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 15px;
  font-weight: 510;
  line-height: 1;
  text-align: left;
  cursor: pointer;
  box-sizing: border-box;
  transition:
    background 0.15s,
    color 0.15s;
}

.nav-item:hover {
  background: var(--nav-hover-bg);
  color: #fff;
}

.nav-item.active {
  background: var(--active-bg);
  color: var(--active-text);
}

.nav-item__icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--nav-icon-slot);
  height: var(--nav-icon-slot);
}

.nav-item__icon svg {
  width: 20px;
  height: 20px;
}

.nav-item__label {
  overflow: hidden;
  max-width: 8rem;
  opacity: 1;
  white-space: nowrap;
  line-height: 1;
  padding-right: 10px;
  transition:
    max-width var(--nav-transition),
    opacity var(--nav-transition),
    padding-right var(--nav-transition);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.lobby-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  background: var(--bg);
  border-right: 1px solid var(--border-soft);
}

@container root (max-width: 1100px) {
  .lobby-side-panel {
    width: 220px;
    padding: 32px 16px;
  }

  .tables-head,
  .tables-row {
    grid-template-columns: minmax(0, 1fr) 90px 110px;
    gap: 12px;
  }
}

/* Chart horizontal-scroll wrapper (header + rows scroll together on narrow screens) */
.chart-scroll {
  min-width: 0;
}

/* Watch tab: live games table */
.watch-head,
.watch-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px 150px 120px;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
}

/* Compact columns once the side panel narrows the content (<=1100px) */
@container root (max-width: 1100px) {
  .watch-head,
  .watch-row {
    grid-template-columns: minmax(0, 1fr) 80px 100px 80px;
    gap: 12px;
  }
}

.watch-head {
  min-height: 48px;
  padding-top: 14px;
  padding-bottom: 14px;
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-soft);
  font-size: 15px;
  font-weight: 590;
  color: #fff;
}

.watch-list {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.watch-row {
  padding-top: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background 0.15s;
}

.watch-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

.watch-col {
  font-size: 14px;
  font-weight: 510;
  color: #fff;
  min-width: 0;
}

.watch-head .watch-col {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 15px;
  font-weight: 590;
  white-space: nowrap;
}

.watch-players {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.watch-player {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.watch-player__stone {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 1.2px 3.6px rgba(0, 0, 0, 0.6);
}

.watch-player__stone.black {
  background: radial-gradient(circle at 32% 30%, #555 0%, #303030 50%, #0a0a0a 100%);
}

.watch-player__stone.white {
  background: radial-gradient(circle at 32% 30%, #fff 0%, #c8c4bc 100%);
}

.watch-player__rank {
  color: var(--text-muted);
}

.watch-empty {
  padding: 3rem 60px;
  color: var(--text-muted);
  text-align: center;
}

/* Legacy lobby grid (Play tab content) */
.lobby-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  padding: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.panel-grow {
  grid-row: span 2;
}

.panel-wide {
  grid-column: 1 / -1;
}

.panel h2 {
  font-size: 1rem;
  margin: 0 0 0.5rem;
  font-weight: 600;
}

.panel-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0 0 1rem;
}

.panel-hint.inline {
  margin: 0;
  font-size: 0.75rem;
}

.status-text {
  font-size: 0.875rem;
  color: var(--accent);
  text-align: center;
  margin: 0.5rem 0 0;
}

.review-move-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 0.5rem;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.overlay-actions .btn-primary,
.overlay-actions .btn-panel {
  width: 100%;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.panel-header h2 {
  margin: 0;
}

.badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  background: var(--bg);
  border-radius: 999px;
  color: var(--text-muted);
  font-weight: 500;
}

.badge.live {
  color: var(--success);
  background: rgba(92, 184, 122, 0.15);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stack label {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Lists */
.list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
}

.list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  margin-bottom: 0.35rem;
  background: var(--bg);
  border: 1px solid transparent;
}

.list li:hover {
  border-color: var(--border);
}

.list li.player-row {
  align-items: flex-start;
  gap: 0.75rem;
}

.list li.player-row.self {
  border-color: var(--active-border);
  background: var(--active-bg-subtle);
}

.player-rank-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 2.75rem;
  gap: 0.15rem;
}

.rank-position {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.player-info-col {
  flex: 1;
  min-width: 0;
}

.player-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.player-elo {
  font-weight: 600;
  color: var(--accent);
}

.player-record {
  opacity: 0.9;
}

.list .player-status {
  font-size: 0.75rem;
}

.list-ranked {
  max-height: 480px;
}

.list .status-online {
  color: var(--success);
}

.list .status-playing {
  color: var(--accent);
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: center;
  padding: 1.5rem;
}

/* Table */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table th,
.table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table th {
  color: var(--text-muted);
  font-weight: 500;
}

/* ===== Game / Watch screen ===== */
.muted {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

#screen-game.active {
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: #050a0f;
}

/* Flat board column — no blue ambient glow behind / above the goban */
#screen-game .top-nav,
#screen-game .game-main,
#screen-game .game-stage {
  background: #050a0f;
}

/* Top navigation bar */
.top-nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 62px;
  padding: 11px 24px 11px 0;
  background: var(--bg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}

.top-nav__rail {
  width: var(--nav-rail-width);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.top-nav .icon-btn.top-nav__menu {
  width: var(--nav-icon-slot);
  height: var(--nav-icon-slot);
}

.top-nav .icon-btn.top-nav__menu svg {
  width: 20px;
  height: 20px;
}

.top-nav__brand {
  font-size: 24px;
  font-weight: 510;
  line-height: 1.2;
  color: #fff;
  letter-spacing: 0.01em;
}

.top-nav__brand--game {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1.32px;
}

/* Game screen icon rail (Figma Navigation-Side) */
.side-nav--game {
  width: var(--nav-rail-width);
  padding: 17px 8px 16px;
  border-right: 1px solid rgba(255, 255, 255, 0.09);
}

.side-nav--game .side-nav__items {
  align-items: center;
}

.side-nav--game .nav-item {
  width: var(--nav-icon-slot);
  padding: 0;
}

/* Body row: side nav | center | panel */
.game-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  gap: 1px;
}

/* Center column */
.game-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
}

.game-meta-hidden {
  display: none;
}

.game-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  overflow: hidden;
}

/* Board */
.board-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  max-width: 792px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board-canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  cursor: crosshair;
  border-radius: 4px;
  overflow: hidden;
  background: #CC8F52;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:hover {
  color: #fff;
}

.icon-btn svg {
  width: 24px;
  height: 24px;
}

.turn-indicator {
  margin-left: auto;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 590;
  color: var(--text-dim);
  white-space: nowrap;
}

.turn-indicator:empty {
  display: none;
}

.turn-indicator.your-turn {
  border-color: var(--active-border);
  color: var(--active-text);
}

/* Board actions live in .panel-actions */

.panel-actions__icon {
  flex-shrink: 0;
}

/* Hidden review slider only — transport UI matches Figma action rows */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}


.playback-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.playback-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.playback-btn svg {
  width: 16px;
  height: 16px;
}

/* Game-over overlay */
.game-overlay {
  position: absolute;
  inset: 0;
  background: rgba(5, 10, 15, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.overlay-card {
  position: relative;
  text-align: center;
  padding: 2rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 360px;
  width: calc(100% - 2rem);
}

.overlay-card__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  color: var(--text-muted);
}

.overlay-card__close:hover {
  color: #fff;
}

.overlay-card__close svg {
  width: 20px;
  height: 20px;
}

.overlay-rematch-notice {
  margin: 0 0 1.25rem;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.875rem;
  line-height: 1.45;
}

.overlay-rematch-notice--incoming {
  background: var(--accent-soft);
  border: 1px solid rgba(0, 137, 255, 0.35);
  color: var(--text);
}

.overlay-rematch-notice--outgoing {
  background: var(--bg-subtle);
  border: 1px solid var(--border-soft);
  color: var(--text-dim);
}

.overlay-rematch-btn--accept {
  animation: rematch-accept-pulse 2s ease-in-out infinite;
}

@keyframes rematch-accept-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(0, 137, 255, 0.35);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(0, 137, 255, 0);
  }
}

.overlay-card h2 {
  margin: 0 0 0.5rem;
}

.overlay-card p {
  color: var(--text-muted);
  margin: 0 0 1.5rem;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.overlay-actions .btn-primary,
.overlay-actions .btn-panel {
  width: 100%;
}

/* Right panel: players, actions, Moves / Settings */
.game-panel {
  width: 380px;
  flex-shrink: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.09);
  overflow: hidden;
  background: var(--bg);
}

.panel-head {
  flex-shrink: 0;
}

.panel-players {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  padding: 20px;
  flex-shrink: 0;
}

.pmini {
  display: flex;
  flex-direction: column;
  gap: 8.5px;
  align-items: flex-start;
  flex: 1 1 0;
  min-width: 0;
}

.pmini--right {
  align-items: flex-end;
}

.pmini__block {
  display: flex;
  flex-direction: column;
  gap: 6.5px;
  min-width: 0;
  width: 100%;
}

.pmini--right .pmini__block {
  align-items: flex-end;
  text-align: right;
}

.pmini__identity {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 590;
  font-synthesis: none;
  font-variation-settings: 'wdth' 100, 'wght' 590;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: 0.96px;
  text-transform: uppercase;
  line-height: 1.45;
}

.pmini--right .pmini__identity {
  align-items: flex-end;
  text-align: right;
}

.pmini__name {
  margin: 0;
  font-size: 12px;
  font-weight: 590;
  line-height: 1.45;
  color: #ffffff;
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.pmini__name-text,
.pmini__rank {
  font: inherit;
  font-size: 12px;
  font-weight: 590;
  line-height: 1.45;
  letter-spacing: 0.96px;
  text-transform: uppercase;
}

.pmini__name-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* letter-spacing adds trailing space after the last glyph; cancel it for a stable gap */
  margin-right: -0.96px;
}

.pmini__rank {
  flex-shrink: 0;
  white-space: nowrap;
}

.pmini--right .pmini__name {
  justify-content: flex-end;
}

.pmini__record {
  margin: 0;
  font: inherit;
  font-size: 12px;
  font-weight: 590;
  line-height: 1.45;
  letter-spacing: 0.96px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
  white-space: nowrap;
}

.pmini__record-label {
  font: inherit;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
}

.pmini__record-val {
  font: inherit;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

.pmini__stats {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pmini__stone {
  flex-shrink: 0;
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.pmini__stone--black {
  background: radial-gradient(circle at 35% 30%, #555 0%, #0a0a0a 100%);
  box-shadow: 0 1.2px 3.6px rgba(0, 0, 0, 0.6);
}

.pmini__stone--white {
  background: radial-gradient(circle at 35% 30%, #fff 0%, #c8c4bc 100%);
  box-shadow: 0 1.2px 2.4px rgba(0, 0, 0, 0.3);
}

.pmini--right .pmini__stats {
  justify-content: flex-end;
}

.pmini__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 0 5px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.09);
  color: #ff5757;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 510;
  font-variation-settings: 'wdth' 100, 'wght' 510;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  box-sizing: border-box;
}

.pmini.active .pmini__badge {
  color: #ff5757;
}

.pmini__periods {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  flex-wrap: wrap;
  min-height: 17px;
}

.pmini--right .pmini__periods {
  justify-content: flex-end;
}

.pmini__periods:empty {
  display: none;
}

.pmini__period {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 17px;
  height: 17px;
  min-width: 17px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
  box-sizing: border-box;
}

.pmini__period__text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex-shrink: 0;
  line-height: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro', system-ui, sans-serif;
  font-size: 10px;
  font-weight: 590;
  font-variation-settings: 'wdth' 100, 'wght' 590;
  text-align: center;
  color: #fff;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  word-break: break-word;
}

.pmini__period:not(.pmini__period--main) .pmini__period__text {
  width: 100%;
}

.pmini__period--main .pmini__period__text {
  white-space: nowrap;
}

.pmini__period__label {
  display: block;
  line-height: 1.45;
  margin-right: -0.8px;
}

.pmini__period.active {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.09);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.09);
  flex-shrink: 0;
}

.panel-actions--review .panel-actions__play {
  display: none;
}

.panel-actions--review .panel-actions__review {
  flex: 1;
  width: 100%;
}

#btn-panel-rematch.overlay-rematch-btn--accept {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.panel-actions--bottom {
  border-top: 1px solid rgba(255, 255, 255, 0.09);
  border-bottom: none;
  padding: 20px;
  margin-top: auto;
}

.history-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.09);
  flex-shrink: 0;
  margin-top: auto;
}

.history-footer .btn-panel {
  flex: 1;
}

.history-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease;
}

.history-nav-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.18);
}

.history-nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.history-nav-btn svg {
  width: 16px;
  height: 16px;
}

.btn-panel {
  flex: 1;
  height: 32px;
  padding: 0 16px;
  border-radius: 80px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 510;
  line-height: 1.45;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-panel--outline {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.4);
  color: #fff;
}

.btn-panel--outline:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
}

.btn-panel--outline:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-panel--tertiary {
  background: transparent;
  border-color: transparent;
  color: rgba(255, 255, 255, 0.8);
}

.btn-panel--tertiary:hover:not(:disabled) {
  color: #fff;
}

.btn-panel--tertiary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.panel-tabs {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  width: 100%;
  padding: 9.5px 20px 0;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  overflow: visible;
  position: relative;
  z-index: 2;
  background: var(--bg);
}

.panel-tab {
  flex: 1 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 7.5px;
  min-width: 0;
  min-height: 30.5px;
  border: none;
  background: none;
  color: rgba(255, 255, 255, 0.8);
  font-family: inherit;
  font-size: 13px;
  font-weight: 510;
  line-height: 1.6;
  cursor: pointer;
  padding: 0;
}

.panel-tab:hover {
  color: rgba(255, 255, 255, 0.8);
}

.panel-tab.active {
  color: #fff;
}

.panel-tab.active:hover {
  color: #fff;
}

.panel-tab::after {
  content: '';
  width: 100%;
  height: 2px;
  background: transparent;
  border-radius: 99px 99px 0 0;
  flex-shrink: 0;
}

.panel-tab.active::after {
  background: #fff;
}

.settings-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 400px;
  padding: 0;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 10px 20px;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  background: none;
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.6;
  text-align: left;
  cursor: pointer;
}

.settings-row__label {
  flex: 1;
  min-width: 0;
}

.settings-row__value {
  flex-shrink: 0;
  font-weight: 510;
  color: rgba(255, 255, 255, 0.6);
}

.settings-row[role='switch'][aria-checked='true'] .settings-row__value {
  color: var(--active-text-dim);
}

.settings-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

#settings-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Move history */
.move-head {
  display: flex;
  gap: 24px;
  align-items: center;
  padding: 8px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  background: var(--bg);
  font-size: 11px;
  font-weight: 590;
  letter-spacing: 0.88px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
  flex-shrink: 0;
}

.move-head span {
  flex: 1;
  min-width: 0;
}

.move-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.move-row {
  display: flex;
  gap: 24px;
  align-items: center;
  padding: 7.5px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  color: #fff;
}

.move-row span {
  flex: 1;
  min-width: 0;
}

.move-row__num {
  flex: 1;
  min-width: 0;
}

.move-cell {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  color: #fff;
  text-align: left;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.move-cell:hover {
  color: var(--active-text-dim);
}

.move-cell.active {
  font-weight: 590;
  color: var(--active-text);
}

.move-cell--empty {
  cursor: default;
  pointer-events: none;
}

.move-row.current {
  background: var(--active-bg);
}

.move-empty {
  padding: 1.5rem 20px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

#history-view {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* App toast (errors, connection status) */
.app-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.75rem 1.25rem;
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 200;
  max-width: min(90vw, 420px);
  font-size: 0.875rem;
  color: #fff;
  text-align: center;
  pointer-events: none;
}

.app-toast--error {
  border-color: rgba(255, 87, 87, 0.6);
}

.app-toast--warn {
  border-color: rgba(255, 193, 7, 0.6);
}

.app-toast__countdown {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  max-width: 320px;
}

.toast p {
  margin: 0 0 0.5rem;
}

.toast-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

@container root (max-width: 900px) {
  #screen-lobby.active {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .lobby-body {
    flex-direction: column;
  }

  .side-nav {
    width: 100%;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px;
  }

  .side-nav__items {
    flex-direction: row;
    width: 100%;
  }

  #screen-lobby.nav-collapsed .side-nav {
    width: 100%;
  }

  .nav-item {
    flex: 0 0 auto;
    width: auto;
  }

  .tables-header,
  .tables-head,
  .tables-row {
    padding-left: 24px;
    padding-right: 24px;
  }

  .tables-header {
    flex-direction: column;
    align-items: stretch;
    padding-top: 24px;
  }

  .btn-new-table {
    align-self: flex-end;
    width: auto;
  }

  .tables-head,
  .tables-row {
    grid-template-columns: minmax(0, 1fr) 90px 110px;
    gap: 12px;
  }

  .watch-head,
  .watch-row {
    grid-template-columns: 1fr 80px 100px 80px;
    padding: 0 24px;
    gap: 12px;
  }

  .lobby-side-panel {
    width: 100%;
    padding: 20px 16px;
    border-left: none;
    border-top: 1px solid var(--border-soft);
  }

  .chart-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #screen-game.active {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .game-body {
    flex-direction: column;
    align-items: stretch;
  }

  #screen-game .side-nav--game {
    width: 100%;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px;
  }

  #screen-game .side-nav--game .side-nav__items {
    flex-direction: row;
    width: 100%;
  }

  #screen-game .side-nav--game .nav-item {
    width: auto;
    flex: 0 0 auto;
  }

  .game-main {
    border-right: none;
  }

  .game-panel {
    width: 100%;
    height: auto;
    max-height: 55vh;
    border-right: none;
    border-top: 1px solid var(--border);
  }
}

@container root (max-width: 600px) {
  .lobby-grid {
    padding: 1rem;
  }

  .panel-grow {
    grid-row: auto;
  }

  .game-subnav__meta {
    display: none;
  }

  /* Icon-only nav tabs */
  .nav-item {
    padding: 9px;
    gap: 0;
  }

  .nav-item__label {
    display: none;
  }

  /* Keep chart columns readable; overflow horizontally instead of squishing */
  .tables-head,
  .tables-list {
    min-width: 440px;
  }

  .watch-head,
  .watch-list {
    min-width: 560px;
  }

  .lobby-side-panel {
    display: none;
  }
}
