:root {
  --dark-team: #0f172a;
  --white-team: #ffffff;
  --accent-blue: #2563eb;
  --border-color: #cbd5e1;
  --key-bg: #f8fafc;
  --key-active: #cbd5e1;
  --warn-yellow: #fef08a;
  --foul-red: #ef4444;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  background: #f1f5f9;
  color: #0f172a;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  user-select: none;
}

/* Offline Notice Banner */
#offlineBanner {
  background: #ea580c;
  color: white;
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  z-index: 250;
}

/* Modal Overlay for Timeouts */
.modal-overlay {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  z-index: 300;
  justify-content: center;
  align-items: center;
  padding: 20px;
}
.modal-card {
  background: white;
  border-radius: 8px;
  width: 100%;
  max-width: 340px;
  padding: 16px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 800;
}
.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.to-btn {
  padding: 12px;
  border-radius: 6px;
  border: none;
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  color: white;
}
.to-w {
  background: #94a3b8;
  color: #0f172a;
}
.to-d {
  background: #334155;
}
.close-modal {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: #64748b;
}

/* 3-FOUL ALERT BANNER */
#foulAlertBanner {
  background: #b91c1c;
  color: white;
  padding: 8px;
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
  z-index: 200;
  animation: flash 1s infinite alternate;
  cursor: pointer;
}
@keyframes flash {
  from { opacity: 0.85; }
  to { opacity: 1; }
}

/* TOP HEADER */
.top-header {
  background: #0f172a;
  color: white;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  z-index: 20;
}
.meta-title {
  font-size: 0.75rem;
  color: #94a3b8;
  margin-bottom: 2px;
  font-weight: 600;
}
.scoreboard {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 1.15rem;
}
.period-pill {
  font-size: 0.7rem;
  background: var(--accent-blue);
  padding: 2px 6px;
  border-radius: 4px;
}
.period-pill.ot {
  background: #9333ea;
}
.period-pill.final {
  background: #16a34a;
}

.sprint-strip {
  display: flex;
  gap: 4px;
  font-size: 0.65rem;
  color: #94a3b8;
  align-items: center;
  margin-top: 3px;
}
.sprint-pill {
  background: #1e293b;
  padding: 1px 5px;
  border-radius: 3px;
  cursor: pointer;
}
.sprint-pill.won {
  color: #38bdf8;
  font-weight: 700;
  border: 1px solid #0284c7;
}

.header-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}
.h-btn {
  border: none;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  color: white;
}
.btn-to { background: #d97706; }
.btn-eoq { background: #475569; border: 1px solid #64748b; }
.btn-share { background: #0284c7; }
.btn-print { background: #1e293b; border: 1px solid #475569; }

/* TABS */
.tab-bar {
  display: none;
  background: white;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  overflow-x: auto;
  white-space: nowrap;
}
body.sheet-mode .tab-bar {
  display: flex;
}
.tab {
  flex: 1;
  text-align: center;
  padding: 9px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #64748b;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.tab.active {
  color: var(--accent-blue);
  border-bottom-color: var(--accent-blue);
}

/* CONTENT AREA */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  padding-bottom: 20px;
}
.panel {
  background: white;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  overflow: hidden;
  margin-bottom: 12px;
}

#view-log {
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  text-align: center;
}
th {
  background: #f8fafc;
  padding: 7px 4px;
  font-size: 0.7rem;
  color: #475569;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 2;
}
td {
  padding: 7px 4px;
  border-bottom: 1px solid #e2e8f0;
}
td[contenteditable="true"] {
  outline: none;
  user-select: text;
}
td[contenteditable="true"]:focus {
  background: #e0f2fe;
}
.cell-left {
  text-align: left;
  padding-left: 8px;
}

tr.soft-deleted {
  opacity: 0.35;
  background: #f1f5f9;
  text-decoration: line-through;
}
.del-col {
  width: 32px;
}
.undo-btn {
  border: none;
  background: none;
  color: #2563eb;
  font-size: 1.1rem;
  cursor: pointer;
  font-weight: bold;
}
.del-btn {
  border: none;
  background: none;
  color: #94a3b8;
  font-size: 1.1rem;
  cursor: pointer;
  font-weight: bold;
}

.row-eoq {
  background: #e2e8f0;
  font-weight: 700;
  color: #334155;
}
.row-unclear {
  background: var(--warn-yellow);
}

/* RESULT SUMMARY TABLE */
.result-header {
  padding: 8px 10px;
  background: #f1f5f9;
  font-size: 0.75rem;
  font-weight: 800;
  color: #334155;
  border-bottom: 1px solid #cbd5e1;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.result-table td {
  font-weight: 800;
  font-size: 0.9rem;
  padding: 8px;
  border: 1px solid #e2e8f0;
}
.roster-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}
.mini-btn {
  border: 1px solid #cbd5e1;
  background: white;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  cursor: pointer;
}
.mini-btn:hover {
  background: #f1f5f9;
}

/* FOULS UI: Mobile Badge vs Print Boxes */
.foul-badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 4px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 800;
  background: #e2e8f0;
  color: #334155;
}
.foul-badge.danger {
  background: #fee2e2;
  color: #991b1b;
}
.foul-badge.disqualified {
  background: #b91c1c;
  color: white;
}
.print-fouls-container {
  display: none;
}

/* HIDE/UNHIDE TOGGLE BAR */
.open-pad-bar {
  display: none;
  background: #2563eb;
  color: white;
  text-align: center;
  padding: 14px;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
  flex-shrink: 0;
  z-index: 150;
}
body.sheet-mode .open-pad-bar {
  display: block;
}

/* DOCKED ENTRY PAD */
.entry-drawer {
  background: white;
  border-top: 2px solid var(--border-color);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 6px env(safe-area-inset-bottom, 6px) 6px;
  flex-shrink: 0;
  z-index: 100;
}
body.sheet-mode .entry-drawer {
  display: none;
}

.drawer-handle {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px 0;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  color: #64748b;
  font-size: 0.7rem;
  font-weight: 800;
  cursor: pointer;
  text-transform: uppercase;
}

.voice-bar {
  background: linear-gradient(135deg, #1d4ed8, #2563eb);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px;
  font-size: 0.85rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
  cursor: pointer;
}
.voice-pulse {
  width: 8px;
  height: 8px;
  background: #ef4444;
  border-radius: 50%;
}
.voice-bar.recording {
  background: #dc2626;
}
.voice-bar.recording .voice-pulse {
  background: white;
}
.voice-bar.offline {
  background: #94a3b8;
  cursor: not-allowed;
  opacity: 0.8;
}
.voice-bar.offline .voice-pulse {
  display: none;
}

.readouts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 2px;
}
.readout-card {
  border: 2px solid var(--border-color);
  background: #f8fafc;
  border-radius: 6px;
  padding: 4px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.readout-card.active {
  border-color: var(--accent-blue);
  background: #eff6ff;
}
.readout-card .tag {
  font-size: 0.68rem;
  font-weight: 800;
  color: #64748b;
}
.readout-card .val {
  font-size: 1.35rem;
  font-weight: 800;
}

.full-numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.num-key {
  background: var(--key-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 11px 0;
  font-size: 1.4rem;
  font-weight: 800;
  text-align: center;
  color: #0f172a;
  cursor: pointer;
  user-select: none;
}
.num-key:active {
  background: var(--key-active);
}
.num-key.util {
  font-size: 0.88rem;
  background: #e2e8f0;
  color: #475569;
  display: flex;
  align-items: center;
  justify-content: center;
}
.num-key.next-btn {
  background: #eff6ff;
  color: var(--accent-blue);
  border-color: #bfdbfe;
  font-size: 0.85rem;
}

.action-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.action-row {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr;
  gap: 4px;
}
.act-btn {
  border: none;
  border-radius: 6px;
  padding: 10px 0;
  font-size: 0.85rem;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}
.act-btn span.sub {
  font-size: 0.65rem;
  opacity: 0.85;
}
.btn-d-goal { background: #064e3b; color: white; }
.btn-d-eject { background: #7f1d1d; color: white; }
.btn-d-pen { background: #7c2d12; color: white; }
.btn-w-goal { background: #dcfce7; color: #14532d; }
.btn-w-eject { background: #fee2e2; color: #7f1d1d; }
.btn-w-pen { background: #ffedd5; color: #7c2d12; }

/* ----------------------------------------- */
/* PRINT STYLES (MATCHES NFHS OFFICIAL PAPER) */
/* ----------------------------------------- */
@media print {
  body {
    background: white;
    color: black;
    display: block;
    height: auto;
    overflow: visible;
    font-family: Arial, sans-serif;
  }
  .top-header, .tab-bar, .open-pad-bar, .entry-drawer, #foulAlertBanner, #offlineBanner, .modal-overlay, .del-col, .roster-actions {
    display: none !important;
  }
  
  @page {
    size: landscape;
    margin: 0.8cm;
  }
  .content-area {
    padding: 0;
    overflow: visible;
    display: grid;
    grid-template-areas: 
      "header header header"
      "dark activity white"
      "dark result white";
    grid-template-columns: 1.25fr 1.9fr 1.25fr;
    gap: 8px;
  }
  
  .panel {
    display: block !important;
    border: 1px solid black;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    break-inside: avoid;
  }
  
  #printHeader {
    display: flex !important;
    grid-area: header;
    border: 1px solid black;
    padding: 4px 8px;
    font-weight: bold;
    font-size: 0.8rem;
    justify-content: space-between;
    margin-bottom: 4px;
  }
  
  #view-dark { grid-area: dark; }
  #view-log { grid-area: activity; max-height: none; overflow: visible; }
  #view-white { grid-area: white; }
  #view-result { grid-area: result; margin-top: 6px; }
  
  table {
    border-collapse: collapse;
    font-size: 0.72rem;
  }
  th, td {
    border: 1px solid black;
    padding: 3px 2px;
    text-align: center;
  }
  th {
    background: #f0f0f0 !important;
    color: black;
    -webkit-print-color-adjust: exact;
  }
  .result-header {
    font-size: 0.75rem;
    border-bottom: 1px solid black;
    background: #e0e0e0 !important;
    color: black;
    -webkit-print-color-adjust: exact;
  }
  
  /* Print Foul Boxes (3 official NFHS boxes) */
  .foul-badge {
    display: none !important;
  }
  .print-fouls-container {
    display: flex !important;
    justify-content: center;
    gap: 2px;
  }
  .print-foul-box {
    display: inline-block;
    width: 18px;
    height: 16px;
    border: 1px solid black;
    font-size: 0.65rem;
    font-weight: bold;
    line-height: 15px;
  }

  tr.soft-deleted {
    display: none !important;
  }
}
