:root {
  --bg: #0d1117;
  --panel: #161b26;
  --panel-2: #1d2433;
  --line: #2a3347;
  --text: #e6edf3;
  --muted: #8b96a8;
  --home: #4da3ff;
  --home-dim: #1f3d61;
  --away: #ff6b57;
  --away-dim: #5a2620;
  --accent: #35d07f;
  --warn: #ffb347;
  --danger: #ff5d5d;
  --pitch-green: #14532d;
  --pitch-green-2: #166534;
  --radius: 12px;
  font-size: 15px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  height: 100%;
  overscroll-behavior: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  gap: 8px;
}

/* ---------- Scoreboard ---------- */
#scoreboard {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px 8px;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.team-name { font-weight: 700; font-size: 0.95rem; }
.team-name.home { color: var(--home); }
.team-name.away { color: var(--away); }

.score {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.15rem;
  background: var(--panel-2);
  padding: 2px 10px;
  border-radius: 8px;
}

.clock {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
  font-size: 1.05rem;
}

.momentum-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.momentum-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  flex-shrink: 0;
}

.momentum-bar {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: var(--panel-2);
  display: flex;
  overflow: hidden;
}

.momentum-home {
  background: linear-gradient(90deg, var(--home), #7cc0ff);
  width: 50%;
  transition: width 0.8s ease;
}

.momentum-away {
  background: linear-gradient(90deg, #ff9a8b, var(--away));
  flex: 1;
  transition: width 0.8s ease;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.tactic-badge {
  font-size: 0.66rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  transition: all 0.3s ease;
}

.tactic-badge.hot {
  border-color: var(--accent);
  color: var(--accent);
  animation: badge-pop 0.5s ease;
}

@keyframes badge-pop {
  0% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* ---------- Pitch ---------- */
#pitch-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  aspect-ratio: 3 / 4;
  background: var(--pitch-green);
  flex-shrink: 0;
}

#pitch { width: 100%; height: 100%; display: block; }

#spectator-layer {
  position: absolute;
  top: 6px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  color: rgba(255,255,255,0.85);
  background: rgba(0,0,0,0.35);
  padding: 2px 8px;
  border-radius: 999px;
  pointer-events: none;
}

.reactions { min-width: 20px; }

#reorg-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 179, 71, 0.92);
  color: #3a2500;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  pointer-events: none;
}

#pitch-banner {
  position: absolute;
  top: 34px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 88%;
  background: rgba(13, 17, 23, 0.9);
  border: 1px solid var(--home);
  color: #cfe6ff;
  font-size: 0.74rem;
  font-weight: 600;
  text-align: center;
  padding: 6px 14px;
  border-radius: 10px;
  pointer-events: none;
  z-index: 6;
  animation: toast-in 0.25s ease;
}

#pitch-banner.warn { border-color: var(--warn); color: #ffe3bd; }

#goal-flash {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.8rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.8);
  background: rgba(13, 17, 23, 0.45);
  z-index: 8;
  pointer-events: none;
  animation: goal-pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1);
}

#goal-flash.conceded { color: var(--danger); font-size: 2rem; }

@keyframes goal-pop {
  0% { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

#chance-flash {
  position: absolute;
  top: 38%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.9);
  z-index: 7;
  pointer-events: none;
  animation: goal-pop 0.3s ease;
}

#chance-flash.danger { color: var(--danger); }

/* ---------- Toasts ---------- */
#toast-stack {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 5;
}

.toast {
  background: rgba(13, 17, 23, 0.88);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  color: var(--text);
  font-size: 0.78rem;
  padding: 8px 10px;
  border-radius: 8px;
  animation: toast-in 0.3s ease;
}

.toast.warn { border-left-color: var(--warn); }
.toast.danger { border-left-color: var(--danger); }

.toast.out { animation: toast-out 0.4s ease forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(-6px); }
}

/* ---------- Overlays ---------- */
#kickoff-overlay, #fulltime-overlay {
  position: absolute;
  inset: 0;
  background: rgba(13, 17, 23, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(3px);
}

.kickoff-card {
  text-align: center;
  padding: 24px;
  max-width: 320px;
}

.kickoff-card h1 { font-size: 1.3rem; margin-bottom: 10px; }
.kickoff-card p { color: var(--muted); font-size: 0.85rem; line-height: 1.5; margin-bottom: 16px; }

.kickoff-card button {
  background: var(--accent);
  color: #04301b;
  font-weight: 800;
  font-size: 1rem;
  border: none;
  padding: 12px 32px;
  border-radius: 999px;
  cursor: pointer;
}

.kickoff-card button:active { transform: scale(0.97); }

/* ---------- Meters ---------- */
#meters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.meter {
  display: grid;
  grid-template-columns: 62px 1fr 36px;
  align-items: center;
  gap: 6px;
}

.meter-label {
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.meter-track {
  height: 7px;
  border-radius: 4px;
  background: var(--panel-2);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  transition: width 0.7s ease, background 0.7s ease;
  background: var(--accent);
}

#meter-fatigue .meter-fill { background: var(--warn); }
#meter-risk .meter-fill { background: var(--danger); }
#meter-threat .meter-fill { background: var(--home); }

.meter-value {
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  text-align: right;
}

.meter.pulse .meter-fill { animation: meter-pulse 0.8s ease; }

@keyframes meter-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.7); }
}

/* ---------- Controls ---------- */
#controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.control-group { display: flex; flex-direction: column; gap: 4px; }

.control-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.control-name {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}

.cooldown-tag {
  font-size: 0.62rem;
  color: var(--warn);
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity 0.2s;
}

.control-group.cooling .cooldown-tag { opacity: 1; }

.option-row {
  display: flex;
  gap: 5px;
}

.opt-btn {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 8px 2px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  overflow: hidden;
}

.opt-btn.active {
  background: var(--home-dim);
  border-color: var(--home);
  color: #cfe6ff;
}

.opt-btn:active:not(:disabled) { transform: scale(0.96); }

.control-group.cooling .opt-btn:not(.active) {
  opacity: 0.38;
  pointer-events: none;
}

.opt-btn .cd-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: rgba(255, 179, 71, 0.15);
  width: 0%;
  pointer-events: none;
}

/* ---------- Feed ---------- */
#feed-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  min-height: 130px;
}

.feed-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}

#feed {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 190px;
  overflow-y: auto;
}

.feed-item {
  font-size: 0.78rem;
  line-height: 1.4;
  display: flex;
  gap: 8px;
  align-items: baseline;
  animation: feed-in 0.35s ease;
  border-left: 2px solid transparent;
  padding-left: 8px;
}

@keyframes feed-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.feed-min {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.7rem;
  flex-shrink: 0;
  width: 26px;
}

.feed-item.micro { color: var(--muted); }
.feed-item.stat { border-left-color: var(--warn); }
.feed-item.chance { border-left-color: var(--home); color: #cfe6ff; }
.feed-item.danger { border-left-color: var(--danger); color: #ffd7d7; }
.feed-item.goal {
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}
.feed-item.tactic { border-left-color: var(--home); }

.reason-tags { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-left: 4px; }

.reason-tag {
  font-size: 0.6rem;
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 4px;
  padding: 1px 5px;
  white-space: nowrap;
}

/* ---------- Explanation panel ---------- */
#explain-panel {
  position: fixed;
  inset: 0;
  background: rgba(13, 17, 23, 0.75);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  backdrop-filter: blur(2px);
}

.explain-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 480px;
  animation: sheet-up 0.3s ease;
}

@keyframes sheet-up {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.explain-card h3 { font-size: 0.95rem; margin-bottom: 12px; }

.causal-chain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}

.chain-step {
  background: var(--home-dim);
  border: 1px solid var(--home);
  color: #cfe6ff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}

.chain-arrow { color: var(--muted); font-size: 0.8rem; }

#explainText {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
  margin-bottom: 14px;
}

#explainClose {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 700;
  padding: 11px;
  border-radius: 10px;
  cursor: pointer;
}

.hidden { display: none !important; }
