/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #090e1a;
  --surface:   #0f1623;
  --surface2:  #18212f;
  --border:    #1e2d42;
  --text:      #e2eaf4;
  --text-muted:#6b80a0;
  --accent:    #38bdf8;
  --accent-dim:#0c3654;
  --home:      #3b82f6;
  --away:      #ef4444;
  --ball:      #fbbf24;
  --radius:    8px;
  --header-h:  52px;
  --sidebar-l: 220px;
  --sidebar-r: 270px;
}

html { height: 100%; }

body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── App Shell ── */
#app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
.header {
  height: var(--header-h);
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}
.header-left  { display: flex; align-items: center; gap: 12px; }
.logo         { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--accent); }
.logo-img     { height: 28px; width: auto; object-fit: contain; }
.header-subtitle { font-size: 0.72rem; color: var(--text-muted); border-left: 1px solid var(--border); padding-left: 12px; }
.header-right { display: flex; align-items: center; gap: 8px; }

.clip-badge {
  font-size: 0.75rem;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 99px;
  padding: 3px 10px;
  font-weight: 600;
}

/* ── Main Layout ── */
.main-layout {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  min-height: 0;
}

/* ── Sidebars ── */
.sidebar-left {
  width: var(--sidebar-l);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 12px;
}

.sidebar-right {
  width: var(--sidebar-r);
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 12px;
}

/* ── Pitch wrapper ── */
.pitch-wrapper {
  flex: 1;
  position: relative;
  background: #0a1a0a;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

#pitch-container {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
}

.pitch-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.88rem;
  pointer-events: none;
}

/* ── Controls ── */
.control-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 7px;
}
.control-section { display: flex; flex-direction: column; }

.select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 0.85rem;
  width: 100%;
  cursor: pointer;
  outline: none;
}
.select:focus { border-color: var(--accent); }

/* Formations */
.formation-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}
.formation-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 5px 4px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
}
.formation-btn:hover  { border-color: var(--accent); color: var(--text); }
.formation-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* Toggles */
.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.toggle { position: relative; display: inline-block; width: 36px; height: 20px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 2px; bottom: 2px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent-dim); border-color: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); background: var(--accent); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: var(--radius);
  font-size: 0.82rem; font-weight: 500;
  padding: 6px 12px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.15s;
  background: transparent; color: var(--text);
}
.btn:hover    { background: var(--surface2); }
.btn-ghost    { color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn-primary  {
  background: var(--accent);
  color: #03111f;
  border-color: var(--accent);
  font-weight: 700;
  justify-content: center;
}
.btn-primary:hover    { filter: brightness(1.1); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }
.btn-search { font-size: 0.9rem; padding: 10px 14px; }

/* Playback */
.playback-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}
.playback-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn-play {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #03111f;
  font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: filter 0.15s;
}
.btn-play:hover { filter: brightness(1.15); }
.btn-play.paused { background: var(--surface2); color: var(--accent); border: 1px solid var(--accent); }

.scrubber {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
.scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.frame-counter {
  font-size: 0.7rem;
  color: var(--text-muted);
  min-width: 40px;
  text-align: right;
}
.phase-hint {
  font-size: 0.7rem;
  color: var(--accent);
  min-height: 14px;
}

/* Loading overlay */
.pitch-overlay-msg {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 1rem;
  color: var(--accent);
  z-index: 10;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Instructions */
.instruction-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-top: auto;
}
.instruction-box p  { margin-bottom: 6px; }
.instruction-box ol { padding-left: 16px; }
.instruction-box strong { color: var(--text); }

/* ── Clips list ── */
.variants-header {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.variants-count { font-size: 0.78rem; color: var(--text-muted); }

.clips-list { display: flex; flex-direction: column; gap: 7px; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  min-height: 120px;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* Clip card */
.clip-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 11px;
  cursor: pointer;
  transition: border-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.clip-card:hover    { border-color: var(--accent); }
.clip-card.selected { border-color: var(--accent); background: #071e3d; }

.clip-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.clip-card-title { font-size: 0.83rem; font-weight: 600; }
.clip-score-big  { font-size: 1rem; font-weight: 700; color: var(--accent); }

.clip-meta { font-size: 0.7rem; color: var(--text-muted); }

.clip-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag {
  font-size: 0.65rem; font-weight: 500;
  padding: 2px 6px;
  border-radius: 99px;
  border: 1px solid;
}
.tag-green  { border-color: #38bdf8; color: #38bdf8; }
.tag-amber  { border-color: #fbbf24; color: #fbbf24; }
.tag-red    { border-color: #ef4444; color: #ef4444; }
.tag-blue   { border-color: #3b82f6; color: #3b82f6; }

/* Score bars */
.score-bars { display: flex; flex-direction: column; gap: 3px; }
.score-bar-row { display: flex; align-items: center; gap: 6px; }
.score-bar-label { font-size: 0.62rem; color: var(--text-muted); width: 42px; flex-shrink: 0; }
.score-bar-bg { flex: 1; background: var(--border); height: 3px; border-radius: 2px; overflow: hidden; }
.score-bar-fill { height: 100%; border-radius: 2px; transition: width 0.4s; }
.score-bar-fill.deriv { background: #3b82f6; }
.score-bar-fill.perf  { background: var(--accent); }
.score-bar-val { font-size: 0.65rem; color: var(--text-muted); width: 26px; text-align: right; flex-shrink: 0; }

/* ── Drawing toolbar ── */
.pitch-toolbar {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 3px;
  background: rgba(22,27,34,0.88);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 6px;
  z-index: 20;
  backdrop-filter: blur(6px);
}
.tool-btn {
  width: 30px; height: 30px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.12s;
}
.tool-btn:hover { background: var(--surface2); color: var(--text); }
.tool-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.tool-btn-dashed {
  /* dashed visual hint */
  text-decoration: underline dashed 1px;
  letter-spacing: -1px;
  opacity: 0.85;
}
.tool-sep {
  width: 1px; height: 18px;
  background: var(--border);
  margin: 0 2px;
}
/* Colour picker button + palette */
.color-picker-wrap {
  position: relative;
}
.color-dot {
  display: block;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.4);
  flex-shrink: 0;
}
.color-palette {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15,22,35,0.97);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  gap: 6px;
  flex-direction: row;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.color-palette.open { display: flex; }
.color-swatch {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s, border-color 0.12s;
  padding: 0;
}
.color-swatch:hover  { transform: scale(1.2); }
.color-swatch.active { border-color: #fff; transform: scale(1.15); }

/* Speed selector */
.speed-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}
.speed-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.speed-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 0.75rem;
  cursor: pointer;
  outline: none;
  flex: 1;
}
.speed-select:focus { border-color: var(--accent); }

/* Phase highlight indicator on pitch */
.phase-indicator {
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  background: rgba(74,222,128,0.15);
  border: 1px solid var(--accent);
  border-radius: 99px;
  padding: 3px 12px;
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 600;
  pointer-events: none;
  display: none;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100vh; }
  .main-layout { flex-direction: column; overflow: visible; }
  .sidebar-left  { width: 100%; flex-direction: row; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar-right { width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .pitch-wrapper { width: 100%; height: 60vw; min-height: 300px; flex: none; }
  .instruction-box { display: none; }
}
