/* ============================================
   Swiss Rounds Tracker
   ============================================ */

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

:root {
  --bg: #141418;
  --bg-surface: #1c1c22;
  --bg-raised: #232329;
  --bg-inset: #19191f;
  --border: #2c2c35;
  --border-light: #38383f;

  --text: #e8e6e3;
  --text-dim: #9e9ba5;
  --text-faint: #5c5a65;

  --teal: #2dd4a8;
  --teal-dim: #1a9e7a;
  --teal-bg: rgba(45, 212, 168, 0.08);
  --teal-border: rgba(45, 212, 168, 0.25);

  --green: #4ade80;
  --green-bg: rgba(74, 222, 128, 0.08);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.07);
  --red-dim: #dc2626;
  --amber: #fbbf24;
  --amber-bg: rgba(251, 191, 36, 0.08);

  --radius: 6px;
  --radius-lg: 8px;
}

/* ---- Base ---- */

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--teal-dim);
  color: #fff;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ---- Header ---- */

header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 54px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
}

header h1 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.header-export {
  justify-self: end;
  padding: 6px 14px;
  font-size: 0.75rem;
}

/* ---- Nav ---- */

nav {
  display: flex;
  gap: 0;
  justify-self: center;
  height: 100%;
  align-items: stretch;
}

.nav-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: 0 16px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
  font-family: inherit;
}

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

.nav-btn.active {
  color: var(--teal);
  border-bottom-color: var(--teal);
}

/* ---- Layout ---- */

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.view { display: none; }
.view.active {
  display: block;
  animation: fadeUp 0.25s ease both;
}

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

/* ---- Cards ---- */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.72rem;
}

/* ---- Forms ---- */

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 5px;
  font-weight: 500;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.86rem;
  font-family: inherit;
  transition: border-color 0.15s;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--teal-dim);
}

input::placeholder, textarea::placeholder {
  color: var(--text-faint);
}

textarea {
  resize: vertical;
  min-height: 72px;
}

.input-row {
  display: flex;
  gap: 8px;
}

.input-row input { flex: 1; }

/* ---- Buttons ---- */

.btn {
  padding: 9px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.btn:active:not(:disabled) { transform: scale(0.97); }

.btn-primary {
  background: var(--teal-dim);
  color: #fff;
}

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

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

.btn-secondary:hover:not(:disabled) {
  border-color: var(--border-light);
  color: var(--text);
}

.btn-danger {
  background: none;
  color: var(--red);
  border: 1px solid rgba(248,113,113,0.25);
}

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

.btn-small {
  padding: 5px 12px;
  font-size: 0.76rem;
  background: var(--bg-raised);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.btn-small:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--border-light);
}

.btn-large {
  padding: 12px 32px;
  font-size: 0.92rem;
}

.btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---- Players ---- */

.player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.player-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 4px 4px 10px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  animation: tagIn 0.15s ease both;
}

@keyframes tagIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

.player-tag .remove-player {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 3px;
  transition: color 0.12s, background 0.12s;
}

.player-tag .remove-player:hover {
  color: var(--red);
  background: var(--red-bg);
}

.player-count {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-faint);
}

.actions-card {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 18px 22px;
}

/* ---- Matchups ---- */

.matchups-card h2 { margin-bottom: 0; }

.matchups-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.matchup {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.matchup.bye {
  opacity: 0.55;
  border-style: dashed;
}

.matchup-name {
  font-weight: 600;
}

.matchup-name.left { text-align: right; }
.matchup-name.right { text-align: left; }

.matchup-vs {
  color: var(--text-faint);
  font-weight: 700;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  text-align: center;
}

/* ---- Timer ---- */

.timer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 18px;
  margin-bottom: 16px;
  gap: 12px;
}

.timer-display {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: 'Courier New', 'Consolas', monospace;
  letter-spacing: 2px;
  min-width: 110px;
  color: var(--text);
  transition: color 0.2s;
}

.timer-display.warning {
  color: var(--amber);
}

.timer-display.danger {
  color: var(--red);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.timer-controls {
  display: flex;
  align-items: center;
  gap: 5px;
}

.timer-select {
  width: auto;
  padding: 5px 8px;
  font-size: 0.78rem;
}

.timer-btn { padding: 6px 14px; }

/* ---- Rounds / Pairings ---- */

.round-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.round-nav {
  display: flex;
  gap: 5px;
}

.pairings-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pairing {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: border-color 0.12s;
}

.pairing.bye {
  opacity: 0.55;
  border-style: dashed;
}

.pairing-player {
  flex: 1;
  font-weight: 550;
  font-size: 0.9rem;
}

.pairing-player.right { text-align: right; }

.pairing-vs {
  color: var(--text-faint);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 1px;
}

.pairing-score {
  display: flex;
  align-items: center;
  gap: 6px;
}

.score-ctrl {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.score-value {
  display: inline-block;
  width: 30px;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-family: 'Courier New', 'Consolas', monospace;
}

.score-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-surface);
  color: var(--text-dim);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
  padding: 0;
  line-height: 1;
  font-family: inherit;
}

.score-btn:hover {
  border-color: var(--teal-dim);
  color: var(--teal);
}

.score-btn:active {
  transform: scale(0.9);
  background: var(--teal-bg);
}

.bracket-score-ctrl { margin-left: auto; }

.bracket-score-ctrl .score-btn {
  width: 22px;
  height: 22px;
  font-size: 0.8rem;
}

.bracket-score-ctrl .score-value {
  width: 20px;
  font-size: 0.9rem;
}

.pairing-score .score-sep {
  color: var(--text-faint);
  font-weight: 700;
}

.pairing.completed {
  border-left: 3px solid var(--green);
  background: var(--green-bg);
}

.round-actions {
  margin-top: 16px;
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ---- Standings ---- */

.standings-controls {
  margin-bottom: 14px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.standings-controls select {
  width: auto;
  display: inline-block;
  padding: 4px 8px;
  margin-left: 4px;
}

.standings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
}

.standings-table th {
  text-align: left;
  padding: 8px 8px;
  border-bottom: 2px solid var(--border);
  color: var(--text-faint);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.standings-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--border);
}

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

.standings-table tr.top-cut-line {
  border-bottom: none;
}

.standings-table tr.top-cut-line td {
  border-bottom: 2px dashed var(--amber);
  padding-bottom: 11px;
}

.standings-table tr.top-cut-line + tr td {
  padding-top: 11px;
}

.standings-table .rank {
  font-weight: 700;
  color: var(--text-faint);
  min-width: 28px;
}

.standings-table tbody tr:nth-child(1) .rank { color: var(--amber); }
.standings-table tbody tr:nth-child(2) .rank { color: #a1a1aa; }
.standings-table tbody tr:nth-child(3) .rank { color: #b87333; }

.standings-table .player-name {
  font-weight: 600;
}

.standings-table .record {
  color: var(--teal);
  font-weight: 600;
}

/* ---- Bracket ---- */

.bracket-status {
  text-align: center;
  padding: 32px 20px;
}

.bracket-status p {
  color: var(--text-faint);
  margin-bottom: 16px;
}

.bracket-container {
  overflow-x: auto;
  padding: 20px 0;
}

.bracket-round {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  vertical-align: top;
  margin-right: 36px;
  min-width: 210px;
}

.bracket-round-title {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-faint);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.bracket-match {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.bracket-match-player {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 12px;
  font-size: 0.84rem;
  border-bottom: 1px solid var(--border);
}

.bracket-match-player:last-child { border-bottom: none; }

.bracket-match-player.winner {
  background: var(--green-bg);
  font-weight: 600;
}

.bracket-match-player.tbd {
  color: var(--text-faint);
  font-style: italic;
}

.bracket-match-player .seed {
  color: var(--text-faint);
  font-size: 0.7rem;
  margin-right: 6px;
  font-weight: 700;
}

.bracket-actions {
  text-align: center;
  margin-top: 16px;
}

/* ---- Toasts ---- */

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 0.84rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: slideIn 0.25s ease;
  max-width: 340px;
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--teal); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ---- Responsive ---- */

@media (max-width: 700px) {
  header {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    height: auto;
    padding: 10px 14px;
    gap: 8px;
  }

  header h1 { font-size: 0.88rem; }

  header nav {
    grid-column: 1 / -1;
    order: 3;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-top: 1px solid var(--border);
    margin: 0 -14px;
    padding: 0 14px;
  }

  header nav::-webkit-scrollbar { display: none; }

  .nav-btn { padding: 0 12px; font-size: 0.76rem; height: 38px; }

  main { padding: 14px 10px 40px; }

  .card { padding: 16px 14px; }

  .form-row { grid-template-columns: 1fr 1fr; gap: 8px; }
}

@media (max-width: 480px) {
  header { grid-template-columns: 1fr; text-align: center; }
  .header-export { justify-self: center; }

  .form-row { grid-template-columns: 1fr; }

  .pairing {
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 12px;
  }

  .pairing-score {
    width: 100%;
    justify-content: center;
    padding-top: 6px;
    margin-top: 2px;
    border-top: 1px solid var(--border);
  }

  .matchup {
    grid-template-columns: 1fr;
    text-align: center;
    gap: 6px;
    padding: 12px 14px;
  }

  .matchup-name.left,
  .matchup-name.right { text-align: center; }

  .standings-table { font-size: 0.76rem; }
  .standings-table th, .standings-table td { padding: 6px 4px; }

  .timer-bar {
    flex-direction: column;
    text-align: center;
    gap: 8px;
    padding: 14px;
  }

  .timer-display { font-size: 2.2rem; }

  .timer-controls { width: 100%; justify-content: center; }

  .toast-container { bottom: 10px; right: 10px; left: 10px; }
  .toast { max-width: 100%; }

  .bracket-round { min-width: 170px; margin-right: 20px; }
}

/* ---- Focus ---- */

:focus-visible {
  outline: 2px solid var(--teal-dim);
  outline-offset: 2px;
}
