/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
  --bg:       #0f172a;
  --surface:  #1e293b;
  --surface2: #293548;
  --border:   #334155;
  --text:     #f1f5f9;
  --muted:    #94a3b8;
  --primary:  #3b82f6;
  --primary-h:#2563eb;
  --danger:   #ef4444;
  --success:  #16a34a;
  --warn:     #f59e0b;
  --r:        10px;
  --r-sm:     6px;
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  user-select: none;
  -webkit-user-select: none;
}
strong { color: var(--text); }

/* ── App shell ────────────────────────────────────────────────────────────── */
#app { height: 100vh; }
.view { height: 100vh; display: flex; flex-direction: column; }
.view.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ── Screen-center layout ─────────────────────────────────────────────────── */
.screen-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px;
}

/* ── Typography ───────────────────────────────────────────────────────────── */
.app-title  { font-size: 2rem; font-weight: 800; letter-spacing: -0.5px; }
.subtitle   { color: var(--muted); font-size: 0.9rem; margin-top: -12px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, opacity 0.12s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-lg  { padding: 14px 36px; font-size: 16px; border-radius: var(--r); }
.btn-sm  { padding: 6px 14px; font-size: 12px; }

.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }

.btn-secondary {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-ghost  { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

/* ── Mode buttons (home screen) ───────────────────────────────────────────── */
.mode-buttons { display: flex; gap: 16px; }
.btn-mode {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 24px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 190px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.btn-mode:hover { border-color: var(--primary); background: var(--surface2); }
.mode-label { font-size: 1.2rem; font-weight: 700; }
.mode-desc  { font-size: 0.78rem; color: var(--muted); }

/* ── Scan / device list ───────────────────────────────────────────────────── */
.scan-area {
  width: 100%; max-width: 460px;
  display: flex; flex-direction: column;
  align-items: center; gap: 14px;
}
.device-list { width: 100%; display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.device-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.device-name { font-weight: 600; }
.device-addr { font-size: 0.72rem; color: var(--muted); font-family: monospace; margin-top: 2px; }

/* ── Connect footer ───────────────────────────────────────────────────────── */
.connect-footer {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: center;
}
.connect-footer.hidden { display: none; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge { padding: 4px 10px; border-radius: 20px; font-size: 0.76rem; font-weight: 600; }
.badge-ok   { background: #14532d; color: #4ade80; }
.badge-warn { background: #451a03; color: #fbbf24; }

/* ── Calibration ──────────────────────────────────────────────────────────── */
.cal-dots        { display: flex; gap: 14px; }
.cal-dot         { width: 22px; height: 22px; border-radius: 50%; background: var(--border); transition: background 0.2s; }
.cal-dot.hit     { background: var(--success); }
.cal-count-text  { font-size: 1.6rem; font-weight: 700; color: var(--muted); }

/* ── Home status ──────────────────────────────────────────────────────────── */
.home-status { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.dot-green   { color: #4ade80; }
.home-links  { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ── Session bar ──────────────────────────────────────────────────────────── */
.session-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}
.mode-pill {
  padding: 3px 10px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.5px;
}
.mode-pill.prone    { background: #1e3a5f; color: #60a5fa; }
.mode-pill.standing { background: #3b1f5e; color: #c084fc; }
.bar-stat  { color: var(--muted); font-size: 0.85rem; }
.bar-flex  { flex: 1; }

/* ── Targets row ──────────────────────────────────────────────────────────── */
.targets-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 16px 20px 8px;
  flex-shrink: 0;
}
.target-card { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.target-lbl  { font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.target-sub  { font-size: 0.68rem; color: var(--muted); min-height: 14px; }

/* ── Shot feed ────────────────────────────────────────────────────────────── */
.feed-wrap   { flex: 1; overflow: hidden; display: flex; flex-direction: column; padding: 0 20px 12px; }
.feed-header { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); padding: 6px 0 4px; }
.shot-feed   { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; }

.feed-row {
  display: flex; gap: 10px; align-items: center;
  padding: 5px 10px; border-radius: var(--r-sm);
  font-size: 0.82rem; background: var(--surface);
}
.f-num  { color: var(--muted); width: 28px; text-align: right; flex-shrink: 0; }
.f-res  { font-weight: 700; width: 60px; flex-shrink: 0; }
.f-tgt  { width: 40px; flex-shrink: 0; }
.f-time { color: var(--muted); }

.feed-row.f-hit    .f-res { color: #4ade80; }
.feed-row.f-repeat .f-res { color: #86efac; }
.feed-row.f-miss   .f-res { color: #f87171; }

/* ── Results ──────────────────────────────────────────────────────────────── */
.res-score    { font-size: 3.5rem; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.res-accuracy { font-size: 1.1rem; color: var(--muted); font-weight: 600; margin-top: -4px; }
.res-targets  { display: flex; gap: 10px; margin: 8px 0; }
.res-dot {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.3px;
}
.res-dot.hit  { background: #14532d; color: #4ade80; border: 2px solid #16a34a; }
.res-dot.miss { background: #3f1c1c; color: #f87171; border: 2px solid #ef4444; }
.res-actions  { display: flex; gap: 12px; align-items: center; }

/* ── Reports ──────────────────────────────────────────────────────────────── */
.reports-header {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.reports-list { flex: 1; overflow-y: auto; padding: 12px 20px; display: flex; flex-direction: column; gap: 6px; }
.report-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 14px 18px;
  display: flex; justify-content: space-between; align-items: center;
  cursor: pointer;
  transition: border-color 0.12s;
}
.report-row:hover { border-color: var(--primary); }
.report-name  { font-family: monospace; font-size: 0.88rem; flex: 1; }
.row-delete {
  background: transparent; border: none; cursor: pointer;
  color: var(--muted); font-size: 0.85rem; padding: 2px 8px; margin-right: 8px;
  border-radius: var(--r-sm);
}
.row-delete:hover { color: var(--danger); background: var(--surface2); }
.report-arrow { color: var(--muted); }

/* ── Toasts ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 18px; border-radius: var(--r-sm);
  font-size: 0.85rem; font-weight: 500; color: #fff;
  background: var(--surface2);
  border: 1px solid var(--border);
  animation: slide-in 0.25s ease;
  transition: opacity 0.5s;
}
.toast.toast-ok    { border-color: #16a34a; }
.toast.toast-error { border-color: #ef4444; }
.toast.toast-warn  { border-color: #f59e0b; }
.toast.fade-out    { opacity: 0; }

@keyframes slide-in {
  from { transform: translateX(80px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Calibration Review ───────────────────────────────────────────────────── */
.cal-result-stats        { font-size: 0.9rem; }
.cal-result-drift        { font-size: 0.85rem; min-height: 20px; text-align: center; }
.cal-result-adjust-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: -4px; }

.drift-ok   { color: #4ade80; }
.drift-info { color: var(--muted); }
.drift-warn { color: var(--warn); }

.d-pad {
  display: grid;
  grid-template-columns: 40px 80px 40px;
  grid-template-rows: repeat(3, 40px);
  gap: 4px;
  align-items: center;
  justify-items: center;
}
.d-pad-btn {
  width: 40px; height: 40px; padding: 0;
  font-size: 18px;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.1s;
}
.d-pad-btn:hover:not(:disabled) { background: var(--border); }
.d-pad-btn:active:not(:disabled) { background: var(--primary); color: #fff; }
.d-pad-center {
  width: 80px; height: 40px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-family: monospace; color: var(--muted);
  letter-spacing: 0.3px;
}
.cal-result-actions {
  display: flex; gap: 12px; align-items: center;
  flex-wrap: wrap; justify-content: center;
}

/* ── Stats ──────────────────────────────────────────────────────────────────── */
.stats-header {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.stats-filters {
  display: flex; gap: 16px; flex-wrap: wrap;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.filter-group { display: flex; gap: 4px; }
.stats-filter-btn {
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem; font-weight: 600;
  cursor: pointer;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.stats-filter-btn:hover { color: var(--text); border-color: var(--primary); }
.stats-filter-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.stats-cards {
  display: flex; gap: 12px; flex-wrap: wrap;
  padding: 16px 20px;
  flex-shrink: 0;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 20px;
  min-width: 120px;
  text-align: center;
}
.stat-value { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.5px; }
.stat-label {
  font-size: 0.72rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.6px; margin-top: 2px;
}
.stats-charts {
  display: flex; gap: 12px;
  padding: 0 20px 8px;
  flex-shrink: 0;
}
.chart-card {
  flex: 1; min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px 14px 6px;
}
.chart-title {
  font-size: 0.72rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 4px;
}
.chart-body svg { width: 100%; height: auto; display: block; }
.chart-body .muted { font-size: 0.8rem; padding: 40px 0; text-align: center; }
.stats-session-list {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
  padding: 8px 20px 16px;
}
.stats-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font-size: 0.82rem;
  transition: border-color 0.12s;
}
.stats-row:hover { border-color: var(--primary); }
.stats-ts   { color: var(--muted); font-family: monospace; font-size: 0.78rem; flex: 1; }
.stats-score { font-weight: 700; font-size: 0.95rem; width: 36px; text-align: center; }
.stats-acc  { color: var(--muted); width: 44px; text-align: right; }
.stats-dur  { color: var(--muted); width: 60px; text-align: right; font-family: monospace; font-size: 0.78rem; }
.report-arrow { color: var(--muted); margin-left: auto; }

/* ── Series options / countdown ─────────────────────────────────────────── */
.series-opts   { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 20px; }
.series-opt    { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.series-select {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 6px 10px; font-size: 14px; cursor: pointer;
}
.series-select:focus { outline: none; border-color: var(--primary); }
.cd-series { font-size: 1rem; font-weight: 600; color: var(--muted); }
.cd-num    { font-size: 7rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.cd-num.pulse { animation: cd-pulse 0.4s ease-out; }
@keyframes cd-pulse { from { transform: scale(1.25); opacity: 0.6; } to { transform: scale(1); opacity: 1; } }

.res-series   { display: flex; flex-direction: column; gap: 4px; min-width: 300px; }
.res-series-total { text-align: center; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.res-series-row {
  display: flex; gap: 14px; align-items: center;
  padding: 6px 12px; border-radius: var(--r-sm);
  background: var(--surface); font-size: 0.85rem;
}
.res-series-row.clickable { cursor: pointer; }
.res-series-row.clickable:hover { background: var(--surface2); }
.res-series-row .rs-num   { color: var(--muted); width: 24px; }
.res-series-row .rs-score { font-weight: 700; width: 36px; }
.res-series-row .rs-acc   { color: var(--muted); flex: 1; }
.res-series-row .rs-dur   { color: var(--muted); }
.res-series.hidden, .res-targets.hidden { display: none; }
.drill-tag  { font-size: 0.7rem; font-weight: 600; padding: 2px 8px; border-radius: 10px;
              background: var(--surface2); color: var(--muted); }
.stats-note { font-size: 0.75rem; flex-basis: 100%; }

/* auth */
.auth-form { display: flex; flex-direction: column; gap: 10px; width: min(320px, 90vw); }
.auth-form input { padding: 12px; border-radius: var(--r); border: 1px solid #444; background: #1c1c1c; color: inherit; font-size: 16px; }
.auth-form input.hidden { display: none; }
