:root {
  --bg: #F4F4F7;
  --card: #FFFFFF;
  --card-2: #EEEEF3;
  --text: #121317;
  --muted: #6E7180;
  --line: #E2E3EA;
  --accent: #FF5A4E;
  --accent-2: #F0306F;
  --accent-ink: #FFFFFF;
  --good: #1FA971;
  --warn: #E58A00;
  --bad: #E5484D;

  --t-easy: #22B07D;
  --t-recovery: #6CC5A6;
  --t-long: #3E7BFA;
  --t-tempo: #F08A24;
  --t-intervals: #E5484D;
  --t-hills: #B5562E;
  --t-fartlek: #D0478E;
  --t-racepace: #8E4EF0;
  --t-race: #FFB800;
  --t-cross: #1AA6B7;
  --t-rest: #A3A6B4;

  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E0F13;
    --card: #1A1B21;
    --card-2: #24252D;
    --text: #F3F3F6;
    --muted: #9497A6;
    --line: #2C2D36;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
h1 { font-size: 30px; font-weight: 800; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

#view {
  padding: calc(var(--safe-top) + 18px) 16px calc(var(--safe-bottom) + 96px);
  max-width: 640px;
  margin: 0 auto;
}
.section { margin-top: 26px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 4px 10px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 0 rgba(0,0,0,.03);
}
.card + .card { margin-top: 10px; }

/* Tab bar */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  padding: 6px 6px calc(var(--safe-bottom) + 6px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
}
#tabs[hidden] { display: none; }
#tabs button {
  flex: 1; border: 0; background: none; padding: 6px 0 2px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10.5px; font-weight: 600; color: var(--muted);
}
#tabs svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs button.active { color: var(--accent); }

/* Buttons */
.btn {
  border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .45; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--card-2); color: var(--text); }
.btn.small { padding: 9px 14px; font-size: 14px; border-radius: 11px; }
.btn.danger { background: none; color: var(--bad); border: 1px solid var(--line); }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 4px 0; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }

/* Forms */
label.field { display: block; margin-top: 16px; }
label.field > span, .field-label { display: block; font-size: 14px; font-weight: 600; margin: 0 2px 6px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 2px 0; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=url], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  padding: 12px 14px; font-size: 16px; outline: none; -webkit-appearance: none; appearance: none;
}
input[type=date] { min-height: 48px; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two label.field { margin-top: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: block; padding: 10px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line);
  font-size: 15px; font-weight: 600;
}
.chip input:checked + span { background: var(--text); color: var(--bg); border-color: var(--text); }
.chips.days .chip span { min-width: 46px; text-align: center; padding: 10px 0; }

input[type=range] { width: 100%; accent-color: var(--accent); }

/* Onboarding */
.hero { padding: 18px 2px 8px; }
.hero .logo { width: 64px; height: 64px; border-radius: 16px; display: block; margin-bottom: 18px; }
.hero p { margin-top: 8px; color: var(--muted); font-size: 17px; }
.form-card { background: var(--card); border-radius: var(--radius); padding: 4px 16px 18px; margin-top: 14px; }
.form-card h3 { padding-top: 14px; }

/* Today */
.greet { font-size: 15px; color: var(--muted); font-weight: 600; }
.countdown { display: inline-flex; gap: 6px; align-items: center; margin-top: 10px; padding: 6px 12px; border-radius: 999px; background: var(--card); font-size: 13px; font-weight: 600; }
.session-hero {
  position: relative; overflow: hidden; border-radius: 22px; padding: 20px; color: #fff;
  background: linear-gradient(135deg, var(--tc, var(--accent)), color-mix(in srgb, var(--tc, var(--accent)) 60%, #000));
}
.session-hero .type { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; opacity: .85; }
.session-hero h2 { font-size: 26px; margin-top: 6px; }
.session-hero .metrics { display: flex; gap: 22px; margin-top: 14px; }
.session-hero .metric b { display: block; font-size: 22px; }
.session-hero .metric small { opacity: .8; font-size: 12px; font-weight: 600; }
.session-hero .desc { margin-top: 14px; opacity: .95; font-size: 15px; }
.session-hero .status { position: absolute; top: 16px; right: 16px; background: rgba(255,255,255,.22); padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.session-hero .btn-row { margin-top: 18px; }
.session-hero .btn { background: #fff; color: #111; }
.session-hero .btn.ghost { background: rgba(255,255,255,.2); color: #fff; }

.steps { list-style: none; margin: 14px 0 0; padding: 0; counter-reset: s; }
.steps li { position: relative; padding: 8px 0 8px 32px; border-top: 1px solid var(--line); font-size: 15px; }
.steps li::before { counter-increment: s; content: counter(s); position: absolute; left: 0; top: 8px; width: 22px; height: 22px; border-radius: 50%; background: var(--card-2); font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.session-hero .steps li { border-color: rgba(255,255,255,.2); }
.session-hero .steps li::before { background: rgba(255,255,255,.22); }

.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.ws-day { border: 0; background: none; padding: 8px 0; border-radius: 14px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ws-day .d { font-size: 11px; font-weight: 700; color: var(--muted); }
.ws-day .n { font-size: 17px; font-weight: 700; }
.ws-day .dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 800; color: #fff; }
.ws-day.today { background: var(--card-2); }
.dot.rest { background: transparent; border: 2px dashed var(--line); }
.dot.skipped { opacity: .35; }

.bar { height: 8px; border-radius: 99px; background: var(--card-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.list-item:first-child { border-top: 0; }
.type-pill { width: 6px; align-self: stretch; border-radius: 6px; background: var(--tc); }
.li-date { width: 42px; text-align: center; flex-shrink: 0; }
.li-date b { display: block; font-size: 18px; }
.li-date small { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.li-title { font-weight: 650; }
.li-sub { font-size: 13px; color: var(--muted); }
.check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; flex-shrink: 0; font-size: 13px; color: #fff; }
.check.done { background: var(--good); border-color: var(--good); }
.check.skipped { background: var(--muted); border-color: var(--muted); }
.check.missed { border-color: var(--bad); }

/* Plan */
.week { background: var(--card); border-radius: var(--radius); padding: 4px 16px; margin-top: 10px; }
.week > summary { list-style: none; padding: 14px 0; cursor: pointer; }
.week > summary::-webkit-details-marker { display: none; }
.week.current { box-shadow: inset 0 0 0 2px var(--accent); }
.phase { display: inline-block; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; padding: 3px 8px; border-radius: 6px; background: var(--card-2); }
.paces { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.pace { background: var(--card-2); border-radius: 12px; padding: 8px 12px; }
.pace small { display: block; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.pace b { font-size: 15px; }

/* Progress */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.stat small { color: var(--muted); font-size: 13px; font-weight: 600; }
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Coach chat */
.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; padding: 11px 14px; border-radius: 18px; font-size: 15.5px; white-space: normal; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--card); border-bottom-left-radius: 6px; }
.msg p + p, .msg ul { margin-top: 8px; }
.msg ul { padding-left: 18px; margin-bottom: 0; }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 62px); z-index: 9;
  padding: 8px 12px; display: flex; gap: 8px; max-width: 640px; margin: 0 auto;
}
.composer textarea { min-height: 46px; max-height: 140px; border-radius: 23px; padding: 12px 16px; box-shadow: 0 4px 20px rgba(0,0,0,.12); }
.composer .btn { border-radius: 50%; width: 46px; height: 46px; padding: 0; flex-shrink: 0; align-self: flex-end; }
.quick { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.quick button { flex-shrink: 0; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 13px; font-size: 14px; font-weight: 600; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }

/* Sheet */
#sheet { position: fixed; inset: 0; z-index: 30; }
#sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); animation: fade .2s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 24px 24px 0 0; padding: 8px 16px calc(var(--safe-bottom) + 20px);
  animation: up .25s cubic-bezier(.2,.8,.2,1); max-width: 640px; margin: 0 auto;
}
.sheet-grab { width: 40px; height: 5px; border-radius: 5px; background: var(--line); margin: 4px auto 14px; }
@keyframes up { from { transform: translateY(100%) } }
@keyframes fade { from { opacity: 0 } }

/* Busy overlay */
#busy { position: fixed; inset: 0; z-index: 40; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); display: grid; place-items: center; padding: 24px; }
#busy[hidden] { display: none; }
.busy-card { text-align: center; max-width: 320px; }
.busy-card #busy-title { font-size: 19px; font-weight: 700; margin-top: 20px; }
.busy-card #busy-detail { margin: 8px 0 22px; font-size: 15px; min-height: 22px; }
.spinner { width: 54px; height: 54px; margin: 0 auto; border-radius: 50%; border: 5px solid var(--card-2); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg) } }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 84px); z-index: 50; background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 14px; font-weight: 600; font-size: 14px; max-width: calc(100% - 32px); text-align: center; }
#toast[hidden] { display: none; }

.notice { border-radius: 14px; padding: 12px 14px; background: color-mix(in srgb, var(--accent) 12%, var(--card)); font-size: 14px; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
