/* ── Variables ── */
:root {
  --bg:         #061209;
  --surface:    #0c1f13;
  --surface2:   #132a1a;
  --border:     #1e3d28;
  --accent:     #b8f542;
  --accent-dim: #7aac22;
  --text:       #e8ede2;
  --text-muted: #4d7055;
  --text-dim:   #8aab90;
  --danger:     #f54242;
  --serve:      #f5c842;

  --font-score:  'Bebas Neue', sans-serif;
  --font-ui:     'Barlow Condensed', sans-serif;
  --font-body:   'Barlow', sans-serif;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
body { font-family: var(--font-body); -webkit-font-smoothing: antialiased; }
button { cursor: pointer; border: none; background: none; font-family: inherit; color: inherit; }
input, select { font-family: inherit; color: inherit; }

#app { height: 100vh; display: flex; flex-direction: column; }

/* ── LOGIN VIEW ── */
.view-login {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

.view-login::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 30% 60%, rgba(184,245,66,0.04) 0%, transparent 70%),
    radial-gradient(ellipse 40% 40% at 70% 30%, rgba(184,245,66,0.03) 0%, transparent 60%);
}

.login-card {
  position: relative;
  width: 360px;
  padding: 48px 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.login-logo {
  font-family: var(--font-score);
  font-size: 13px;
  letter-spacing: 0.3em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.login-title {
  font-family: var(--font-ui);
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1;
  color: var(--text);
  margin-bottom: 36px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.login-field label {
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.login-field input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 16px;
  color: var(--text);
  transition: border-color 0.15s;
  outline: none;
}

.login-field input:focus { border-color: var(--accent); }

.btn-primary {
  width: 100%;
  padding: 15px;
  background: var(--accent);
  color: var(--bg);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  border-radius: 3px;
  transition: background 0.15s, transform 0.1s;
}

.btn-primary:hover { background: #ceff5a; }
.btn-primary:active { transform: scale(0.98); }

.login-error {
  margin-top: 14px;
  font-size: 13px;
  color: var(--danger);
  text-align: center;
  min-height: 20px;
  font-family: var(--font-ui);
}

/* ── SETUP VIEW ── */
.view-setup {
  height: 100vh;
  overflow-y: auto;
  padding: 32px 24px 48px;
  background: var(--bg);
}

.setup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 36px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.setup-title {
  font-family: var(--font-ui);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--text);
}

.setup-subtitle {
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.btn-ghost {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--font-ui);
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  text-transform: uppercase;
  transition: border-color 0.15s, color 0.15s;
}

.btn-ghost:hover { border-color: var(--text-dim); color: var(--text); }

.setup-section {
  margin-bottom: 32px;
}

.setup-section-label {
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.players-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-group label {
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.field-group input,
.field-group select {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 15px;
  color: var(--text);
  transition: border-color 0.15s;
  outline: none;
  width: 100%;
}

.field-group input:focus,
.field-group select:focus { border-color: var(--accent); }

.field-group select option { background: var(--surface2); }

/* Toggle group */
.toggle-group {
  display: flex;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.toggle-group button {
  flex: 1;
  padding: 11px 8px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  transition: background 0.15s, color 0.15s;
  border-right: 1px solid var(--border);
}

.toggle-group button:last-child { border-right: none; }
.toggle-group button.active { background: var(--accent); color: var(--bg); }

.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.serve-select {
  display: flex;
  gap: 12px;
}

.serve-btn {
  flex: 1;
  padding: 14px 12px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 3px;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dim);
  transition: all 0.15s;
}

.serve-btn.active {
  border-color: var(--serve);
  color: var(--serve);
  background: rgba(245, 200, 66, 0.06);
}

.start-btn {
  width: 100%;
  padding: 18px;
  background: var(--accent);
  color: var(--bg);
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  border-radius: 3px;
  transition: background 0.15s, transform 0.1s;
  margin-top: 8px;
}

.start-btn:hover { background: #ceff5a; }
.start-btn:active { transform: scale(0.99); }

/* ── SCOREBOARD VIEW ── */
.view-scoreboard {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
  position: relative;
  overflow: hidden;
  user-select: none;
}

/* Background court texture suggestion */
.view-scoreboard::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 100%, rgba(184,245,66,0.025) 0%, transparent 60%);
  pointer-events: none;
}

/* ── TOP BAR: sets history ── */
.sb-topbar {
  position: relative;
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
  min-height: 64px;
}

.sb-player-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 28px;
  min-width: 0;
}

.sb-player-label.p1 { flex: 1; justify-content: flex-start; }
.sb-player-label.p2 { flex: 1; justify-content: flex-end; flex-direction: row-reverse; }

.sb-player-name {
  font-family: var(--font-ui);
  font-size: clamp(18px, 3vw, 28px);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.sb-serve-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--serve);
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.3s;
  box-shadow: 0 0 8px var(--serve);
}

.sb-serve-dot.visible { opacity: 1; }

.sb-sets-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  flex-shrink: 0;
}

.sb-set-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
}

.sb-set-box.won {
  border-color: var(--accent-dim);
  background: rgba(184,245,66,0.05);
}

.sb-set-score {
  font-family: var(--font-score);
  font-size: 22px;
  line-height: 1;
  color: var(--text);
}

.sb-set-score.loser { color: var(--text-muted); }

/* ── MAIN SCORE AREA ── */
.sb-main {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0;
}

.sb-player-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px 0;
}

.sb-game-score {
  font-family: var(--font-score);
  font-size: clamp(100px, 20vw, 200px);
  line-height: 0.9;
  color: var(--text);
  transition: color 0.2s;
  letter-spacing: -0.02em;
}

.sb-game-score.leading { color: var(--accent); }
.sb-game-score.special {
  font-family: var(--font-ui);
  font-weight: 900;
  font-size: clamp(40px, 8vw, 80px);
  letter-spacing: 0.02em;
}

.sb-current-set-score {
  font-family: var(--font-ui);
  font-size: clamp(28px, 5vw, 52px);
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.sb-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 0 16px;
}

.sb-divider-line {
  width: 1px;
  height: clamp(80px, 14vw, 140px);
  background: var(--border);
}

.sb-tiebreak-label {
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--accent);
  writing-mode: vertical-rl;
  white-space: nowrap;
  display: none;
}

.sb-tiebreak-label.visible { display: block; }

/* ── MATCH WINNER OVERLAY ── */
.sb-winner-overlay {
  position: absolute;
  inset: 0;
  background: rgba(6,18,9,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
  backdrop-filter: blur(4px);
}

.sb-winner-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.sb-winner-label {
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--accent);
}

.sb-winner-name {
  font-family: var(--font-score);
  font-size: clamp(48px, 10vw, 96px);
  color: var(--text);
  letter-spacing: 0.02em;
}

.sb-winner-sub {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 0.1em;
}

.btn-new-match {
  margin-top: 16px;
  padding: 14px 36px;
  background: var(--accent);
  color: var(--bg);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  border-radius: 3px;
  transition: background 0.15s;
}

.btn-new-match:hover { background: #ceff5a; }

/* ── BOTTOM BAR: button assignment ── */
.sb-bottombar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 28px;
  border-top: 1px solid var(--border);
  min-height: 48px;
}

.sb-btn-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.sb-btn-badge {
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  flex-shrink: 0;
}

.sb-center-info {
  display: flex;
  align-items: center;
  gap: 20px;
}

.sb-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s infinite;
}

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

.sb-status-text {
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sb-settings-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 2px;
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  transition: all 0.15s;
}

.sb-settings-btn:hover { border-color: var(--text-muted); color: var(--text); }

/* ── Connection indicator ── */
.ws-disconnected .sb-status-dot {
  background: var(--danger);
  animation: none;
}

/* ── Animations ── */
@keyframes scoreIn {
  from { transform: scale(0.85) translateY(8px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.score-update { animation: scoreIn 0.2s ease-out; }

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

.view-login, .view-setup, .view-scoreboard { animation: fadeIn 0.3s ease-out; }

/* ── History view ── */
.view-history {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 28px;
  border-bottom: 1px solid var(--border);
}

.history-title {
  font-family: var(--font-ui);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 28px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.history-players {
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 600;
}

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

.history-date {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.history-sets {
  display: flex;
  gap: 8px;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text-dim);
}

/* ── Responsive tweaks for landscape iPad ── */
@media (orientation: landscape) and (min-height: 600px) {
  .sb-game-score { font-size: clamp(100px, 22vh, 200px); }
}

@media (orientation: portrait) {
  .sb-main { grid-template-columns: 1fr; grid-template-rows: 1fr auto 1fr; }
  .sb-player-score { flex-direction: row; justify-content: center; gap: 32px; }
  .sb-game-score { font-size: clamp(80px, 25vw, 160px); }
  .sb-divider { flex-direction: row; padding: 12px 0; }
  .sb-divider-line { width: clamp(60px, 12vw, 100px); height: 1px; }
  .sb-tiebreak-label { writing-mode: horizontal-tb; }
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
