/* ============ RESET & BASE ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #20B2AA;
  --primary-dark: #178f89;
  --accent: #FF9800;
  --bg: #F5F5F5;
  --text: #333333;
  --text-muted: #777777;
  --card: #ffffff;
  --green: #4CAF50;
  --yellow: #FFC107;
  --red: #F44336;
  --border: #e2e2e2;
  --mono: 'Monaco', 'Consolas', 'Courier New', monospace;
}
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ============ HEADER & NAV ============ */
header.hero {
  position: relative;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  max-width: 1024px;
  margin: 0 auto;
  line-height: 0;
}
header.hero img { width: 100%; height: auto; display: block; }
/* "SEASON ____" overlaid on the empty teal ribbon in the artwork */
.hero-season {
  position: absolute;
  left: 46%;
  top: 80%;
  transform: translate(-50%, -50%) rotate(-1.5deg);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  font-size: clamp(12px, 2.6vw, 27px);
  line-height: 1;
  text-shadow: 0 1px 4px rgba(0,0,0,0.45);
  white-space: nowrap;
}
nav {
  display: flex;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  position: sticky;
  top: 0;
  z-index: 50;
}
nav button {
  flex: 1;
  min-height: 48px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.15s ease;
  padding: 8px 4px;
}
nav button:hover { background: #f0fbfa; color: var(--primary); }
nav button.active { color: var(--primary); border-bottom-color: var(--primary); }
nav button .tab-icon { display: block; font-size: 18px; }

/* ============ LAYOUT ============ */
main { max-width: 1024px; margin: 0 auto; padding: 16px; }
section.tab { display: none; animation: fadeIn 0.2s ease; }
section.tab.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 16px;
}
.card h2 { font-size: 20px; margin-bottom: 12px; }
.card h3 { font-size: 16px; margin-bottom: 8px; }

.flex-row { display: flex; gap: 16px; flex-wrap: wrap; }
.flex-row > .card { flex: 1 1 300px; }

/* ============ BADGES & STATUS ============ */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  vertical-align: middle;
}
.badge.leeward { background: var(--primary); }
.badge.aiea { background: var(--accent); }
.badge.today { background: var(--green); }

.muted { color: var(--text-muted); font-size: 13px; }

/* ============ TABLES ============ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 8px; text-align: left; white-space: nowrap; }
thead th {
  background: #fafafa;
  border-bottom: 2px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  user-select: none;
}
thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: var(--primary); }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:nth-child(even) { background: #fafafa; }
tbody tr:hover { background: #f0fbfa; }
td.num, th.num { text-align: right; font-family: var(--mono); }
.score { font-family: var(--mono); font-weight: 700; font-size: 16px; }

tr.avg-high td:first-child { border-left: 4px solid var(--green); }
tr.avg-mid td:first-child { border-left: 4px solid var(--yellow); }
tr.avg-low td:first-child { border-left: 4px solid var(--red); }
tr.avg-none td:first-child { border-left: 4px solid var(--border); }

/* ============ FORMS & BUTTONS ============ */
input, select {
  font-family: inherit;
  font-size: 16px;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
input[type="number"].score-input {
  width: 76px;
  min-height: 48px;
  text-align: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 18px;
  padding: 8px 4px;
}
input.invalid { outline: 2px solid var(--red); border-color: var(--red); }

button.btn {
  min-height: 44px;
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.05s ease, filter 0.15s ease;
}
button.btn:active { transform: scale(0.97); }
button.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary { background: #fff; color: var(--primary); border: 2px solid var(--primary); }
.btn-secondary:hover { background: #f0fbfa; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-sm { min-height: 32px; padding: 4px 12px; font-size: 13px; }

.form-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text-muted); }

.venue-toggle { display: flex; gap: 0; border-radius: 6px; overflow: hidden; border: 2px solid var(--primary); }
.venue-toggle button {
  min-height: 44px;
  padding: 8px 20px;
  border: none;
  background: #fff;
  color: var(--primary);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.venue-toggle button.selected { background: var(--primary); color: #fff; }

.count-badge {
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 700;
}
.player-substat { font-size: 11px; color: var(--text-muted); font-family: var(--mono); }

/* ============ TOASTS ============ */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 6px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  font-size: 14px;
  font-weight: 600;
  animation: slideIn 0.25s ease;
  max-width: 320px;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.info { background: var(--primary); }
@keyframes slideIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }

/* ============ MODAL ============ */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#modal-overlay.open { display: flex; }
.modal {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}
.modal h3 { font-size: 18px; margin-bottom: 8px; }
.modal p { font-size: 14px; color: var(--text-muted); margin-bottom: 20px; }
.modal .modal-actions { display: flex; gap: 12px; justify-content: flex-end; }

/* ============ PLAYER DETAILS ============ */
.stat-grid { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.stat-box { flex: 1 1 80px; text-align: center; background: #fafafa; border-radius: 6px; padding: 10px 6px; }
.stat-box .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.stat-box .value { font-family: var(--mono); font-weight: 700; font-size: 22px; }
.venue-card-leeward { border-top: 4px solid var(--primary); }
.venue-card-aiea { border-top: 4px solid var(--accent); }
.game-history { max-height: 320px; overflow-y: auto; }
.sparkline { display: block; margin: 8px 0; }
.trend-up { color: var(--green); font-weight: 700; }
.trend-down { color: var(--red); font-weight: 700; }
.trend-flat { color: var(--text-muted); font-weight: 700; }

.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; flex-wrap: wrap; }
.perf-badge { padding: 4px 14px; border-radius: 14px; font-size: 13px; font-weight: 800; letter-spacing: 0.5px; white-space: nowrap; }
.perf-badge.hot { background: #ffe9d6; color: #e65100; }
.perf-badge.up { background: #e6f4e7; color: #2e7d32; }
.perf-badge.steady { background: #ececec; color: #666; }
.perf-badge.down { background: #fdecea; color: #c62828; }
.stat-box .sub { font-size: 11px; color: var(--text-muted); font-family: var(--mono); margin-top: 2px; }
.stat-box[title] { cursor: help; }
.stat-box .info { font-size: 10px; color: var(--primary); opacity: 0.7; }
.lastday { background: #f0fbfa; border: 1px solid #d3efed; border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; }
.lastday .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 2px; }
.lastday .scores { font-family: var(--mono); font-weight: 700; font-size: 19px; letter-spacing: 1px; }
.lastday strong { font-family: var(--mono); color: var(--text); }
.trend-graph { width: 100%; height: auto; display: block; }
.graph-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); margin: 2px 2px 12px; }
.trend-box { border-left: 4px solid var(--border); border-radius: 4px; background: #fafafa; padding: 10px 14px; margin-bottom: 12px; }
.trend-title { font-weight: 800; font-size: 15px; margin-bottom: 4px; }
.trend-line { font-size: 13px; color: var(--text-muted); }
.trend-line strong { font-family: var(--mono); color: var(--text); font-size: 14px; }
.trend-diff { font-size: 13px; font-weight: 700; margin-top: 4px; }

/* ============ SCORE SHEET (screen + print) ============ */
.paper {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 24px;
  max-width: 820px;
  margin: 0 auto;
}
.paper h2.sheet-title { text-align: center; font-size: 24px; letter-spacing: 2px; margin-bottom: 4px; }
.paper .sheet-sub { display: flex; justify-content: space-between; font-size: 15px; margin: 10px 8px 14px; font-weight: 600; }
.sheet-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sheet-table th, .sheet-table td { border: 1px solid #999; padding: 6px 4px; text-align: center; white-space: nowrap; }
.sheet-table thead th { background: #efefef; color: var(--text); text-transform: none; letter-spacing: 0; }
.sheet-table td.pname { text-align: left; font-weight: 700; padding-left: 8px; }
.sheet-table td.mono { font-family: var(--mono); font-weight: 700; }
.sheet-table td.hcell { color: #555; font-family: var(--mono); }
.sheet-table tr.total-row td { font-weight: 700; background: #f5f5f5; font-family: var(--mono); }
.sheet-table tbody tr:hover { background: inherit; }
.sheet-table tbody tr:nth-child(even) { background: inherit; }
.sheet-foot { margin-top: 10px; font-size: 11px; color: var(--text-muted); text-align: right; }

/* ============ SETTINGS ============ */
.settings-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.danger-zone { border: 1px solid var(--red); }
.danger-zone h2 { color: var(--red); }

footer {
  text-align: center;
  padding: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 767px) {
  header h1 { font-size: 20px; }
  nav button { font-size: 10px; }
  main { padding: 8px; }
  .card { padding: 12px; }
  th, td { padding: 8px 6px; font-size: 13px; }
  input[type="number"].score-input { width: 58px; }
  .paper { padding: 10px; }
}

.print-only { display: none; }

/* ============ PRINT ============ */
@media print {
  .print-only { display: block; text-align: center; margin-bottom: 12px; }
  .print-only h2 { font-size: 22px; letter-spacing: 1px; }
  header, nav, footer, .no-print, #toast-container, #modal-overlay, #player-print-frame, #sheet-print-frame { display: none !important; }
  body { background: #fff; }
  main { max-width: none; padding: 0; }
  .card, .paper { box-shadow: none; border: none; margin: 0; max-width: none; }
  .sheet-table th, .sheet-table td { border: 1px solid #000; }

  /* Last 18 Games: print the full table, never the on-screen scrollable/clipped view */
  .game-history { max-height: none !important; height: auto !important; overflow: visible !important; }
  /* Drop interactive-only bits: delete (X) buttons and their column */
  #player-venue-cards .btn-danger,
  #player-venue-cards .game-history thead th:last-child,
  #player-venue-cards .game-history tbody td:last-child { display: none !important; }
  /* Stack the venue cards and keep each section + each row whole across page breaks */
  .flex-row { display: block !important; }
  .card, .venue-card-leeward, .venue-card-aiea { break-inside: avoid; page-break-inside: avoid; }
  tr { break-inside: avoid; page-break-inside: avoid; }
}
