:root {
  color-scheme: dark;
  --bg: #08090b;
  --panel: #121419;
  --panel-2: #191c22;
  --text: #f7f7f2;
  --muted: #aeb3bd;
  --line: #2c3038;
  --red: #f04438;
  --orange: #ff8a1f;
  --steel: #9aa4b2;
  --green: #4ade80;
  --radius: 8px;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(240, 68, 56, .12), transparent 280px),
    radial-gradient(circle at 18% 0%, rgba(255, 138, 31, .18), transparent 260px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
.app-shell { width: min(100%, 760px); margin: 0 auto; padding: 16px 14px 96px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 6px 0 16px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.45rem; text-transform: uppercase; letter-spacing: 0; }
h2 { font-size: 1.6rem; letter-spacing: 0; }
h3 { font-size: 1.05rem; letter-spacing: 0; }
.kicker { color: var(--orange); font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.app-icon { width: 52px; height: 52px; border-radius: 12px; border: 1px solid var(--line); object-fit: cover; }
.install-btn {
  min-height: 40px;
  border-radius: var(--radius);
  padding: 0 12px;
  background: linear-gradient(135deg, var(--red), var(--orange));
  color: #160907;
  font-weight: 950;
}
.view { display: none; }
.view.active { display: block; animation: rise .16s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hero-panel, .control-card, .workout-card, .cue-box, .warning-box, .exercise-panel, .objective-inner, dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,.015)), var(--panel);
  box-shadow: 0 18px 44px rgba(0,0,0,.28);
}
.hero-panel { padding: 18px; min-height: 360px; display: flex; flex-direction: column; justify-content: flex-end; background-image: linear-gradient(180deg, rgba(8,9,11,.2), rgba(8,9,11,.9)), url("/icon-512.png"); background-size: 78%, cover; background-position: top center, center; background-repeat: no-repeat; }
.hero-panel h2 { font-size: clamp(2rem, 14vw, 5rem); line-height: .92; text-transform: uppercase; max-width: 8ch; }
.today-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 18px 0; }
.today-grid div, .stats-strip > div, .progress-grid > div {
  background: rgba(255,255,255,.055);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius);
  padding: 11px;
}
.today-grid span, .stats-strip span, .progress-grid span { display: block; color: var(--muted); font-size: .72rem; }
.today-grid strong, .stats-strip strong, .progress-grid strong { display: block; margin-top: 3px; font-size: .98rem; }

.primary-action, .danger-btn, .ghost-btn, .icon-btn, .file-btn {
  min-height: 48px;
  border-radius: var(--radius);
  padding: 0 14px;
  font-weight: 900;
  color: var(--text);
}
.primary-action { width: 100%; background: linear-gradient(135deg, var(--red), var(--orange)); color: #160907; text-transform: uppercase; }
.danger-btn { background: #3a1111; border: 1px solid #702020; }
.ghost-btn, .icon-btn, .file-btn { display: inline-flex; align-items: center; justify-content: center; background: var(--panel-2); border: 1px solid var(--line); }
.full { width: 100%; margin-top: 12px; }
.section-head, .workout-top, .button-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 18px 0 12px; }
.stats-strip, .progress-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.list { display: grid; gap: 10px; }
.empty-state:empty::before { content: "No workouts logged yet. Start with the 15-minute protocol."; display: block; color: var(--muted); padding: 16px; border: 1px dashed var(--line); border-radius: var(--radius); }

.item {
  padding: 13px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
}
.item-top { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.pill { display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 999px; background: #261515; color: #ffb199; font-size: .72rem; font-weight: 800; white-space: nowrap; }
.muted { color: var(--muted); font-size: .86rem; margin-top: 6px; }
.mini-list { margin: 10px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; color: #dce0e7; }
.mini-list li { padding-left: 12px; border-left: 3px solid var(--red); }

.control-card, .settings-form { display: grid; gap: 12px; padding: 14px; }
fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 12px;
}
legend {
  color: var(--orange);
  font-size: .75rem;
  font-weight: 900;
  text-transform: uppercase;
  padding: 0 6px;
}
label { display: grid; gap: 7px; color: var(--muted); font-weight: 800; font-size: .82rem; }
select, input, textarea {
  width: 100%;
  min-height: 46px;
  color: var(--text);
  background: #0d0f13;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}
textarea { resize: vertical; }
.toggle-row { grid-template-columns: 1fr auto; align-items: center; }
.toggle-row input { width: 22px; height: 22px; min-height: 22px; }
.workout-card { padding: 14px; }
.warning-box, .cue-box { padding: 14px; margin-bottom: 12px; color: #ffe0cf; }
.cue-box p { margin-top: 8px; color: var(--muted); line-height: 1.45; }
.rules-card ul, .objective-inner ul { margin: 10px 0 0; padding-left: 18px; color: #f4d5c5; }
.objective-card { margin: 12px 0; }
.objective-inner { padding: 14px; }
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}
.detail-grid div {
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius);
  padding: 10px;
  background: rgba(255,255,255,.045);
}
.detail-grid span { display: block; color: var(--muted); font-size: .72rem; }
.detail-grid strong { display: block; margin-top: 3px; font-size: .88rem; }
.lab-section { display: grid; gap: 10px; margin-top: 16px; }
.lab-section > h3 { color: var(--orange); text-transform: uppercase; font-size: .9rem; }
.piana-card .primary-action { margin-top: 4px; }

.workout-screen { min-height: calc(100vh - 130px); }
.timer-ring {
  width: min(84vw, 330px);
  aspect-ratio: 1;
  margin: 18px auto;
  border-radius: 50%;
  display: grid;
  place-content: center;
  text-align: center;
  border: 14px solid #242832;
  outline: 2px solid rgba(240,68,56,.45);
  background: radial-gradient(circle, rgba(240,68,56,.16), transparent 60%);
}
.timer-ring span { font-size: 3.4rem; font-weight: 950; line-height: 1; }
.timer-ring small { margin-top: 8px; color: var(--muted); }
.exercise-panel { padding: 18px; }
.exercise-panel h3 { margin-top: 6px; font-size: 1.75rem; }
.exercise-panel p { margin-top: 8px; color: var(--muted); }
.workout-actions { display: grid; gap: 10px; margin-top: 14px; }

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 760px);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: rgba(8,9,11,.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.tabbar button {
  min-height: 48px;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: clamp(.64rem, 2.6vw, .76rem);
  font-weight: 900;
}
.tabbar button.active { color: #130807; background: linear-gradient(135deg, var(--red), var(--orange)); }

.badge-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.badge { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; background: var(--panel); color: var(--muted); font-weight: 900; }
.badge.earned { color: var(--text); border-color: rgba(255,138,31,.5); background: #24160e; }
dialog { width: min(92vw, 520px); color: var(--text); padding: 0; }
dialog::backdrop { background: rgba(0,0,0,.72); }
.rating-form { padding: 16px; display: grid; gap: 12px; }
.rating-form span { color: var(--orange); }
.file-btn input { display: none; }

body.light-mode {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-2: #e9edf2;
  --text: #111318;
  --muted: #555e6b;
  --line: #cdd3dc;
  color-scheme: light;
}

@media (min-width: 680px) {
  .app-shell { padding-inline: 24px; }
  .hero-panel { min-height: 430px; background-size: 50%, cover; }
  .control-card, .settings-form { grid-template-columns: 1fr 1fr; }
  .settings-form fieldset { align-content: start; }
  .settings-form .primary-action { grid-column: 1 / -1; }
  .workout-actions { grid-template-columns: 1.4fr 1fr 1fr; }
}
