:root {
  --bg: #0b0d0b;
  --panel: #171a16;
  --panel-2: #22261f;
  --line: #343a2f;
  --accent: #c6f135;
  --on-accent: #0b0d0b;
  --warn: #ff8a4c;
  --text: #ffffff;
  --dim: #b4b7aa;
  --radius: 14px;
  --tap: 60px;
  color-scheme: dark;
}
:root[data-theme="sun"] {
  --bg: #ffffff;
  --panel: #f1f2ec;
  --panel-2: #e3e5dc;
  --line: #9a9e90;
  --accent: #111311;
  --on-accent: #d9ff4a;
  --warn: #b33a00;
  --text: #000000;
  --dim: #3d4038;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 600 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, select, input { font: inherit; color: inherit; touch-action: manipulation; }
label.btn { touch-action: manipulation; }
[hidden] { display: none !important; }

.screen {
  max-width: 720px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 112px);
  min-height: 100dvh;
}

/* top bar */
.topbar { display: flex; align-items: center; gap: 10px; min-height: 52px; }
.topbar h1 { flex: 1; margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -.3px; }
.icon-btn {
  width: 52px; height: 52px; display: grid; place-items: center; flex: none;
  background: none; border: 0; border-radius: 12px; color: var(--text); cursor: pointer;
}
.icon-btn:active { background: var(--panel-2); }

/* buttons */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px; border-radius: var(--radius);
  background: var(--panel-2); border: 2px solid var(--line); color: var(--text);
  font-weight: 700; font-size: 19px; cursor: pointer; text-decoration: none; user-select: none;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn-xl { min-height: 68px; font-size: 21px; width: 100%; }
.btn-lg { min-height: 64px; flex: 1; }
.btn-wide { width: 100%; margin-top: 10px; border-color: var(--accent); }

/* segmented control */
.seg { display: flex; background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); padding: 4px; gap: 4px; }
.seg-btn {
  flex: 1; min-height: 60px; border: 0; border-radius: 10px; background: none;
  font-weight: 700; font-size: 19px; cursor: pointer; color: var(--dim);
}
.seg-btn[aria-checked="true"] { background: var(--accent); color: var(--on-accent); }
.seg-sm { flex: 1; padding: 3px; }
.seg-sm .seg-btn { min-height: 48px; font-size: 16px; white-space: nowrap; padding: 0 8px; }

/* home */
.home-body { margin-top: 18px; display: flex; flex-direction: column; gap: 22px; }
.setup { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.setup li { display: flex; gap: 12px; align-items: baseline; font-size: 18px; font-weight: 600; color: var(--text); }
.setup li::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); transform: translateY(-3px); }

/* dock (thumb zone) */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: linear-gradient(to top, var(--bg) 75%, transparent);
  max-width: 720px; margin: 0 auto;
}
.dock-row { flex-direction: row; }

/* analysis */
.speed {
  flex: none; min-height: 54px; padding: 0 8px; border-radius: 12px;
  background: var(--panel); border: 2px solid var(--line); font-weight: 700; font-size: 16px;
}
.stage-wrap { position: relative; margin-top: 8px; min-height: 220px; background: #000; border-radius: var(--radius); overflow: hidden; display: flex; justify-content: center; }
.stage { position: relative; line-height: 0; }
.stage video { display: block; max-width: 100%; max-height: 54dvh; width: auto; height: auto; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.busy {
  position: absolute; inset: auto 0 0 0; padding: 14px 16px 16px;
  background: rgba(0,0,0,.78); color: #fff; display: flex; flex-direction: column; gap: 10px;
}
.busy-text { font-size: 18px; font-weight: 700; }
.bar { height: 10px; border-radius: 5px; background: rgba(255,255,255,.18); overflow: hidden; }
.bar > div { height: 100%; width: 0; background: #c6f135; transition: width .15s; }
.err { margin-top: 10px; padding: 12px 14px; border-radius: 12px; background: var(--panel); border: 2px solid var(--warn); color: var(--text); font-size: 16px; }

.scrubber { width: 100%; margin: 14px 0 6px; height: 36px; accent-color: var(--accent); }

.events { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ev {
  min-height: 64px; border-radius: var(--radius); border: 2px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer;
}
.ev-name { font-size: 17px; font-weight: 800; }
.ev-t { font-size: 14px; color: var(--dim); font-variant-numeric: tabular-nums; }
.ev.on-frame { border-color: var(--text); }
.ev[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.ev[aria-pressed="true"] .ev-t { color: var(--on-accent); }

.transport { display: flex; gap: 8px; margin-top: 8px; }

/* metric cards */
.cards { margin-top: 18px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--panel); border-radius: var(--radius); padding: 14px 16px; }
.card h2 { margin: 0 0 10px; font-size: 15px; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; color: var(--dim); }
.rows { display: grid; grid-template-columns: 1fr auto; gap: 10px 12px; align-items: baseline; }
.rows .k { font-size: 17px; }
.rows .k small { display: block; font-size: 13px; font-weight: 600; color: var(--dim); }
.rows .v { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.rows .v.warn { color: var(--warn); }
.rows .v.na { font-size: 18px; color: var(--dim); }
.tempo { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.tempo .v { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.tempo .k { font-size: 14px; color: var(--dim); }
.tempo .v.warn { color: var(--warn); }
.card-btn { display: block; width: 100%; text-align: left; border: 0; color: inherit; font: inherit; cursor: pointer; }
.card-btn:active { background: var(--panel-2); }
.tag { display: inline-block; margin-top: 10px; font-size: 13px; color: var(--dim); }

/* sheets */
.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 720px;
  background: var(--panel); color: var(--text); border-radius: 22px 22px 0 0;
}
.sheet::backdrop { background: rgba(0,0,0,.6); }
.sheet form { display: flex; flex-direction: column; gap: 14px; padding: 20px 16px calc(env(safe-area-inset-bottom) + 16px); }
.sheet h2 { margin: 0 0 4px; font-size: 22px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; }
.field .seg { flex: 0 0 200px; }
.num { display: flex; align-items: center; gap: 8px; }
.num input {
  width: 96px; min-height: 52px; padding: 0 12px; font-size: 22px; font-weight: 800; text-align: right;
  border-radius: 12px; border: 2px solid var(--line); background: var(--bg);
}
#exportPreview { width: 100%; max-height: 50dvh; background: #000; border-radius: 12px; }
