/* VBallScore — shared styles. Mobile-first, big touch targets, no frameworks. */

:root {
  --bg: #0a1f3a;
  --fg: #fff;
  --gold: #f5a623;
  --blue: #3567c7;
  --orange: #e58a2b;
  --error: #ff5252;
  --chrome: rgba(0, 0, 0, 0.35);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  font-family: inherit;
  border: 0;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

/* ===== SPLASH ===== */
body.splash {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1rem;
}
body.splash main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  max-width: 30rem;
}
.wordmark {
  font-size: clamp(2.5rem, 12vw, 5rem);
  margin: 0;
  letter-spacing: -0.02em;
  font-weight: 900;
}
.tagline {
  font-size: clamp(1rem, 3vw, 1.25rem);
  opacity: 0.75;
  margin: 0 0 1rem;
}
.cta {
  font-size: 1.25rem;
  font-weight: 700;
  padding: 1rem 2.5rem;
  border-radius: 999px;
  background: var(--gold);
  color: #1a1a1a;
  min-width: 14rem;
  transition: transform 0.1s ease, opacity 0.2s ease;
}
.cta:active { transform: scale(0.97); }
.cta:disabled { opacity: 0.5; cursor: wait; }
.error {
  color: var(--error);
  font-size: 0.9rem;
  margin: 0.5rem 0 0;
}

.recent {
  margin-top: 2rem;
  width: 100%;
  max-width: 28rem;
  text-align: left;
}
.recent-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.6;
  margin: 0 0 0.5rem;
  font-weight: 700;
}
.recent-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem;
  display: grid;
  gap: 0.4rem;
}
.recent-list li a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--fg);
  text-decoration: none;
  font-size: 1rem;
}
.recent-list li a:active { background: rgba(255, 255, 255, 0.16); }
.recent-list .rid {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 700;
  letter-spacing: 0.05em;
}
.recent-list .rage {
  font-size: 0.85rem;
  opacity: 0.65;
}
.text-btn {
  background: none;
  color: var(--fg);
  opacity: 0.5;
  font-size: 0.85rem;
  text-decoration: underline;
  padding: 0.25rem 0;
}
.text-btn:hover { opacity: 0.85; }

/* ===== MATCH HEADER ===== */
body.match {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  overflow: hidden;
}
.match-header {
  background: var(--chrome);
  padding: 0.5rem 1rem;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 0.5rem;
  align-items: center;
}
.match-header .back {
  color: var(--fg);
  text-decoration: none;
  font-weight: 800;
  font-size: 0.9rem;
  letter-spacing: 0.05em;
}
.match-header .match-id,
.match-header .match-title {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.85rem;
  opacity: 0.7;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.match-header .match-title.has-title {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  opacity: 1;
}
body.match[data-role="scorer"] .match-title { cursor: pointer; }
.match-header .presence {
  font-size: 0.85rem;
  opacity: 0.85;
}
.icon-btn {
  background: rgba(255, 255, 255, 0.15);
  color: var(--fg);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.3); }

/* ===== SCOREBOARD (two color blocks) ===== */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  overflow: hidden;
}
.team {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-width: 0;
  padding: 1rem;
  text-align: center;
}
.team-a { background: var(--orange); }
.team-b { background: var(--blue); }

.team-name {
  margin: 0;
  font-size: clamp(1rem, 4vw, 1.75rem);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: text;
}
.score {
  font-size: clamp(8rem, 35vw, 18rem);
  font-weight: 900;
  line-height: 0.9;
  color: #fff;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
}
.sets {
  font-size: 1rem;
  opacity: 0.8;
}
.plus, .minus {
  position: absolute;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 1.5rem;
  font-weight: 800;
  display: grid;
  place-items: center;
}
.plus { top: 0.75rem; right: 0.75rem; }
.minus { bottom: 0.75rem; right: 0.75rem; }
.plus:active, .minus:active { background: rgba(255, 255, 255, 0.45); transform: scale(0.95); }

.swap {
  background: var(--chrome);
  color: #fff;
  width: 3rem;
  font-size: 1.5rem;
  display: grid;
  place-items: center;
}
.swap:active { background: rgba(0, 0, 0, 0.55); }

/* Score-change animations: pulse + floating delta indicator. */
@keyframes scorePop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}
.score.pop { animation: scorePop 0.35s ease-out; }

@keyframes floatUp {
  0%   { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -4rem); }
}
.float-indicator {
  position: absolute;
  top: 35%;
  left: 50%;
  transform: translate(-50%, 0);
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 900;
  color: rgba(255, 255, 255, 0.95);
  pointer-events: none;
  animation: floatUp 0.85s ease-out forwards;
  z-index: 5;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.float-indicator.minus {
  color: rgba(255, 220, 220, 0.85);
  font-size: clamp(1.5rem, 5vw, 2.5rem);
}

/* Watcher mode: hide score-change controls */
body.match[data-role="watcher"] .plus,
body.match[data-role="watcher"] .minus,
body.match[data-role="watcher"] .swap,
body.match[data-role="watcher"] .match-footer .actions,
body.match[data-role="watcher"] .team-name { cursor: default; }
body.match[data-role="watcher"] .plus,
body.match[data-role="watcher"] .minus,
body.match[data-role="watcher"] .swap,
body.match[data-role="watcher"] .match-footer .actions { display: none; }

/* ===== FOOTER ===== */
.match-footer {
  background: var(--chrome);
  padding: 0.5rem 1rem;
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.game-history {
  font-size: 0.85rem;
  opacity: 0.85;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  flex: 1 1 auto;
  min-width: 0;
}
.match-footer .actions {
  display: flex;
  gap: 0.5rem;
}
.action {
  background: rgba(255, 255, 255, 0.15);
  color: var(--fg);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
}
.action:active { background: rgba(255, 255, 255, 0.3); }
.action.danger { background: rgba(255, 82, 82, 0.25); }
.action.danger:active { background: rgba(255, 82, 82, 0.5); }

/* ===== MATCH-END CELEBRATION OVERLAY ===== */
.match-ended-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10, 31, 58, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 1.5rem;
  animation: fadeIn 0.4s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.end-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 2rem 1.5rem;
  max-width: 30rem;
  width: 100%;
  text-align: center;
  color: var(--fg);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.end-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  opacity: 0.65;
  margin: 0;
}
.end-winner {
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 900;
  margin: 0;
  line-height: 1.1;
  color: var(--gold);
}
.end-winner.tie { color: var(--fg); }
.end-sets {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.end-team-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  font-size: 1.1rem;
}
.end-team-row.winner {
  background: rgba(245, 166, 35, 0.2);
  border-left: 4px solid var(--gold);
}
.end-team-name { font-weight: 600; }
.end-team-sets {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.5rem;
}
.end-history-list {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.9rem;
  opacity: 0.7;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}
.end-duration {
  font-size: 0.85rem;
  opacity: 0.55;
}
.end-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

/* ===== CONNECTION STATUS ===== */
.connection-status {
  position: fixed;
  bottom: 0.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: var(--fg);
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 100;
}

/* ===== RESPONSIVE: narrow phones in portrait ===== */
@media (max-width: 480px) and (orientation: portrait) {
  .scoreboard {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto 1fr;
  }
  .swap {
    width: 100%;
    height: 2.5rem;
  }
}

/* ===== CAMERA MODE =====
   Activated by adding class "camera-mode" to body. The <video> fills
   the screen behind everything; the scoreboard shrinks to a compact
   bottom strip; chrome (header, footer) becomes semi-transparent so
   the camera feed shows through.
   When the user (or their phone's screen recorder) records the screen,
   the score is "burned in" to the captured video. */
.camera-container {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: #000;
}
.camera-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.camera-exit {
  position: absolute;
  top: env(safe-area-inset-top, 0.5rem);
  right: 0.75rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 1.5rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  z-index: 20;
}
.camera-exit:active { background: rgba(0, 0, 0, 0.85); }

body.camera-mode {
  background: #000;
}
body.camera-mode .match-header,
body.camera-mode .match-footer {
  background: rgba(0, 0, 0, 0.4);
  position: relative;
  z-index: 10;
}
/* In camera mode: scoreboard becomes a translucent overlay docked to bottom
   so the camera fills the upper area. Team color blocks stay vivid for
   on-camera readability but are sized down. */
body.camera-mode .scoreboard {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  height: 30vh;
  grid-template-columns: 1fr auto 1fr;
}
body.camera-mode .team {
  background-blend-mode: normal;
}
body.camera-mode .team-a,
body.camera-mode .team-b {
  /* Slightly translucent so a hint of camera shows through the edges */
  filter: brightness(1.05);
}
body.camera-mode .score {
  font-size: clamp(4rem, 18vw, 8rem);
}
body.camera-mode .team-name {
  font-size: clamp(0.9rem, 3vw, 1.25rem);
}
body.camera-mode .sets {
  display: none;
}
body.camera-mode .match-footer {
  display: none;
}
body.camera-mode .match-header .back,
body.camera-mode .match-header .match-id {
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}
.camera-btn {
  background: rgba(245, 166, 35, 0.85) !important;
  color: #1a1a1a !important;
}
.camera-btn:active { background: rgba(245, 166, 35, 1) !important; }
body.camera-mode .camera-btn {
  background: rgba(255, 82, 82, 0.85) !important;
  color: #fff !important;
}
body.camera-mode .camera-btn::before { content: "Exit "; }
