:root {
  color-scheme: dark;
  --bg: #090b0e;
  --panel: #11151a;
  --panel-2: #161b21;
  --panel-3: #1b222a;
  --line: #28313b;
  --text: #f4f6f8;
  --muted: #98a3af;
  --accent: #ff4d36;
  --accent-2: #ff795f;
  --good: #74d69b;
  --warn: #ffc857;
  --danger: #ff6b6b;
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error-text { color: var(--danger); min-height: 1.2em; }
.eyebrow { margin: 0 0 6px; color: var(--accent-2); font-weight: 800; letter-spacing: .13em; font-size: 11px; }

.app-shell { min-height: 100vh; padding-bottom: calc(88px + var(--safe-bottom)); }
.hero { padding: calc(22px + env(safe-area-inset-top, 0px)) 18px 18px; border-bottom: 1px solid var(--line); background: radial-gradient(circle at top right, rgba(255,77,54,.16), transparent 38%), var(--bg); }
.hero-topline { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.hero h1 { margin: 0; font-size: clamp(28px, 8vw, 42px); line-height: 1; letter-spacing: -.04em; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-weight: 900; }
.countdown-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 17px; min-height: 105px; display: flex; flex-direction: column; justify-content: center; }
.stat-card.accent { border-color: rgba(255,77,54,.55); background: linear-gradient(145deg, rgba(255,77,54,.22), var(--panel)); }
.stat-number { font-size: 36px; line-height: 1; font-weight: 900; letter-spacing: -.05em; }
.stat-label { margin-top: 7px; color: var(--muted); font-size: 13px; }
.hero-meta { margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hero-meta > div { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.meta-label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; margin-bottom: 4px; }
.today-card { margin-top: 12px; background: #f4f6f8; color: #0c0e11; border-radius: var(--radius); padding: 16px; }
.today-card h3 { margin: 0 0 6px; font-size: 20px; }
.today-card .today-kicker { font-size: 11px; font-weight: 900; letter-spacing: .1em; color: #6d7580; }
.today-card .today-workout { padding: 10px 0 0; margin-top: 10px; border-top: 1px solid #d9dde2; }
.today-card .today-workout strong { display: block; }
.sync-status { font-size: 11px; color: var(--muted); text-align: right; margin-top: 8px; }

main { width: min(100%, 900px); margin: 0 auto; padding: 20px 14px; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 14px; }
.section-heading h2 { margin: 0; font-size: 28px; letter-spacing: -.035em; }
.view { display: none; }
.view.active { display: block; }

.week { border: 1px solid var(--line); border-radius: 20px; overflow: clip; margin: 0 0 18px; background: var(--panel); scroll-margin-top: 14px; }
.week.current { border-color: rgba(255,77,54,.6); box-shadow: 0 0 0 1px rgba(255,77,54,.12); }
.week-header { padding: 16px; background: linear-gradient(180deg, var(--panel-2), var(--panel)); }
.week-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.week-title { margin: 0; font-size: 21px; }
.week-dates { color: var(--muted); font-size: 12px; margin-top: 4px; }
.week-tools { display: flex; gap: 7px; align-items: center; }
.phase-select { width: auto; min-width: 128px; padding: 8px 30px 8px 10px; }
.week-notes { margin-top: 13px; display: grid; grid-template-columns: 1fr; gap: 8px; }
.week.collapsed .week-body { display: none; }
.week-toggle { width: 34px; height: 34px; border-radius: 10px; }

.day { border-top: 1px solid var(--line); background: var(--panel); scroll-margin-top: 12px; }
.day.today { background: linear-gradient(90deg, rgba(255,77,54,.08), transparent 45%); }
.day-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.day-date { width: 44px; flex: 0 0 44px; text-align: center; border-right: 1px solid var(--line); padding-right: 10px; }
.day-date strong { display: block; font-size: 20px; line-height: 1; }
.day-date span { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; margin-top: 3px; }
.day-title-input { font-weight: 800; text-transform: uppercase; letter-spacing: .02em; background: transparent !important; border: 0 !important; padding: 8px 0 !important; }
.day-actions { margin-left: auto; display: flex; gap: 6px; }
.workout-list { padding: 0 12px 12px 68px; }
.workout-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 15px; margin-bottom: 9px; overflow: hidden; }
.workout-card:last-child { margin-bottom: 0; }
.workout-main { width: 100%; border: 0; background: transparent; color: var(--text); text-align: left; padding: 13px; }
.workout-top { display: flex; justify-content: space-between; gap: 12px; }
.workout-name { font-weight: 850; font-size: 15px; }
.workout-category { color: var(--accent-2); font-size: 10px; text-transform: uppercase; letter-spacing: .09em; font-weight: 800; }
.workout-plan-preview { margin-top: 6px; font-size: 13px; line-height: 1.4; color: #c9d0d7; white-space: pre-line; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.result-strip { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); }
.result-pill { padding: 9px 12px; font-size: 11px; color: var(--muted); }
.result-pill + .result-pill { border-left: 1px solid var(--line); }
.result-pill.done { color: var(--good); font-weight: 800; }
.empty-day { color: var(--muted); font-size: 12px; padding: 1px 0 4px; }

.btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 12px; padding: 11px 14px; font-weight: 750; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.ghost { background: transparent; }
.btn.danger { color: #ff8c8c; border-color: rgba(255,107,107,.35); }
.btn.small { padding: 8px 10px; font-size: 12px; }
.btn.icon { padding: 8px 10px; min-width: 37px; }

input, textarea, select { width: 100%; background: var(--panel-3); color: var(--text); border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; outline: none; }
textarea { min-height: 95px; resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus { border-color: rgba(255,77,54,.75); box-shadow: 0 0 0 3px rgba(255,77,54,.09); }
label { display: block; font-size: 12px; color: var(--muted); font-weight: 700; }
label > span { display: block; margin-bottom: 6px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-section { padding: 14px 0; border-top: 1px solid var(--line); }
.form-section:first-child { border-top: 0; padding-top: 0; }
.form-section h4 { margin: 0 0 10px; }
.details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.check-row { display: flex; gap: 8px; align-items: center; }
.check-row input { width: auto; }

.template-grid { display: grid; gap: 10px; }
.template-card { border: 1px solid var(--line); background: var(--panel); border-radius: 16px; padding: 14px; }
.template-card h3 { margin: 0 0 5px; }
.template-card p { color: var(--muted); font-size: 13px; white-space: pre-line; }
.template-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.race-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 15px; margin-bottom: 12px; }
.race-card h3 { margin-top: 0; }
.station-grid { display: grid; grid-template-columns: 1fr; gap: 9px; }

.bottom-nav { position: fixed; z-index: 30; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(5, 1fr); border-top: 1px solid var(--line); background: rgba(10,12,15,.94); backdrop-filter: blur(16px); padding: 7px 4px calc(7px + var(--safe-bottom)); }
.bottom-nav button { border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 50px; justify-content: center; }
.bottom-nav button span { font-size: 18px; }
.bottom-nav button small { font-size: 10px; }
.bottom-nav button.active { color: var(--accent-2); }

.modal { width: min(94vw, 650px); max-height: 90vh; overflow: auto; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 20px; padding: 0; box-shadow: 0 24px 100px rgba(0,0,0,.65); }
.modal::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(4px); }
.modal-header { position: sticky; z-index: 2; top: 0; background: rgba(17,21,26,.97); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); padding: 14px 15px; display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { margin: 0; }
.modal-body { padding: 15px; }
.modal-footer { position: sticky; bottom: 0; display: flex; flex-wrap: wrap; gap: 8px; background: rgba(17,21,26,.97); border-top: 1px solid var(--line); padding: 12px 15px; }
.close-btn { border: 0; background: var(--panel-3); color: var(--text); width: 36px; height: 36px; border-radius: 50%; }

.lock-screen { min-height: 100vh; padding: 24px; display: grid; place-items: center; background: radial-gradient(circle at top, rgba(255,77,54,.18), transparent 35%), var(--bg); }
.lock-card { width: min(100%, 420px); border: 1px solid var(--line); background: var(--panel); border-radius: 24px; padding: 26px; }
.lock-card h1 { font-size: 34px; margin: 0 0 10px; }
.brand-mark { width: 60px; height: 60px; border-radius: 16px; display: grid; place-items: center; background: var(--text); color: var(--bg); font-size: 28px; font-weight: 950; margin-bottom: 22px; }
.brand-mark span { color: var(--accent); }
.pin-form { display: grid; gap: 10px; margin-top: 20px; }

.toast { position: fixed; z-index: 100; left: 50%; top: calc(15px + env(safe-area-inset-top, 0px)); transform: translate(-50%, -18px); opacity: 0; pointer-events: none; background: #edf0f3; color: #111; border-radius: 999px; padding: 10px 15px; font-size: 12px; font-weight: 800; transition: .25s ease; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.history-item { padding: 11px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.history-item:last-child { border: 0; }

@media (min-width: 700px) {
  .hero { padding-left: max(24px, calc((100vw - 900px)/2)); padding-right: max(24px, calc((100vw - 900px)/2)); }
  .countdown-grid { grid-template-columns: 1fr 1fr; }
  .week-notes { grid-template-columns: 1fr 1fr; }
  .station-grid { grid-template-columns: 1fr 1fr; }
}
