:root {
  color-scheme: light;
  --background: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #142033;
  --muted: #667085;
  --line: #e5e7eb;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #eff6ff;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --warning: #9a3412;
  --warning-soft: #fff7ed;
  --danger: #b91c1c;
  --shadow: 0 12px 30px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; }
html { background: var(--background); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { touch-action: manipulation; }
.hidden { display: none !important; }

.app-shell { max-width: 880px; margin: 0 auto; padding-bottom: 92px; }
.hero {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 18px 16px 17px;
  color: #fff;
  background: linear-gradient(145deg, #0f172a, #172554 62%, #1d4ed8);
  border-radius: 0 0 24px 24px;
  box-shadow: var(--shadow);
}
.eyebrow { font-size: 11px; font-weight: 850; letter-spacing: .11em; opacity: .78; }
.hero h1 { margin: 4px 0 5px; font-size: clamp(24px, 6vw, 34px); line-height: 1.1; }
.hero p { margin: 0; max-width: 680px; color: #dbeafe; font-size: 14px; }
.install-button {
  position: absolute;
  top: 17px;
  right: 16px;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 999px;
  padding: 8px 12px;
  color: #fff;
  background: rgba(255,255,255,.12);
  font-weight: 800;
}
.progress-track { height: 9px; margin-top: 15px; overflow: hidden; background: rgba(255,255,255,.18); border-radius: 999px; }
.progress-bar { width: 0; height: 100%; background: #93c5fd; transition: width .25s ease; }
.progress-copy { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; color: #dbeafe; font-size: 12px; }

.week-tabs {
  position: sticky;
  top: 130px;
  z-index: 18;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 14px 6px;
  background: var(--background);
  scrollbar-width: none;
}
.week-tabs::-webkit-scrollbar { display: none; }
.week-tab {
  flex: 0 0 auto;
  padding: 10px 15px;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 850;
}
.week-tab.active { color: #fff; background: var(--brand); }

main { padding: 9px 14px 18px; }
.notice-card {
  margin-bottom: 13px;
  padding: 12px 13px;
  border: 1px solid #a5f3fc;
  border-radius: 14px;
  background: #ecfeff;
  color: #155e75;
  font-size: 13px;
  line-height: 1.48;
}
.session-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.session-card {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  text-align: left;
  box-shadow: 0 2px 6px rgba(15, 23, 42, .04);
}
.session-card.selected { border: 2px solid var(--brand); box-shadow: 0 8px 22px rgba(37,99,235,.12); }
.session-card.done { border-color: #86efac; background: var(--success-soft); }
.session-day { color: var(--muted); font-size: 11px; font-weight: 850; letter-spacing: .07em; }
.session-card h3 { margin: 6px 0; font-size: 16px; }
.badge { display: inline-block; max-width: 100%; padding: 4px 7px; overflow: hidden; border-radius: 999px; background: #eef2ff; color: #3730a3; font-size: 10px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.session-card.done .badge { background: #dcfce7; color: #166534; }

.workout-card { margin-top: 14px; padding: 16px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); }
.workout-card h2 { margin: 0 0 4px; font-size: 21px; }
.workout-subtitle { margin-bottom: 13px; color: var(--muted); font-size: 13px; }
.safety-card { margin-bottom: 14px; padding: 12px; border: 1px solid #fed7aa; border-radius: 14px; background: var(--warning-soft); color: var(--warning); font-size: 13px; line-height: 1.48; }
.exercise-card { padding: 16px 0; border-top: 1px solid var(--line); }
.exercise-card:first-of-type { padding-top: 0; border-top: 0; }
.exercise-head { display: grid; grid-template-columns: 118px 1fr; gap: 12px; align-items: start; }
.guide-image { display: block; width: 118px; aspect-ratio: 3 / 2; object-fit: cover; border: 1px solid var(--line); border-radius: 13px; background: #e2e8f0; }
.exercise-name { font-size: 17px; font-weight: 850; line-height: 1.25; }
.prescription { margin: 4px 0 7px; color: var(--brand-dark); font-size: 14px; font-weight: 850; }
.cues { margin: 0; padding-left: 18px; color: #334155; font-size: 13px; line-height: 1.42; }
.cues li { margin-bottom: 3px; }
.exercise-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.log-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 11px; }
.log-inputs input, .login-card input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}
.exercise-check { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; font-weight: 700; }
.exercise-check input { width: 20px; height: 20px; accent-color: var(--success); }
.workout-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.helper-copy { margin-top: 10px; color: var(--muted); font-size: 12px; line-height: 1.4; }

.button {
  min-height: 44px;
  padding: 10px 14px;
  border: 0;
  border-radius: 12px;
  font-weight: 850;
  cursor: pointer;
}
.button:disabled { opacity: .5; cursor: not-allowed; }
.button.primary { background: var(--brand); color: #fff; }
.button.primary:hover { background: var(--brand-dark); }
.button.secondary { background: #eef2f7; color: var(--ink); }
.button.ghost { border: 1px solid var(--line); background: #fff; color: var(--ink); }
.button.danger { background: #fee2e2; color: #991b1b; }
.button.scan { min-height: 38px; padding: 8px 11px; background: #111827; color: #fff; font-size: 13px; }

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 24;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 10px max(12px, calc((100vw - 880px) / 2 + 12px)) calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(14px);
}
.bottom-bar .button { flex: 1; max-width: 250px; }
.timer-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 13px; padding: 13px 14px; border-radius: 16px; background: #111827; color: #fff; }
.timer-card small { display: block; color: #cbd5e1; font-weight: 800; }
.timer-card strong { font-size: 28px; font-variant-numeric: tabular-nums; }

.scanner-dialog, .login-dialog { width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; padding: 0; border: 0; background: rgba(2,6,23,.66); }
.scanner-dialog::backdrop, .login-dialog::backdrop { background: rgba(2,6,23,.66); }
.scanner-panel {
  width: min(100%, 760px);
  min-height: 100%;
  margin-left: auto;
  padding: 16px 14px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
  background: var(--background);
}
.scanner-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.scanner-header h2 { margin: 3px 0 3px; font-size: 25px; }
.scanner-header p { margin: 0; color: var(--muted); font-size: 13px; }
.icon-button { display: grid; width: 44px; height: 44px; flex: 0 0 44px; place-items: center; border: 0; border-radius: 50%; background: #e2e8f0; color: #0f172a; font-size: 27px; }
.scanner-security { margin: 13px 0; padding: 11px 12px; border: 1px solid #bae6fd; border-radius: 13px; background: #f0f9ff; color: #075985; font-size: 12px; line-height: 1.45; }
.camera-frame {
  position: relative;
  width: 100%;
  min-height: 240px;
  overflow: hidden;
  border-radius: 18px;
  background: #020617;
  box-shadow: var(--shadow);
}
.camera-frame video, .camera-frame img { display: block; width: 100%; height: auto; min-height: 240px; max-height: 62vh; object-fit: contain; background: #020617; }
.camera-placeholder { position: absolute; inset: 0; display: grid; place-content: center; padding: 20px; color: #cbd5e1; text-align: center; }
.camera-placeholder span { font-size: 52px; }
.camera-placeholder p { margin: 8px 0 0; }
.box-layer { position: absolute; inset: 0; pointer-events: none; }
.detection-box { position: absolute; border: 4px solid #94a3b8; border-radius: 10px; box-shadow: 0 0 0 1px rgba(15,23,42,.7); }
.detection-box.target { border-color: #22c55e; }
.detection-box.alternative { border-color: #f59e0b; }
.detection-label { position: absolute; top: -34px; left: -4px; max-width: min(280px, 85vw); padding: 6px 8px; border-radius: 8px 8px 8px 0; background: #0f172a; color: #fff; font-size: 12px; font-weight: 850; white-space: nowrap; }
.scan-status { margin: 11px 0; color: var(--muted); font-size: 13px; }
.scan-status.busy { color: var(--brand-dark); font-weight: 800; }
.scan-status.error { color: var(--danger); font-weight: 750; }
.scanner-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.scan-summary { margin-top: 13px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: #334155; font-size: 13px; line-height: 1.45; }
.scan-results { display: grid; gap: 9px; margin-top: 12px; }
.result-card { padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.result-card.target { border-color: #86efac; background: var(--success-soft); }
.result-card.alternative { border-color: #fcd34d; background: #fffbeb; }
.result-top { display: flex; justify-content: space-between; gap: 12px; }
.result-name { font-weight: 850; }
.result-chip { flex: 0 0 auto; align-self: start; padding: 4px 7px; border-radius: 999px; background: #e2e8f0; color: #334155; font-size: 10px; font-weight: 850; text-transform: uppercase; }
.result-card.target .result-chip { background: #dcfce7; color: #166534; }
.result-card.alternative .result-chip { background: #fef3c7; color: #92400e; }
.result-card p { margin: 7px 0 0; color: #475569; font-size: 12px; line-height: 1.43; }
.scanner-help { margin-top: 14px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: #334155; font-size: 13px; }
.scanner-help summary { cursor: pointer; font-weight: 850; }
.scanner-help ul { padding-left: 18px; line-height: 1.5; }

.login-dialog { display: none; place-items: center; padding: 18px; }
.login-dialog[open] { display: grid; }
.login-card { width: min(100%, 390px); padding: 20px; border-radius: 20px; background: #fff; box-shadow: var(--shadow); }
.login-card h2 { margin: 0 0 6px; }
.login-card p { margin: 0 0 15px; color: var(--muted); font-size: 13px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; font-weight: 800; }
.form-error { min-height: 22px; padding-top: 7px; color: var(--danger); font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 7px; }

@media (max-width: 620px) {
  .week-tabs { top: 130px; }
  .session-card { padding: 11px; }
  .session-card h3 { font-size: 14px; }
  .exercise-head { grid-template-columns: 1fr; }
  .guide-image { width: 100%; max-height: 190px; }
  .install-button { position: static; margin-top: 10px; }
}

@media (max-width: 420px) {
  .progress-copy { font-size: 11px; }
  .badge { max-width: 88px; }
  .bottom-bar { flex-wrap: wrap; }
  .bottom-bar .button { min-width: 100px; max-width: none; }
}
