/* Motion Tracker — house style: dark, serif headlines, clean sans for UI/numerics.
   Mobile-first, full-bleed, safe-area aware. */

:root {
  --bg: #0E1116;
  --bg-2: #161a21;
  --ink: #F5F3EE;
  --muted: #9aa3ad;
  --line: rgba(245, 243, 238, 0.10);
  --green: #5FB67A;
  --amber: #E0A341;
  --red: #E5544B;
  --accent: #E0A341;
  --serif: ui-serif, Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

/* The `hidden` attribute must win over component display rules below
   (.hud/.modal/.install-banner set display:flex, which would otherwise
   override the UA [hidden]{display:none} and leave panels stuck open). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  /* prevent double-tap / pinch zoom on the UI without blocking video */
  touch-action: manipulation;
  overscroll-behavior: none;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; }
button { font-family: var(--sans); cursor: pointer; }

/* ===== Camera + overlay (full-bleed, behind everything until live) ===== */
#cam, #overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#cam { background: #000; z-index: 0; display: none; }
#overlay { z-index: 1; display: none; pointer-events: none; }
body.live #cam { display: block; }
body.live #overlay { display: block; }
#cam.mirror { transform: scaleX(-1); }

/* ===== Screens ===== */
.screen { position: relative; z-index: 2; }

#home {
  min-height: 100%;
  padding: calc(var(--safe-t) + 28px) calc(var(--safe-r) + 20px)
           calc(var(--safe-b) + 120px) calc(var(--safe-l) + 20px);
  max-width: 720px;
  margin: 0 auto;
}
body.live #home { display: none; }

.masthead h1 { font-size: 2.6rem; margin: 0; line-height: 1; }
.tagline { color: var(--muted); margin: 8px 0 0; font-size: 1rem; }

.section-title {
  font-size: 1.15rem; margin: 32px 0 14px;
  color: var(--ink);
}

/* Exercise grid */
.grid {
  list-style: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
}
.ex-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  min-height: 88px;
  display: flex; flex-direction: column; justify-content: space-between;
  transition: border-color .15s, transform .05s;
}
.ex-card:active { transform: scale(0.99); }
.ex-card.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.ex-card .name { font-weight: 600; font-size: 1.05rem; }
.ex-card .meta { color: var(--muted); font-size: .8rem; margin-top: 6px; text-transform: uppercase; letter-spacing: .04em; }
.ex-card .pr { color: var(--accent); font-size: .8rem; margin-top: 4px; }

/* History */
.history { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.history li {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.history .h-name { font-weight: 600; }
.history .h-sub { color: var(--muted); font-size: .82rem; }
.history .h-rom { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 600; }

/* Install banner */
.install-banner {
  margin-top: 20px; padding: 12px 14px; border-radius: 12px;
  background: var(--bg-2); border: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; font-size: .92rem;
}
.link { background: none; border: none; color: var(--accent); font-size: .92rem; padding: 6px; }
.link.subtle { color: var(--muted); margin-left: auto; }

/* Footer */
.site-footer { margin-top: 40px; border-top: 1px solid var(--line); padding-top: 20px; }
.ai-link { color: var(--accent); text-decoration: none; font-size: .95rem; }
.fine { color: var(--muted); font-size: .8rem; margin-top: 10px; line-height: 1.5; }

/* ===== Big start button ===== */
.start-btn {
  position: fixed; z-index: 5;
  left: calc(var(--safe-l) + 16px); right: calc(var(--safe-r) + 16px);
  bottom: calc(var(--safe-b) + 16px);
  height: 64px; border: none; border-radius: 16px;
  background: var(--accent); color: #1a1206;
  font-size: 1.2rem; font-weight: 700; letter-spacing: .01em;
}
.start-btn:active { filter: brightness(0.95); }

/* ===== Live HUD ===== */
.hud {
  position: fixed; inset: 0; z-index: 4;
  display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 14px)
           calc(var(--safe-b) + 16px) calc(var(--safe-l) + 14px);
  pointer-events: none;
}
.hud > * { pointer-events: auto; }

.hud-top { display: flex; justify-content: space-between; align-items: flex-start; }
.hud-ex {
  font-family: var(--serif); font-size: 1.25rem; font-weight: 600;
  background: rgba(8,10,13,0.55); padding: 6px 12px; border-radius: 10px;
  backdrop-filter: blur(6px);
}

.hud-metrics {
  margin: 14px auto 0; display: flex; gap: 10px;
  background: rgba(8,10,13,0.5); padding: 10px 14px; border-radius: 14px;
  backdrop-filter: blur(6px);
}
.metric { text-align: center; min-width: 86px; }
.metric span {
  display: block; font-size: 2.6rem; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.metric label { display: block; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; margin-top: 4px; }

/* Cue toast */
.cue {
  margin: 14px auto 0; max-width: 540px;
  background: rgba(224,163,65,0.95); color: #1a1206;
  padding: 12px 16px; border-radius: 12px; font-weight: 600; font-size: 1rem;
  text-align: center; box-shadow: 0 6px 24px rgba(0,0,0,0.35);
}

.hud-bottom { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.hud-actions { display: flex; gap: 10px; }
.pill.recording { background: var(--red); color: #fff; border-color: transparent; animation: recpulse 1.4s ease-in-out infinite; }
@keyframes recpulse { 50% { filter: brightness(1.25); } }

.range-pill {
  padding: 12px 18px; border-radius: 999px; font-weight: 700; font-size: 1rem;
  background: rgba(8,10,13,0.55); backdrop-filter: blur(6px);
  border: 2px solid var(--muted); color: var(--muted);
}
.range-pill[data-status="in"] { border-color: var(--green); color: var(--green); }
.range-pill[data-status="near"] { border-color: var(--amber); color: var(--amber); }
.range-pill[data-status="out"] { border-color: var(--red); color: var(--red); }

/* Buttons */
.pill {
  min-height: 48px; padding: 0 20px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(8,10,13,0.6); color: var(--ink);
  font-size: 1rem; font-weight: 600; backdrop-filter: blur(6px);
}
.pill.primary { background: var(--accent); color: #1a1206; border-color: transparent; }
.pill.danger { background: var(--red); color: #fff; border-color: transparent; }
.pill.is-on { background: var(--accent); color: #1a1206; border-color: transparent; }
.pill:active { filter: brightness(0.95); }

/* ===== Modal / summary ===== */
.modal {
  position: fixed; inset: 0; z-index: 6;
  background: rgba(6,8,11,0.78);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px; padding-bottom: calc(var(--safe-b) + 16px);
}
.card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 18px;
  width: 100%; max-width: 560px; padding: 22px; max-height: 86vh; overflow: auto;
}
.card h2 { margin: 0 0 14px; font-size: 1.6rem; }
.card-actions { display: flex; gap: 10px; margin-top: 18px; }
.card-actions .pill { flex: 1; }

.sum-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.sum-stat { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; }
.sum-stat b { display: block; font-size: 1.8rem; font-variant-numeric: tabular-nums; }
.sum-stat small { color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-size: .68rem; }
.pr-badge { color: var(--accent); font-weight: 700; }
.recs { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.recs li { background: var(--bg); border-left: 3px solid var(--accent); border-radius: 8px; padding: 10px 12px; font-size: .95rem; line-height: 1.4; }

/* ===== Status / error toast ===== */
.status {
  position: fixed; z-index: 7; left: 50%; top: calc(var(--safe-t) + 20px);
  transform: translateX(-50%);
  background: var(--bg-2); border: 1px solid var(--line); color: var(--ink);
  padding: 14px 18px; border-radius: 12px; max-width: 88vw; text-align: center;
  font-size: .95rem; line-height: 1.45; box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
.status.error { border-color: var(--red); }
.status .status-action { margin-top: 10px; }

@media (min-width: 640px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}
