:root {
  --bg: #F6F5F1;
  --card: #FFFFFF;
  --ink: #12161C;
  --muted: #6E737B;
  --line: #E4E2DC;
  --soft: rgba(18, 22, 28, 0.05);
  /* cor de destaque: preto por padrão; a cor favorita da pessoa substitui (js/theme.js) */
  --accent: var(--ink);
  --accent-soft: #D3D1CB;
  --accent-ink: var(--bg);
  --ok: #1F9D6B;
  --warn-bg: #FFF3E3;
  --warn-ink: #8A4B00;
  --danger: #C8372D;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --font: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B0E13; --card: #141922; --ink: #EEF1F5; --muted: #8C949F; --line: #232A35;
    --soft: rgba(255,255,255,.05); --accent-soft: #343A45;
    --ok: #3CC48E; --warn-bg: #2E2414; --warn-ink: #F5C27A; --danger: #FF6B5E;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .3; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

.app {
  max-width: 520px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 20px calc(env(safe-area-inset-bottom) + 40px);
}

/* ---------- barra superior ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.brand { font-weight: 800; font-size: 18px; letter-spacing: -0.01em; }
.brand::first-letter { color: var(--accent); }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; display: grid; place-items: center; }
.icon-btn:hover:not(:disabled) { background: var(--soft); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.text-btn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 8px 4px; }
.text-btn.block { display: block; margin: 8px auto 0; }
.text-btn.danger { color: var(--danger); }
.lang { display: inline-flex; background: var(--soft); border-radius: 10px; padding: 3px; }
.lang button { border: 0; background: none; border-radius: 8px; padding: 6px 10px; font-weight: 700; font-size: 13px; color: var(--muted); }
.lang [aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---------- botões ---------- */
.primary-btn {
  display: block; width: 100%; min-height: 54px; border: 0; border-radius: 16px; margin-top: 16px;
  background: var(--accent); color: var(--accent-ink); font-size: 17px; font-weight: 700;
}
.primary-btn:active { transform: scale(.98); }
.ghost-btn {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: 50px; margin-top: 12px;
  border: 1.5px solid var(--line); border-radius: 14px; background: var(--card); font-weight: 600; cursor: pointer; text-align: center;
}
.danger-btn { display: block; width: 100%; margin-top: 10px; min-height: 48px; border: 0; background: none; color: var(--danger); font-weight: 600; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }
.btn-row .primary-btn, .btn-row .ghost-btn { margin-top: 12px; }

/* ---------- configuração (a frase) ---------- */
.hero-title { font-size: 26px; letter-spacing: -0.02em; line-height: 1.15; margin: 8px 0 6px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-top: 14px; }
.sentence-text { font-size: 22px; line-height: 2; margin: 0; font-weight: 500; letter-spacing: -0.01em; }
.inline {
  border: 0; border-bottom: 2px solid var(--accent); background: transparent; border-radius: 0;
  font-weight: 700; color: var(--accent); padding: 0 2px; font-size: inherit; -webkit-appearance: none; appearance: none;
  min-height: 36px; max-width: 100%;
}
select.inline { padding-right: 18px; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 9px) 55%, calc(100% - 4px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }
.inline.num { width: 3.2em; text-align: center; }
.inline::placeholder { color: var(--accent); opacity: .45; }
input[type="date"].inline { min-width: 0; text-align: left; }
input[type="date"].inline::-webkit-date-and-time-value { text-align: left; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.field-label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin: 18px 0 8px; }
.field {
  display: block; width: 100%; min-height: 48px; border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--bg); padding: 10px 12px; font-size: 16px;
}
textarea.field { resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.chip {
  min-height: 44px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card);
  font-weight: 600; font-size: 14px; text-transform: capitalize; padding: 0;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.error { color: var(--danger); font-weight: 600; min-height: 1em; margin: 12px 0 0; }
.setup-cta {
  position: sticky; bottom: 0; z-index: 3; margin: 0 -20px; padding: 16px 20px calc(env(safe-area-inset-bottom) + 12px);
  background: linear-gradient(to bottom, transparent, var(--bg) 18px);
}
.setup-cta .error { margin: 0 0 8px; min-height: 0; }
.setup-cta .primary-btn { margin-top: 0; }
.primary-btn:disabled { opacity: .55; cursor: default; transform: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* campo de data: formato no idioma do app enquanto vazio */
.date-wrap { position: relative; display: inline-block; }
.date-ph { display: none; position: absolute; left: 2px; top: 50%; transform: translateY(-50%); pointer-events: none;
  color: var(--accent); opacity: .45; font-weight: 700; white-space: nowrap; line-height: 1; }
.date-wrap.empty .date-ph { display: block; }
.date-wrap.empty input:not(:focus)::-webkit-datetime-edit { color: transparent; }
.date-wrap.empty input:not(:focus) { color: transparent; }
.date-wrap.empty input:focus + .date-ph { display: none; }

/* segundo passo */
.build-steps { list-style: none; padding: 0; margin: 12px 0 4px; display: grid; gap: 10px; }
.build-steps li { display: flex; align-items: center; gap: 12px; font-size: 16px; color: var(--muted); transition: color .3s; }
.build-steps li.active, .build-steps li.done { color: var(--ink); }
.b-ico { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; transition: background .3s, border-color .3s; }
.build-steps li.active .b-ico { border-color: var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.build-steps li.done .b-ico { background: var(--accent); border-color: var(--accent); animation: none; }
.build-steps li.done .b-ico::after { content: ""; width: 9px; height: 5px; border: solid var(--accent-ink); border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }
@keyframes spin { to { transform: rotate(360deg); } }
.details-lead { margin: 0; font-size: 15px; font-weight: 600; }
.details .field-label:first-of-type { margin-top: 12px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: var(--soft); }
.seg button { min-height: 40px; border: 0; border-radius: 10px; background: transparent; font-weight: 600; font-size: 15px; color: var(--muted); }
.seg [aria-checked="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.goal-value { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.goal-value .field { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.goal-unit { color: var(--muted); font-weight: 600; }
.goal-unit:empty { display: none; }
.hint.bad { color: var(--danger); font-weight: 600; }
.race-goal { margin: 4px 0 0; font-size: 15px; font-weight: 600; color: var(--accent); }

.setup-links { display: flex; justify-content: center; align-items: center; gap: 8px; margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.privacy-note { color: var(--muted); font-size: 14px; text-align: center; line-height: 1.5; margin: 24px 0 0; }
.tip { background: var(--card); box-shadow: var(--shadow); border-radius: 16px; padding: 12px 14px; font-size: 14px; line-height: 1.45; color: var(--muted); margin-top: 8px; }
.tip.warn { background: var(--warn-bg); color: var(--warn-ink); box-shadow: none; margin-top: 16px; }

/* ---------- visão geral ---------- */
.hero { margin: 8px 0 4px; }
.eyebrow { margin: 0; color: var(--muted); font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.race-title { margin: 4px 0 2px; font-size: 34px; letter-spacing: -0.03em; line-height: 1.1; overflow-wrap: anywhere; }
.race-meta { margin: 0; color: var(--muted); font-size: 15px; }
.race-meta::first-letter { text-transform: uppercase; }
.countdown { display: inline-block; margin: 12px 0 0; padding: 6px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--ink); font-weight: 700; font-size: 15px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0 0; }
.stats div { background: var(--card); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 4px 0 0; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stats small { font-size: 12px; color: var(--muted); font-weight: 600; display: block; letter-spacing: 0; }
.card-title { margin: 0; font-size: 16px; font-weight: 700; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chart-card { padding: 16px 12px 12px; }
.chart-card .card-title { padding: 0 6px 6px; }
.chart { width: 100%; height: auto; display: block; }
.chart .baseline { stroke: var(--line); }
.chart .bar-plan { fill: var(--accent-soft); }
.chart .bar-plan.current { stroke: var(--accent); stroke-width: 1.5; }
.chart .bar-done { fill: var(--accent); }
.chart .bar-race { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 3 2.5; }
.chart .bar-none { fill: var(--line); }
.chart .flag { fill: var(--ink); stroke: var(--ink); stroke-width: 1.5; stroke-linejoin: round; }
.chart .now { fill: var(--accent); }
.chart .axis { font-size: 10px; fill: var(--muted); text-anchor: middle; font-family: var(--font); }
.chart .axis.current { fill: var(--ink); font-weight: 800; }
.chart .hit { fill: transparent; cursor: pointer; outline: none; }
.chart .hit:hover, .chart .hit:focus-visible { fill: var(--soft); }
.legend { display: flex; align-items: center; gap: 6px; margin: 6px 6px 0; font-size: 12px; color: var(--muted); }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.plan { background: var(--accent-soft); }
.sw.done { background: var(--accent); margin-left: 6px; }
.disclaimer { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 20px 4px 0; }

/* ---------- treinos ---------- */
.sessions { list-style: none; margin: 8px 0 0; padding: 0; }
.session { display: flex; align-items: center; gap: 4px; border-top: 1px solid var(--line); }
.session:first-child { border-top: 0; }
.check {
  flex: none; width: 44px; height: 44px; border: 0; background: none; display: grid; place-items: center; padding: 0;
}
.check svg { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); fill: none; stroke: transparent; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; padding: 3px; transition: background .15s, border-color .15s; }
.session.done .check svg { background: var(--ok); border-color: var(--ok); stroke: #fff; }
.session.race:not(.done) .check svg { border-color: var(--accent); }
.s-body { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 0; background: none; text-align: left; padding: 12px 4px; }
.s-main { display: flex; flex-direction: column; min-width: 0; }
.s-type { font-weight: 700; font-size: 16px; }
.s-date { color: var(--muted); font-size: 13px; }
.s-date b { color: var(--accent); }
.s-km { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.s-km small { color: var(--muted); font-weight: 600; font-size: 12px; }
.session.done .s-type { color: var(--muted); }
.session.missed .s-date { color: var(--danger); }
.session.missed .s-type, .session.missed .s-km { opacity: .55; }
.session.is-today { background: linear-gradient(90deg, var(--soft), transparent); border-radius: 12px; }
.sessions.big { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 12px 4px 6px; margin-top: 16px; }
.sessions.big .s-body { padding: 16px 4px; }

/* ---------- semana ---------- */
.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.week-title { text-align: center; }
.week-title h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.week-title p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.progress-bar { height: 6px; border-radius: 3px; background: var(--accent-soft); margin: 14px 0 0; overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .4s; }

/* ---------- sheets ---------- */
.sheet {
  width: 100%; max-width: 520px; margin: auto auto 0; border: 0; border-radius: 26px 26px 0 0;
  background: var(--bg); color: var(--ink); padding: 8px 20px calc(env(safe-area-inset-bottom) + 24px);
  max-height: 90dvh; overflow-y: auto;
}
.sheet[open] { animation: sheet-in .26s cubic-bezier(.2,.9,.3,1); }
.sheet.closing { animation: sheet-out .16s ease-in forwards; }
.sheet::backdrop { background: rgba(0,0,0,.35); }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }
.sheet-title { margin: 0 0 12px; font-size: 20px; text-align: center; }
.sheet-sub { margin: 0 0 12px; color: var(--muted); font-size: 14px; line-height: 1.5; text-align: center; }
.sub-title { font-size: 15px; margin: 20px 0 8px; }
.sheet hr { border: 0; border-top: 1px solid var(--line); margin: 22px 0 0; }
.stepper { display: flex; gap: 10px; align-items: center; }
.stepper .field { text-align: center; font-size: 20px; font-weight: 700; }
.step-btn { flex: none; width: 48px; height: 48px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--card); font-size: 22px; }
.switch { display: flex; align-items: center; gap: 10px; margin-top: 18px; font-weight: 600; min-height: 44px; }
.switch input { width: 22px; height: 22px; accent-color: var(--ok); }
.qr { display: grid; place-items: center; margin: 6px auto 4px; }
.qr svg { width: min(240px, 70vw); height: auto; background: #fff; border-radius: 12px; }
.qr svg path { fill: #000; }
.menu { display: flex; flex-direction: column; }
.menu button, .menu a {
  display: block; text-align: left; border: 0; background: none; padding: 14px 6px; font-size: 17px; font-weight: 600;
  border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none;
}
.menu-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 6px 0; font-weight: 600; }
.plan-list { list-style: none; padding: 0; margin: 0; }
.plan-row { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.plan-main { flex: 1; text-align: left; border: 0; background: none; padding: 12px 4px; display: flex; flex-direction: column; gap: 2px; }
.plan-main span { color: var(--muted); font-size: 13px; }
.plan-main b { font-size: 16px; }
.plan-main .pill { color: var(--accent); font-weight: 700; font-size: 12px; margin-left: 4px; }
.install { text-align: center; }
.install-icon { width: 64px; height: 64px; border-radius: 15px; margin: 4px auto 10px; display: block; box-shadow: var(--shadow); }
.install .sheet-title { font-size: 22px; letter-spacing: -0.01em; }
.install .tip.warn { text-align: left; margin: 0 0 8px; }
.steps { list-style: none; counter-reset: step; padding: 0; margin: 16px 0 4px; text-align: left; display: grid; gap: 10px; }
.steps li { counter-increment: step; display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); font-size: 15px; line-height: 1.4; }
.steps li::before { content: counter(step); flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 13px; display: grid; place-items: center; }
.step-ico { flex: none; width: 36px; height: 36px; border-radius: 10px; background: var(--soft); display: grid; place-items: center; color: #0A84FF; }
.step-ico svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.step-ico img { width: 36px; height: 36px; border-radius: 9px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 32px; height: 32px; border-radius: 50%; border: 0; padding: 0; background: var(--c); cursor: pointer;
  box-shadow: 0 0 0 2px var(--card), 0 0 0 3px transparent; position: relative; flex: none;
}
.swatch.on { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--c); }
.swatch.custom { background: conic-gradient(#e0457b, #ee6a1f, #f2c12e, #1f9d6b, #0e9aa7, #2f6feb, #7a5af8, #e0457b); }
.swatch.custom.on { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--c); }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }
.sheet .swatches { justify-content: center; gap: 8px; margin: 8px 0 4px; }
.sheet .swatch { width: 34px; height: 34px; }
.privacy-list { padding-left: 20px; line-height: 1.55; font-size: 15px; }
.privacy-list li { margin-bottom: 10px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translate(-50%, 12px); opacity: 0;
  padding: 12px 18px; border-radius: 999px; background: var(--ink); color: var(--bg); font-weight: 600; font-size: 15px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); transition: opacity .2s, transform .2s; z-index: 30; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}
@media (max-width: 360px) { .sentence-text { font-size: 19px; } .stats dd { font-size: 19px; } }
