/* Gym PWA — dark, mobile-first (390px), safe-area aware. No external fonts/assets. */
:root {
  --bg: #0b0b0f;
  --bg2: #141419;
  --card: #1a1a21;
  --line: rgba(255, 255, 255, .08);
  --text: #f5f5f7;
  --muted: #9a9aa3;
  --cyan: #32d2f5;
  --green: #30d158;
  --red: #ff453a;
  --grey: #8e8e93;
  --gold: #ffd60a;
  --radius: 20px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --tabbar-h: 68px;
  --spring: cubic-bezier(.2, 1.4, .3, 1);
  color-scheme: dark;
}

[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; min-height: 100dvh; color: var(--text);
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(50, 210, 245, .10), transparent 60%),
    radial-gradient(80% 50% at 100% 100%, rgba(120, 80, 255, .08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body.modal-open { overflow: hidden; }
body.busy { cursor: progress; }
body.busy * { pointer-events: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
h1 { font-size: 28px; font-weight: 700; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 20px; margin: 0; }
.noscript { padding: 24px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hint { color: var(--muted); font-size: 13px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; text-align: center; font-size: 22px; }
.spacer { width: 44px; flex: none; }

.screen {
  max-width: 520px; margin: 0 auto;
  padding: calc(12px + var(--safe-t)) calc(16px + var(--safe-r)) calc(var(--tabbar-h) + 40px + var(--safe-b)) calc(16px + var(--safe-l));
}
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; margin-bottom: 8px; }
.section-title { font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin: 24px 4px 8px; }

/* ---------- Liquid-Glass approximation (floating layer only) ---------- */
.glass {
  position: relative;
  background: linear-gradient(135deg, rgba(255, 255, 255, .14), rgba(255, 255, 255, .05));
  -webkit-backdrop-filter: blur(20px) saturate(180%) contrast(90%);
  backdrop-filter: blur(20px) saturate(180%) contrast(90%);
  border: 1px solid rgba(255, 255, 255, .18);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .35),
    inset 1px 1px 2px rgba(255, 255, 255, .12),
    0 10px 30px rgba(0, 0, 0, .35);
  isolation: isolate;
  transition: transform .35s var(--spring), box-shadow .3s ease, background .3s ease;
}
.glass::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(115deg, rgba(255, 255, 255, .18), transparent 42%);
  mix-blend-mode: screen;
}
.glass:active { transform: scale(.94); transition-duration: .12s; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 4px 14px rgba(0, 0, 0, .35); }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: rgba(40, 40, 48, .92); }
}

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + var(--safe-b));
  width: min(calc(100% - 24px - var(--safe-l) - var(--safe-r)), 440px);
  height: var(--tabbar-h);
  display: flex; align-items: center; justify-content: space-around;
  border-radius: 34px; padding: 0 6px;
}
.tabbar:active { transform: translateX(-50%); }
.tab {
  flex: 1; height: 56px; border: 0; background: none; border-radius: 26px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 10.5px; font-weight: 600;
  transition: transform .35s var(--spring), color .2s, background .25s;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab:active { transform: scale(.88); transition-duration: .1s; }
.tab.active { color: var(--text); background: rgba(255, 255, 255, .12); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2); }
.tab-center.active { color: var(--cyan); }
.tab-center svg { width: 28px; height: 28px; }

/* ---------- calorie ring ---------- */
.date-label { font-size: 17px; font-weight: 600; }
.ring { position: relative; width: min(300px, 82vw); aspect-ratio: 1; margin: 8px auto 4px; }
.ring-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.ring-track { fill: none; stroke: rgba(255, 255, 255, .08); }
.ring-fill {
  fill: none; stroke: var(--grey); stroke-linecap: round;
  transition: stroke-dashoffset .8s cubic-bezier(.3, 1.1, .4, 1), stroke .4s ease;
  filter: drop-shadow(0 0 10px currentColor);
}
.ring[data-state="deficit"] .ring-fill { stroke: var(--green); color: rgba(48, 209, 88, .45); }
.ring[data-state="surplus"] .ring-fill { stroke: var(--red); color: rgba(255, 69, 58, .45); }
.ring[data-state="maintenance"] .ring-fill { stroke: var(--grey); color: rgba(142, 142, 147, .3); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-value { font-size: clamp(56px, 18vw, 76px); font-weight: 700; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.ring-unit { color: var(--muted); font-size: 14px; margin-top: 6px; font-weight: 500; }
.ring-burned {
  position: absolute; left: 50%; bottom: 17%; transform: translateX(-50%);
  font-size: 15px; font-weight: 600; color: var(--cyan); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.stats { text-align: center; color: var(--muted); font-size: 13.5px; margin: 6px 0 10px; font-variant-numeric: tabular-nums; }
.pill {
  width: fit-content; margin: 0 auto; padding: 6px 14px; border-radius: 999px; font-weight: 700; font-size: 15px;
  background: rgba(142, 142, 147, .16); color: var(--grey); font-variant-numeric: tabular-nums;
}
.pill[data-state="deficit"] { background: rgba(48, 209, 88, .15); color: var(--green); }
.pill[data-state="surplus"] { background: rgba(255, 69, 58, .15); color: var(--red); }

/* ---------- FABs ---------- */
.fab-row { display: flex; gap: 12px; justify-content: center; margin: 20px 0 4px; }
.fab {
  flex: 1; max-width: 180px; min-height: 58px; border-radius: 22px; font-size: 17px; font-weight: 650;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; color: var(--text);
}
.fab-icon { font-size: 22px; line-height: 1; }

/* ---------- cards, lists, buttons ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.card-title { margin: 0 0 6px; font-size: 17px; }
.setup { text-align: center; }
.setup p { margin: 0 0 12px; color: var(--muted); }
.list, .ex-list { list-style: none; margin: 0; padding: 0; }
.list > li { margin: 0 0 8px; }
.list-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; min-height: 60px;
}
.list-item.tap:active { background: #22222b; }
.li-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.li-title { font-weight: 600; overflow-wrap: anywhere; }
.li-sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.li-value { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.li-value.stack { display: flex; flex-direction: column; align-items: flex-end; }
.chev { color: var(--muted); font-size: 22px; }
.empty { color: var(--muted); text-align: center; padding: 20px; border: 1px dashed var(--line); border-radius: 16px; }
.badge { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 800; background: var(--gold); color: #111; vertical-align: 2px; }
.badge.alt { background: rgba(50, 210, 245, .2); color: var(--cyan); }

.btn {
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--line);
  background: #24242c; font-weight: 600; transition: transform .3s var(--spring), background .2s;
}
.btn:active { transform: scale(.96); transition-duration: .1s; }
.btn.primary { background: var(--cyan); color: #00141a; border-color: transparent; }
.btn.danger { background: rgba(255, 69, 58, .16); color: var(--red); border-color: rgba(255, 69, 58, .3); }
.btn.small { min-height: 40px; font-size: 14px; }
.btn.block { width: 100%; }
.btn.link { background: none; border: 0; color: var(--muted); text-decoration: underline; font-weight: 500; }
.btn:disabled { opacity: .5; }
.icon-btn {
  min-width: 44px; min-height: 44px; border: 0; border-radius: 14px; background: rgba(255, 255, 255, .06);
  font-size: 20px; display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.icon-btn:disabled { opacity: .25; }
.icon-btn:active { transform: scale(.9); }
.row-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.row-btns > .btn { flex: 1; }
.set-row { display: flex; align-items: center; gap: 12px; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--muted); font-weight: 600; }
input[type="text"], input[type="password"], input[type="date"], select {
  width: 100%; min-height: 50px; padding: 0 14px; border-radius: 14px; font-size: 17px;
  background: #101015; border: 1px solid rgba(255, 255, 255, .12); outline: none; -webkit-appearance: none; appearance: none;
}
input:focus, select:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(50, 210, 245, .2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: #24242c; font-weight: 600; font-size: 14px; }
.chip:active { transform: scale(.94); }
.seg { display: flex; background: #101015; border: 1px solid rgba(255, 255, 255, .12); border-radius: 14px; padding: 3px; min-height: 50px; }
.seg-opt { flex: 1; position: relative; display: flex; }
.seg-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.seg-opt span { flex: 1; display: flex; align-items: center; justify-content: center; border-radius: 11px; font-weight: 600; font-size: 15px; color: var(--muted); }
.seg-opt input:checked + span { background: #2c2c36; color: var(--text); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .15); }
.seg-opt input:focus-visible + span { outline: 2px solid var(--cyan); }

/* ---------- sheet modal ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .5);
  display: flex; align-items: flex-end; justify-content: center; animation: fadeIn .2s ease;
}
.backdrop.closing { animation: fadeOut .18s ease forwards; }
.sheet {
  width: 100%; max-width: 520px; max-height: 88dvh; overflow-y: auto;
  background: var(--bg2); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 28px 28px 0 0; padding: 8px calc(18px + var(--safe-r)) calc(20px + var(--safe-b)) calc(18px + var(--safe-l));
  animation: slideUp .35s var(--spring);
}
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .2); margin: 4px auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
@keyframes slideUp { from { transform: translateY(40%); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; } }

.toast {
  position: fixed; z-index: 60; left: 50%; top: calc(14px + var(--safe-t)); transform: translate(-50%, -150%);
  padding: 12px 18px; border-radius: 16px; background: rgba(40, 40, 48, .95); border: 1px solid var(--line);
  font-weight: 600; font-size: 15px; max-width: 90vw; text-align: center; opacity: 0; visibility: hidden;
  transition: transform .35s var(--spring), opacity .25s ease, visibility 0s linear .35s;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; transition: transform .35s var(--spring), opacity .2s ease; }

/* ---------- workouts ---------- */
.day-tabs { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 12px; }
.day-tab {
  min-height: 52px; border-radius: 14px; border: 1px solid var(--line); background: var(--card);
  font-weight: 700; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.day-tab .dot { width: 5px; height: 5px; border-radius: 50%; background: transparent; }
.day-tab.today .dot { background: var(--cyan); }
.day-tab.active { background: var(--text); color: #000; border-color: transparent; }
.day-head { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 8px 0 2px; }
.day-title { background: none; border: 0; font-size: 24px; font-weight: 700; padding: 4px 10px; border-radius: 12px; }
.day-title.placeholder { color: var(--muted); }
.day-title:active { background: rgba(255, 255, 255, .06); }
.ex { display: flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; margin: 0 0 10px; padding: 4px 6px 4px 4px; }
.ex-tap { flex: 1; display: flex; align-items: center; gap: 14px; min-height: 68px; padding: 8px 10px; cursor: pointer; position: relative; border-radius: 14px; }
.ex-tap:active { background: rgba(255, 255, 255, .04); }
.ex-check { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ex-box {
  flex: none; width: 34px; height: 34px; border-radius: 11px; border: 2.5px solid rgba(255, 255, 255, .35);
  display: flex; align-items: center; justify-content: center; transition: transform .35s var(--spring), background .2s, border-color .2s;
}
.ex-box::after { content: ""; width: 9px; height: 17px; border: solid #00140a; border-width: 0 3.5px 3.5px 0; transform: rotate(45deg) scale(0); margin-top: -4px; transition: transform .3s var(--spring); }
.ex-check:checked + .ex-box { background: var(--green); border-color: var(--green); transform: scale(1.06); }
.ex-check:checked + .ex-box::after { transform: rotate(45deg) scale(1); }
.ex-check:focus-visible + .ex-box { outline: 2px solid var(--cyan); outline-offset: 2px; }
.ex-text { display: flex; flex-direction: column; min-width: 0; }
.ex-name { font-size: 17px; font-weight: 650; overflow-wrap: anywhere; }
.ex-detail { color: var(--muted); font-size: 14px; }
.ex.done .ex-name { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(255, 255, 255, .3); }

/* ---------- PRs ---------- */
.pr-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; color: var(--gold); }

/* ---------- timer ---------- */
.timer-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.big-mode {
  min-height: 108px; border-radius: 26px; color: var(--text);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.big-mode-title { font-size: 24px; font-weight: 800; letter-spacing: .06em; }
.big-mode-sub { color: var(--muted); font-size: 14px; font-weight: 600; }
.timer-ring { width: min(260px, 70vw); margin-top: 22px; }
.timer-ring .ring-fill { stroke: var(--cyan); color: rgba(50, 210, 245, .45); transition: stroke-dashoffset .25s linear; }
.timer-ring[data-mode="cardio"] .ring-fill { stroke: #ff9f0a; color: rgba(255, 159, 10, .45); }
.timer-time { font-size: clamp(52px, 16vw, 68px); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.03em; line-height: 1; }
.timer-ring.finished { animation: pulse 1s ease 3; }
@keyframes pulse { 50% { transform: scale(1.05); filter: brightness(1.5); } }
.ctrl-row { display: flex; gap: 12px; justify-content: center; margin: 22px 0 10px; }
.ctrl { flex: 1; max-width: 170px; min-height: 64px; border-radius: 24px; font-size: 19px; font-weight: 700; color: var(--text); }
.primary-ctrl { background: linear-gradient(135deg, rgba(50, 210, 245, .45), rgba(50, 210, 245, .18)); }

/* ---------- lock ---------- */
.lock { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: calc(20px + var(--safe-t)) 20px calc(20px + var(--safe-b)); }
.lock-card { width: 100%; max-width: 360px; text-align: center; display: flex; flex-direction: column; gap: 16px; }
.lock-icon { font-size: 48px; }
.lock .field { text-align: left; }
.steps { margin: 6px 0 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.steps li { margin: 4px 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .glass:active, .tab:active, .btn:active, .chip:active, .icon-btn:active { transform: none; }
  .tabbar:active { transform: translateX(-50%); }
}
