/* ===================================================================
   Americano Badminton Tournament — Main Stylesheet
   Mobile-first | Responsive | Accessible
   =================================================================== */

/* ── Reset & Variables ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:        #1a73e8;
  --brand-dark:   #1558b0;
  --brand-light:  #e8f0fe;
  --green:        #34a853;
  --green-light:  #e6f4ea;
  --red:          #ea4335;
  --red-light:    #fce8e6;
  --orange:       #fa7b17;
  --yellow:       #fbbc04;
  --gray-50:      #f8f9fa;
  --gray-100:     #f1f3f4;
  --gray-200:     #e8eaed;
  --gray-400:     #bdc1c6;
  --gray-600:     #80868b;
  --gray-800:     #3c4043;
  --gray-900:     #202124;
  --white:        #ffffff;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow:       0 2px 8px rgba(0,0,0,.12), 0 1px 4px rgba(0,0,0,.08);
  --shadow-lg:    0 4px 16px rgba(0,0,0,.15), 0 2px 8px rgba(0,0,0,.10);
  --radius:       12px;
  --radius-sm:    8px;
  --font:         'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--gray-100);
  color: var(--gray-900);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Typography ────────────────────────────────────────────────── */
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.35rem; font-weight: 600; }
h3 { font-size: 1.1rem;  font-weight: 600; }
h4 { font-size: .95rem;  font-weight: 600; }
p  { color: var(--gray-800); }

/* ── Layout ────────────────────────────────────────────────────── */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1rem 3rem;
}

/* ── Header / Topbar ───────────────────────────────────────────── */
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.topbar-logo {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--brand);
  text-decoration: none;
  letter-spacing: -.5px;
}
.topbar-logo span { color: var(--gray-400); }
.topbar-name {
  font-weight: 600;
  color: var(--gray-900);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-badge {
  font-size: .75rem;
  font-weight: 700;
  padding: .2rem .6rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.status-setup    { background: var(--yellow);   color: #5a3800; }
.status-upcoming { background: #0d9488;          color: var(--white); }
.status-active   { background: var(--green);    color: var(--white); }
.status-finished { background: var(--gray-600); color: var(--white); }

/* ── Tab navigation ────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: 1.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab-btn {
  background: none;
  border: none;
  padding: .75rem 1.1rem;
  font-size: .9rem;
  font-weight: 600;
  color: var(--gray-600);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover   { color: var(--brand); }
.tab-btn.active  { color: var(--brand); border-bottom-color: var(--brand); }

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.25rem;
  margin-bottom: 1rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: .5rem;
}

/* ── Court Cards ───────────────────────────────────────────────── */
.courts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

/* ── Rounds two-column layout ──────────────────────────────────── */
.rounds-layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 1rem;
  align-items: start;
}

/* ── Court Sidebar (next-round preview) ────────────────────────── */
.round-sidebar {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  overflow: hidden;
  position: sticky;
  top: 70px;
}
.sb-header {
  background: #7c3aed;
  color: #fff;
  padding: .6rem 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 700;
  font-size: .85rem;
}
.sb-round-label { flex: 1; }
.sb-next-count {
  background: rgba(255,255,255,.25);
  border-radius: 999px;
  padding: .1rem .5rem;
  font-size: .72rem;
  font-weight: 800;
}
.sb-next-courts {
  padding: .5rem .6rem .6rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.sb-next-court {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.sb-next-court--empty {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4rem .7rem;
  font-size: .85rem;
  font-weight: 600;
  color: var(--gray-800);
  border-style: dashed;
}
.sb-next-icon { font-size: 1rem; }
.sb-court-num {
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--brand);
  background: var(--brand-light);
  padding: .22rem .7rem;
}
.sb-lineup {
  display: flex;
  flex-direction: column;
  padding: .3rem .7rem .4rem;
  gap: .15rem;
}
.sb-lineup-team {
  font-size: .82rem;
  font-weight: 600;
  color: var(--gray-900);
  line-height: 1.3;
}
.sb-lineup-vs {
  font-size: .7rem;
  color: var(--gray-400);
  font-style: italic;
  font-weight: 700;
  line-height: 1;
}
.sb-next-hint {
  padding: .5rem .9rem .65rem;
  font-size: .72rem;
  color: var(--gray-600);
  border-top: 1px solid var(--gray-200);
  line-height: 1.4;
}
.sb-ondeck {
  padding: .4rem .6rem .5rem;
  border-top: 1px solid var(--gray-200);
}
.sb-ondeck-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--orange);
  margin-bottom: .3rem;
}
.sb-ondeck-player {
  font-size: .83rem;
  font-weight: 600;
  color: var(--gray-800);
  padding: .25rem 0;
  border-bottom: 1px dashed var(--gray-200);
}
.sb-ondeck-player:last-child { border-bottom: none; }
.court-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 2px solid var(--gray-200);
  transition: border-color .15s;
}
.court-card.scored { border-color: var(--green); }
.court-header {
  background: var(--brand);
  color: var(--white);
  padding: .6rem 1rem;
  font-weight: 700;
  font-size: .9rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.court-header .court-icon { font-size: 1rem; opacity: .85; }
.court-body { padding: 1rem; }

.team-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem 0;
}
.team-row + .team-row {
  border-top: 2px dashed var(--gray-200);
  margin-top: .25rem;
  padding-top: .75rem;
}
.team-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-600);
  min-width: 2rem;
}
.team-players {
  flex: 1;
  font-weight: 600;
  font-size: .9rem;
  color: var(--gray-900);
}
.team-players .player-name + .player-name::before { content: ' & '; color: var(--gray-400); }

.score-display {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--brand);
  min-width: 2.5rem;
  text-align: right;
}
.score-display.winner { color: var(--green); }
.score-display.loser  { color: var(--gray-600); }

/* Score input inside a court card (admin view) */
.score-inputs {
  display: flex;
  gap: .5rem;
  align-items: center;
  justify-content: center;
  margin-top: .75rem;
  padding-top: .75rem;
  border-top: 1px solid var(--gray-200);
}
.score-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
}
.score-field label {
  font-size: .7rem;
  font-weight: 700;
  color: var(--gray-600);
  text-transform: uppercase;
}
.score-field input[type="number"] {
  width: 5rem;
  padding: .4rem .3rem;
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s;
  -moz-appearance: textfield;
}
.score-field input[type="number"]::-webkit-inner-spin-button,
.score-field input[type="number"]::-webkit-outer-spin-button { opacity: 1; }
.score-field input:focus { border-color: var(--brand); }
.score-sep { font-size: 1.5rem; font-weight: 800; color: var(--gray-400); padding: 0 .1rem; margin-top: 1.2rem; }

.btn-save-score {
  display: block;
  width: 100%;
  margin-top: .75rem;
  padding: .55rem;
  background: var(--brand);
  color: var(--white);
  font-weight: 700;
  font-size: .9rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
}
.btn-save-score:hover { background: var(--brand-dark); }
.btn-save-score:disabled { background: var(--gray-400); cursor: not-allowed; }

/* ── Sit-out panel ─────────────────────────────────────────────── */
.sitout-panel {
  background: var(--yellow);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: .75rem;
}
.sitout-icon { font-size: 1.5rem; line-height: 1; }
.sitout-content h4 { color: #5a3800; margin-bottom: .35rem; }
.sitout-list { list-style: none; padding: 0; }
.sitout-list li { font-size: .9rem; color: #5a3800; padding: .15rem 0; }
.sitout-list li strong { font-weight: 700; }

/* ── Standings table ───────────────────────────────────────────── */
.standings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.standings-table th {
  text-align: left;
  padding: .5rem .75rem;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--gray-600);
  border-bottom: 2px solid var(--gray-200);
}
.standings-table td {
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--gray-100);
}
.standings-table tr:last-child td { border-bottom: none; }
.standings-table tbody tr:hover { background: var(--gray-50); }

.rank-cell {
  font-weight: 800;
  font-size: 1rem;
  text-align: center;
  width: 2.5rem;
}
.rank-1 { color: #c9920f; }
.rank-2 { color: var(--gray-600); }
.rank-3 { color: #a0522d; }

.points-cell {
  font-weight: 700;
  font-size: 1rem;
  color: var(--brand);
}

/* ── Round history accordion ───────────────────────────────────── */
.round-view-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .75rem;
}
.round-view-header h2 { margin: 0; }
.round-summary {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  margin-bottom: .5rem;
  overflow: hidden;
}
.round-summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  background: var(--gray-50);
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: .9rem;
  border: none;
  width: 100%;
  text-align: left;
  gap: .5rem;
}
.round-summary-header:hover { background: var(--gray-100); }
.round-chevron { transition: transform .2s; font-size: .8rem; color: var(--gray-600); }
.round-summary.open .round-chevron { transform: rotate(180deg); }
.round-detail {
  display: none;
  padding: .75rem 1rem;
  font-size: .85rem;
}
.round-summary.open .round-detail { display: block; }
.round-match-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .3rem 0;
  border-bottom: 1px solid var(--gray-100);
  gap: .5rem;
  flex-wrap: wrap;
}
.round-match-row:last-child { border-bottom: none; }
.match-players { flex: 1; font-weight: 500; }
.match-score { font-weight: 700; color: var(--brand); white-space: nowrap; }

/* ── Buttons (general) ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .65rem 1.2rem;
  font-size: .9rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, transform .1s;
  text-decoration: none;
  line-height: 1;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--brand); color: var(--white); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-success { background: var(--green); color: var(--white); }
.btn-success:hover { background: #2d9248; }
.btn-danger  { background: var(--red); color: var(--white); }
.btn-danger:hover { background: #c5221f; }
.btn-ghost   { background: transparent; color: var(--brand); border: 2px solid var(--brand); }
.btn-ghost:hover { background: var(--brand-light); }
.btn-sm { padding: .4rem .8rem; font-size: .8rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-full { width: 100%; justify-content: center; }

/* ── Forms ─────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: .35rem;
}
.form-control {
  display: block;
  width: 100%;
  padding: .6rem .8rem;
  font-size: .95rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s;
  font-family: var(--font);
}
.form-control:focus { border-color: var(--brand); }
.form-hint {
  font-size: .78rem;
  color: var(--gray-600);
  margin-top: .25rem;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

/* ── Player list ───────────────────────────────────────────────── */
.player-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  margin: .75rem 0;
}
.player-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-200);
}
.player-item-name { flex: 1; font-weight: 500; }
.player-item-btn {
  background: none;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: .1rem .3rem;
  border-radius: 4px;
  transition: background .1s;
}
.player-item-btn:hover { background: var(--red-light); }
.player-count-hint {
  font-size: .82rem;
  color: var(--gray-600);
  text-align: right;
  margin-top: .25rem;
}

/* ── Add player row ────────────────────────────────────────────── */
.add-player-row {
  display: flex;
  gap: .5rem;
  margin-bottom: .5rem;
}
.add-player-row .form-control { flex: 1; }

/* ── Share bar ─────────────────────────────────────────────────── */
.share-bar {
  background: var(--brand-light);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
}
.share-bar h4 { color: var(--brand-dark); flex: 1 1 100%; margin-bottom: .25rem; }
.copy-input-row {
  display: flex;
  gap: .35rem;
  flex: 1;
  min-width: 0;
}
.copy-input {
  flex: 1;
  font-size: .8rem;
  padding: .4rem .6rem;
  border: 1px solid var(--brand);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--gray-900);
  outline: none;
  min-width: 0;
}

/* ── Alerts ─────────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: .9rem;
  font-weight: 500;
  display: flex;
  gap: .5rem;
  align-items: flex-start;
}
.alert-warning { background: #fff3cd; color: #664d03; border: 1px solid #ffe69c; }
.alert-danger  { background: var(--red-light); color: #842029; border: 1px solid #f5c2c7; }
.alert-success { background: var(--green-light); color: #0a3622; border: 1px solid #a3cfbb; }
.alert-info    { background: var(--brand-light); color: #084298; border: 1px solid #b6d4fe; }

/* ── Toast notification ────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--gray-900);
  color: var(--white);
  padding: .65rem 1.25rem;
  border-radius: 999px;
  font-size: .875rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 10000;
  transition: transform .25s ease, opacity .25s ease;
  opacity: 0;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ── Loading spinner ───────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  border: 3px solid var(--gray-200);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}
.loading-full {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
  gap: 1rem;
  color: var(--gray-600);
  font-size: .95rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Hero (homepage) ───────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--brand) 0%, #0d47a1 100%);
  color: var(--white);
  padding: 3rem 1rem 2.5rem;
  text-align: center;
  margin-bottom: 2rem;
}
.hero h1 { font-size: 2rem; margin-bottom: .5rem; }
.hero p   { opacity: .85; font-size: 1.05rem; margin-bottom: 1.5rem; }

/* ── Section spacer ────────────────────────────────────────────── */
.section-title {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-600);
  margin: 1.5rem 0 .5rem;
}

/* ── Finished podium ───────────────────────────────────────────── */
.podium {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: .75rem;
  margin: 1.5rem 0;
}
.podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
}
.podium-block {
  width: 5rem;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}
.podium-block-1 { background: #c9920f; height: 5rem; }
.podium-block-2 { background: #80868b; height: 3.5rem; }
.podium-block-3 { background: #a0522d; height: 2.5rem; }
.podium-name { font-weight: 700; font-size: .9rem; text-align: center; max-width: 5.5rem; word-break: break-word; }
.podium-pts  { font-size: .8rem; color: var(--gray-600); }

/* ── Refresh indicator ─────────────────────────────────────────── */
.refresh-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--gray-600);
  font-size: .78rem;
  margin-bottom: 1rem;
}
.refresh-dot {
  width: .5rem;
  height: .5rem;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}

/* ── Admin-only indicator ──────────────────────────────────────── */
.admin-ribbon {
  background: var(--orange);
  color: var(--white);
  font-size: .72rem;
  font-weight: 700;
  padding: .15rem .5rem;
  border-radius: 999px;
  margin-left: .5rem;
  vertical-align: middle;
}

/* ── Misc utilities ────────────────────────────────────────────── */
.text-center  { text-align: center; }
.text-muted   { color: var(--gray-600); }
.text-sm      { font-size: .85rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

/* ── Print styles ──────────────────────────────────────────────── */
@media print {
  .topbar, .tabs, .share-bar, .btn,
  .score-inputs, #toast, .refresh-bar { display: none !important; }
  .court-card { break-inside: avoid; border: 2px solid #000; }
  .courts-grid { grid-template-columns: 1fr 1fr; }
  body { background: #fff; color: #000; }
}

/* ── Responsive adjustments ────────────────────────────────────── */@media (max-width: 760px) {
  .rounds-layout {
    grid-template-columns: 1fr;
  }
  .round-sidebar {
    position: static;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
  .sb-header {
    grid-column: 1 / -1;
  }
  .sb-sitout {
    grid-column: 1 / -1;
  }
}
@media (max-width: 600px) {
  h1 { font-size: 1.4rem; }
  .courts-grid { grid-template-columns: 1fr; }
  .standings-table th:nth-child(4),
  .standings-table td:nth-child(4) { display: none; } /* hide sit-outs on small */
  .podium-block { width: 4rem; }
  .hero h1 { font-size: 1.6rem; }
}
