:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface2: #f0f0f0;
  --text: #1a1a1a;
  --text2: #666;
  --border: #e0e0e0;
  --primary: #1a73e8;
  --primary-light: #e8f0fe;
  --danger: #dc3545;
  --success: #28a745;
  --warning: #ffc107;
  --serve: #2196f3;
  --reception: #4caf50;
  --attack: #f44336;
  --block: #9c27b0;
  --dig: #009688;
  --set-action: #ff9800;
  --ace: #1b5e20;
  --kill: #b71c1c;
  --error: #d32f2f;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --radius: 8px;
  --radius-sm: 4px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ---- NAV ---- */
nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
nav.hidden { display: none; }
.nav-brand {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--primary);
  text-decoration: none;
}
.nav-links { display: flex; gap: 4px; }
.nav-link {
  padding: 8px 16px;
  color: var(--text2);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: .9rem;
  transition: all .15s;
}
.nav-link:hover, .nav-link.active { background: var(--primary-light); color: var(--primary); }
.nav-right { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
}
.btn:hover { background: var(--surface2); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { opacity: .9; background: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { opacity: .9; background: var(--danger); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }

/* ---- FORMS ---- */
input, select, textarea {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
label { font-weight: 500; font-size: .875rem; display: block; margin-bottom: 4px; }
.form-group { margin-bottom: 12px; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }

/* ---- LAYOUT ---- */
#app { padding: 20px; max-width: 1400px; margin: 0 auto; }
.loading { text-align: center; padding: 60px; color: var(--text2); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h2, .card-header h3 { font-size: 1.1rem; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 1.4rem; }

/* ---- LOGIN ---- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  text-align: center;
}
.login-box {
  background: var(--surface);
  padding: 48px;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,.1);
  max-width: 420px;
}
.login-box h1 { font-size: 2rem; margin-bottom: 8px; color: var(--primary); }
.login-box p { color: var(--text2); margin-bottom: 32px; }
.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 32px;
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: all .2s;
}
.google-btn:hover { border-color: var(--primary); box-shadow: 0 2px 12px rgba(26,115,232,.2); }
.google-btn svg { width: 20px; height: 20px; }

/* ---- DASHBOARD ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}
.stat-card .stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: .8rem; color: var(--text2); text-transform: uppercase; }

/* ---- TABLES ---- */
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 600; background: var(--surface2); font-size: .75rem; text-transform: uppercase; letter-spacing: .5px; }
tr:hover { background: var(--primary-light); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mono { font-family: 'JetBrains Mono', monospace; }

/* ---- MATCH LIST ---- */
.match-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all .15s;
}
.match-card:hover { border-color: var(--primary); box-shadow: 0 2px 12px rgba(26,115,232,.1); }
.match-teams { display: flex; flex-direction: column; gap: 4px; }
.match-team { font-weight: 600; }
.match-score { font-family: 'JetBrains Mono', monospace; font-size: 1.5rem; font-weight: 700; }
.match-meta { color: var(--text2); font-size: .8rem; text-align: right; }
.match-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
}
.match-status.live { background: #ffebee; color: var(--danger); }
.match-status.upcoming { background: #e3f2fd; color: var(--primary); }
.match-status.finished { background: #e8f5e9; color: var(--success); }

/* ---- TEAM DETAIL ---- */
.player-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.player-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: .9rem;
}
.player-info { flex: 1; }
.player-info .name { font-weight: 600; }
.player-info .position { font-size: .8rem; color: var(--text2); }
.pos-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: .7rem;
  font-weight: 600;
  background: var(--surface2);
}
.pos-badge.S { background: #fff3e0; color: #e65100; }
.pos-badge.OH { background: #e3f2fd; color: #1565c0; }
.pos-badge.MB { background: #f3e5f5; color: #7b1fa2; }
.pos-badge.OP { background: #fce4ec; color: #c62828; }
.pos-badge.L { background: #e8f5e9; color: #2e7d32; }

/* ---- LIVE SCORING ---- */
.scoreboard {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.team-score {
  flex: 1;
  text-align: center;
}
.team-score .team-name { font-size: .9rem; font-weight: 600; margin-bottom: 4px; }
.team-score .sets-won {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text2);
  margin-bottom: 4px;
}
.team-score .current-score {
  font-family: 'JetBrains Mono', monospace;
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
}
.team-score.home .current-score { color: var(--danger); }
.team-score.away .current-score { color: var(--primary); }
.set-info {
  padding: 0 32px;
  text-align: center;
  min-width: 120px;
}
.set-info .set-label { font-size: .8rem; color: var(--text2); }
.set-info .set-number { font-size: 1.4rem; font-weight: 700; }
.set-info .serving-indicator {
  font-size: .75rem;
  color: var(--success);
  font-weight: 600;
  margin-top: 4px;
}

.live-content {
  display: grid;
  grid-template-columns: 1fr 280px 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.team-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.team-panel h3 {
  font-size: .9rem;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.players-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
}
.player-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: all .1s;
  font-size: .78rem;
}
.player-btn:hover { border-color: var(--primary); background: var(--primary-light); }
.player-btn.selected { border-color: var(--primary); background: var(--primary); color: #fff; }
.player-btn .num {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  min-width: 20px;
}
.player-btn .pname { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-btn.libero { border-style: dashed; }
.player-btn.libero .num { color: var(--success); }
.player-btn.selected.libero .num { color: #fff; }

.action-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.selected-display {
  text-align: center;
  padding: 8px;
  min-height: 48px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.selected-display .sel-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.2rem;
  color: var(--primary);
}
.selected-display .sel-name { font-size: .85rem; }
.selected-display.empty { color: var(--text2); font-weight: 400; }

.action-types {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.action-type-btn {
  padding: 8px 4px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: .85rem;
  cursor: pointer;
  text-align: center;
  transition: all .1s;
  background: var(--surface);
}
.action-type-btn:hover { opacity: .85; }
.action-type-btn.selected { color: #fff; }
.action-type-btn[data-action="serve"] { border-color: var(--serve); color: var(--serve); }
.action-type-btn[data-action="serve"].selected { background: var(--serve); color: #fff; }
.action-type-btn[data-action="reception"] { border-color: var(--reception); color: var(--reception); }
.action-type-btn[data-action="reception"].selected { background: var(--reception); color: #fff; }
.action-type-btn[data-action="attack"] { border-color: var(--attack); color: var(--attack); }
.action-type-btn[data-action="attack"].selected { background: var(--attack); color: #fff; }
.action-type-btn[data-action="block"] { border-color: var(--block); color: var(--block); }
.action-type-btn[data-action="block"].selected { background: var(--block); color: #fff; }
.action-type-btn[data-action="dig"] { border-color: var(--dig); color: var(--dig); }
.action-type-btn[data-action="dig"].selected { background: var(--dig); color: #fff; }
.action-type-btn[data-action="set"] { border-color: var(--set-action); color: var(--set-action); }
.action-type-btn[data-action="set"].selected { background: var(--set-action); color: #fff; }

.result-btns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.result-btn {
  padding: 10px 4px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: .9rem;
  cursor: pointer;
  text-align: center;
  transition: all .1s;
  background: var(--surface);
}
.result-btn:hover { transform: scale(1.03); }
.result-btn.terminal-positive { border-color: var(--success); background: #e8f5e9; color: var(--success); }
.result-btn.terminal-negative { border-color: var(--danger); background: #ffebee; color: var(--danger); }
.result-btn.non-terminal { border-color: #ff9800; background: #fff3e0; color: #e65100; }

.action-controls {
  display: flex;
  gap: 4px;
}
.action-controls .btn { flex: 1; justify-content: center; }

.quick-score {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.quick-score .btn { flex: 1; font-size: .75rem; }

/* ---- ACTION LOG ---- */
.action-log {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  max-height: 400px;
  overflow-y: auto;
}
.action-log h3 {
  font-size: .9rem;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.log-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: .78rem;
  border-bottom: 1px solid var(--surface2);
}
.log-entry:hover { background: var(--surface2); }
.log-rally {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text2);
  min-width: 28px;
  font-size: .7rem;
}
.log-player {
  font-weight: 600;
  min-width: 40px;
}
.log-action {
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
  font-size: .7rem;
  color: #fff;
}
.log-action.serve { background: var(--serve); }
.log-action.reception { background: var(--reception); }
.log-action.attack { background: var(--attack); }
.log-action.block { background: var(--block); }
.log-action.dig { background: var(--dig); }
.log-result { font-weight: 700; font-size: .9rem; }
.log-result.point { color: var(--success); }
.log-result.error { color: var(--danger); }
.log-score {
  font-family: 'JetBrains Mono', monospace;
  font-size: .75rem;
  color: var(--text2);
  margin-left: auto;
}
.log-entry .log-del {
  cursor: pointer;
  color: var(--text2);
  padding: 2px 4px;
  font-size: .7rem;
  opacity: 0;
  transition: opacity .15s;
}
.log-entry:hover .log-del { opacity: 1; }
.log-del:hover { color: var(--danger); }

/* ---- LIVE TABS ---- */
.live-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
  border-bottom: 2px solid var(--border);
}
.live-tab {
  padding: 8px 20px;
  cursor: pointer;
  font-weight: 600;
  font-size: .85rem;
  color: var(--text2);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all .15s;
}
.live-tab:hover { color: var(--text); }
.live-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---- STATS PANEL ---- */
.stats-table { font-size: .75rem; }
.stats-table th { font-size: .65rem; padding: 4px 6px; }
.stats-table td { padding: 4px 6px; text-align: center; }
.stats-table .player-col { text-align: left; font-weight: 600; }

/* ---- REPORT ---- */
.report-container { max-width: 1100px; margin: 0 auto; }
.report-header {
  text-align: center;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.report-header h1 { font-size: 1.3rem; }
.report-header .match-result { font-size: 2rem; font-weight: 700; margin: 8px 0; }
.report-header .match-info { font-size: .85rem; color: var(--text2); }

.report-sets {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 12px 0;
}
.report-set {
  padding: 8px 16px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: .85rem;
}
.report-set .set-label { font-size: .7rem; color: var(--text2); }
.report-set .set-score { font-weight: 700; font-size: 1.1rem; }

.report-team-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  overflow-x: auto;
}
.report-team-section h2 {
  font-size: 1rem;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

.report-table { font-size: .72rem; white-space: nowrap; }
.report-table th { font-size: .62rem; padding: 4px 5px; }
.report-table td { padding: 4px 5px; text-align: center; }
.report-table .player-col { text-align: left; font-weight: 600; white-space: nowrap; }
.report-table .section-header { background: var(--primary-light); font-weight: 700; color: var(--primary); }
.report-table .team-total td { font-weight: 700; background: var(--surface2); }

/* ---- MODAL ---- */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal h2 { margin-bottom: 16px; font-size: 1.1rem; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---- RESPONSIVE ---- */
@media (max-width: 900px) {
  .live-content { grid-template-columns: 1fr; }
  .action-panel { order: -1; }
  .scoreboard { flex-direction: row; padding: 12px; }
  .team-score .current-score { font-size: 2rem; }
  .set-info { padding: 0 16px; }
  .form-row { flex-direction: column; }
  nav { padding: 0 12px; }
  .nav-links { gap: 0; }
  .nav-link { padding: 8px 10px; font-size: .8rem; }
}

@media print {
  nav, .live-tabs, .action-panel, .action-log, .btn { display: none !important; }
  .report-container { max-width: 100%; }
  .report-team-section { break-inside: avoid; }
  body { background: #fff; }
}

/* ---- TUTORIAL ---- */
.tutorial-step {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.tutorial-step:last-child { border-bottom: none; }
.step-title {
  font-weight: 700;
  font-size: .8rem;
  color: var(--primary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.tutorial-step p { margin: 3px 0; }
.tutorial-step.active-step {
  background: var(--primary-light);
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--primary);
}
.tutorial-step.active-step .step-title { color: var(--primary); font-size: .85rem; }

@media (max-width: 1100px) {
  #tutorial-panel { display: none; }
}

/* ---- UTILITY ---- */
.hidden { display: none !important; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.text-muted { color: var(--text2); }
.text-sm { font-size: .8rem; }
.empty-state { text-align: center; padding: 40px; color: var(--text2); }
