/* ==================== RESET & BASE ==================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* Application design tokens. Keep legacy aliases below for existing markup. */
  --color-page: #f6f8f6;
  --color-surface: #ffffff;
  --color-surface-elevated: #ffffff;
  --color-surface-subtle: #eef5ef;
  --color-text-primary: #1e2b22;
  --color-text-secondary: #647168;
  --color-text-muted: #849087;
  --color-border: #dfe7e0;
  --color-brand: #16803c;
  --color-brand-hover: #11652f;
  --color-success: #15803d;
  --color-warning: #b45309;
  --color-error: #b91c1c;
  --color-info: #2563a6;
  --color-player-a: #1d4ed8;
  --color-player-b: #c2410c;
  --color-goal: #d97706;
  --color-board-highlight: #dbeafe;
  --color-capture-highlight: #dc2626;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 40px;

  --control-height: 42px;
  --input-height: 46px;
  --card-padding: 20px;
  --modal-padding: 28px;
  --nav-item-gap: 5px;
  --transition-fast: 150ms;
  --transition-standard: 200ms;

  /* Compatibility aliases retained for legacy game and dashboard selectors. */
  --bg-primary: var(--color-page);
  --bg-secondary: var(--color-surface);
  --bg-card: var(--color-surface);
  --bg-soft: var(--color-surface-subtle);
  --text-primary: var(--color-text-primary);
  --text-secondary: var(--color-text-secondary);
  --text-faint: var(--color-text-muted);
  --accent-blue: var(--color-brand);
  --accent-cyan: #0f9f58;
  --p1-color: var(--color-player-a);
  --p2-color: var(--color-player-b);
  --goal-color: var(--color-goal);
  --success-color: var(--color-success);
  --warning-color: var(--color-warning);
  --error-color: var(--color-error);
  --border-light: var(--color-border);
  --shadow-sm: 0 1px 2px rgba(23,32,51,.05);
  --shadow-md: 0 6px 16px rgba(23,32,51,.07);
  --shadow-lg: 0 16px 40px rgba(23,32,51,.10);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;

  /* Auth-specific aliases share the authoritative application token block. */
  --auth-bg: var(--color-surface);
  --auth-bg-darker: #f8faf9;
  --auth-text-primary: var(--color-text-primary);
  --auth-text-secondary: var(--color-text-secondary);
  --auth-text-muted: var(--color-text-muted);
  --auth-border: var(--color-border);
  --auth-border-focus: var(--color-brand);
  --auth-brand: var(--color-brand);
  --auth-brand-hover: var(--color-brand-hover);
  --auth-brand-dark: #0f553c;
  --auth-error: var(--color-error);
  --auth-error-bg: #fef2f2;
  --auth-error-border: #fecaca;
  --auth-success: var(--color-success);
  --auth-shadow-sm: 0 1px 2px rgba(23, 32, 51, .05);
  --auth-shadow-md: 0 4px 12px rgba(23, 32, 51, .08);
  --auth-shadow-lg: 0 12px 40px rgba(23, 32, 51, .12);
  --auth-shadow-xl: 0 20px 60px rgba(23, 32, 51, .16);
  --auth-radius-sm: 8px;
  --auth-radius-md: 14px;
  --auth-radius-lg: 22px;
  --auth-radius-xl: 32px;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Be Vietnam Pro', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

button, input { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: 2px;
  border-radius: 4px;
}

svg { width: 1em; height: 1em; display: block; }

/* Shared SVG icon baseline. View-specific styles may refine color or size. */
svg.ui-icon,
svg.summary-icon,
svg.td-icon,
svg.tournament-meta-icon,
svg.tournament-action-icon,
svg.modal-close-icon {
  width: 25px;
  height: 25px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ==================== SCREENS ==================== */
.screen { display: none; flex-direction: column; align-items: center; width: 100%; min-height: 100vh; }
.screen.active { display: flex; animation: screenIn .35s cubic-bezier(.2,.8,.2,1); }

@keyframes screenIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
body.no-motion *, body.no-motion *::before, body.no-motion *::after {
  animation-duration: .01ms !important; transition-duration: .01ms !important;
}

/* ==================== LOADING ==================== */
#loading { justify-content: center; align-items: center; }

.loading-content {
  text-align: center;
  padding: 48px 56px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-light);
}

.brand-mark, .brand-mini {
  display: grid; place-items: center; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
  color: #fff; box-shadow: 0 10px 24px rgba(37,99,235,.28);
}
.brand-mark { width: 56px; height: 56px; margin: 0 auto 18px; font-size: 26px; }
.brand-mini { width: 36px; height: 36px; font-size: 18px; }

.loading-title, .lobby-hero h1, .game-header h1 {
  background: linear-gradient(100deg, var(--text-primary) 10%, var(--accent-blue) 60%, var(--accent-cyan) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.loading-title { font-size: 2.6rem; margin-bottom: 6px; letter-spacing: -1px; }
.loading-subtitle { color: var(--text-secondary); margin-bottom: 26px; font-size: .85rem; letter-spacing: 3px; font-weight: 600; }

.loading-spinner {
  width: 42px; height: 42px; border: 3px solid var(--border-light);
  border-top-color: var(--accent-blue); border-radius: 50%; margin: 0 auto 18px;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--text-secondary); font-size: .85rem; }

/* ==================== LOBBY ==================== */
#lobby { padding: 28px; justify-content: center; }
.lobby-shell { width: min(1080px, 100%); display: grid; grid-template-columns: 1.05fr .95fr; gap: 30px; align-items: center; }
.lobby-hero { padding: 20px 10px; }
.lobby-hero .brand-mark { margin: 0 0 18px; }
.eyebrow { font-size: .68rem; letter-spacing: 2px; font-weight: 700; color: var(--text-faint); }
.lobby-hero h1 { font-size: clamp(2.6rem, 6vw, 4.2rem); line-height: .98; letter-spacing: -2px; margin: 10px 0 18px; }
.lobby-hero h1 span, .game-header h1 span { color: var(--accent-cyan); -webkit-text-fill-color: var(--accent-cyan); }
.lobby-hero p { max-width: 520px; color: var(--text-secondary); font-size: 1rem; line-height: 1.65; }
.hero-stats { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.hero-stats span { padding: 9px 13px; border: 1px solid var(--border-light); background: #fff; border-radius: 12px; color: var(--text-secondary); font-size: .78rem; box-shadow: var(--shadow-sm); }
.hero-stats b { color: var(--text-primary); margin-right: 4px; }

.lobby-card { background: var(--bg-card); border-radius: var(--radius-lg); padding: 34px; width: 100%; box-shadow: var(--shadow-lg); border: 1px solid var(--border-light); }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 22px; }
.section-heading h2 { font-size: 1.25rem; margin-top: 4px; }
.online-dot { font-size: .68rem; color: var(--success-color); font-weight: 700; display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.online-dot i, .player-status i { width: 7px; height: 7px; border-radius: 50%; background: var(--success-color); box-shadow: 0 0 0 3px rgba(22,163,74,.15); }
.online-dot.offline i, .conn-pill.offline i { background: var(--error-color); box-shadow: 0 0 0 3px rgba(220,38,38,.15); }
.online-dot.connecting i, .conn-pill.connecting i { background: var(--warning-color); box-shadow: 0 0 0 3px rgba(217,119,6,.15); }

.form-group { margin-bottom: 18px; text-align: left; }
.form-group label { display: block; margin-bottom: 7px; font-size: .74rem; color: var(--text-secondary); font-weight: 600; }
.input-shell { display: flex; align-items: center; gap: 10px; padding: 0 14px; border: 1px solid var(--border-light); border-radius: 5px; background: var(--bg-soft); transition: border-color .15s, box-shadow .15s; }
.input-shell svg, .input-shell > span { color: var(--text-faint); font-size: 18px; flex-shrink: 0; }
.input-shell:focus-within { border-color: var(--accent-blue); box-shadow: 0 0 0 3px rgba(37,99,235,.1); background: #fff; }
.form-group input { width: 100%; background: transparent; border: 0; padding: 12px 0; color: var(--text-primary); outline: none; }
.form-group input::placeholder { color: var(--text-faint); }
.field-error { min-height: 1.1em; margin-top: 6px; font-size: .74rem; color: var(--error-color); }

.room-input-group { display: flex; gap: 8px; margin-bottom: 10px; }
.room-input-group input { flex: 1; }
.room-shell { flex: 1; }

.icon-btn, .header-action {
  border: 1px solid var(--border-light); background: #fff; color: var(--text-secondary);
  border-radius: 11px; transition: .15s; display: grid; place-items: center;
}
.icon-btn { width: 46px; height: 46px; font-size: 18px; }
.icon-btn:hover, .header-action:hover { background: var(--bg-soft); border-color: var(--accent-blue); color: var(--accent-blue); transform: translateY(-1px); }

.primary-btn {
  width: 100%; padding: 14px; border-radius: 13px; border: none;
  background: linear-gradient(100deg, var(--accent-blue), var(--accent-cyan));
  color: #fff; font-weight: 700; font-size: .95rem; letter-spacing: .3px;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  box-shadow: 0 10px 24px rgba(37,99,235,.22); transition: transform .15s, box-shadow .15s;
}
.primary-btn svg { font-size: 20px; }
.primary-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(37,99,235,.3); }
.primary-btn:active { transform: translateY(0); }
.primary-btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }

/* Match action buttons share the compact size of “Xem diễn biến”. */
.tournament-retry-action {
  width: auto;
  min-width: 0;
  padding: 11px;
  border-radius: 10px;
  font-size: .84rem;
  box-shadow: none;
  white-space: nowrap;
}
.tournament-retry-action:hover { transform: none; box-shadow: none; }

/* Keep the two match actions on one compact horizontal row. */
.schedule-card-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}
.schedule-action-cell {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
}
.schedule-table th:last-child,
.schedule-table td.schedule-action-cell {
  text-align: center;
  vertical-align: middle;
}
.schedule-action-cell .action-content {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 6px;
  width: 100%;
  min-height: 36px;
}
.schedule-action-cell .action-content > .secondary-btn,
.schedule-action-cell .action-content > .primary-btn {
  width: auto;
  min-width: 0;
  flex: 0 0 auto;
  white-space: nowrap;
  padding-left: 8px;
  padding-right: 8px;
}
.schedule-action-cell > .secondary-btn,
.schedule-action-cell > .primary-btn,
.schedule-card-footer > .secondary-btn,
.schedule-card-footer > .primary-btn {
  width: auto;
  flex: 0 0 auto;
  white-space: nowrap;
}
.schedule-card-footer .schedule-card-winner {
  flex: 1 1 auto;
  min-width: 0;
}

.secondary-btn {
  width: 100%; padding: 11px; border-radius: 10px; border: 1px solid var(--border-light);
  background: #fff; color: var(--text-secondary); font-size: .84rem; transition: all .15s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.secondary-btn svg { font-size: 16px; }
.secondary-btn:hover { background: var(--bg-soft); color: var(--text-primary); border-color: var(--accent-blue); }

.status-msg { margin-top: 18px; padding: 12px; border-radius: 10px; background: #fef2f2; border: 1px solid #fecaca; color: var(--error-color); font-size: .85rem; text-align: center; }
.status-msg.success { background: #f0fdf4; border-color: #bbf7d0; color: var(--success-color); }

/* mode select as buttons */
.mode-select { display: flex; gap: 10px; }
.mode-card {
  flex: 1; padding: 18px 12px; border-radius: 15px; border: 1.5px solid var(--border-light);
  background: #fff; text-align: center; display: flex; flex-direction: column; align-items: center;
  gap: 5px; transition: all .18s; position: relative; font: inherit; color: inherit;
}
.mode-card:hover { border-color: var(--accent-blue); background: #eff6ff; transform: translateY(-1px); }
.mode-card.selected { border-color: var(--accent-blue); background: #eff6ff; box-shadow: inset 0 0 0 1px rgba(37,99,235,.25); }
.mode-icon { font-size: 26px; color: var(--accent-blue); margin-bottom: 2px; }
.mode-title { font-weight: 700; font-size: .8rem; color: var(--text-primary); letter-spacing: .3px; }
.mode-desc { font-size: .72rem; color: var(--text-secondary); }
.mode-check { position: absolute; right: 10px; top: 10px; opacity: 0; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-blue); color: #fff; font-size: 12px; }
.mode-card.selected .mode-check { opacity: 1; }
.mode-card:disabled, .mode-card.locked { opacity: .4; cursor: not-allowed; pointer-events: none; }
.label-hint { text-transform: none; font-weight: 500; color: var(--text-faint); letter-spacing: 0; }

.lobby-tip { margin-top: 16px; text-align: center; color: var(--text-faint); font-size: .74rem; }
kbd { padding: 2px 6px; border-radius: 6px; border: 1px solid var(--border-light); background: var(--bg-soft); color: var(--text-secondary); font-size: .72rem; }

/* ==================== GAME HEADER ==================== */
.game-header {
  width: 100%; padding: 13px 22px; background: rgba(255,255,255,.9); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-light); display: flex; justify-content: space-between;
  align-items: center; flex-wrap: wrap; gap: 10px; position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow-sm);
}
.game-header h1 { font-size: 1.2rem; }
.brand-inline { display: flex; align-items: center; gap: 10px; }
.brand-inline small { display: block; color: var(--text-faint); font-size: .58rem; letter-spacing: 1.5px; margin-top: 3px; }

.room-info { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--text-secondary); flex-wrap: wrap; }
.room-info strong { color: var(--text-primary); }
.back-link { color: var(--accent-blue); text-decoration: none; font-size: .82rem; font-weight: 600; display: flex; align-items: center; gap: 5px; }
.back-link svg { font-size: 15px; }
.back-link:hover { text-decoration: underline; }

.conn-pill { display: flex; align-items: center; gap: 6px; padding: 7px 11px; border-radius: 20px; background: var(--bg-soft); font-size: .68rem; font-weight: 600; color: var(--success-color); }
.conn-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--success-color); box-shadow: 0 0 0 3px rgba(22,163,74,.15); }
.conn-pill.offline { color: var(--error-color); }
.conn-pill.connecting { color: var(--warning-color); }

.room-pill { padding: 8px 12px; border-radius: 10px; background: var(--bg-soft); border: 1px solid var(--border-light); font-size: .7rem; color: var(--text-secondary); }
.room-pill strong { color: var(--text-primary); font-family: ui-monospace, monospace; }

.header-action { width: 38px; height: 38px; font-size: 17px; }

/* ==================== GAME MAIN ==================== */
.game-main { display: flex; justify-content: center; align-items: center; gap: 22px; padding: 26px 24px; flex-wrap: wrap; max-width: 1250px; width: 100%; margin: 0 auto; }

/* ==================== PLAYER PANELS ==================== */
.player-panel {
  background: var(--bg-card); border-radius: 18px; padding: 19px; min-width: 190px; width: 190px;
  border: 1px solid var(--border-light); transition: all .25s; flex-shrink: 0; box-shadow: var(--shadow-md); position: relative; overflow: hidden;
}
.player-panel::before { content: ""; position: absolute; left: 0; top: 0; width: 100%; height: 3px; background: var(--p1-color); }
.player2-panel::before { background: var(--p2-color); }
.player-panel.active { border-color: rgba(37,99,235,.35); box-shadow: 0 0 0 3px rgba(37,99,235,.08), var(--shadow-md); }
.player-panel.player2-panel.active { border-color: rgba(225,29,72,.35); box-shadow: 0 0 0 3px rgba(225,29,72,.08), var(--shadow-md); }
.player-panel.my-side { background: #eff6ff; }
.player-panel.player2-panel.my-side { background: #fff1f2; }

.player-header { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.player-avatar { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: .68rem; font-weight: 800; }
.p1-avatar { background: rgba(37,99,235,.12); color: var(--p1-color); }
.p2-avatar { background: rgba(225,29,72,.12); color: var(--p2-color); }
.player-panel h3 { font-size: .64rem; color: var(--text-faint); letter-spacing: 1.4px; margin: 0 0 3px; }
.player-name { font-style: normal; color: var(--text-primary); font-weight: 700; max-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-side-label { font-size: .6rem; letter-spacing: 1.4px; color: var(--text-faint); margin-bottom: 10px; }
.you-badge { display: inline-block; margin-left: 7px; padding: 2px 7px; border-radius: 6px; background: linear-gradient(100deg, var(--accent-blue), var(--accent-cyan)); color: #fff; font-size: .62rem; font-weight: 700; vertical-align: middle; }

.piece-counts { display: flex; gap: 7px; justify-content: space-between; }
.piece-stat { display: flex; flex-direction: column; align-items: center; min-width: 48px; padding: 9px 5px; border: 1px solid var(--border-light); background: var(--bg-soft); border-radius: 12px; gap: 3px; }
.piece-icon { font-size: 35px; color: var(--text-primary); }
#player1-panel .piece-icon { color: var(--p1-color); }
#player2-panel .piece-icon { color: var(--p2-color); }
.piece-count { font-size: .85rem; font-weight: 700; color: var(--text-primary); }
.piece-stat small { color: var(--text-faint); font-size: .58rem; }

.player-status { margin-top: 13px; color: var(--text-faint); font-size: .64rem; display: flex; align-items: center; gap: 6px; }
.player-panel.active .player-status { color: var(--success-color); }

/* ==================== BOARD ==================== */
.board-section { position: relative; }
.board-topbar { display: flex; justify-content: space-between; align-items: end; margin: 0 0 8px 29px; }
.board-topbar strong { display: block; font-size: .95rem; margin-top: 2px; }
.board-hint { font-size: .62rem; color: var(--text-faint); }

.board-wrapper { display: flex; flex-direction: column; align-items: center; }
.board-row { display: flex; align-items: stretch; }
.coord-header { display: flex; padding-left: 25px; margin-bottom: 4px; }
.coord-header .corner { width: 25px; flex-shrink: 0; }
.coord-header .coord { width: min(8.33vw, 61px); text-align: center; font-size: .72rem; color: var(--text-faint); font-weight: 700; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 4px; }
.coord-side { display: flex; flex-direction: column; width: 25px; flex-shrink: 0; margin-right: 4px; }
.coord-side .coord { flex: 1; display: flex; align-items: center; justify-content: center; font-size: .72rem; color: var(--text-faint); font-weight: 700; }

.board {
  display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr);
  gap: 2px; background: #dbe4ef; border-radius: 16px; overflow: hidden;
  width: min(62vw, 560px); height: min(62vw, 560px); border: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg); padding: 2px; position: relative;
}
.cell { aspect-ratio: 1; background: #fff; display: flex; align-items: center; justify-content: center; position: relative; cursor: pointer; transition: background .14s, transform .1s; }
.cell:hover { background: #eff6ff; }
.cell.goal { background: linear-gradient(145deg, rgba(217,119,6,.10), rgba(217,119,6,.02)); }
.cell.last-from, .cell.last-to { background: rgba(37,99,235,.08); }
.cell.selected { background: #dbeafe !important; box-shadow: inset 0 0 0 2px var(--accent-blue); z-index: 2; }
.cell.valid-move::after { content: ""; position: absolute; width: 30%; height: 30%; background: rgba(22,163,74,.55); border-radius: 50%; z-index: 1; }
.cell.capture-move::after { content: ""; position: absolute; width: 100%; height: 100%; background: rgba(220,38,26,.12); border-radius: 50%; z-index: 0; }

.piece { width: 70%; height: 70%; z-index: 1; transition: transform .18s; }
.piece svg { width: 100%; height: 100%; }
.piece.player1 { color: var(--p1-color); }
.piece.player2 { color: var(--p2-color); }
.piece.moving { transition: transform .28s cubic-bezier(.3,.8,.4,1); }
.piece.capturing { animation: pieceCaptured .28s ease-out forwards; }
@keyframes pieceCaptured { to { transform: scale(0); opacity: 0; } }

.goal-flag { width: 34%; height: 34%; opacity: .35; position: absolute; z-index: 0; pointer-events: none; color: var(--goal-color); }

.board-legend { display: flex; justify-content: center; gap: 18px; margin-top: 10px; color: var(--text-faint); font-size: .68rem; }
.legend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.legend-dot.move { background: var(--success-color); }
.legend-dot.capture { background: var(--error-color); }
.legend-dot.goal { background: var(--goal-color); }

.board.spectating,
.mini-board.spectating {
  opacity: .65;
  pointer-events: none;
  cursor: not-allowed;
}
.board.spectating .cell,
.mini-board.spectating .cell {
  cursor: not-allowed;
}
.board.spectating .cell:hover,
.mini-board.spectating .cell:hover {
  background: #fff;
}
.board.spectating::after {
  content: "ĐANG XEM";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,.55);
  color: var(--text-secondary);
  font-weight: 800;
  font-size: .85rem;
  letter-spacing: 1.5px;
  border-radius: inherit;
  z-index: 5;
  pointer-events: none;
}
.mini-board.spectating::after {
  font-size: .65rem;
}

/* ==================== TURN INDICATOR ==================== */
.turn-indicator {
  text-align: center; padding: 13px 20px; font-size: 1rem; font-weight: 700; margin: 0 20px 14px;
  border-radius: 14px; background: var(--bg-card); border: 1px solid var(--border-light);
  min-width: 300px; max-width: min(85vw, 560px); box-shadow: var(--shadow-sm); letter-spacing: .2px;
}
.turn-indicator.my-turn { color: var(--success-color); border-color: #bbf7d0; background: #f0fdf4; }
.turn-indicator.opponent-turn { color: var(--warning-color); border-color: #fde68a; background: #fffbeb; }
.turn-indicator.winner { color: var(--goal-color); border-color: #fde68a; background: #fffbeb; animation: pulse 1.6s infinite; }
.turn-indicator.waiting { color: var(--accent-blue); }
.turn-indicator.error { color: var(--error-color); border-color: #fecaca; background: #fef2f2; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .88; transform: scale(1.015); } }

/* ==================== TOAST ==================== */
#toast-container {
  position: fixed;
  right: 24px;
  bottom: 28px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  width: min(92vw, 390px);
  pointer-events: none;
}
.toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 11px;
  width: min(100%, 390px);
  padding: 13px 13px 13px 15px;
  overflow: hidden;
  border: 1px solid #e2e8e4;
  border-radius: 14px;
  background: #fff;
  color: var(--text-primary);
  box-shadow: 0 12px 30px rgba(30, 43, 34, .13), 0 2px 6px rgba(30, 43, 34, .06);
  transform: translateY(22px);
  opacity: 0;
  transition: transform .28s ease, opacity .22s ease;
  line-height: 1.4;
}
.toast::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: #64748b; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast-marker { display: grid; place-items: center; flex: 0 0 auto; width: 30px; height: 30px; margin-top: 1px; border-radius: 9px; background: #f1f5f2; color: #52635a; }
.toast-marker svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.toast-content { display: grid; gap: 2px; min-width: 0; padding-top: 1px; }
.toast-label { color: #52635a; font-size: .68rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.toast-message { color: #27342d; font-size: .83rem; overflow-wrap: anywhere; }
.toast-close { width: 26px; height: 26px; margin: -3px -3px 0 auto; padding: 0; border: 0; border-radius: 7px; background: transparent; color: #849188; font-size: 0; line-height: 1; }
.toast-close::before { content: '\00D7'; font-size: 1.15rem; }
.toast-close:hover { background: #f1f5f2; color: #27342d; }
.toast-success::before, .toast-capture::before { background: #16803c; }
.toast-success .toast-marker, .toast-capture .toast-marker { background: #e8f5eb; color: #16803c; }
.toast-error::before { background: #c2413b; }
.toast-error .toast-marker { background: #fff0ef; color: #b42318; }
.toast-info::before { background: #3578b8; }
.toast-info .toast-marker { background: #edf5fb; color: #3578b8; }
/* Keep the original error token available for theme overrides. */
/* .toast-error { background: var(--error-color); } */

/* ==================== QUICK BAR ==================== */
.quick-bar { display: flex; justify-content: center; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; color: var(--text-faint); font-size: .68rem; }
.quick-bar button { display: flex; align-items: center; gap: 7px; border: 1px solid var(--border-light); background: #fff; color: var(--text-secondary); border-radius: 10px; padding: 8px 12px; }
.quick-bar button svg { font-size: 15px; }
.quick-bar button:hover { background: var(--bg-soft); border-color: var(--accent-blue); color: var(--accent-blue); }
.shortcut-hint { display: flex; align-items: center; gap: 5px; }

/* ==================== MODALS ==================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.42); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 2000; opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal-box {
  background: #fff; border-radius: 20px; padding: 24px 26px; width: min(92vw, 520px);
  box-shadow: var(--shadow-lg); border: 1px solid var(--border-light);
  transform: translateY(10px) scale(.98); transition: transform .2s;
}
.modal-overlay.open .modal-box { transform: none; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h4 { font-size: .78rem; letter-spacing: 1.5px; color: var(--text-secondary); }
.modal-close { width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--border-light); background: var(--bg-soft); color: var(--text-secondary); display: grid; place-items: center; font-size: 15px; }
.modal-close:hover { background: #fee2e2; color: var(--error-color); border-color: #fecaca; }

.rules-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rules-grid div { display: flex; gap: 9px; align-items: flex-start; padding: 9px 10px; border-radius: 10px; background: var(--bg-soft); }
.rules-grid b { color: var(--accent-blue); font-size: .62rem; flex-shrink: 0; }
.rules-grid span { font-size: .72rem; color: var(--text-secondary); line-height: 1.4; }

.settings-list { display: flex; flex-direction: column; gap: 4px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 4px; border-bottom: 1px solid var(--border-light); font-size: .88rem; color: var(--text-primary); }
.settings-row:last-child { border-bottom: none; }
.switch { appearance: none; width: 42px; height: 24px; border-radius: 20px; background: var(--border-light); position: relative; transition: background .2s; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch:checked { background: var(--accent-blue); }
.switch:checked::after { transform: translateX(18px); }

.result-box { text-align: center; }
.result-icon { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 50%; background: linear-gradient(135deg, #fde68a, #fbbf24); color: #92400e; display: grid; place-items: center; font-size: 30px; }
.result-icon.defeat { background: linear-gradient(135deg, #fecaca, #f87171); color: #7f1d1d; }
#result-title { font-size: 1.5rem; margin-bottom: 6px; letter-spacing: -.3px; }
#result-sub { color: var(--text-secondary); font-weight: 600; margin-bottom: 4px; }
.result-meta { color: var(--text-faint); font-size: .8rem; margin-bottom: 20px; }
.result-actions { display: flex; flex-direction: column; gap: 10px; }

/* ==================== FOOTER ==================== */
.game-footer {
  width: 100%; padding: 12px 20px; background: rgba(255,255,255,.9); border-top: 1px solid var(--border-light);
  display: flex; justify-content: center; align-items: center; gap: 20px; font-size: .82rem; color: var(--text-secondary);
  flex-wrap: wrap; position: sticky; bottom: 0;
}
.game-footer span { display: flex; align-items: center; gap: 5px; }
.footer-icon { font-size: 15px; }
#spectator-info { color: var(--accent-blue); font-weight: 500; display: flex; align-items: center; gap: 5px; }
#reset-btn { display: flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border-light); background: #fff; color: var(--text-primary); font-size: .82rem; transition: all .15s; }
#reset-btn svg { font-size: 14px; }
#reset-btn:hover { background: var(--bg-soft); border-color: var(--accent-blue); }

/* ==================== ARENA ==================== */
#arena { padding-bottom: 30px; }
.arena-toolbar { width: min(920px, calc(100% - 40px)); display: flex; justify-content: space-between; align-items: end; margin: 22px auto 0; }
.arena-toolbar strong { display: block; margin-top: 4px; font-size: 1.02rem; }
.arena-capacity { padding: 8px 11px; border: 1px solid var(--border-light); border-radius: 9px; color: var(--text-secondary); font-size: .64rem; background: #fff; }

.arena-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; width: 100%; max-width: 920px; margin: 16px auto 30px; padding: 0 20px; }
.board-panel { background: var(--bg-card); border-radius: 18px; padding: 14px; box-shadow: var(--shadow-md); border: 1px solid var(--border-light); display: flex; flex-direction: column; gap: 9px; transition: transform .15s, border-color .15s; }
.board-panel:hover { transform: translateY(-2px); border-color: rgba(37,99,235,.25); }
.board-panel-header { display: flex; justify-content: space-between; align-items: center; }
.board-panel-title { font-weight: 700; font-size: .88rem; color: var(--text-primary); letter-spacing: .3px; }
.board-panel-code { font-size: .68rem; color: var(--text-faint); font-family: monospace; }

.mini-players { display: flex; justify-content: space-between; font-size: .74rem; gap: 8px; padding: 7px 9px; border-radius: 10px; background: var(--bg-soft); }
.mini-player { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mini-player.p2 { text-align: right; align-items: flex-end; }
.mini-player-name { font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.mini-piece-counts { color: var(--text-faint); font-size: .68rem; }

.mini-board { display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); gap: 1px; background: #dbe4ef; border-radius: 12px; overflow: hidden; width: 100%; aspect-ratio: 1; border: 1px solid var(--border-light); position: relative; }
.mini-board .cell { aspect-ratio: 1; background: #fff; display: flex; align-items: center; justify-content: center; position: relative; cursor: pointer; }
.mini-board .cell:hover { background: #eff6ff; }
.mini-board .cell.goal { background: rgba(217,119,6,.08); }
.mini-board .cell.selected { background: #dbeafe !important; box-shadow: inset 0 0 0 2px var(--accent-blue); }
.mini-board .cell.valid-move::after { content: ""; position: absolute; width: 30%; height: 30%; background: rgba(22,163,74,.55); border-radius: 50%; }
.mini-board .cell.capture-move::after { content: ""; position: absolute; width: 58%; height: 58%; border: 2px solid rgba(220,38,38,.6); border-radius: 50%; }
.mini-board .piece { width: 66%; height: 66%; }

.board-panel-turn { text-align: center; font-size: .72rem; font-weight: 700; padding: 7px; border-radius: 9px; background: var(--bg-soft); color: var(--accent-blue); }
.board-panel-turn.my-turn { color: var(--success-color); background: #f0fdf4; }
.board-panel-turn.opponent-turn { color: var(--warning-color); background: #fffbeb; }
.board-panel-turn.winner { color: var(--goal-color); background: #fffbeb; }
.board-panel-turn.waiting { color: var(--accent-blue); }
.board-panel-turn.full { color: var(--text-faint); }

.board-panel-footer { display: flex; justify-content: center; gap: 8px; }
.join-board-btn, .reset-board-btn { padding: 8px 16px; border-radius: 9px; border: none; font-size: .74rem; font-weight: 700; letter-spacing: .3px; transition: transform .15s; display: flex; align-items: center; gap: 6px; }
.join-board-btn { background: linear-gradient(100deg, var(--accent-blue), var(--accent-cyan)); color: #fff; }
.reset-board-btn { background: var(--bg-soft); border: 1px solid var(--border-light); color: var(--text-primary); }
.join-board-btn:hover, .reset-board-btn:hover { transform: translateY(-1px); }
.spectator-info-mini { text-align: center; font-size: .68rem; color: var(--accent-blue); min-height: 1em; display: flex; align-items: center; justify-content: center; gap: 5px; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 1024px) { .game-main { gap: 15px; } }

@media (max-width: 900px) {
  .lobby-shell { grid-template-columns: 1fr; max-width: 620px; }
  .lobby-hero { text-align: center; }
  .lobby-hero .brand-mark { margin: 0 auto 18px; }
  .hero-stats { justify-content: center; }

  .game-main { flex-direction: column; align-items: center; }
  .player-panel { display: flex; align-items: center; gap: 20px; min-width: auto; width: min(560px, 90vw); justify-content: space-between; padding: 14px 18px; }
  .player-header { margin-bottom: 0; }
  .piece-counts { margin-bottom: 0; }
  .board { width: min(90vw, 520px); height: min(90vw, 520px); }
}

@media (max-width: 700px) {
  .arena-grid { grid-template-columns: 1fr; max-width: 460px; }
  .mode-select { flex-direction: column; }
}

@media (max-width: 600px) {
  .lobby-card { padding: 22px; margin: 0; }
  .game-header { padding: 10px 14px; }
  .game-header h1 { font-size: 1rem; }
  .room-info .back-link span, .room-info .conn-pill span { display: none; }
  .board { width: 94vw; height: 94vw; border-radius: 12px; }
  .coord-header .coord, .coord-side .coord { font-size: .62rem; }
  .turn-indicator { font-size: .9rem; padding: 11px 14px; }
  .rules-grid { grid-template-columns: 1fr; }
  .player-panel { width: 94vw; padding: 12px 14px; }
}

@media (max-width: 400px) {
  .player-panel { flex-direction: column; gap: 10px; text-align: center; }
  .piece-counts { justify-content: center; }
  .shortcut-hint { display: none; }
}

@media (max-width: 600px) {
  #toast-container { right: 12px; bottom: 14px; width: calc(100vw - 24px); }
  .toast { width: 100%; padding: 12px 11px 12px 13px; }
  .toast-message { font-size: .8rem; }
}

/* ==================== UTILITY ==================== */
[hidden] {
  display: none !important;
}

.hidden { display: none !important; }
.text-center { text-align: center; }

/* ==================== DASHBOARD FOUNDATION (staged extraction) ==================== */
.ui-message,
.table-message {
  color: var(--text-secondary);
  text-align: center;
  padding: 22px;
}

.ui-message p { margin-bottom: 12px; }

.table-message .secondary-btn {
  width: auto;
  margin-left: 12px;
  padding: 6px 10px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 15px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}

.data-table th {
  background: var(--bg-soft);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.85rem;
}

.data-table tr:last-child td { border-bottom: none; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.status-badge {
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: bold;
}

.status-draft { background: #e2e8f0; color: #475569; }
.status-registration_open { background: #dbeafe; color: #1e40af; }
.status-registration_closed { background: #fff5df; color: #87611b; }
.status-scheduled,
.status-queued { background: #f1f5f2; color: #607066; }
.status-in_progress,
.status-active { background: #e4f1eb; color: #176b50; }
.status-failed,
.status-error { background: #fff0ef; color: #a0463e; }
.status-running { background: #fef08a; color: #854d0e; }
.status-completed { background: #bbf7d0; color: #166534; }
.status-cancelled { background: #fecaca; color: #991b1b; }
