/* ===== CSS Reset ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Ensure [hidden] attribute always hides elements even if display is set by other rules */
[hidden] { display: none !important; }

fieldset {
  border: none;
  padding: 0;
  min-inline-size: 0;
}

legend {
  padding: 0;
  float: left;
  width: 100%;
}

legend + * {
  clear: left;
}

/* ===== Design Tokens ===== */
:root {
  /* Palette — scoreboard dark / electric amber */
  --color-bg:           #0f0f0f;
  --color-surface:      #1a1a1a;
  --color-surface-2:    #252525;
  --color-surface-3:    #2d2d2d;
  --color-accent:       #f5a623;
  --color-accent-hover: #f0b848;
  --color-accent-glow:  rgba(245, 166, 35, 0.12);
  --color-accent-border: rgba(245, 166, 35, 0.3);
  --color-text:         #f0f0f0;
  --color-text-muted:   #888888;
  --color-text-dim:     #444444;
  --color-success:      #34d399;
  --color-danger:       #ef4444;
  --color-danger-bg:    rgba(239, 68, 68, 0.12);
  --color-warning:      #f5a623;
  --color-border:       #2a2a2a;
  --color-pending:      #f5a623;
  --color-complete:     #34d399;

  /* Typography — system font stack, no web fonts required */
  --font-display: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-body:    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:    'SF Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;

  /* Spacing */
  --space-xs:  0.25rem;
  --space-sm:  0.5rem;
  --space-md:  1rem;
  --space-lg:  1.5rem;
  --space-xl:  2rem;
  --space-2xl: 3rem;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 9999px;

  /* Touch */
  --touch-target: 44px;

  /* Motion */
  --transition: 0.18s ease;
  --expand-transition: max-height 200ms ease-out;
}

/* ===== Base ===== */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-weight: 400;
  background-color: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

/* ===== Header & Navigation ===== */
.app-header {
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 var(--space-md);
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.app-title {
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-accent);
  white-space: nowrap;
  padding: var(--space-sm) 0;
}

/* Tab navigation (2 primary tabs) */
.app-tabs {
  display: flex;
  flex: 1;
  gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.app-tabs::-webkit-scrollbar {
  display: none;
}

/* Hide tabs when no active tournament */
body[data-has-tournament="false"] .app-tabs {
  display: none;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target);
  padding: var(--space-sm) var(--space-md);
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  position: relative;
  transition: color var(--transition);
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: var(--space-sm);
  right: var(--space-sm);
  height: 2px;
  background-color: var(--color-accent);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform var(--transition);
}

.nav-link:hover {
  color: var(--color-text);
}

.nav-link.active {
  color: var(--color-accent);
}

.nav-link.active::after {
  transform: scaleX(1);
}

/* ===== Hamburger Menu ===== */
.hamburger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background-color var(--transition);
  margin-left: auto;
  flex-shrink: 0;
}

.hamburger-btn:hover {
  color: var(--color-text);
  background-color: var(--color-surface-2);
}

.hamburger-menu-wrapper {
  position: relative;
}

.hamburger-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 200px;
  background-color: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 200;
  overflow: hidden;
}

.hamburger-menu.open {
  display: block;
}

.hamburger-menu a,
.hamburger-menu button {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: var(--touch-target);
  padding: var(--space-sm) var(--space-md);
  background: none;
  border: none;
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 400;
  text-decoration: none;
  cursor: pointer;
  text-align: left;
  transition: background-color var(--transition);
}

.hamburger-menu a:hover,
.hamburger-menu button:hover {
  background-color: var(--color-surface-3);
}

.hamburger-menu-divider {
  height: 1px;
  background-color: var(--color-border);
  margin: var(--space-xs) 0;
}

.hamburger-menu .menu-item-danger {
  color: var(--color-danger);
}

/* ===== Main Content Area ===== */
#app {
  flex: 1;
  padding: var(--space-md);
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

/* ===== View fade-in ===== */
.view {
  animation: viewIn 0.22s ease;
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== Typography ===== */
h2 {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--color-border);
}

h3 {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  padding: var(--space-sm) var(--space-lg);
  border: none;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background-color var(--transition), opacity var(--transition), transform var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--color-accent);
  color: #0d0b09;
  font-weight: 700;
}

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

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

.btn-secondary:hover:not(:disabled) {
  background-color: var(--color-surface-3);
}

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

.btn-danger:hover:not(:disabled) {
  background-color: var(--color-danger-bg);
}

.btn-sm {
  min-height: var(--touch-target);
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.775rem;
}

.btn-full {
  width: 100%;
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: var(--space-md);
}

label,
.form-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: var(--space-xs);
}

input[type="text"],
input[type="search"],
select,
.input {
  display: block;
  width: 100%;
  min-height: var(--touch-target);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-size: 0.95rem;
  font-family: var(--font-body);
  transition: border-color var(--transition), background-color var(--transition);
  -webkit-appearance: none;
}

input[type="text"]:focus,
input[type="search"]:focus,
select:focus,
.input:focus {
  outline: none;
  border-color: var(--color-accent);
  background-color: var(--color-surface-3);
}

input::placeholder {
  color: var(--color-text-dim);
}

select option {
  background-color: var(--color-surface-2);
}

.form-row {
  display: flex;
  gap: var(--space-sm);
  align-items: flex-end;
}

.form-row .form-group {
  flex: 1;
  margin-bottom: 0;
}

/* ===== Radio Buttons ===== */
.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-xs);
}

.radio-label {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch-target);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  transition: border-color var(--transition), background-color var(--transition), color var(--transition);
}

.radio-label input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.radio-label:has(input:checked) {
  border-color: var(--color-accent);
  background-color: var(--color-accent-glow);
  color: var(--color-accent);
}

/* ===== Toggle Switch ===== */
.toggle-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  min-height: var(--touch-target);
  margin-bottom: var(--space-md);
}

.toggle-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  margin: 0;
}

.toggle {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background-color: var(--color-surface-3);
  border: 1px solid var(--color-border);
  border-radius: 28px;
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: var(--color-text-muted);
  border-radius: 50%;
  transition: transform var(--transition), background-color var(--transition);
}

.toggle input:checked + .toggle-slider {
  background-color: var(--color-accent-glow);
  border-color: var(--color-accent-border);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background-color: var(--color-accent);
}

/* ===== Messages ===== */
.error-message {
  color: var(--color-danger);
  font-size: 0.85rem;
  margin-top: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-danger-bg);
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--color-danger);
}

.error-message:empty {
  display: none;
}

.info-message {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin-top: var(--space-sm);
  line-height: 1.6;
}

.warning-banner {
  background-color: rgba(196, 136, 42, 0.12);
  border: 1px solid var(--color-warning);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  color: var(--color-warning);
  font-size: 0.85rem;
  margin-bottom: var(--space-md);
}

.storage-warning {
  background-color: rgba(196, 136, 42, 0.12);
  border-bottom: 2px solid var(--color-warning);
  padding: var(--space-sm) var(--space-md);
  color: var(--color-warning);
  font-size: 0.85rem;
  text-align: center;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: var(--space-2xl) var(--space-xl);
  color: var(--color-text-muted);
  font-size: 0.9rem;
  line-height: 1.7;
}

.empty-state a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.empty-state-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-xl);
  gap: var(--space-md);
  min-height: 40vh;
}

.empty-state-card h2 {
  margin: 0;
  border-bottom: none;
}

.empty-state-card p {
  color: var(--color-text-muted);
  margin: 0;
  max-width: 28ch;
}

.no-tournament-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-surface);
  border: 1px solid var(--color-accent-border);
  border-left: 3px solid var(--color-accent);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
}

.no-tournament-banner p {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

/* ===== Accessibility ===== */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Danger Zone ===== */
.danger-zone {
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-md);
  margin-top: var(--space-lg);
}

/* ===== Card surfaces ===== */
/* Gold-accent top border for interactive cards */
.add-player-form,
.record-game-form,
.round-robin-section {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: 2px solid var(--color-accent-border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
}

/* ===== Player List (US1) ===== */
.player-list {
  list-style: none;
  margin-bottom: var(--space-lg);
}

.player-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  min-height: var(--touch-target);
  transition: border-color var(--transition);
}

.player-item:hover {
  border-color: var(--color-accent-border);
}

.player-name {
  font-weight: 500;
  font-size: 0.95rem;
}

.player-actions {
  display: flex;
  gap: var(--space-sm);
}

/* ===== Record Game Form (US2) ===== */
.cube-section {
  background-color: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
}

/* ===== Leaderboard (US3) ===== */
.leaderboard-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 300px;
}

.leaderboard-table th {
  background-color: var(--color-surface-2);
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.leaderboard-table th:nth-child(n+3) {
  text-align: right;
}

.leaderboard-table td {
  padding: var(--space-sm) var(--space-md);
  border-top: 1px solid var(--color-border);
  font-size: 0.9rem;
}

.leaderboard-table td:nth-child(n+3) {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.leaderboard-table .rank-1 {
  background-color: rgba(201, 162, 43, 0.06);
}

.leaderboard-table .rank-1 td:first-child::before {
  content: '🏆 ';
}

.rank-cell {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--color-text-muted);
}

.pts-cell {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--color-accent) !important;
  font-size: 0.95rem !important;
}

/* ===== Game History (US4) ===== */
.history-filter {
  margin-bottom: var(--space-md);
}

.history-list {
  list-style: none;
}

.history-item {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  overflow: hidden;
  transition: border-color var(--transition);
}

.history-item:hover {
  border-color: var(--color-accent-border);
}

.history-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  min-height: var(--touch-target);
  cursor: pointer;
  gap: var(--space-sm);
  transition: background-color var(--transition);
}

.history-summary:hover {
  background-color: var(--color-surface-2);
}

.history-players {
  flex: 1;
  font-size: 0.875rem;
  line-height: 1.5;
  min-width: 0;
}

.history-winner {
  font-weight: 600;
  color: var(--color-accent);
}

.history-vs {
  color: var(--color-text-muted);
}

.history-time {
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

.history-pts {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--color-accent);
  font-size: 0.875rem;
  white-space: nowrap;
}

.history-actions {
  display: flex;
  gap: var(--space-xs);
}

.history-expand-icon {
  color: var(--color-text-dim);
  font-size: 0.75rem;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.history-item.expanded .history-expand-icon {
  transform: rotate(180deg);
}

.history-breakdown {
  display: none;
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-bg);
  border-top: 1px solid var(--color-border);
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.history-item.expanded .history-breakdown {
  display: block;
}

.breakdown-formula {
  font-family: var(--font-mono);
  color: var(--color-text);
  font-size: 0.85rem;
}

/* ===== Round-Robin Schedule (US5) ===== */
.schedule-list {
  list-style: none;
  margin-top: var(--space-md);
}

.schedule-pairing {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  min-height: var(--touch-target);
}

.pairing-players {
  font-size: 0.875rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-sm);
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.badge-pending {
  background-color: rgba(196, 136, 42, 0.15);
  color: var(--color-pending);
}

.badge-complete {
  background-color: rgba(77, 140, 84, 0.15);
  color: var(--color-complete);
}

/* Schedule panel inside Leaderboard */
.schedule-panel {
  margin-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-lg);
}

/* ===== Tournament Name Prompt (002) ===== */
.name-prompt {
  max-width: 480px;
  margin: var(--space-2xl) auto;
  padding: var(--space-xl);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: 2px solid var(--color-accent-border);
  border-radius: var(--radius-lg);
}

.name-prompt h2 {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-accent);
  margin-bottom: var(--space-lg);
}

.name-prompt .form-row {
  gap: var(--space-sm);
}

/* Tournament name heading on Players view */
.tournament-name {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-accent);
  margin-bottom: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-accent-glow);
  border-left: 2px solid var(--color-accent);
  border-radius: var(--radius-sm);
}

/* ===== Club Tab (002) ===== */
.club-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

.club-note {
  text-align: center;
  padding: var(--space-xl);
  color: var(--color-text-muted);
  font-size: 0.875rem;
  line-height: 1.6;
  background-color: var(--color-surface);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
}

/* All-Time leaderboard table */
.all-time-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 280px;
}

.all-time-table th {
  background-color: var(--color-surface-2);
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.all-time-table th:nth-child(n+3) {
  text-align: right;
}

.all-time-table td {
  padding: var(--space-sm) var(--space-md);
  border-top: 1px solid var(--color-border);
  font-size: 0.9rem;
}

.all-time-table td:nth-child(n+3) {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.all-time-table .rank-1 {
  background-color: rgba(201, 162, 43, 0.06);
}

.all-time-table .wins-cell {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--color-accent);
}

/* Archive list */
.archive-list {
  list-style: none;
}

.archive-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  min-height: var(--touch-target);
  cursor: pointer;
  gap: var(--space-sm);
  transition: border-color var(--transition), background-color var(--transition);
}

.archive-item:hover {
  border-color: var(--color-accent-border);
  background-color: var(--color-surface-2);
}

.archive-item-name {
  font-weight: 500;
  font-size: 0.95rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.archive-item-meta {
  display: flex;
  gap: var(--space-md);
  align-items: center;
  flex-shrink: 0;
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

.archive-item-games {
  font-family: var(--font-mono);
}

/* Tournament detail (read-only) */
.tournament-detail {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.tournament-detail-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.tournament-detail-title {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--color-accent);
  flex: 1;
}

.tournament-detail-meta {
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

.section-heading {
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
}

/* Games list inside detail view */
.detail-games-list {
  list-style: none;
}

.detail-game-item {
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  font-size: 0.875rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.detail-game-winner {
  font-weight: 600;
  color: var(--color-accent);
}

/* ===== Match Hub (003) ===== */
.hub-columns {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.hub-col {
  min-width: 0;
}

.match-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  min-height: var(--touch-target);
  transition: border-color var(--transition);
}

.match-card--active {
  border-left: 3px solid var(--color-accent);
  background-color: var(--color-accent-glow);
}

.match-card--complete {
  border-left: 3px solid var(--color-complete);
  background-color: rgba(77, 140, 84, 0.04);
}

.match-card__players {
  flex: 1;
  font-weight: 500;
  font-size: 0.95rem;
  min-width: 0;
}

.match-card__score {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.completed-matches-section {
  margin-bottom: var(--space-md);
}

.start-match-form {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: 2px solid var(--color-accent-border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  margin-top: var(--space-md);
}

.badge-active {
  background-color: rgba(196, 136, 42, 0.15);
  color: var(--color-warning);
}

.badge-winner {
  background-color: rgba(77, 140, 84, 0.15);
  color: var(--color-complete);
}

.badge-ended-early {
  background: var(--color-warning, #f59e0b);
  color: #fff;
}

/* ===== Match Detail (003) ===== */
.match-header {
  margin-bottom: var(--space-lg);
}

.match-header h2 {
  margin-bottom: var(--space-sm);
}

.match-scores {
  display: flex;
  align-items: baseline;
  gap: var(--space-md);
}

.score-display {
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--color-accent);
  letter-spacing: 0.05em;
  line-height: 1;
}

.target-label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
}

.match-complete-banner {
  background-color: rgba(77, 140, 84, 0.1);
  border: 1px solid var(--color-complete);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  color: var(--color-complete);
  font-size: 0.95rem;
  text-align: center;
  margin-bottom: var(--space-lg);
}

.match-complete-banner strong {
  color: var(--color-accent);
}

.game-form {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: 2px solid var(--color-accent-border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
}

.game-log {
  margin-top: var(--space-lg);
}

.game-log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.game-log-table th {
  background-color: var(--color-surface-2);
  padding: var(--space-xs) var(--space-sm);
  text-align: left;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
}

.game-log-table td {
  padding: var(--space-xs) var(--space-sm);
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
}

.game-log-table td:first-child {
  font-family: var(--font-mono);
  color: var(--color-text-dim);
  width: 2rem;
}

.game-log-table td:last-child {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--color-accent);
  text-align: right;
}

/* ===== Game History match grouping (003) ===== */
.match-group {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  overflow: hidden;
}

.match-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-surface-2);
  border-bottom: 1px solid var(--color-border);
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.match-group-players {
  font-weight: 600;
  font-size: 0.875rem;
}

.match-group-target {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* ===== Club detail match list (003) ===== */
.detail-match-item {
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.detail-match-winner {
  font-weight: 600;
  color: var(--color-accent);
}

/* ===== Responsive ===== */
@media (min-width: 480px) {
  .app-header {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    padding: var(--space-sm) var(--space-lg);
  }

  .app-title {
    margin-bottom: 0;
    white-space: nowrap;
  }
}

@media (min-width: 640px) {
  #app {
    padding: var(--space-lg);
  }

  .form-row {
    flex-wrap: nowrap;
  }

  .hub-columns {
    flex-direction: row;
    align-items: flex-start;
    gap: var(--space-xl);
  }

  .hub-col--players {
    flex: 0 0 260px;
  }

  .hub-col--matches {
    flex: 1;
  }
}

/* ============================================================
   LIVE VIEW (004-ux-redesign)
   ============================================================ */

/* ===== Live View container ===== */
.view--live {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* ===== Tournament header (compact bar) ===== */
.live-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.live-header__row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 0;
  min-height: var(--touch-target);
}

.live-header__name {
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--color-text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-header__players-btn {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  font-family: var(--font-body);
  cursor: pointer;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  min-height: var(--touch-target);
  transition: color var(--transition), background-color var(--transition);
  white-space: nowrap;
}

.live-header__players-btn:hover {
  color: var(--color-text);
  background-color: var(--color-surface-2);
}

.live-header__add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  background: none;
  border: 1px solid var(--color-accent-border);
  border-radius: var(--radius-sm);
  color: var(--color-accent);
  font-size: 1.1rem;
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition);
}

.live-header__add-btn:hover {
  background-color: var(--color-accent-glow);
  border-color: var(--color-accent);
}

/* ===== Collapsible roster ===== */
.live-roster {
  max-height: 0;
  overflow: hidden;
  transition: var(--expand-transition);
}

.live-roster[data-expanded="true"] {
  max-height: 600px;
}

.live-roster-inner {
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.live-roster__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-xs) 0;
  border-bottom: 1px solid var(--color-border);
}

.live-roster__row:last-child {
  border-bottom: none;
}

.live-roster__name {
  font-size: 0.9375rem;
  color: var(--color-text);
}

.live-roster__empty {
  color: var(--color-text-muted);
  font-size: 0.875rem;
  margin: 0;
}

/* ===== Inline add-player form ===== */
.live-add-player {
  max-height: 0;
  overflow: hidden;
  transition: var(--expand-transition);
}

.live-add-player[data-expanded="true"] {
  max-height: 120px;
}

.live-add-player-inner {
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* ===== Live match cards ===== */
.live-card {
  background-color: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  margin-bottom: var(--space-md);
  overflow: hidden;
  position: relative;
}

.live-card--active {
  border-left: 3px solid var(--color-accent);
}

.live-card--complete {
  border-left: 3px solid var(--color-success);
  opacity: 0.65;
}

.live-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-sm) var(--space-sm) var(--space-md);
  gap: var(--space-sm);
}

/* Score row: names flanking the score */
.live-card__score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-xs) var(--space-md) var(--space-md);
  gap: var(--space-sm);
}

.live-card__player {
  flex: 1;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-card__player--right {
  text-align: right;
}

.live-card__score-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  gap: 2px;
}

.live-card__score {
  font-family: var(--font-mono);
  font-size: 2.75rem;
  font-weight: 700;
  color: var(--color-accent);
  line-height: 1;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.live-card--complete .live-card__score {
  color: var(--color-success);
}

.live-card__target {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Score pulse animation */
@keyframes score-pulse {
  0%   { transform: scale(1);    opacity: 1; }
  40%  { transform: scale(1.18); opacity: 0.8; }
  100% { transform: scale(1);    opacity: 1; }
}

.score-updated {
  animation: score-pulse 350ms ease-out;
}

/* Card meta row: game count + actions */
.live-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-md) var(--space-sm);
}

.live-card__game-count {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
}

.live-card__actions {
  display: flex;
  gap: var(--space-xs);
  align-items: center;
}

/* Winner label on completed cards */
.live-card__winner {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-success);
  padding: 0 var(--space-md) var(--space-sm);
}

/* Overflow ⋯ button */
.live-card__overflow-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: var(--radius-pill);
  transition: color var(--transition), background-color var(--transition);
  position: relative;
}

.live-card__overflow-btn:hover {
  color: var(--color-text);
  background-color: var(--color-surface-2);
}

.live-card__overflow-menu {
  display: none;
  position: absolute;
  top: calc(100% + 2px);
  right: 0;
  min-width: 160px;
  background-color: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 50;
  overflow: hidden;
}

.live-card__overflow-menu.open {
  display: block;
}

.live-card__overflow-menu button {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: var(--touch-target);
  padding: var(--space-sm) var(--space-md);
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--transition);
  color: var(--color-danger);
}

.live-card__overflow-menu button:hover {
  background-color: var(--color-surface-3);
}

/* ===== Inline game recording form ===== */
.live-card__form-wrap {
  max-height: 0;
  overflow: hidden;
  transition: var(--expand-transition);
}

.live-card__form-wrap[data-expanded="true"] {
  max-height: 500px;
}

.live-card__form {
  padding: var(--space-md);
  border-top: 1px solid var(--color-border);
  background-color: var(--color-surface-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.live-card__form .form-row {
  gap: var(--space-sm);
}

.live-card__form .form-group {
  margin-bottom: 0;
}

/* ===== New match form (collapsible) ===== */
.live-new-match {
  margin-bottom: var(--space-md);
}

.live-new-match__toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  min-height: var(--touch-target);
  padding: var(--space-sm) var(--space-md);
  background: none;
  border: 1px solid var(--color-accent-border);
  border-radius: var(--radius-pill);
  color: var(--color-accent);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition);
  width: 100%;
  justify-content: center;
}

.live-new-match__toggle:hover:not(:disabled) {
  background-color: var(--color-accent-glow);
  border-color: var(--color-accent);
}

.live-new-match__toggle:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.live-new-match__form-wrap {
  max-height: 0;
  overflow: hidden;
  transition: var(--expand-transition);
}

.live-new-match__form-wrap[data-expanded="true"] {
  max-height: 400px;
}

.live-new-match__form {
  padding: var(--space-md);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* ===== Player pick grid ===== */
.pick-panel {
  padding: var(--space-md);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.pick-prompt {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin: 0 0 var(--space-sm) 0;
}

.pick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
}

.pick-btn {
  min-height: var(--touch-target);
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 600;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background-color: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition);
}

.pick-btn:hover:not(:disabled) {
  border-color: var(--color-accent);
  background-color: var(--color-accent-glow);
}

.pick-btn--selected {
  background-color: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
  cursor: default;
}

.pick-btn--selected:hover:not(:disabled) {
  background-color: var(--color-accent);
  border-color: var(--color-accent);
}

.pick-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pick-btn__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.25rem;
  margin-left: 0.375rem;
  border-radius: var(--radius-pill, 9999px);
  background: var(--color-primary, #f59e0b);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
}

.pick-confirm {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.pick-pill {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 600;
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-pill);
  border: none;
  cursor: pointer;
}

.pick-pill--selected {
  background-color: var(--color-accent);
  color: #fff;
}

.pick-pill--selected:hover {
  opacity: 0.85;
}

.pick-vs {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  font-weight: 600;
}

.pick-start-form {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.pick-start-form .live-form__label {
  flex: 0 0 auto;
}

.pick-start-form .btn-primary {
  min-height: var(--touch-target);
}

.pick-target-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex: 1 1 100%;
}

.pick-winner-grid {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.cube-pick-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: 0.25rem;
}

.pick-winner-grid .pick-btn {
  flex: 1 1 0;
  min-width: 0;
}

.live-card__form [data-action="submit-game"],
[data-game-form] [data-action="submit-game"] {
  width: 100%;
  min-height: 48px;
  font-size: 1rem;
  font-weight: 600;
  margin-top: 0.5rem;
}

/* ===== Completed matches section label ===== */
.live-completed-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-dim);
  margin-bottom: var(--space-sm);
  margin-top: var(--space-lg);
}

/* ===== Live empty state ===== */
.live-empty {
  text-align: center;
  padding: var(--space-xl) var(--space-lg);
  color: var(--color-text-muted);
  font-size: 0.9rem;
}
