:root {
  color-scheme: light;
  --ink: #17231f;
  --muted: #687770;
  --line: #dce4df;
  --paper: #fffefb;
  --canvas: #f3f5f1;
  --green: #176b4d;
  --green-soft: #e5f3ec;
  --blue: #2d5e8e;
  --blue-soft: #e8f0f8;
  --orange: #c66d2d;
  --red: #b43d3d;
  --shadow: 0 18px 50px rgba(23, 35, 31, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--canvas); min-width: 320px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--paper); border-radius: 10px; padding: .68rem 1rem; cursor: pointer; font-weight: 650; }
button:hover:not(:disabled) { border-color: #aab9b1; transform: translateY(-1px); }
button:disabled { opacity: .48; cursor: not-allowed; }
button.primary { color: white; background: var(--green); border-color: var(--green); }
button.large { padding: .9rem 1.4rem; font-size: 1rem; }
button.full { width: 100%; }
input, select, textarea { width: 100%; border: 1px solid #cbd6d0; background: white; border-radius: 9px; padding: .72rem .8rem; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid rgba(45, 94, 142, .2); border-color: var(--blue); }
label > span, .select-control > span { display: block; margin-bottom: .38rem; color: #45564e; font-size: .78rem; font-weight: 700; }
textarea { resize: vertical; }
[hidden], .step-panel[hidden] { display: none !important; }
.eyebrow { margin: 0 0 .35rem; color: var(--green); font-size: .69rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.status { min-height: 1.4em; color: var(--muted); margin: .6rem 0 0; }
.status.error { color: var(--red); }
.muted { color: var(--muted); }
kbd { margin-left: .45rem; border: 1px solid rgba(255,255,255,.45); border-radius: 5px; padding: .1rem .36rem; font: 600 .72rem ui-monospace, monospace; }

.topbar { height: 68px; display: flex; align-items: center; justify-content: space-between; padding: 0 2rem; background: rgba(255, 254, 251, .94); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; backdrop-filter: blur(12px); }
.brand { border: 0; padding: 0; background: transparent; display: flex; align-items: center; gap: .75rem; text-align: left; }
.brand:hover:not(:disabled) { transform: none; border-color: transparent; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; color: white; background: var(--green); font-weight: 850; letter-spacing: -.04em; }
.brand small, .brand strong { display: block; }
.brand small { color: var(--muted); font-size: .65rem; text-transform: uppercase; letter-spacing: .1em; }
.brand strong { font-size: .96rem; }
.topbar-actions { display: flex; align-items: center; gap: .8rem; }
.auth-controls { display: flex; align-items: center; gap: .55rem; color: var(--muted); font-size: .76rem; }
.auth-controls button { padding: .45rem .65rem; }
.workspace-label { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .76rem; }
.icon-button { width: 40px; height: 40px; padding: 0; font-size: 1.05rem; }

.login-page { min-height: 100vh; background: radial-gradient(circle at top left, #e8f1ec 0, transparent 42%), var(--bg); }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: min(100%, 420px); padding: 2rem; border: 1px solid var(--line); border-radius: 22px; background: var(--paper); box-shadow: var(--shadow); }
.login-card .brand-mark { margin-bottom: 1.4rem; }
.login-card h1 { margin: .15rem 0 .6rem; font-size: 2rem; letter-spacing: -.04em; }
.login-card form { display: grid; gap: 1rem; margin-top: 1.6rem; }

.exercise-screen { max-width: 1180px; margin: 0 auto; padding: 9vh 2rem 5rem; }
.welcome { max-width: 710px; margin-bottom: 3rem; }
.welcome h1 { margin: .2rem 0 1rem; font-size: clamp(2.4rem, 6vw, 4.8rem); line-height: .98; letter-spacing: -.055em; }
.welcome > p:last-child { color: var(--muted); font-size: 1.08rem; }
.exercise-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; }
.exercise-card { min-height: 210px; padding: 1.35rem; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); box-shadow: 0 8px 25px rgba(23,35,31,.035); cursor: pointer; display: flex; flex-direction: column; justify-content: space-between; transition: transform .18s, box-shadow .18s, border-color .18s; }
.exercise-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: #a9bdb3; }
.exercise-card-icon { width: 43px; height: 43px; display: grid; place-items: center; border-radius: 13px; background: var(--green-soft); color: var(--green); font-size: 1.25rem; }
.exercise-card h2 { margin: .8rem 0 .3rem; font-size: 1.22rem; }
.exercise-card p { margin: 0; color: var(--muted); font-size: .83rem; }
.exercise-card-progress { display: flex; align-items: center; justify-content: space-between; margin-top: 1.5rem; font-size: .77rem; }
.mini-progress { height: 5px; flex: 1; margin-right: .8rem; border-radius: 10px; background: #e7ece9; overflow: hidden; }
.mini-progress i { display: block; height: 100%; background: var(--green); }

.studio { max-width: 1440px; margin: 0 auto; padding: 0 2rem 4rem; }
.exercise-context { display: grid; grid-template-columns: 180px 1fr auto; align-items: center; gap: 1rem; padding: 1.75rem 0 1.2rem; }
.exercise-context h1 { margin: 0; font-size: 1.55rem; letter-spacing: -.025em; }
.back-button { justify-self: start; border: 0; background: transparent; padding-left: 0; color: var(--muted); }
.exercise-progress { color: var(--muted); font-size: .8rem; }
.stepper { display: grid; grid-template-columns: repeat(6, 1fr); gap: .45rem; padding: .5rem; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.72); position: sticky; top: 78px; z-index: 20; box-shadow: 0 8px 24px rgba(23,35,31,.05); }
.stepper button { position: relative; display: grid; grid-template-columns: 28px 1fr; grid-template-rows: auto auto; column-gap: .6rem; text-align: left; border: 0; background: transparent; padding: .65rem .7rem; }
.stepper button > span { grid-row: 1 / 3; align-self: center; width: 27px; height: 27px; display: grid; place-items: center; border-radius: 50%; background: #e8eeea; font-size: .75rem; }
.stepper button strong { font-size: .82rem; }
.stepper button small { color: var(--muted); font-size: .68rem; }
.stepper button.active { background: var(--ink); color: white; }
.stepper button.active small { color: #bfcac5; }
.stepper button.active > span { background: var(--green); }
.stepper button.done > span { background: var(--green-soft); color: var(--green); }
.workspace { margin-top: 1rem; }
.step-panel { min-height: 620px; border: 1px solid var(--line); border-radius: 20px; background: var(--paper); box-shadow: var(--shadow); padding: clamp(1.3rem, 3vw, 2.5rem); }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 2rem; margin-bottom: 2rem; }
.page-heading h2 { margin: .15rem 0 .5rem; font-size: clamp(1.8rem, 3vw, 2.55rem); letter-spacing: -.04em; }
.page-heading p:last-child { margin: 0; color: var(--muted); max-width: 670px; }
.select-control { min-width: 260px; }
.summary-pill, .count-badge { border-radius: 999px; background: var(--green-soft); color: var(--green); padding: .55rem .85rem; font-size: .78rem; font-weight: 750; }

.upload-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(310px, .75fr); gap: 1.2rem; }
.upload-card, .recording-library { border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem; background: #fbfcfa; }
.drop-zone { min-height: 180px; border: 1.5px dashed #aebdb5; border-radius: 14px; display: grid; place-items: center; align-content: center; gap: .35rem; text-align: center; background: white; cursor: pointer; }
.drop-zone.dragging { border-color: var(--green); background: var(--green-soft); }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-zone small { color: var(--muted); }
.drop-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: var(--green-soft); color: var(--green); font-size: 1.5rem; }
.upload-queue { display: grid; gap: .55rem; margin: .8rem 0; }
.upload-item { display: grid; grid-template-columns: minmax(150px,1fr) 170px minmax(180px,1fr) 32px; gap: .55rem; align-items: center; padding: .7rem; border: 1px solid var(--line); border-radius: 11px; background: white; }
.upload-item strong, .upload-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item small { color: var(--muted); font-size: .7rem; }
.upload-item input { padding: .5rem; }
.upload-item button { border: 0; padding: .4rem; }
.metadata-card { margin-top: .9rem; padding: 1rem; border-radius: 13px; background: white; border: 1px solid var(--line); }
.metadata-card h3 { margin: 0 0 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; }
.form-grid.compact { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.advanced { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .9rem; }
.advanced summary { cursor: pointer; color: #40524a; font-weight: 700; }
.advanced[open] summary { margin-bottom: 1rem; }
.advanced .form-grid { margin-top: .8rem; }
.action-row { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; }
.action-row .status { margin: 0; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .85rem; }
.section-title h3 { margin: 0; }
.recording-list { display: grid; gap: .65rem; max-height: 650px; overflow: auto; }
.recording-item { padding: .9rem; border: 1px solid var(--line); border-radius: 12px; background: white; }
.recording-item-head { display: flex; justify-content: space-between; gap: .7rem; }
.recording-item h4 { margin: 0; }
.recording-item p { margin: .5rem 0 0; color: var(--muted); font-size: .76rem; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: .2rem .48rem; font-size: .66rem; font-weight: 750; background: #edf1ef; color: #53635c; }
.badge.good { background: var(--green-soft); color: var(--green); }
.badge.validation { background: var(--blue-soft); color: var(--blue); }

.annotation-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .65fr); gap: 1.1rem; }
.video-workbench, .rep-editor { border: 1px solid var(--line); border-radius: 16px; background: #f9faf8; padding: 1rem; }
.video-workbench video { width: 100%; max-height: 66vh; border-radius: 12px; background: #0d1210; }
.annotation-transport { display: flex; align-items: center; gap: .7rem; margin-top: .8rem; }
.annotation-transport output { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.mark-button { background: var(--green); color: white; border-color: var(--green); flex: 1; }
.rep-counter { display: flex; justify-content: space-between; align-items: center; padding: .8rem 0 1rem; border-bottom: 1px solid var(--line); }
.rep-counter strong { font-size: 2.5rem; line-height: 1; }
.rep-list { display: grid; gap: .45rem; max-height: 390px; overflow: auto; padding: .8rem 0; }
.rep-row { display: grid; grid-template-columns: 34px minmax(0,1fr) 34px; align-items: center; gap: .5rem; padding: .55rem; border-radius: 9px; background: white; border: 1px solid var(--line); }
.rep-row input { padding: .45rem; font-variant-numeric: tabular-nums; }
.rep-row button { padding: .35rem; border: 0; }
.rep-time-editor { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: .35rem; }
.rep-time-editor button { border: 1px solid var(--line); padding: .35rem .48rem; }
.inline-message { margin-top: .7rem; padding: .7rem; background: #fff3df; border-radius: 9px; }

.focus-card { max-width: 620px; margin: 3rem auto; padding: 2.4rem; text-align: center; border: 1px solid var(--line); border-radius: 18px; background: linear-gradient(145deg, #fbfcfa, #f0f5f1); }
.focus-card h3 { margin: .8rem 0 .4rem; font-size: 1.35rem; }
.focus-card p { color: var(--muted); }
.focus-icon { width: 55px; height: 55px; display: grid; place-items: center; margin: auto; border-radius: 17px; background: var(--green-soft); color: var(--green); font-size: 1.5rem; }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; margin-bottom: 1.5rem; }
.metric-card { padding: 1.05rem; border: 1px solid var(--line); border-radius: 14px; background: #fbfcfa; }
.metric-card span, .metric-card small { color: var(--muted); display: block; }
.metric-card strong { display: block; font-size: 1.8rem; margin: .25rem 0; }
.repcheck-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem; }
.repcheck-card { padding: 1rem; border: 1px solid var(--line); border-radius: 14px; }
.repcheck-card-head { display: flex; justify-content: space-between; gap: .5rem; }
.rep-numbers { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .5rem; margin-top: 1rem; text-align: center; }
.rep-numbers strong { font-size: 1.8rem; display: block; }
.rep-numbers small { color: var(--muted); }
.run-model-fieldset { border: 0; padding: 0; margin: 1.2rem 0; text-align: left; }
.run-model-fieldset legend { font-size: .75rem; font-weight: 750; color: var(--muted); margin-bottom: .5rem; }
.run-model-list { display: grid; gap: .45rem; }
.run-model-option { display: flex; align-items: center; gap: .65rem; padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 10px; background: white; }
.run-model-option input { width: auto; }
.run-model-option span, .run-model-option strong, .run-model-option small { display: block; }
.run-model-option small { color: var(--muted); font-size: .7rem; }
.run-progress { padding: 1.2rem; border: 1px solid var(--line); border-radius: 15px; background: #fbfcfa; }
.progress-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.progress-current { min-height: 1.5em; color: var(--blue); font-weight: 700; }
.progress-track { height: 9px; margin: .8rem 0; border-radius: 99px; background: #e3e9e5; overflow: hidden; }
.progress-track i { display: block; height: 100%; background: var(--green); transition: width .25s; }
.run-model-statuses { display: flex; flex-wrap: wrap; gap: .45rem; margin: .8rem 0; }
.run-model-status { padding: .45rem .6rem; border-radius: 9px; background: var(--green-soft); }
.run-model-status strong, .run-model-status small { display: block; }
.run-model-status small { color: var(--muted); font-size: .68rem; }
.progress-log { max-height: 240px; overflow: auto; display: grid; gap: .35rem; color: var(--muted); font-size: .76rem; }
.progress-log span { padding: .35rem .45rem; border-radius: 6px; background: #f1f5f2; }

.calibration-layout { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(310px, .55fr); gap: 1rem; }
.calibration-main, .threshold-panel { min-width: 0; }
.calibration-stage { position: relative; aspect-ratio: 16/9; max-height: 58vh; overflow: hidden; border-radius: 15px; background: #101714; }
.calibration-stage video, .calibration-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.calibration-stage canvas { pointer-events: none; }
.calibration-transport { display: grid; grid-template-columns: 44px 1fr 92px; align-items: center; gap: .6rem; margin: .7rem 0; }
.calibration-transport output { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .78rem; }
.chart-card { border: 1px solid var(--line); border-radius: 14px; padding: .9rem; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .5rem; }
.chart-head span, .chart-head strong { display: block; }
.chart-head span { color: var(--muted); font-size: .72rem; }
.chart-head select { max-width: 280px; }
#angle-chart { width: 100%; height: 220px; }
.detected-events { margin-top: .8rem; padding: .9rem; border: 1px solid #ecd2d2; border-radius: 14px; background: #fffafa; }
.event-track { position: relative; height: 10px; margin: .6rem .25rem 1rem; border-radius: 10px; background: #f0dede; }
.event-track i { position: absolute; top: -3px; width: 4px; height: 16px; margin-left: -2px; border-radius: 4px; background: #b43d3d; }
.event-chips { display: flex; gap: .45rem; overflow-x: auto; padding-bottom: .25rem; }
.event-chips button { flex: 0 0 auto; display: grid; gap: .1rem; text-align: left; border-color: #e5c4c4; background: white; }
.event-chips button strong, .event-chips button span { display: block; }
.event-chips button span { color: var(--muted); font-size: .7rem; }
.event-chips button.active { color: white; background: #b43d3d; border-color: #b43d3d; }
.event-chips button.active span { color: #ffeaea; }
.threshold-panel { border: 1px solid var(--line); border-radius: 15px; padding: 1rem; background: #fbfcfa; align-self: start; position: sticky; top: 170px; max-height: calc(100vh - 190px); overflow: auto; }
.threshold-panel > p { color: var(--muted); font-size: .78rem; }
.threshold-heading { display: flex; justify-content: space-between; gap: .7rem; align-items: flex-start; }
.threshold-heading h3 { margin: 0; }
.threshold-list { display: grid; gap: .65rem; margin: .8rem 0; }
.threshold-control { padding: .8rem; border: 1px solid var(--line); border-radius: 11px; background: white; }
.threshold-control-head { display: flex; justify-content: space-between; gap: .6rem; margin-bottom: .55rem; }
.threshold-control-head small { color: var(--muted); }
.threshold-control-fields { display: grid; grid-template-columns: 1fr 72px; gap: .55rem; align-items: center; }
.threshold-control-fields input[type="range"] { padding: 0; }
.threshold-control-fields input[type="number"] { padding: .45rem; }
.button-stack { display: grid; gap: .5rem; margin-top: 1rem; }
.diagnostic-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: .55rem; }
.diagnostic { padding: .65rem; border-radius: 9px; background: #f2f5f3; }
.diagnostic span, .diagnostic strong { display: block; }
.diagnostic span { color: var(--muted); font-size: .7rem; }
.event-log { margin-top: 1rem; font-size: .75rem; color: var(--muted); }

.final-run-layout { display: grid; grid-template-columns: minmax(300px,.8fr) minmax(0,1.2fr); gap: 1rem; }
.run-card { margin: 0; max-width: none; }
.readiness-list { display: grid; gap: .55rem; text-align: left; margin: 1.2rem 0; }
.readiness-item { display: flex; justify-content: space-between; gap: 1rem; padding: .65rem .8rem; border-radius: 9px; background: white; }
.readiness-item strong.good { color: var(--green); }
.readiness-item strong.warn { color: var(--orange); }

.report-note { padding: .9rem 1rem; margin-bottom: 1rem; border-left: 4px solid var(--blue); background: var(--blue-soft); border-radius: 8px; }
.report-note.warning { border-color: var(--orange); background: #fff2df; }
.report-section { margin-top: 1rem; padding: 1.2rem; border: 1px solid var(--line); border-radius: 15px; }
.error-chart { display: grid; gap: .55rem; }
.error-row { display: grid; grid-template-columns: minmax(180px,260px) 1fr 50px; align-items: center; gap: .8rem; }
.error-bar { position: relative; height: 24px; border-radius: 5px; background: linear-gradient(to right, #f7e7e7 0 49.7%, #ccd7d1 49.7% 50.3%, #e7f2ec 50.3%); }
.error-bar i { position: absolute; top: 4px; height: 16px; min-width: 3px; border-radius: 4px; background: var(--green); }
.condition-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px,1fr)); gap: .7rem; }
.condition-card { padding: .8rem; border-radius: 10px; background: #f5f7f5; }
.condition-card strong, .condition-card span { display: block; }
.condition-card span { color: var(--muted); font-size: .74rem; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .7rem .75rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; }
.download-row { display: flex; flex-wrap: wrap; gap: .55rem; margin-top: 1rem; }
.download-row a { display: inline-flex; text-decoration: none; color: var(--blue); border: 1px solid #cbd8e5; border-radius: 9px; padding: .55rem .75rem; font-size: .78rem; font-weight: 700; }
.step-actions { display: flex; justify-content: space-between; margin-top: 2rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }

dialog { width: min(720px, calc(100vw - 2rem)); border: 0; border-radius: 18px; padding: 0; box-shadow: 0 30px 100px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(18,27,23,.48); backdrop-filter: blur(4px); }
.dialog-shell { padding: 1.4rem; }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; }
.dialog-head h2 { margin: 0; }
.dialog-head button { border: 0; font-size: 1.4rem; padding: .3rem; }
.check-list, .model-list { display: grid; gap: .55rem; margin: .8rem 0 1.2rem; }
.check-item, .model-item { display: flex; justify-content: space-between; gap: 1rem; padding: .75rem; border: 1px solid var(--line); border-radius: 10px; }
.check-item small, .model-item small { display: block; color: var(--muted); }

@media (max-width: 980px) {
  .stepper { overflow-x: auto; grid-template-columns: repeat(6, minmax(130px, 1fr)); }
  .upload-layout, .annotation-layout, .calibration-layout, .final-run-layout { grid-template-columns: 1fr; }
  .threshold-panel { position: static; max-height: none; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 650px) {
  .topbar, .studio { padding-left: 1rem; padding-right: 1rem; }
  .workspace-label { display: none; }
  .exercise-screen { padding: 3.5rem 1rem; }
  .exercise-context { grid-template-columns: 1fr auto; }
  .exercise-context > div:nth-child(2) { grid-column: 1 / 3; grid-row: 1; }
  .exercise-context .back-button { grid-row: 2; }
  .page-heading { display: block; }
  .select-control { display: block; margin-top: 1rem; min-width: 0; }
  .form-grid, .metric-grid { grid-template-columns: 1fr; }
  .upload-item { grid-template-columns: 1fr 34px; }
  .upload-item input { grid-column: 1 / 2; }
  .error-row { grid-template-columns: 100px 1fr 40px; }
}
