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

:root {
  --bg:        #0d1117;
  --card:      #111822;
  --border:    #1e2736;
  --text:      #ccd0d9;
  --muted:     #445566;
  --score:     #f0e040;
  --make:      #2ecc71;
  --miss:      #e74c3c;
  --orange:    #f39c12;
  --blue:      #2980b9;
  --blue-dark: #1f618d;
  --radius:    10px;
}

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

/* ── Screen system ────────────────────────────────────────────────── */
[data-screen] {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  overflow-y: auto;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
  background: var(--bg);
}
[data-screen].active {
  opacity: 1;
  pointer-events: auto;
}

/* ── Common header ────────────────────────────────────────────────── */
.screen-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.screen-header h1 { font-size: 1.1rem; font-weight: 600; flex: 1; }
#review-progress {
  font-size: 1.1rem; font-weight: 700; color: var(--text);
  white-space: nowrap; padding-right: 44px; /* clear fixed BLE icon */
}
.back-btn {
  background: none; border: none; color: #667; cursor: pointer;
  font-size: 1.3rem; padding: 4px 8px; border-radius: 6px;
}
.back-btn:hover { background: #1e2736; }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: var(--radius);
  font-size: 1rem; font-weight: 700; cursor: pointer;
  padding: 14px 24px; width: 100%;
  transition: filter 0.15s, transform 0.1s;
  touch-action: manipulation;
}
.btn:active   { filter: brightness(0.85); transform: scale(0.97); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; transform: none; }
.btn-blue   { background: var(--blue);   color: #fff; }
.btn-green  { background: var(--make);   color: #fff; }
.btn-red    { background: var(--miss);   color: #fff; }
.btn-dark   { background: #1e2736;       color: var(--text); border: 1px solid var(--border); }
.btn-orange { background: var(--orange); color: #fff; }
.btn-sm     { font-size: 0.85rem; padding: 9px 16px; width: auto; }

/* ── Card ─────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

/* ── Toast ────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #222e3c; color: var(--text); border: 1px solid var(--border);
  padding: 10px 20px; border-radius: 20px; font-size: 0.88rem;
  opacity: 0; transition: opacity 0.25s; pointer-events: none;
  z-index: 999; white-space: nowrap;
}
#toast.show           { opacity: 1; }
#toast.toast-success  { border-color: var(--make);   color: var(--make); }
#toast.toast-warn     { border-color: var(--orange); color: var(--orange); }
#toast.toast-error    { border-color: var(--miss);   color: var(--miss); }

/* ── Global BLE indicator ─────────────────────────────────────────── */
#global-ble-status {
  font-size: 0.72rem; color: var(--muted);
  position: fixed; top: 10px; right: 14px; z-index: 100;
}

/* ══ AUTH ═════════════════════════════════════════════════════════ */
#screen-auth {
  align-items: center; justify-content: center; padding: 24px;
}
.auth-logo  { font-size: 4rem; margin-bottom: 8px; }
.auth-title { font-size: 1.4rem; font-weight: 700; color: var(--score); margin-bottom: 4px; }
.auth-sub   { font-size: 0.85rem; color: var(--muted); margin-bottom: 28px; }

.auth-box   { width: min(100%, 340px); display: flex; flex-direction: column; gap: 12px; }

.auth-tabs  { display: flex; gap: 8px; margin-bottom: 4px; }
.auth-tab {
  flex: 1; padding: 8px;
  border: 1px solid var(--border); border-radius: 8px;
  background: none; color: var(--muted); font-weight: 600; font-size: 0.85rem;
  cursor: pointer; transition: all 0.15s;
}
.auth-tab.active { background: var(--blue); border-color: var(--blue); color: #fff; }

.auth-input {
  background: #0d1117; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 12px 14px; font-size: 0.95rem; width: 100%;
}
.auth-input:focus { outline: none; border-color: var(--blue); }

#auth-error { font-size: 0.82rem; color: var(--miss); min-height: 1.2em; }

.auth-divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 0.78rem;
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ══ DASHBOARD ════════════════════════════════════════════════════ */
#screen-dashboard .screen-header { background: var(--card); }

.dash-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--border); object-fit: cover; display: none;
}
#dash-user-name { font-size: 0.85rem; color: var(--muted); font-weight: 400; }

.dash-body {
  flex: 1; display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  gap: 16px; padding: 24px;
}
.dash-btn-group { width: min(100%, 400px); display: flex; flex-direction: column; gap: 12px; }
.dash-big-btn   { font-size: 1.15rem; padding: 20px 24px; }
.app-version    { font-size: 0.7rem; color: var(--muted); }

/* ══ PRACTICE SETUP ═══════════════════════════════════════════════ */
.setup-body { flex: 1; padding: 20px; display: flex; flex-direction: column; gap: 16px; }

.setup-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.setup-icon  { font-size: 1.6rem; }
.setup-info  { flex: 1; }
.setup-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.setup-state { font-size: 0.88rem; color: var(--muted); }
.setup-state.ok { color: var(--make); }

#setup-cam-preview {
  width: 100%; aspect-ratio: 16/9;
  border-radius: var(--radius); object-fit: cover;
  background: #000; display: none;
}
.setup-note { font-size: 0.78rem; color: var(--muted); text-align: center; padding: 0 12px; }

/* Toggle switch */
.toggle-switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0;
  background: #1e2736; border-radius: 26px; cursor: pointer;
  transition: background 0.2s;
}
.toggle-track::before {
  content: ''; position: absolute;
  width: 20px; height: 20px; left: 3px; bottom: 3px;
  background: #667; border-radius: 50%; transition: transform 0.2s, background 0.2s;
}
.toggle-switch input:checked + .toggle-track { background: #1f618d; }
.toggle-switch input:checked + .toggle-track::before { transform: translateX(20px); background: var(--make); }

/* ══ PRACTICE ACTIVE ══════════════════════════════════════════════ */
#screen-practice-active { padding: 0; overflow: hidden; background: #000; }

#active-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover; opacity: 0.6;
}
.active-overlay {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; height: 100%;
}
.active-score-block {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
}
#active-score-row  { display: flex; align-items: baseline; gap: 6px; }
#active-makes { font-size: clamp(100px,28vw,180px); font-weight: 900; color: var(--score); line-height: 1; }
#active-sep   { font-size: clamp(50px,14vw,90px);   color: #555; }
#active-total { font-size: clamp(50px,14vw,90px);   color: #555; }
#active-pct   { font-size: clamp(20px,5.5vw,30px);  color: #555; }
#active-event { font-size: clamp(14px,4vw,22px); color: #444; font-style: italic; min-height: 1.8em; text-align: center; padding: 0 12px; }

#active-cal-wrap {
  width: min(80%,300px); height: 5px; background: #1e2736;
  border-radius: 3px; overflow: hidden; opacity: 0; transition: opacity 0.3s;
}
#active-cal-wrap.visible { opacity: 1; }
#active-cal-bar { height: 100%; width: 0%; background: var(--orange); border-radius: 3px; transition: width 0.3s; }

.active-footer {
  flex-shrink: 0; padding: 16px 20px 28px;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
#active-stop-btn { width: min(100%,240px); font-size: 1.1rem; padding: 16px; }

.active-di {
  display: flex; gap: 14px; font-size: 0.72rem;
  color: var(--muted); padding: 44px 16px 8px;
  align-items: center; flex-shrink: 0;
}
.active-di span { color: var(--text); }

/* ══ REVIEW ════════════════════════════════════════════════════════ */
.review-body { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 12px; }

#review-video {
  width: 100%; max-height: 33vh; aspect-ratio: 16/9;
  border-radius: var(--radius); background: #111; object-fit: cover;
}
#review-prediction { font-size: 0.95rem; font-weight: 700; text-align: center; padding: 2px 0; }
#review-top-btns { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.review-sub-row  { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.label-btn {
  padding: 10px 8px; border: 2px solid var(--border);
  border-radius: var(--radius); background: var(--card);
  color: var(--text); font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: all 0.15s; touch-action: manipulation;
}
.label-btn:active             { transform: scale(0.96); }
.label-btn.selected           { border-color: var(--blue); background: #172030; }
.label-btn.label-btn-disabled { opacity: 0.35; cursor: not-allowed; }

/* Comment field — Feature 16 */
#review-comment {
  width: 100%; height: 54px; resize: none;
  background: #0d1117; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 8px 10px; font-size: 0.85rem;
  font-family: inherit;
}
#review-comment:focus { outline: none; border-color: var(--blue); }
#review-comment-label { font-size: 0.72rem; color: var(--muted); }

.review-actions { display: flex; gap: 10px; }

/* ══ UPLOAD ════════════════════════════════════════════════════════ */
.upload-body {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 20px; padding: 24px;
}
.upload-icon  { font-size: 3rem; }
#upload-status  { font-size: 0.9rem;  color: var(--muted); text-align: center; }
#upload-summary { font-size: 0.88rem; color: var(--make);  text-align: center; }

.upload-bar-wrap {
  width: min(100%,360px); height: 8px;
  background: var(--border); border-radius: 4px; overflow: hidden;
}
#upload-progress {
  height: 100%; width: 0%;
  background: var(--blue); border-radius: 4px; transition: width 0.3s;
}

/* ══ HISTORY ════════════════════════════════════════════════════════ */
.history-body {
  flex: 1; padding: 16px; display: flex; flex-direction: column;
  gap: 16px; overflow-y: auto;
}
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-card  {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; text-align: center;
}
.stat-val   { font-size: 1.8rem; font-weight: 900; color: var(--score); }
.stat-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.history-section-title {
  font-size: 0.75rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.07em; margin-bottom: 8px;
}
#trend-chart-wrap {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px;
  height: 180px; position: relative;
}
#trend-chart { width: 100%; height: 100%; }

.session-item {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
  margin-bottom: 6px;
  display: grid; grid-template-columns: 1fr 44px 72px 72px; align-items: center; gap: 4px;
}
.session-hdr    { background: transparent; border-color: transparent; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 2px; }
.session-totals { border-top: 1px solid var(--border); margin-top: 4px; }
.sh-date        { font-size: 0.82rem; color: var(--text); }
.session-time   { color: var(--muted); font-size: 0.78rem; }
.sh-dur         { font-size: 0.82rem; color: var(--muted); text-align: center; }
.sh-score       { font-size: 0.82rem; text-align: center; line-height: 1.35; }

#history-loading { color: var(--muted); text-align: center; padding: 40px; font-size: 0.9rem; }

/* ══ OTA ════════════════════════════════════════════════════════════ */
.ota-body { flex: 1; padding: 20px; display: flex; flex-direction: column; gap: 16px; }

.ota-version-row   { display: flex; gap: 12px; }
.ota-version-card  {
  flex: 1; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; text-align: center;
}
.ota-ver-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.ota-ver-val   { font-size: 1.2rem; font-weight: 800; color: var(--score); margin-top: 4px; }

.ota-bar-wrap  { width: 100%; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
#ota-progress-bar {
  height: 100%; width: 0%;
  background: var(--blue); border-radius: 4px; transition: width 0.25s;
}
#ota-update-status { font-size: 0.85rem; color: var(--muted); min-height: 1.2em; }

/* ══ DEVICE INFO page extras ══════════════════════════════════ */
.di-section-title {
  font-size: 0.7rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.07em;
}
.di-section-divider {
  font-size: 0.7rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.07em; text-align: center;
  border-top: 1px solid var(--border); padding-top: 10px; margin-top: 4px;
}
.di-info-grid {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.di-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 14px; border-bottom: 1px solid var(--border);
}
.di-row:last-child { border-bottom: none; }
.di-label { font-size: 0.78rem; color: var(--muted); }
.di-val   { font-size: 0.82rem; color: var(--text); font-weight: 600; font-family: monospace; }
.di-baseline-result {
  font-size: 0.78rem; color: var(--muted);
  font-family: monospace; min-height: 1.5em;
  width: 100%;
}
.di-baseline-table {
  width: 100%; border-collapse: collapse; font-size: 0.78rem;
  font-family: monospace; margin-top: 4px;
}
.di-baseline-table thead th {
  background: var(--card-bg, #1e2130); color: var(--muted);
  font-size: 0.72rem; font-weight: 600; text-align: left;
  padding: 4px 8px; border-bottom: 1px solid var(--border, #2a2d3e);
}
.di-baseline-table tbody td {
  padding: 3px 8px; color: var(--text); border-bottom: 1px solid var(--border, #2a2d3e);
}
.di-baseline-table tbody tr:last-child td { border-bottom: none; }
.di-baseline-warn { color: var(--orange, #e67e22); font-style: italic; }

.ota-note {
  font-size: 0.78rem; color: var(--muted); line-height: 1.5;
  text-align: center; padding: 0 8px;
}
