/* Battle Board — two-player game picker.
   Tokens, reset, body, Inter font, .chip, focus-visible, touch-action,
   .visually-hidden, and reduced-motion come from /assets/base.css. */

/* Battle-specific additions to the shared palette */
:root {
  --good: #27d17a;
  --error: #ff5d5d;

  /* Player identity colors */
  --player-a: var(--accent);            /* TagWhy purple */
  --player-a-soft: rgba(138, 124, 255, 0.18);
  --player-b: #ff7aa8;                  /* warm pink */
  --player-b-soft: rgba(255, 122, 168, 0.18);

  --card-bg: linear-gradient(160deg, #141826, #101321);
  --card-bg-primary: linear-gradient(160deg, #161a2d, #0f1220);
  --box-bg: radial-gradient(circle at 0 0, #272b4a 0, #181b2a 42%, #101320 78%);
  --inset-bg: #101322;
}

/* ============================================================
   SCREEN TOGGLING
   ============================================================ */

.game-screen,
.menu-screen,
.settings-screen {
  position: relative;
  z-index: 1;
  /* clip: entrance animations translate children downward; without this the
     shifted boxes extend the page's scroll area and flash a scrollbar */
  overflow: clip;
}

.game-screen.hidden,
.menu-screen.hidden,
.settings-screen.hidden { display: none; }

/* ============================================================
   MENU SCREEN
   ============================================================ */

.menu-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 58px); /* leave room for .site-foot */
  padding: 40px 20px;
}

.menu-panel {
  width: 100%;
  max-width: 440px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 48px 36px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  box-shadow: var(--shadow-soft);
  animation: menu-entrance 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes menu-entrance {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.menu-title {
  font-size: clamp(28px, 5vw, 42px);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-align: center;
  line-height: 1.2;
  margin: 0;
}
.menu-title .accent { color: var(--accent); }

.menu-subtitle {
  color: var(--muted);
  font-size: 15px;
  margin: -16px 0 0;
  text-align: center;
}

.menu-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.menu-players {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.menu-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.menu-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.menu-input {
  background: var(--inset-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  width: 100%;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.menu-input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.menu-input::placeholder { color: rgba(167, 167, 194, 0.4); }

.menu-vs {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  padding-bottom: 14px;
  flex-shrink: 0;
}

.menu-target {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.menu-target-row {
  display: flex;
  align-items: center;
  gap: 0;
}

.menu-stepper-btn {
  width: 40px;
  height: 40px;
  background: var(--inset-bg);
  border: 1px solid var(--line);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.menu-stepper-btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.menu-stepper-btn:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

.menu-stepper-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

.menu-target-input {
  width: 52px;
  height: 40px;
  background: var(--inset-bg);
  border: 1px solid var(--line);
  border-left: none;
  border-right: none;
  color: var(--text);
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
}
.menu-target-input::-webkit-outer-spin-button,
.menu-target-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.menu-target-input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.menu-start-btn {
  width: 100%;
  justify-content: center;
  padding: 14px 24px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.04em;
  gap: 10px;
  margin-top: 4px;
}

.menu-start-btn .icon {
  width: 20px;
  height: 20px;
}

.menu-history-teaser {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.menu-history-teaser .icon {
  width: 16px;
  height: 16px;
  opacity: 0.5;
  stroke: currentColor;
  fill: none;
}

/* Staggered field entrance */
.menu-form > * {
  animation: menu-field-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.menu-form > *:nth-child(1) { animation-delay: 0.1s; }
.menu-form > *:nth-child(2) { animation-delay: 0.18s; }
.menu-form > *:nth-child(3) { animation-delay: 0.26s; }

@keyframes menu-field-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   SETTINGS SCREEN
   ============================================================ */

.settings-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 58px); /* leave room for .site-foot */
  padding: 40px 20px;
}

.settings-panel {
  width: 100%;
  max-width: 500px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: var(--shadow-soft);
  animation: menu-entrance 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

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

.settings-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0;
}

.settings-add {
  display: flex;
  gap: 8px;
}

.settings-input {
  flex: 1;
  background: var(--inset-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.settings-input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.settings-input::placeholder { color: rgba(167, 167, 194, 0.4); }

.settings-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 40px;
}

.settings-game-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--inset-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 6px 8px 6px 14px;
  font-size: 0.8rem;
  color: var(--text);
  animation: menu-field-in 0.25s ease both;
}

.settings-remove {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.settings-remove:hover {
  color: var(--error);
  background: rgba(255, 93, 93, 0.1);
}

.settings-empty {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 12px 0;
  margin: 0;
}

.settings-notice {
  color: #ffb86b;
  font-size: 0.8rem;
  text-align: center;
  margin: 0;
  animation: settings-notice-in 0.25s ease;
}

@keyframes settings-notice-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.settings-presets {
  display: flex;
  gap: 8px;
}

/* Sectioned settings layout */
.settings-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.settings-section[hidden] { display: none !important; }

/* Two-column settings on wider screens — library left, everything else right */
@media (min-width: 700px) {
  .settings-panel {
    max-width: 860px;
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    column-gap: 36px;
    row-gap: 18px;
    align-content: start;
  }

  .settings-head { grid-column: 1 / -1; }

  .settings-section-library {
    grid-column: 1;
    grid-row: 2 / span 4;
  }

  .settings-section:not(.settings-section-library) { grid-column: 2; }
}

.settings-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin: 0;
}

.settings-goal {
  display: flex;
  align-items: center;
  gap: 12px;
}

.settings-goal-text {
  font-size: 0.85rem;
  color: var(--muted);
}

.settings-series-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.settings-danger {
  color: #ff8a8a;
  border-color: rgba(255, 93, 93, 0.35);
}

.settings-danger:hover:not(:disabled) {
  background: rgba(255, 93, 93, 0.1);
  border-color: var(--error);
  color: #ffa3a3;
}

.settings-danger.armed {
  background: rgba(255, 93, 93, 0.14);
  border-color: var(--error);
  color: #ffb3b3;
  animation: settings-notice-in 0.2s ease;
}

/* Chip removal animation */
.settings-game-chip.removing {
  animation: chip-out 0.16s ease forwards;
  pointer-events: none;
}

@keyframes chip-out {
  to { opacity: 0; transform: scale(0.75); }
}

.settings-mode {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.settings-mode-hint {
  color: var(--muted);
  font-size: 0.78rem;
  margin: 0;
}

.settings-mode-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.settings-mode-toggle {
  display: flex;
  gap: 0;
}

.settings-mode-btn {
  background: var(--inset-bg);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 8px 16px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.settings-mode-btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.settings-mode-btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-left: none; }

.settings-mode-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.settings-mode-btn:hover:not(.active) {
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text);
}

/* Mobile adjustments */
@media (max-width: 600px) {
  .menu-screen { padding: 24px 16px; }
  .menu-panel { padding: 36px 24px 32px; gap: 22px; }
  .menu-players { flex-direction: column; align-items: stretch; gap: 8px; }
  .menu-vs { display: none; }
  .menu-title { font-size: 28px; }
  .settings-screen { padding: 24px 16px; }
  .settings-panel { padding: 24px 20px; }
}

/* ============================================================
   APP WRAPPER
   ============================================================ */

.app {
  width: 100%;
  max-width: 1460px;
  margin: 0 auto;
  padding: 40px 28px 44px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

@media (max-width: 768px) {
  .app { padding: 28px 18px 30px; gap: 16px; }
}

@media (max-width: 480px) {
  .app { padding: 20px 12px 24px; }
}

/* ============================================================
   SCATTERED BACKGROUND DECORATIONS
   ============================================================ */
.battle-bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.battle-bg-item {
  position: absolute;
  opacity: 0.06;
  color: var(--muted);
}
.battle-bg-item svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  fill: none;
}

/* Entrance animations */
.app > * {
  animation: card-entrance 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.app > *:nth-child(1) { animation-delay: 0s; }
.app > *:nth-child(2) { animation-delay: 0.05s; }
.app > *:nth-child(3) { animation-delay: 0.1s; }
.app > *:nth-child(4) { animation-delay: 0.15s; }
.app > *:nth-child(5) { animation-delay: 0.2s; }

@keyframes card-entrance {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   PAGE HEADER — centered, non-sticky
   ============================================================ */

.page-header {
  text-align: center;
  padding: 8px 0 4px;
  position: relative;
  z-index: 1;
}

.page-header h1 {
  font-size: clamp(26px, 4vw, 38px);
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.page-header h1 .accent { color: var(--accent); }

.page-header p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.muted { color: var(--muted); }

/* ============================================================
   TOOLBAR — mode toggle + reset
   ============================================================ */

.toolbar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  background: #161925;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 15px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.14s ease, background 0.14s ease,
              border-color 0.14s ease, box-shadow 0.14s ease, opacity 0.14s ease;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 10px 22px rgba(138, 124, 255, 0.45);
}

.btn.primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 14px 32px rgba(138, 124, 255, 0.75);
}

.btn.ghost { background: #141622; }

.btn.ghost:hover:not(:disabled) {
  border-color: var(--accent);
  background: #1a2030;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
  pointer-events: none;
}

.btn.small {
  padding: 7px 12px;
  font-size: 13px;
}

/* Keyboard hint pills inside buttons */
.kbd-hint-inline {
  display: inline-block;
  padding: 1px 6px;
  font: 600 10px var(--font-mono);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  color: rgba(255, 255, 255, 0.85);
}

@media (hover: none) and (pointer: coarse) {
  .kbd-hint-inline { display: none; }
}

/* Win buttons get player colors */
.win-btn {
  padding: 12px 22px;
  font-weight: 600;
  font-size: 15px;
  min-width: 120px;
  justify-content: center;
}

.win-btn .win-btn-label {
  flex: 1;
  text-align: center;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.win-a {
  background: var(--player-a);
  border-color: var(--player-a);
  color: #fff;
  box-shadow: 0 10px 22px var(--player-a-soft);
}

.win-a:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 14px 32px rgba(138, 124, 255, 0.7);
}

.win-b {
  background: var(--player-b);
  border-color: var(--player-b);
  color: #fff;
  box-shadow: 0 10px 22px var(--player-b-soft);
}

.win-b:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 14px 32px rgba(255, 122, 168, 0.65);
}

/* Tie button — neutral, smaller, between A and B */
.win-tie {
  background: #1a1e2c;
  border-color: rgba(167, 167, 192, 0.5);
  color: var(--muted);
  box-shadow: none;
  padding: 10px 14px;
  min-width: 74px;
  font-size: 13px;
  font-weight: 500;
  flex: 0 0 auto;
}

.win-tie:hover:not(:disabled) {
  color: var(--text);
  border-color: rgba(167, 167, 192, 0.85);
  background: #1f2335;
  transform: translateY(-1px);
}

.win-a, .win-b { flex: 1 1 0; }

/* Mode toggle pill */

.mode-toggle {
  background: #151922;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 4px 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.mode-pill {
  padding: 5px 11px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  border-radius: var(--radius-pill);
  background: transparent;
  border: none;
  color: var(--muted);
  transition: background 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}

.mode-pill.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(138, 124, 255, 0.7);
}

.mode-pill:not(.active):hover {
  background: #1c2231;
  color: var(--text);
}

/* ============================================================
   LAYOUT
   ============================================================ */

.layout {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(0, 700px) minmax(240px, 1fr);
  gap: 20px;
  align-items: start;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

.card-score   { grid-column: 2; grid-row: 1; }
.card-primary { grid-column: 2; grid-row: 2; }
.card-rounds  { grid-column: 1; grid-row: 1 / span 2; }
.card-stats   { grid-column: 3; grid-row: 1 / span 2; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .card-score   { grid-column: 1; grid-row: 1; }
  .card-primary { grid-column: 1; grid-row: 2; }
  .card-rounds  { grid-column: 1; grid-row: 3; }
  .card-stats   { grid-column: 1; grid-row: 4; }
}

/* ============================================================
   CARD
   ============================================================ */

.card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  padding: 22px 22px 24px;
  border-radius: var(--radius-lg);
  box-shadow: 0 22px 46px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(
    circle at top right,
    rgba(138, 124, 255, 0.08),
    transparent 60%
  );
}

.card-primary {
  background: var(--card-bg-primary);
}

.card > * { position: relative; }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.card-header h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ============================================================
   SETUP
   ============================================================ */

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

@media (max-width: 640px) {
  .setup-grid { grid-template-columns: 1fr; }
}

.setup-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 14px;
}

.setup-label {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.setup-input {
  padding: 9px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--inset-bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.setup-input::placeholder { color: rgba(167, 167, 194, 0.7); }

.setup-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(138, 124, 255, 0.3);
}

.setup-inline-field {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.setup-label.inline {
  font-size: 14px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
}

.small-number {
  width: 70px;
  max-width: 90px;
  text-align: center;
  font-size: 15px;
  padding: 8px 10px;
}

.setup-players {
  grid-column: 1 / -1;
  align-items: center;
  text-align: center;
}

.players-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
}

.players-row .setup-input {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
}

.players-vs {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.setup-field-end {
  align-items: flex-end;
  justify-content: flex-end;
}

.setup-field-end .btn {
  width: 100%;
  justify-content: center;
  padding-top: 10px;
  padding-bottom: 10px;
}

.status-text {
  margin: 6px 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.status-text strong { color: #fff; }

/* ============================================================
   INLINE NOTICE (replaces alert/confirm)
   ============================================================ */

.notice {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  animation: notice-in 0.2s ease;
}

.notice-info {
  background: rgba(138, 124, 255, 0.1);
  border: 1px solid rgba(138, 124, 255, 0.4);
  color: var(--text);
}

.notice-warn {
  background: rgba(255, 93, 93, 0.08);
  border: 1px solid rgba(255, 93, 93, 0.35);
  color: #ffdada;
}

.notice-actions {
  display: flex;
  gap: 8px;
}

.notice-btn {
  background: transparent;
  border: 1px solid currentColor;
  color: inherit;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-pill);
  font-family: inherit;
  opacity: 0.9;
}

.notice-btn:hover { opacity: 1; }

@keyframes notice-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   TOP PILLS
   ============================================================ */

.pill-bar {
  display: inline-flex;
  padding: 5px;
  border-radius: var(--radius-pill);
  background: #111526;
  border: 1px solid rgba(167, 167, 192, 0.5);
  gap: 5px;
  flex-wrap: wrap;
}

.pill {
  padding: 5px 12px;
  font-size: 13px;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
}

.pill span {
  font-weight: 600;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   GAME BOXES (random / select / winner)
   ============================================================ */

.game-box {
  margin-top: 16px;
  border-radius: var(--radius-md);
  padding: 14px;
  background: var(--box-bg);
  border: 1px solid rgba(167, 167, 192, 0.4);
  animation: box-in 0.25s ease;
}

@keyframes box-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.game-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.game-sub {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
}

/* Picker head: title + best-of stepper */
.picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

/* Pending box: centered "next game" state with big CTA */
.pending-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 26px 18px;
  text-align: center;
}

.pending-box .game-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 700;
}

.pick-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 26px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
  border-radius: var(--radius-pill);
  box-shadow: 0 10px 28px rgba(138, 124, 255, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.pick-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 32px rgba(138, 124, 255, 0.5);
}

.pick-btn .pick-btn-arrow {
  font-size: 18px;
  line-height: 1;
  transition: transform 0.15s ease;
}

.pick-btn:hover .pick-btn-arrow {
  transform: translateX(3px);
}

.remove-last {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 13px;
  padding: 4px 8px;
  cursor: pointer;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.15s ease;
}

.remove-last:hover {
  color: var(--player-b, #ff7aa8);
}

.remove-last.hidden { display: none !important; }

/* Winner head: title + mini inner score */
.winner-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

/* Compact best-of stepper */
.stepper {
  display: inline-flex;
  align-items: center;
  background: #111526;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 0;
  user-select: none;
}

.step-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  font-family: inherit;
}

.step-btn:hover:not(:disabled) {
  background: rgba(138, 124, 255, 0.22);
  color: #fff;
}

.step-btn:disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

.stepper-label {
  min-width: 56px;
  text-align: center;
  padding: 0 4px;
  line-height: 1;
}

.stepper-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stepper-sub {
  font-size: 9px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-top: 3px;
}

/* ============================================================
   ROLL OVERLAY (big centered modal with slot-machine reel)
   ============================================================ */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.overlay.hidden { display: none !important; }

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 6, 12, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: overlay-fade 0.2s ease;
}

@keyframes overlay-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.overlay-dialog {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  background: var(--card-bg, #12141e);
  border: 1px solid var(--line, rgba(167, 167, 192, 0.4));
  border-radius: var(--radius-md, 14px);
  padding: 22px 22px 20px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  animation: overlay-pop 0.22s ease;
}

@keyframes overlay-pop {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.overlay-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.overlay-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex: 1;
}

.overlay-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line, rgba(167, 167, 192, 0.4));
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.overlay-close:hover {
  background: #222740;
  color: #fff;
  border-color: var(--accent);
}

.overlay-body { display: block; }
.overlay-body.hidden { display: none !important; }

/* Slot-machine reel */

.reel-window {
  position: relative;
  height: 180px;
  overflow: hidden;
  border-radius: var(--radius-md, 14px);
  background: linear-gradient(180deg, #0a0c16 0%, #161a2c 50%, #0a0c16 100%);
  border: 1px solid var(--line, rgba(167, 167, 192, 0.35));
  mask-image: linear-gradient(180deg, transparent 0%, #000 25%, #000 75%, transparent 100%);
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 25%, #000 75%, transparent 100%);
}

.reel-center {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 60px;
  transform: translateY(-50%);
  border-top: 1px solid rgba(138, 124, 255, 0.55);
  border-bottom: 1px solid rgba(138, 124, 255, 0.55);
  pointer-events: none;
  z-index: 2;
}

.reel-track {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 60px; /* centers the first item in the 180px window */
  transform: translateY(0);
  will-change: transform;
}

.reel-track.spinning {
  transition: transform 2.6s cubic-bezier(0.12, 0.72, 0.18, 1);
}

.reel-item {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  padding: 0 12px;
  text-align: center;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reel-item.landed {
  color: var(--accent);
  text-shadow: 0 0 24px rgba(138, 124, 255, 0.6);
}

.overlay-foot {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

/* Big chip grid for Select mode inside the overlay */

.overlay-chip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  max-height: 360px;
  overflow: auto;
  padding: 2px;
}

.overlay-chip-grid .game-chip {
  padding: 16px 14px;
  font-size: 15px;
}

/* Select mode game list (legacy, unused but kept for safety) */

.game-list {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}

.game-chip {
  border-radius: var(--radius-pill);
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid rgba(210, 215, 240, 0.9);
  background: #181c30;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s ease, border-color 0.12s ease,
              color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}

.game-chip:hover {
  border-color: var(--accent);
  background: #222740;
  color: #fff;
  transform: translateY(-1px);
}

.game-chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(138, 124, 255, 0.7);
}

.winner-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

/* Compact inner-game scoreboard next to the game title */
.mini-score {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: #111526;
  border: 1px solid var(--line);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.mini-a { color: var(--player-a); }
.mini-b { color: var(--player-b); }
.mini-sep { color: var(--muted); font-weight: 300; }

/* ============================================================
   HERO SCOREBOARD
   ============================================================ */

.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 18px 6px 14px;
  margin-bottom: 6px;
}

.player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.player-name {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-a .player-name { color: var(--player-a); }
.player-b .player-name { color: var(--player-b); }

.player-score {
  font-size: clamp(48px, 8vw, 76px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  transition: color 0.25s ease, text-shadow 0.25s ease, transform 0.25s ease;
}

.player-a .player-score.lead {
  color: var(--player-a);
  text-shadow: 0 0 30px rgba(138, 124, 255, 0.4);
}

.player-b .player-score.lead {
  color: var(--player-b);
  text-shadow: 0 0 30px rgba(255, 122, 168, 0.4);
}

.player-score.bump {
  animation: score-bump 0.35s ease;
}

@keyframes score-bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.score-sep {
  font-size: clamp(36px, 6vw, 52px);
  color: var(--muted);
  line-height: 1;
  font-weight: 300;
}

.series-meta {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 14px;
  min-height: 1.2em;
}

/* ============================================================
   STATUS DOT CHIP
   ============================================================ */

.series-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  background: #111526;
  border: 1px solid rgba(167, 167, 192, 0.4);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.series-status-chip[data-status="running"] {
  color: var(--accent);
  border-color: rgba(138, 124, 255, 0.5);
}

.series-status-chip[data-status="running"] .status-dot {
  background: var(--accent);
  animation: pulse 1.5s ease infinite;
}

.series-status-chip[data-status="finished"] {
  color: var(--good);
  border-color: rgba(39, 209, 122, 0.5);
}

.series-status-chip[data-status="finished"] .status-dot {
  background: var(--good);
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(138, 124, 255, 0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(138, 124, 255, 0); }
}

/* ============================================================
   ROUNDS TABLE
   ============================================================ */

.rounds-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  margin-bottom: 2px;
}

.rounds-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.score-table,
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 8px;
}

.score-table th,
.score-table td,
.history-table th,
.history-table td {
  padding: 7px 4px;
}

.score-table th,
.history-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1px solid rgba(167, 167, 192, 0.4);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.score-table td,
.history-table td {
  border-bottom: 1px solid rgba(167, 167, 192, 0.15);
}

.score-table tbody tr {
  transition: background 0.15s ease;
}

.score-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.history-table { font-size: 12px; }

.score-table th:nth-child(1),
.score-table td:nth-child(1) {
  width: 24px;
  text-align: right;
  padding-right: 6px;
  color: var(--muted);
}

.score-table th:nth-child(3),
.score-table td:nth-child(3) {
  text-align: center;
  width: 90px;
}

.score-table th:nth-child(4),
.score-table td:nth-child(4) {
  text-align: right;
  width: 70px;
  font-variant-numeric: tabular-nums;
}

.score-empty,
.history-empty {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
  padding: 8px 0;
}

.history-empty { font-size: 12px; }

/* Result cell color-coding in rounds table */
.winner-a { color: var(--player-a); font-weight: 600; }
.winner-b { color: var(--player-b); font-weight: 600; }
.winner-tie {
  color: var(--muted);
  font-style: italic;
  font-weight: 500;
}

/* Highlight the round that clinched a game */
.round-decided td { background: rgba(138, 124, 255, 0.06); }

/* ============================================================
   LIBRARY & HISTORY SECTIONS
   ============================================================ */

/* Bottom card: library + history, side-by-side */
.card-bottom {
  padding: 22px 22px 20px;
}

.bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}

@media (max-width: 768px) {
  .bottom-grid {
    grid-template-columns: 1fr;
    gap: 22px;
  }
}

.bottom-section {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.bottom-section + .bottom-section {
  position: relative;
}

@media (min-width: 769px) {
  .bottom-section + .bottom-section::before {
    content: "";
    position: absolute;
    left: -14px;
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgba(167, 167, 192, 0.18);
  }
}

.bottom-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.bottom-title {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  font-weight: 600;
}

.library-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.library-input {
  padding: 7px 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--inset-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  min-width: 160px;
}

.library-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  max-height: 190px;
  overflow-y: auto;
  margin-top: 4px;
}

@media (max-width: 640px) {
  .library-list { grid-template-columns: 1fr; }
}

.library-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  border-radius: var(--radius-pill);
  padding: 5px 9px;
  background: #121526;
  border: 1px solid rgba(167, 167, 192, 0.4);
  transition: border-color 0.12s ease, background 0.12s ease;
}

.library-item:hover {
  border-color: rgba(138, 124, 255, 0.5);
}

.library-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-remove {
  border-radius: var(--radius-pill);
  padding: 3px 9px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid rgba(255, 93, 93, 0.4);
  background: rgba(255, 93, 93, 0.08);
  color: #ff9c9c;
  line-height: 1;
}

.library-remove:hover {
  border-color: var(--error);
  background: rgba(255, 93, 93, 0.2);
}

/* ============================================================
   UTILITIES
   ============================================================ */

.hidden { display: none !important; }

#confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 200;
}

/* Muted state */
.icon-btn[aria-pressed="false"] {
  opacity: 0.5;
}

.series-actions {
  display: flex;
  justify-content: center;
  margin: 10px 0 2px;
}

.series-actions.hidden { display: none !important; }

.sparkline-wrap {
  display: flex;
  justify-content: center;
  margin: 2px 0 6px;
  min-height: 40px;
}

#sparkline {
  width: 240px;
  height: 40px;
  max-width: 100%;
  opacity: 0.9;
}

/* ==========================================================================
   DASHBOARD CLEANUP — setup lives in the menu screen, library/mode live in
   the settings screen. The original markup stays (script.js reads/writes it)
   but is hidden from view.
   ========================================================================== */

.game-screen .setup-grid,
.game-screen .card-bottom,
.game-screen .toolbar {
  display: none !important;
}

/* With the setup form gone, the game box sits flush at the top of the card */
.game-screen .card-primary .game-box { margin-top: 0; }

/* ==========================================================================
   PROGRESS DOTS — wins toward the series target, under each score
   ========================================================================== */

.player-dots {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
  min-height: 9px;
}

.player-dots .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.player-a .player-dots .dot.filled {
  background: var(--player-a);
  border-color: var(--player-a);
  box-shadow: 0 0 8px rgba(138, 124, 255, 0.55);
}

.player-b .player-dots .dot.filled {
  background: var(--player-b);
  border-color: var(--player-b);
  box-shadow: 0 0 8px rgba(255, 122, 168, 0.55);
}

/* ==========================================================================
   MATCH POINT — one win from taking the series
   ========================================================================== */

.series-status-chip[data-status="matchpoint"] {
  color: #ffd166;
  border-color: rgba(255, 209, 102, 0.55);
}

.series-status-chip[data-status="matchpoint"] .status-dot {
  background: #ffd166;
  animation: mp-dot-pulse 1.1s ease infinite;
}

@keyframes mp-dot-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 209, 102, 0.55); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 209, 102, 0); }
}

.player-a .player-score.match-point {
  animation: mp-score-pulse-a 1.4s ease-in-out infinite;
}

.player-b .player-score.match-point {
  animation: mp-score-pulse-b 1.4s ease-in-out infinite;
}

@keyframes mp-score-pulse-a {
  0%, 100% { text-shadow: 0 0 0 rgba(138, 124, 255, 0); }
  50%      { text-shadow: 0 0 26px rgba(138, 124, 255, 0.85); }
}

@keyframes mp-score-pulse-b {
  0%, 100% { text-shadow: 0 0 0 rgba(255, 122, 168, 0); }
  50%      { text-shadow: 0 0 26px rgba(255, 122, 168, 0.85); }
}

/* ==========================================================================
   SETTINGS TOGGLE — small switch (loser picks next game)
   ========================================================================== */

.settings-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.settings-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.settings-toggle-track {
  width: 36px;
  height: 20px;
  border-radius: var(--radius-pill);
  background: var(--inset-bg);
  border: 1px solid var(--line);
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.settings-toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.2s ease, background 0.2s ease;
}

.settings-toggle input:checked + .settings-toggle-track {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.settings-toggle input:checked + .settings-toggle-track::after {
  transform: translateX(16px);
  background: var(--accent);
}

.settings-toggle input:focus-visible + .settings-toggle-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.settings-toggle-label {
  font-size: 0.85rem;
  color: var(--text);
}

.settings-toggle:hover .settings-toggle-track {
  border-color: var(--accent);
}

/* ==========================================================================
   DASHBOARD v2 — score on top, picker in the middle,
   rounds + stats side by side at the bottom
   ========================================================================== */


.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-tile {
  background: var(--inset-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 10px 11px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.stat-value {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-value.stat-streak {
  font-size: 15px;
  font-weight: 700;
  padding-top: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-streak.streak-a { color: var(--player-a); }
.stat-streak.streak-b { color: var(--player-b); }

.stat-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}

/* ==========================================================================
   VICTORY SCREEN
   ========================================================================== */

.victory-dialog {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 40px 48px 36px;
  max-width: 420px;
}

.victory-trophy {
  width: 56px;
  height: 56px;
  color: #ffd166;
  filter: drop-shadow(0 0 18px rgba(255, 209, 102, 0.45));
  animation: victory-trophy-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes victory-trophy-in {
  from { opacity: 0; transform: scale(0.4) rotate(-12deg); }
  to   { opacity: 1; transform: scale(1) rotate(0); }
}

.victory-label {
  margin: 10px 0 0;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.victory-name {
  margin: 0;
  font-size: clamp(28px, 6vw, 40px);
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.victory-name.victory-a { color: var(--player-a); text-shadow: 0 0 30px rgba(138, 124, 255, 0.5); }
.victory-name.victory-b { color: var(--player-b); text-shadow: 0 0 30px rgba(255, 122, 168, 0.5); }

.victory-score {
  font-size: 30px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.victory-meta {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.victory-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

/* Staggered entrance for dialog children */
.victory-dialog > * {
  animation: menu-field-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.victory-dialog > *:nth-child(2) { animation-delay: 0.1s; }
.victory-dialog > *:nth-child(3) { animation-delay: 0.18s; }
.victory-dialog > *:nth-child(4) { animation-delay: 0.26s; }
.victory-dialog > *:nth-child(5) { animation-delay: 0.34s; }

/* ==========================================================================
   HANDICAP STEPPER LABEL
   ========================================================================== */

.settings-handicap-label {
  min-width: 110px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  background: var(--inset-bg);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ==========================================================================
   MENU HISTORY LIST
   ========================================================================== */

button.menu-history-teaser {
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-pill);
  transition: background 0.2s ease, color 0.2s ease;
}

button.menu-history-teaser:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.teaser-chevron {
  width: 14px;
  height: 14px;
  opacity: 0.5;
  transition: transform 0.25s ease;
}

button.menu-history-teaser.open .teaser-chevron { transform: rotate(180deg); }

.menu-history-list[hidden] { display: none; }

.menu-history-list {
  /* hide the inner scrollbar - macOS flashes it during the expand animation */
  scrollbar-width: none;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
  max-height: 180px;
  overflow-y: auto;
  /* fade only — a translateY here extends the page scroll area mid-animation
     and flashes a scrollbar */
  animation: history-list-fade 0.3s ease;
}

.menu-history-list::-webkit-scrollbar { display: none; }

@keyframes history-list-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  background: var(--inset-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}

.history-row-winner {
  flex: 1;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.history-row-score {
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.history-row-date {
  color: var(--muted);
  font-size: 0.72rem;
}

/* ==========================================================================
   SHORT VIEWPORTS - compact everything so the page never grows a scrollbar
   ========================================================================== */

@media (max-height: 860px) {
  .menu-screen, .settings-screen { min-height: 100dvh; padding: 24px 20px; }

  .app { padding: 14px 28px 18px; gap: 12px; }
  /* Reserve a header band at least as tall as the fixed top-right util icons
     (top:16px + 40px = 56px) so the dashboard cards never slide under them on
     short/laptop viewports. */
  .page-header {
    padding: 0;
    min-height: 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .page-header h1 { font-size: 22px; margin-bottom: 0; }

  .layout { gap: 14px; }
  .card { padding: 16px 18px 16px; }

  .scoreboard { padding: 10px 6px 8px; margin-bottom: 2px; }
  .player-score { font-size: clamp(38px, 6vh, 56px); }
  .player-dots { margin-top: 5px; }
  .sparkline-wrap { margin: 0 0 2px; }

  .pending-box { padding: 14px 12px; gap: 10px; }
  .pick-btn { padding: 11px 20px; font-size: 15px; }
  .win-btn { padding: 10px 16px; }

  .stat-tile { padding: 9px 8px 7px; gap: 2px; }
  .stat-value { font-size: 18px; }
  .stat-value.stat-streak { font-size: 13px; padding-top: 3px; }

  .menu-panel { padding: 30px 32px 26px; gap: 20px; }
  .menu-history-list { max-height: clamp(70px, calc(100dvh - 560px), 180px); }
}


/* ==========================================================================
   LIVE VIEW - broadcast overlay + spectator screen
   ========================================================================== */

/* Cast button glows while broadcasting */
.util-btn.live-active {
  color: var(--accent);
  border-color: rgba(138, 124, 255, 0.55);
  box-shadow: 0 0 14px rgba(138, 124, 255, 0.35);
}

/* Menu: watch entry point */
.menu-watch-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-pill);
  transition: color 0.18s ease, background 0.18s ease;
}
.menu-watch-btn:hover { color: var(--accent); background: var(--accent-soft); }
.menu-watch-btn .icon { width: 16px; height: 16px; stroke: currentColor; fill: none; }

/* Live overlay */
.live-dialog { max-width: 360px; width: 100%; }
.live-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 22px 22px;
}
.live-body.hidden { display: none !important; }

.live-text {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}
.live-main-btn { width: 100%; justify-content: center; }

#liveHostIdle, #liveHostActive {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}
#liveHostIdle.hidden, #liveHostActive.hidden { display: none !important; }

.live-code-label {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.live-code {
  margin: 0;
  font-size: 42px;
  font-weight: 800;
  letter-spacing: 0.25em;
  text-indent: 0.25em;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(138, 124, 255, 0.5);
  cursor: pointer;
  user-select: all;
}
.live-watchers {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.live-join { display: flex; gap: 8px; }
.live-join input {
  flex: 1;
  min-width: 0;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  text-align: center;
  padding: 10px 14px;
}
.live-join input::placeholder { color: var(--muted); opacity: 0.5; letter-spacing: 0.2em; }
.live-join input:focus { outline: none; border-color: var(--accent); }

.live-status { margin: 0; font-size: 13px; color: var(--muted); text-align: center; }
.live-status.error { color: #ff7aa8; }
.live-status[hidden] { display: none; }

/* Spectator screen */
.spectate-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  position: relative;
  z-index: 1;
}
.spectate-screen.hidden { display: none !important; }

.spectate-panel {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  background: linear-gradient(160deg, #141826, #101321);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 36px 32px 28px;
  box-shadow: var(--shadow-soft);
}

.spectate-live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #ff7aa8;
}
.spectate-live .live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: live-pulse 1.6s ease-in-out infinite;
}
.spectate-live.ended { color: var(--muted); }
.spectate-live.ended .live-dot { animation: none; }

@keyframes live-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 122, 168, 0.55); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 122, 168, 0); }
}

.spectate-board {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  width: 100%;
}
.sp-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 110px;
}
.sp-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sp-score {
  font-size: 64px;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.sp-score.sp-a { color: #8a7cff; }
.sp-score.sp-b { color: #ff7aa8; }
.sp-sep { font-size: 32px; color: var(--muted); }

.sp-score.bump { animation: sp-bump 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes sp-bump {
  0% { transform: scale(1); }
  45% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.sp-score.match-point { animation: sp-mp 1.4s ease-in-out infinite; }
@keyframes sp-mp {
  0%, 100% { text-shadow: 0 0 0 rgba(255, 209, 102, 0); }
  50%      { text-shadow: 0 0 18px rgba(255, 209, 102, 0.7); }
}

.spectate-status {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}
.spectate-game {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.spectate-game[hidden] { display: none; }

.spectate-rounds {
  width: 100%;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.2);
}
.spectate-rounds[hidden] { display: none; }

@media (max-width: 480px) {
  .sp-score { font-size: 48px; }
  .spectate-panel { padding: 28px 20px 22px; }
  .spectate-board { gap: 16px; }
}

/* ==========================================================================
   MOBILE CLEANUP 2026-06-05 - fixed top buttons were overlapping the header,
   and the win-button row overflowed the edge on narrow phones.
   ========================================================================== */
@media (max-width: 768px) {
  /* The dashboard's app wrapper sits under the fixed home + util buttons
     (each 40px tall at top:16). Clear them so the title/score never collide. */
  #gameScreen .app { padding-top: 68px; }

  /* Win row: let the three buttons share the row instead of running off-edge */
  .winner-row { flex-wrap: nowrap; gap: 6px; }
  .win-btn { min-width: 0; flex: 1 1 0; padding: 11px 8px; font-size: 14px; }
  .win-tie { flex: 0 0 auto; padding: 11px 14px; }
}

/* On phones short enough to hit the max-height rule, that query set a 14px
   top padding - re-clear the fixed buttons here too (more specific + later). */
@media (max-height: 860px) and (max-width: 768px) {
  #gameScreen .app { padding-top: 68px; }
}

@media (max-width: 420px) {
  /* Tighten the win labels so even 3 long names fit one row */
  .win-btn { font-size: 13px; padding: 10px 6px; }
  .win-tie { padding: 10px 11px; }
}

/* ---- Icon-only Undo button ---- */
#btnUndo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}
#btnUndo .icon {
  width: 1.05rem;
  height: 1.05rem;
}
@media (max-width: 600px) {
  #btnUndo { min-width: 40px; min-height: 40px; }
}
