:root {
  color-scheme: dark;
  --ink: #f8fafc;
  --muted: #bdc4d2;
  --panel: rgba(12, 16, 27, .9);
  --accent: #ff6b35;
  --accent-dark: #d94b1c;
  --good: #43e08d;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #05070c;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input { font: inherit; }

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.app-shell {
  position: fixed;
  inset: 0;
  width: min(100%, 34rem);
  height: 100dvh;
  margin: auto;
  overflow: hidden;
  background: #080b14;
  box-shadow: 0 0 4rem rgba(0, 0, 0, .55);
}

.camera-stage { position: absolute; inset: 0; overflow: hidden; }

#camera {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .25s ease;
}

#camera.ready { opacity: 1; }
#camera.mirrored { transform: scaleX(-1); }

.shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,.64), transparent 24%, transparent 68%, rgba(0,0,0,.78));
}

header {
  position: fixed;
  z-index: 5;
  top: 0;
  left: 50%;
  display: flex;
  width: min(100%, 34rem);
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: max(.85rem, env(safe-area-inset-top)) .9rem .7rem;
  transform: translateX(-50%);
}

header h1 { margin: 0; font-size: clamp(1.15rem, 5vw, 1.5rem); letter-spacing: -.035em; }

.status {
  display: inline-flex;
  align-items: center;
  gap: .42rem;
  min-height: 2rem;
  padding: .32rem .68rem;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 999px;
  background: rgba(8,11,20,.72);
  font-size: .82rem;
  font-weight: 750;
  backdrop-filter: blur(12px);
}

.status-dot { width: .62rem; height: .62rem; border-radius: 50%; background: #8f96a6; }
.status.recording .status-dot { background: #ff4565; box-shadow: 0 0 0 .25rem rgba(255,69,101,.18); }
.status.armed .status-dot, .status.complete .status-dot { background: var(--good); }

.level-ladder {
  position: absolute;
  z-index: 3;
  top: 15%;
  right: max(.8rem, env(safe-area-inset-right));
  bottom: 19%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}

.level-ladder.left-side {
  right: auto;
  left: max(.8rem, env(safe-area-inset-left));
}

.level {
  display: grid;
  width: 2.65rem;
  height: 2.05rem;
  place-items: center;
  border: 2px solid rgba(255,255,255,.88);
  border-radius: 999px;
  background: rgba(4,7,12,.62);
  color: #fff;
  font-size: .95rem;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 2px #000;
  backdrop-filter: blur(5px);
  transform: translateX(calc(-1 * var(--curve-shift, 0rem)));
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

.level-ladder.left-side .level { transform: translateX(var(--curve-shift, 0rem)); }

.level.hit {
  border-color: #b8ffd7;
  background: var(--good);
  color: #062515;
  text-shadow: none;
  transform: translateX(calc(-1 * var(--curve-shift, 0rem))) scale(1.08);
}

.level-ladder.left-side .level.hit { transform: translateX(var(--curve-shift, 0rem)) scale(1.08); }

.message {
  position: fixed;
  z-index: 5;
  top: 10%;
  left: 50%;
  width: min(calc(100% - 7rem), 25rem);
  transform: translateX(-58%);
  text-align: center;
  text-shadow: 0 2px 12px #000;
  pointer-events: none;
}

.message strong { display: block; font-size: clamp(1.4rem, 7vw, 2.35rem); line-height: 1.05; }
.message span { display: block; margin-top: .4rem; color: #f0f2f7; font-size: clamp(.86rem, 3.4vw, 1.02rem); }

.countdown {
  position: fixed;
  z-index: 9;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.38);
  font-size: clamp(8rem, 48vw, 17rem);
  font-weight: 950;
  text-shadow: 0 .08em .25em #000;
}

.panel {
  position: fixed;
  z-index: 8;
  left: 50%;
  bottom: max(.8rem, env(safe-area-inset-bottom));
  width: min(calc(100% - 1.25rem), 32rem);
  max-height: calc(100dvh - 4.8rem);
  overflow-y: auto;
  transform: translateX(-50%);
  padding: 1.1rem;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 1.25rem;
  background: var(--panel);
  box-shadow: 0 1rem 4rem rgba(0,0,0,.45);
  backdrop-filter: blur(18px);
}

.panel h2 { margin: 0 0 .55rem; font-size: clamp(1.45rem, 6vw, 2rem); line-height: 1.08; }
.panel > p:not(.eyebrow, .note) { margin: 0 0 .85rem; color: var(--muted); line-height: 1.42; }
.eyebrow { margin: 0 0 .38rem; color: #ffb08f; font-size: .72rem; font-weight: 900; letter-spacing: .14em; }

.steps {
  display: grid;
  gap: .65rem;
  margin: .85rem 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps li {
  display: grid;
  grid-template-columns: 1.7rem minmax(0, 1fr);
  gap: 0 .62rem;
  align-items: start;
  counter-increment: step;
}

.steps li::before {
  grid-row: span 2;
  content: counter(step);
  display: grid;
  width: 1.65rem;
  height: 1.65rem;
  place-items: center;
  border-radius: 50%;
  background: #333a4a;
  font-size: .78rem;
  font-weight: 900;
}

.steps strong { font-size: .94rem; }
.steps span { color: var(--muted); font-size: .84rem; line-height: 1.32; }

.option { display: flex; align-items: center; gap: .55rem; margin: .4rem 0 .75rem; color: #e6e8ed; font-size: .92rem; }
.option input { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); }

.field { display: grid; grid-template-columns: auto 1fr; gap: .7rem; align-items: center; margin-bottom: .85rem; color: var(--muted); font-size: .88rem; font-weight: 750; }
.field select { min-height: 2.65rem; padding: .45rem .65rem; border: 1px solid rgba(255,255,255,.18); border-radius: .7rem; background: #252b39; color: #fff; }

.button {
  display: grid;
  width: 100%;
  min-height: 3.2rem;
  place-items: center;
  padding: .7rem 1rem;
  border: 0;
  border-radius: .9rem;
  background: #343b4b;
  color: #fff;
  cursor: pointer;
  font-weight: 850;
  text-align: center;
  text-decoration: none;
}

.button.primary { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); }
.button.finish { background: #fff; color: #111722; }
.button:disabled { cursor: wait; opacity: .55; }
.note { min-height: 1.25rem; margin: .55rem 0 0; color: #ffb8c3; font-size: .82rem; }

.session-controls {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  width: min(calc(100% - 1.5rem), 28rem);
  transform: translateX(-50%);
}

.result-video { width: 100%; max-height: 46vh; margin: .2rem 0 .85rem; border-radius: .8rem; background: #000; }
.share-panel { margin: 0 0 .85rem; padding: .8rem; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.045); }
.share-button { min-height: 2.8rem; background: #285fba; }
.share-note { margin: .58rem 0 0; color: var(--muted); font-size: .78rem; line-height: 1.35; }
.share-result { display: grid; gap: .35rem; margin-top: .7rem; padding: .7rem; border-left: 4px solid var(--good); background: rgba(67,224,141,.1); }
.share-result span { color: #c8f8dc; font-size: .78rem; font-weight: 750; }
.share-result a { color: #fff; font-weight: 850; }
.share-status { min-height: 1.15em; margin: .55rem 0 0; color: #cdd4e1; font-size: .8rem; }
.share-status.error { color: #ffb8c3; }
.actions { display: grid; gap: .65rem; }
.actions.two { grid-template-columns: 1fr 1fr; }
.save-link { background: #343b4b; }

#analysisCanvas,
#recordingCanvas { position: fixed; width: 1px; height: 1px; opacity: .001; pointer-events: none; }
.hidden { display: none !important; }

@media (orientation: landscape) and (max-height: 540px) {
  .panel { max-height: calc(100dvh - 1rem); }
  .message { top: 14%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
