:root {
  --bg: #0b1020;
  --p1: #1e6fd9;
  --p1-dark: #14508f;
  --p2: #d94f1e;
  --p2-dark: #993813;
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.7);
  --bar: #11162a;
  --accent: #ffd23f;
  --danger: #e23b3b;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  user-select: none;
}

body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bar);
  padding: 8px 12px;
  gap: 8px;
  flex: 0 0 auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  z-index: 5;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 6px; }
.topbar-center { text-align: center; flex: 1; }
.sport-indicator { font-weight: 700; font-size: 1rem; white-space: nowrap; }
.set-summary { font-size: 1.1rem; font-weight: 700; letter-spacing: 1px; }
.sets-won { font-size: 0.75rem; color: var(--muted); }
.badge {
  display: none;
  background: var(--accent);
  color: #000;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  letter-spacing: 1px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text);
  font-size: 1.1rem;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.25); }

/* Scoreboard */
.scoreboard {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.player-half {
  flex: 1 1 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: filter 0.1s;
  min-height: 0;
}
.player-half:active { filter: brightness(1.15); }
.player-half.p1 { background: linear-gradient(160deg, var(--p1), var(--p1-dark)); }
.player-half.p2 { background: linear-gradient(160deg, var(--p2), var(--p2-dark)); }

.player-name {
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.9;
}
.server-dot {
  color: var(--accent);
  font-size: 0.7rem;
  margin-left: 6px;
  vertical-align: middle;
}
.big-score {
  font-size: 30vw;
  font-weight: 900;
  line-height: 1;
  margin: 0.1em 0;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}
.games-line { font-size: 1rem; font-weight: 600; opacity: 0.85; }
.tap-hint { font-size: 0.7rem; opacity: 0.5; margin-top: 6px; text-transform: uppercase; letter-spacing: 1px; }

/* Match banner */
.match-banner {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--accent);
  color: #000;
  text-align: center;
  padding: 14px;
  font-size: 1.2rem;
  font-weight: 800;
  z-index: 8;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  align-items: flex-start;
  justify-content: center;
  z-index: 10;
  padding: 16px;
  overflow-y: auto;
}
.modal-content {
  background: #161c33;
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  margin: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h2 { font-size: 1.3rem; }

.setting-block { margin-bottom: 18px; }
.setting-label { display: block; font-weight: 700; margin-bottom: 8px; font-size: 0.95rem; }
.hint-text { font-size: 0.78rem; color: var(--muted); margin-bottom: 8px; }

.toggle-group { display: flex; gap: 8px; flex-wrap: wrap; }
.toggle {
  flex: 1 1 auto;
  min-width: 70px;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid transparent;
  color: var(--text);
  padding: 12px 10px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.toggle:active { transform: scale(0.97); }
.toggle.active { background: var(--accent); color: #000; border-color: #fff; }

.keymap-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.keymap-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid rgba(255,255,255,0.12); }
.keymap-table td { padding: 8px 4px; border-bottom: 1px solid rgba(255,255,255,0.06); vertical-align: middle; }
.keycell { font-family: ui-monospace, monospace; color: var(--accent); }
.keycell.listening { color: #fff; font-style: italic; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.rebind-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none; color: var(--text);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 0.8rem; font-weight: 600;
}
.rebind-btn:active { background: var(--accent); color: #000; }

.button-row { display: flex; gap: 10px; }
.secondary-btn, .danger-btn {
  flex: 1;
  padding: 14px; border: none; border-radius: 10px;
  font-size: 0.95rem; font-weight: 700; cursor: pointer; color: #fff;
}
.secondary-btn { background: #2a3358; }
.danger-btn { background: var(--danger); }
.secondary-btn:active, .danger-btn:active { transform: scale(0.98); }

/* Landscape / tablet: two-column split */
@media (orientation: landscape) and (min-width: 700px) {
  .scoreboard { flex-direction: row; }
  .player-half { flex: 1 1 50%; }
  .big-score { font-size: 22vh; }
}

@media (min-width: 700px) and (orientation: portrait) {
  .big-score { font-size: 26vw; }
}
