:root {
  --bg: #0e0f13;
  --card: #191b22;
  --card2: #22242e;
  --text: #f2f3f7;
  --muted: #9aa0ae;
  --accent: #4ade80;
  --accent-dim: #14532d;
  --danger: #f87171;
  --border: #2b2e3a;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  height: 100%;
  overscroll-behavior-y: none;
}

#app { display: flex; flex-direction: column; min-height: 100dvh; }

#view {
  flex: 1;
  padding: calc(var(--safe-top) + 16px) 16px calc(96px + var(--safe-bottom));
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

h1 { font-size: 26px; margin-bottom: 2px; }
h2 { font-size: 17px; margin-bottom: 10px; }
.subtitle { color: var(--muted); font-size: 14px; margin-bottom: 18px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.card h2 { display: flex; align-items: center; justify-content: space-between; }
.badge {
  font-size: 11px; font-weight: 600; letter-spacing: 0.4px;
  padding: 3px 8px; border-radius: 999px;
  background: var(--accent-dim); color: var(--accent);
}
.badge.gray { background: var(--card2); color: var(--muted); }

/* Segmented control */
.segmented { display: flex; background: var(--card2); border-radius: 10px; padding: 3px; gap: 3px; }
.segmented button {
  flex: 1; border: none; background: transparent; color: var(--muted);
  padding: 9px 4px; border-radius: 8px; font-size: 15px; font-weight: 600;
}
.segmented button.active { background: var(--accent); color: #06220f; }

/* Toggles */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; }
.toggle-row + .toggle-row { border-top: 1px solid var(--border); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .knob {
  position: absolute; inset: 0; background: var(--card2); border-radius: 999px;
  transition: background 0.15s; cursor: pointer;
}
.switch .knob::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  background: #fff; border-radius: 50%; transition: transform 0.15s;
}
.switch input:checked + .knob { background: var(--accent); }
.switch input:checked + .knob::after { transform: translateX(20px); }

/* Stretch checklist */
.stretch-step { display: flex; gap: 12px; padding: 10px 0; align-items: flex-start; }
.stretch-step + .stretch-step { border-top: 1px solid var(--border); }
.stretch-step input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; margin-top: 2px; }
.stretch-step .meta { color: var(--muted); font-size: 13px; }
.stretch-step.done .name { text-decoration: line-through; color: var(--muted); }

/* Exercises */
.exercise { padding: 14px 0; }
.exercise + .exercise { border-top: 1px solid var(--border); }
.exercise-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.exercise-name { font-weight: 600; font-size: 16px; }
.exercise-target { color: var(--muted); font-size: 13px; white-space: nowrap; }
.exercise-notes { color: var(--muted); font-size: 13px; margin-top: 3px; }
.lasttime { margin-top: 6px; font-size: 13px; color: var(--accent); }
.lasttime.none { color: var(--muted); }

.sets { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.set-row { display: flex; align-items: center; gap: 8px; }
.set-row .set-num { width: 20px; color: var(--muted); font-size: 13px; flex: none; }
.set-row input {
  width: 0; flex: 1; background: var(--card2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 10px; font-size: 16px; text-align: center;
}
.set-row input:focus { outline: none; border-color: var(--accent); }
.set-row .x { color: var(--muted); }
.set-row .del { background: none; border: none; color: var(--muted); font-size: 18px; padding: 4px 6px; }

button.small {
  background: var(--card2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; font-size: 14px; font-weight: 600; margin-top: 8px;
}

button.primary {
  width: 100%; background: var(--accent); color: #06220f; border: none;
  border-radius: 12px; padding: 15px; font-size: 16px; font-weight: 700; margin-top: 6px;
}
button.primary:disabled { opacity: 0.5; }
button.secondary {
  width: 100%; background: var(--card2); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 13px; font-size: 15px; font-weight: 600; margin-top: 8px;
}
button.danger { color: var(--danger); border-color: var(--danger); }

/* Forms */
label.field { display: block; margin-bottom: 12px; }
label.field .label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input[type="text"], input[type="number"], input[type="password"], input[type="time"], select, textarea {
  width: 100%; background: var(--card2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 12px; font-size: 16px; font-family: inherit;
}
textarea { min-height: 120px; font-family: ui-monospace, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

/* Choice chips (onboarding) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  background: var(--card2); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 9px 15px; font-size: 14px;
}
.chips button.active { background: var(--accent); border-color: var(--accent); color: #06220f; font-weight: 600; }

/* History */
.session-item { padding: 12px 0; }
.session-item + .session-item { border-top: 1px solid var(--border); }
.session-date { font-weight: 600; }
.session-detail { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* Tab bar */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: space-around;
  background: rgba(14, 15, 19, 0.92);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 8px 0 calc(8px + var(--safe-bottom));
}
#tabbar .tab {
  background: none; border: none; color: var(--muted); font-size: 11px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 18px;
}
#tabbar .tab.active { color: var(--accent); }
#tabbar .tab-icon { font-size: 18px; }

/* Toast */
#toast {
  position: fixed; bottom: calc(90px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 12px; font-size: 14px; max-width: 90%;
  z-index: 100; box-shadow: 0 6px 24px rgba(0,0,0,0.4);
}

.muted { color: var(--muted); font-size: 13px; line-height: 1.5; }
.spacer { height: 10px; }
details.help { margin-top: 10px; }
details.help summary { color: var(--muted); font-size: 13px; cursor: pointer; }
details.help p { margin-top: 8px; }
.rest-day { text-align: center; padding: 30px 10px; color: var(--muted); }
.rest-day .big { font-size: 40px; margin-bottom: 10px; }
