:root {
  --bg: #0b0b0e;
  --surface: #15151a;
  --surface-2: #1e1e25;
  --surface-3: #2a2a33;
  --line: #2c2c36;
  --text: #f4f4f7;
  --muted: #9c9cab;
  --accent: #ff6f91;
  --accent-2: #ffb3c6;
  --accent-ink: #2a0a14;
  --good: #4ade80;
  --blue: #60a5fa;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 18px;
  --radius-sm: 12px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { min-height: 100dvh; overscroll-behavior-y: none; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }

#app { max-width: 640px; margin: 0 auto; min-height: 100dvh; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 18px 10px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.brand { font-weight: 900; font-style: italic; font-size: 26px; letter-spacing: -1px; text-decoration: none; }
.brand span { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.streak { display: inline-flex; align-items: center; gap: 4px; padding: 6px 11px; border-radius: 999px;
  background: var(--surface-2); font-weight: 800; font-size: 14px; }
.streak:empty { display: none; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-3) center/cover; display: grid;
  place-items: center; font-weight: 800; font-size: 14px; text-decoration: none; color: var(--muted); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .6; }
.sync-dot.ok { background: var(--good); opacity: 1; }
.sync-dot.busy { background: var(--warn); opacity: 1; animation: pulse 1s infinite; }
.sync-dot.err { background: var(--danger); opacity: 1; }
@keyframes pulse { 50% { opacity: .3; } }

main { padding: 4px 16px calc(var(--tabbar-h) + var(--safe-b) + 28px); outline: none; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  bottom: calc(10px + var(--safe-b)); width: min(calc(100% - 24px), 460px);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(30, 30, 37, .86); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line); border-radius: 26px; padding: 6px;
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 5px;
  border-radius: 20px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600; }
.tabbar svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--text); background: var(--surface-3); }
.tabbar a.active svg { stroke: var(--accent); }

/* ---------- generic ---------- */
h1 { font-size: 30px; font-weight: 900; letter-spacing: -.8px; margin: 6px 0 4px; }
h2 { font-size: 18px; font-weight: 800; margin: 26px 0 10px; letter-spacing: -.2px; }
h3 { font-size: 16px; margin: 0; font-weight: 800; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
  padding: 0 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface-2);
  font-weight: 700; cursor: pointer; text-decoration: none; user-select: none; touch-action: manipulation; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; border-radius: 11px; font-size: 14px; }
.btn.icon { width: 44px; padding: 0; }
.btn:disabled { opacity: .45; pointer-events: none; }

.seg { display: flex; background: var(--surface-2); border-radius: 13px; padding: 4px; gap: 4px; }
.seg button { flex: 1; min-height: 36px; border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  font-weight: 700; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 2px; font-weight: 600; }
.input, select.input, textarea.input { width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 13px;
  border: 1px solid var(--line); background: var(--surface-2); font-size: 16px; outline: none; }
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 80px; resize: vertical; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); font-size: 12px; font-weight: 700; color: var(--muted); }
.pill.good { color: var(--good); background: rgba(74, 222, 128, .12); }
.pill.accent { color: var(--accent); background: rgba(255, 111, 145, .12); }

/* ---------- today ---------- */
.daynav { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 12px; }
.daynav .title { text-align: center; }
.daynav .title b { display: block; font-size: 22px; font-weight: 900; letter-spacing: -.4px; }
.weekstrip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 14px; }
.weekstrip button { border: 0; background: transparent; padding: 6px 0; border-radius: 12px; cursor: pointer; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; }
.weekstrip .d { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 14px;
  font-weight: 800; color: var(--text); background: var(--surface-2); position: relative; }
.weekstrip .d.part { box-shadow: inset 0 0 0 2px var(--accent); }
.weekstrip .d.done { background: var(--accent); color: var(--accent-ink); }
.weekstrip button.sel .d { outline: 2px solid var(--text); outline-offset: 2px; }
.weekstrip button.future { opacity: .35; }

.summary { display: flex; gap: 16px; align-items: center; }
.ring { position: relative; width: 96px; height: 96px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .lbl { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.05; }
.ring .lbl b { font-size: 22px; font-weight: 900; }
.ring .lbl small { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.stats-inline { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; flex: 1; }
.stats-inline div b { display: block; font-size: 18px; font-weight: 900; }
.stats-inline div span { font-size: 12px; color: var(--muted); font-weight: 600; }

.ex-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.ex-card + .ex-card { margin-top: 12px; }
.ex-card.done { border-color: rgba(74, 222, 128, .45); }
.ex-head { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.thumb { width: 64px; height: 64px; border-radius: 14px; flex: none; background: #fff; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb.ph { display: grid; place-items: center; background: var(--surface-3); color: var(--accent); font-weight: 900; font-size: 22px; }
.ex-head .meta { flex: 1; min-width: 0; }
.ex-head .meta h3 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-count { font-size: 15px; font-weight: 800; margin-top: 3px; }
.ex-count .of { color: var(--muted); font-weight: 600; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .35s ease; }
.done .bar > i { background: var(--good); }
.sets { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.set-chip { display: inline-flex; align-items: baseline; gap: 5px; padding: 6px 10px; border-radius: 10px;
  background: var(--surface-2); font-weight: 800; font-size: 14px; border: 0; cursor: pointer; }
.set-chip small { color: var(--muted); font-weight: 600; font-size: 11px; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.quick .btn { min-height: 46px; padding: 0 4px; font-size: 16px; }
.remaining { font-size: 12px; color: var(--muted); margin-top: 8px; font-weight: 600; }

.empty { text-align: center; padding: 28px 12px; color: var(--muted); }

/* ---------- sheets ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .6); display: flex; align-items: flex-end;
  justify-content: center; animation: fade .15s ease; }
.sheet { width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto; background: var(--surface);
  border-radius: 24px 24px 0 0; border: 1px solid var(--line); border-bottom: 0;
  padding: 10px 18px calc(22px + var(--safe-b)); animation: up .22s cubic-bezier(.2, .8, .2, 1); overscroll-behavior: contain; }
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--surface-3); margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 21px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 24px; border-bottom: 1px solid var(--line); }
}

.hero-img { background: #fff; border-radius: 16px; overflow: hidden; aspect-ratio: 3 / 2; }
.hero-img img { width: 100%; height: 100%; object-fit: contain; }
ol.steps { padding-left: 20px; margin: 8px 0; line-height: 1.5; }
ol.steps li { margin-bottom: 6px; }

.stepper { display: flex; align-items: center; gap: 10px; }
.stepper .input { text-align: center; font-size: 30px; font-weight: 900; min-height: 64px; }
.stepper .btn { min-width: 56px; min-height: 64px; font-size: 24px; }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list .item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border: 0; background: transparent;
  width: 100%; text-align: left; text-decoration: none; cursor: pointer; }
.list .item + .item { border-top: 1px solid var(--line); }
.list .item .thumb { width: 46px; height: 46px; border-radius: 11px; }
.chev { color: var(--muted); }

.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--surface-3); transition: .2s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); }

/* ---------- timer ---------- */
.timer-face { position: relative; width: min(78vw, 320px); aspect-ratio: 1; margin: 18px auto 10px; }
.timer-face svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-face .center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.timer-face .big { font-size: clamp(52px, 17vw, 76px); font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: -2px; }
.timer-face .phase { font-size: 15px; font-weight: 800; text-transform: uppercase; letter-spacing: 1.5px; }
.timer-face .phase.work { color: var(--accent); }
.timer-face .phase.rest { color: var(--good); }
.timer-controls { display: flex; justify-content: center; gap: 14px; margin: 8px 0 18px; }
.timer-controls .btn { min-width: 110px; min-height: 56px; font-size: 18px; border-radius: 18px; }
.presets { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.presets .btn { flex: none; }
.laps { font-variant-numeric: tabular-nums; }

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.kpi b { display: block; font-size: 20px; font-weight: 900; letter-spacing: -.4px; }
.kpi span { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal .h { text-align: center; font-size: 11px; color: var(--muted); font-weight: 700; }
.cal .c { aspect-ratio: 1; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center;
  font-size: 13px; font-weight: 700; border: 0; cursor: pointer; color: var(--text); }
.cal .c.l1 { background: rgba(255, 111, 145, .25); }
.cal .c.l2 { background: rgba(255, 111, 145, .55); }
.cal .c.l3 { background: var(--accent); color: var(--accent-ink); }
.cal .c.today { outline: 2px solid var(--text); outline-offset: 1px; }
.cal .c.out { visibility: hidden; }

.history-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.history-row:last-child { border: 0; }

/* ---------- toast ---------- */
#toast { position: fixed; z-index: 80; left: 0; right: 0; margin: 0 auto; width: fit-content; bottom: calc(var(--tabbar-h) + var(--safe-b) + 24px);
  transform: translateY(20px); opacity: 0; pointer-events: none; transition: .25s;
  background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 14px; font-weight: 700; font-size: 14px;
  max-width: calc(100% - 32px); display: flex; gap: 12px; align-items: center; }
#toast.show { opacity: 1; transform: none; pointer-events: auto; }
#toast button { background: none; border: 0; color: var(--accent); font-weight: 900; cursor: pointer; padding: 0; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; animation: fall 1.6s ease-in forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); opacity: .8; } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (min-width: 700px) { main { padding-top: 10px; } }

/* bilingual exercise names: main name + the other language's name, smaller */
.alt-name { display: inline-block; font-size: 12px; font-weight: 600; color: var(--muted, #9c9cab); margin-left: 2px; }
.ex-head .meta h3 + .alt-name { display: block; margin: -2px 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-head h2 + .alt-name { display: block; margin-top: 2px; font-size: 13px; }
.aka { line-height: 2; }
.chip { display: inline-block; padding: 1px 9px; border-radius: 999px; background: #1e1e25; border: 1px solid #2a2a33; font-size: 12px; white-space: nowrap; }

/* routine session table (Today) */
.routine { margin-bottom: 4px; }
.rt-title h3 { margin: 0; }
.stamp { display: inline-block; margin-top: 4px; padding: 1px 8px; border: 2px solid var(--muted); border-radius: 6px; color: var(--muted);
  font-size: 11px; font-weight: 900; letter-spacing: 1px; text-transform: uppercase; transform: rotate(-2deg); }
.stamp.go { border-color: #60a5fa; color: #60a5fa; }
.stamp.done { border-color: var(--good); color: var(--good); }
.rt-head, .rt-row { display: grid; grid-template-columns: 1fr 62px 58px 40px; align-items: center; gap: 6px; }
.rt-head { margin: 12px 0 2px; font-size: 11px; font-weight: 800; letter-spacing: .6px; color: var(--muted); text-transform: uppercase; }
.rt-head span:nth-child(2), .rt-head span:nth-child(3) { text-align: center; }
.rt-row { padding: 9px 0; border-top: 1px solid var(--line); }
.rt-name { all: unset; cursor: pointer; min-width: 0; display: flex; flex-direction: column; }
.rt-name:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.rt-slot { font-size: 15px; font-weight: 900; text-transform: uppercase; letter-spacing: .3px; }
.rt-ex { font-size: 12px; color: var(--accent-2); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rt-ex i { font-style: normal; color: var(--muted); font-weight: 600; }
.rt-reps, .rt-rounds { text-align: center; font-size: 20px; font-weight: 900; color: #60a5fa; }
.rt-reps small, .rt-rounds small { font-size: 11px; font-weight: 800; }
.rt-rounds small { color: var(--muted); }
.rt-reps .fail { color: var(--danger); font-size: 12px; letter-spacing: .5px; }
.rt-check { width: 36px; height: 36px; border-radius: 50%; border: 2px solid #60a5fa; background: transparent; color: #60a5fa;
  font-size: 20px; font-weight: 900; cursor: pointer; justify-self: end; }
.rt-check.on { background: #60a5fa; color: #0b0b0e; }
.rt-row.ok .rt-slot { color: var(--muted); }
.rt-help { margin: 10px 0 0; }
/* routine editor */
.rt-edit { background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; gap: 10px; }
.rt-edit .row { gap: 8px; }
.rt-edit select.input { min-width: 0; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 14px; margin-right: 14px; cursor: pointer; }
.chk input { width: 18px; height: 18px; accent-color: var(--accent); }
.radio { position: relative; width: 24px; height: 24px; flex: none; }
.radio input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.radio i { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--surface-3); }
.radio input:checked + i { border-color: var(--accent); box-shadow: inset 0 0 0 5px var(--surface), inset 0 0 0 12px var(--accent); }
.radio input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

/* FeatureGap feedback launcher: sit above the bottom tab bar instead of on top of "More" */
#featuregap-launcher { bottom: calc(10px + var(--tabbar-h) + var(--safe-b) + 14px) !important; right: 16px !important; }
