/* ==========================================================================
   Bingham Mighty Mite B2 -- design system
   Sideline tool: bright sun, one hand, mid-practice. Legibility and tap
   target size are functional requirements here, not aesthetic choices.
   ========================================================================== */

:root {
  --bg: #14231B;
  --surface: #1C2E22;
  --surface-2: #24392B;
  --text: #F4F6F1;
  --text-muted: #8C9C90;
  --accent: #E8B93E;
  --accent-text: #14231B;
  --alert: #C1443C;
  --header-bg: #0047AB;
  --header-text-muted: rgba(244, 246, 241, 0.72);

  --font-display: 'Oswald', 'Arial Narrow', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --tap: 44px;
  --radius: 10px;
  --radius-lg: 16px;
  --gap: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin: 0 0 8px 0;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; color: var(--accent); }
h3 { font-size: 1rem; color: var(--text-muted); }

p, label, span, div { color: inherit; }

a { color: var(--accent); }

.num, .stat, .score, .jersey {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* -------------------------------------------------------------------- */
/* Yard-line divider -- the signature element, used everywhere instead  */
/* of <hr>.                                                             */
/* -------------------------------------------------------------------- */
.yard-line {
  border: none;
  border-top: 2px dashed var(--text-muted);
  opacity: 0.35;
  margin: 16px 0;
}

/* -------------------------------------------------------------------- */
/* Layout                                                                */
/* -------------------------------------------------------------------- */
#app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--header-bg);
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#help-btn {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: transparent;
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}

#app-header .team-name {
  font-family: var(--font-display);
  font-size: 1.3rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text);
}

#app-header .conference {
  color: var(--header-text-muted);
  font-size: 0.8rem;
}

main#view-root {
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

/* -------------------------------------------------------------------- */
/* Bottom tab bar -- primary nav, thumb-reachable                       */
/* -------------------------------------------------------------------- */
#tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  background: var(--surface);
  border-top: 1px solid rgba(140, 156, 144, 0.2);
  padding-bottom: env(safe-area-inset-bottom);
}

#tab-bar button {
  flex: 1;
  min-height: calc(var(--tap) + 8px);
  background: none;
  border: none;
  border-right: 1px solid rgba(140, 156, 144, 0.15);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 10px 4px 8px;
  cursor: pointer;
  white-space: normal;
  line-height: 1.15;
}

#tab-bar button:last-child { border-right: none; }

#tab-bar button.active {
  color: var(--accent);
  box-shadow: inset 0 3px 0 var(--accent);
}

#tab-bar button:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* -------------------------------------------------------------------- */
/* Sub-tabs (segmented control used within a primary tab)               */
/* -------------------------------------------------------------------- */
.subtabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
}

.subtabs button {
  flex: none;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(140, 156, 144, 0.3);
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.subtabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

/* -------------------------------------------------------------------- */
/* Cards                                                                 */
/* -------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: var(--gap);
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card-title {
  font-weight: 700;
  font-size: 1.02rem;
}

.card-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--surface-2);
  color: var(--text-muted);
}

.badge.live { background: var(--alert); color: var(--text); }
.badge.final { background: var(--surface-2); color: var(--text); }
.badge.upcoming { background: var(--surface-2); color: var(--accent); }
.badge.inactive { background: transparent; border: 1px solid var(--text-muted); color: var(--text-muted); }

.jersey-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 6px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 700;
}

/* -------------------------------------------------------------------- */
/* Buttons & form controls                                              */
/* -------------------------------------------------------------------- */
button, input, select, textarea {
  font-family: var(--font-body);
  font-size: 1rem;
}

/* Instant press feedback on every button -- fires on touchdown, before any
   JS/state-driven re-render happens. Sideline taps need to feel registered
   immediately, not just once the screen catches up. */
button {
  transition: transform 0.08s ease, filter 0.08s ease;
}

button:not(:disabled):active {
  transform: scale(0.93);
  filter: brightness(1.18);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius);
  border: none;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--alert); color: var(--text); }
.btn.ghost { background: transparent; border: 1px solid rgba(140, 156, 144, 0.4); color: var(--text-muted); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  border-radius: var(--radius);
  background: var(--surface-2);
  border: none;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(140, 156, 144, 0.3);
  background: var(--surface);
  color: var(--text);
}

.field textarea { min-height: 90px; resize: vertical; }

.field input::placeholder, .field textarea::placeholder { color: var(--text-muted); opacity: 0.7; }

.search-box input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(140, 156, 144, 0.3);
  background: var(--surface);
  color: var(--text);
  margin-bottom: var(--gap);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 16px;
}

/* -------------------------------------------------------------------- */
/* PIN screen                                                            */
/* -------------------------------------------------------------------- */
#pin-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

#pin-screen h1 { font-size: 2rem; }

#pin-input {
  width: 220px;
  text-align: center;
  letter-spacing: 0.5em;
  font-size: 1.6rem;
  font-family: var(--font-display);
  padding: 14px;
  border-radius: var(--radius);
  border: 2px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  margin: 20px 0 10px;
}

#pin-error {
  color: var(--alert);
  font-weight: 600;
  min-height: 20px;
}

/* -------------------------------------------------------------------- */
/* Pending-write banner                                                  */
/* -------------------------------------------------------------------- */
#sync-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  text-align: center;
  padding: 8px 12px;
  font-weight: 700;
  font-size: 0.85rem;
  transform: translateY(-100%);
  transition: transform 0.2s ease;
}

#sync-banner.show { transform: translateY(0); }
#sync-banner.pending { background: var(--alert); color: var(--text); }
#sync-banner.saved { background: var(--accent); color: var(--accent-text); }

/* -------------------------------------------------------------------- */
/* Depth chart                                                           */
/* -------------------------------------------------------------------- */
.depth-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--surface-2);
  margin-bottom: 6px;
}

.depth-slot .order-num {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--accent);
  min-width: 22px;
}

.depth-slot .name { flex: 1; font-weight: 600; }

.depth-slot .reorder-btns { display: flex; gap: 4px; }
.depth-slot .reorder-btns button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: var(--surface);
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

/* -------------------------------------------------------------------- */
/* Playbook                                                              */
/* -------------------------------------------------------------------- */
.play-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.play-thumb {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: none;
  text-align: left;
  padding: 0;
}

.play-thumb img, .play-thumb .thumb-fallback {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  background: var(--surface-2);
  display: block;
}

.play-thumb .thumb-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-family: var(--font-display);
}

.play-thumb .meta { padding: 8px 10px; }
.play-thumb .meta .name { font-weight: 700; font-size: 0.9rem; }
.play-thumb .tags { color: var(--text-muted); font-size: 0.72rem; margin-top: 2px; }

#canvas-wrap {
  position: relative;
  width: 100%;
  background: #0f1c14;
  border-radius: var(--radius);
  overflow: hidden;
  touch-action: none;
}

#play-canvas { display: block; width: 100%; height: auto; touch-action: none; }

.canvas-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

.canvas-toolbar button.tool-active { background: var(--accent); color: var(--accent-text); }

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.color-swatch.selected { border-color: var(--text); }

/* -------------------------------------------------------------------- */
/* Live game mode -- full screen, minimal chrome, one tap matters most   */
/* -------------------------------------------------------------------- */
#live-game-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 12px 12px;
}

.live-scoreboard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 6px 16px;
}

.live-scoreboard .score {
  font-family: var(--font-display);
  font-size: 2.6rem;
  font-variant-numeric: tabular-nums;
}

.live-scoreboard .team-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.live-score-btns { display: flex; gap: 6px; margin-top: 4px; }
.live-score-btns button {
  min-width: 40px;
  min-height: 40px;
  border-radius: 8px;
  border: none;
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 700;
  font-size: 1.1rem;
}

#lg-toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  left: 50%;
  z-index: 90;
  transform: translateX(-50%) translateY(-16px);
  background: var(--accent);
  color: var(--accent-text);
  padding: 9px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  max-width: 90%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

#lg-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.player-tap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  overflow-y: auto;
  flex: 1;
  padding-bottom: 8px;
}

.player-tap-btn {
  min-height: 64px;
  border-radius: var(--radius);
  border: 2px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}

.player-tap-btn .jersey { font-family: var(--font-display); font-size: 1.3rem; color: var(--accent); }
.player-tap-btn .pname { font-size: 0.68rem; color: var(--text-muted); text-align: center; }

.player-tap-btn.flash {
  border-color: var(--accent);
  background: var(--accent);
  transition: background 0.1s ease, border-color 0.1s ease;
}
.player-tap-btn.flash .jersey,
.player-tap-btn.flash .pname { color: var(--accent-text); }

.stat-type-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

.stat-type-row button {
  min-height: var(--tap);
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.stat-type-row button.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* -------------------------------------------------------------------- */
/* Live game: yards/direction/play detail sheet                         */
/* -------------------------------------------------------------------- */
#lg-sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 85;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

#lg-sheet-card {
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  margin: 0;
  padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
}

.yard-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.yard-chip-row button {
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 2px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.yard-chip-row button.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.direction-row {
  display: flex;
  gap: 8px;
}

.direction-row button {
  flex: 1;
  min-height: var(--tap);
  border-radius: var(--radius);
  border: 2px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.direction-row button.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* -------------------------------------------------------------------- */
/* Assistant floating action button                                     */
/* -------------------------------------------------------------------- */
#assistant-fab {
  position: fixed;
  right: 14px;
  bottom: calc(64px + env(safe-area-inset-bottom) + 14px);
  z-index: 35;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

#assistant-fab .fab-icon { font-size: 1.3rem; line-height: 1; }
#assistant-fab .fab-label {
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

#assistant-fab.active { background: var(--header-bg); color: var(--text); }

/* -------------------------------------------------------------------- */
/* AI Assistant chat                                                     */
/* -------------------------------------------------------------------- */
#assistant-view { display: flex; flex-direction: column; height: calc(100dvh - 140px); }

.chat-log { flex: 1; overflow-y: auto; padding-right: 2px; }

.chat-msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.chat-msg.user { background: var(--accent); color: var(--accent-text); margin-left: auto; }
.chat-msg.assistant { background: var(--surface); }
.chat-msg.action { background: var(--surface-2); border-left: 3px solid var(--accent); font-size: 0.9rem; }
.chat-msg.error { background: rgba(193, 68, 60, 0.2); border-left: 3px solid var(--alert); }

.chat-input-row { display: flex; gap: 8px; padding-top: 10px; }
.chat-input-row textarea { flex: 1; min-height: var(--tap); max-height: 120px; }

.ai-action-item { border-bottom: 1px dashed rgba(140,156,144,0.25); padding: 10px 0; }
.ai-action-item:last-child { border-bottom: none; }

/* -------------------------------------------------------------------- */
/* Print (Depth Chart)                                                   */
/* -------------------------------------------------------------------- */
@media print {
  #app-header, #tab-bar, #sync-banner, .no-print { display: none !important; }
  body { padding-bottom: 0; background: #fff; color: #000; }
  main#view-root { max-width: none; padding: 0; }
  .card { background: #fff; border: 1px solid #999; break-inside: avoid; }
  .depth-slot { background: #f0f0f0; color: #000; }
  .depth-slot .order-num { color: #000; }
}

@media (max-width: 380px) {
  .live-scoreboard .score { font-size: 2.1rem; }
  #app-header .team-name { font-size: 1.1rem; }
}
