:root {
  color-scheme: dark;
  --bg: #071525;
  --surface: #0d2238;
  --surface-2: #132c47;
  --line: #29435f;
  --text: #f5f8fc;
  --muted: #9cb0c8;
  --accent: #ffb12e;
  --accent-ink: #071525;
  --cyan: #61d3ff;
  --green: #52e2ae;
  --danger: #ff6b6b;
  --radius: 20px;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  background: linear-gradient(180deg, #0a1d31 0, var(--bg) 38%);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 720px;
  margin: auto;
  padding: calc(22px + env(safe-area-inset-top)) 20px 18px;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.8rem, 8vw, 2.5rem); letter-spacing: -.04em; }
h2 { font-size: 1.35rem; }
h3 { margin-bottom: 4px; }
.eyebrow { margin-bottom: 2px; color: var(--cyan); font-size: .73rem; font-weight: 800; letter-spacing: .19em; }
.muted { color: var(--muted); }

#app { max-width: 720px; margin: auto; padding: 0 16px 32px; outline: none; }
.stack { display: grid; gap: 14px; }
.card {
  background: rgba(13, 34, 56, .92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 12px 35px rgba(0, 0, 0, .16);
}
.hero { padding: 22px; background: linear-gradient(145deg, #14385b, #0d2238); }
.hero h2 { font-size: 1.6rem; margin-bottom: 7px; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.stat { border-radius: 14px; padding: 12px 8px; text-align: center; background: #091a2d; }
.stat strong { display: block; font-size: 1.2rem; }
.stat span { color: var(--muted); font-size: .75rem; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 8px 2px 0; }
.section-title h2 { margin: 0; }

.primary-button, .secondary-button, .danger-button {
  display: inline-flex;
  width: 100%;
  min-height: 50px;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  padding: 12px 16px;
  border: 1px solid transparent;
  font-weight: 750;
}
.primary-button { background: var(--accent); color: var(--accent-ink); }
.secondary-button { background: var(--surface-2); border-color: var(--line); color: var(--text); }
.danger-button { background: transparent; border-color: #713d49; color: #ff9a9a; }
.small-button { width: auto; min-height: 40px; padding: 8px 13px; }
.icon-button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--text); font-size: 1.3rem; }
.link-button { border: 0; padding: 6px; background: transparent; color: var(--cyan); font-weight: 700; }

.bottom-nav {
  position: fixed;
  z-index: 10;
  bottom: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  background: rgba(7, 21, 37, .96);
  backdrop-filter: blur(14px);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}
.nav-button { border: 0; background: transparent; color: var(--muted); padding: 7px; font-size: .75rem; }
.nav-button span { display: block; font-size: 1.3rem; line-height: 1.1; }
.nav-button.active { color: var(--accent); }

.routine-row, .history-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.routine-row + .routine-row, .history-row + .history-row { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.routine-row p, .history-row p { margin: 0; }
.pill { display: inline-block; border-radius: 999px; padding: 5px 9px; background: #173b4b; color: var(--green); font-size: .75rem; font-weight: 700; }
.routine-description, .workout-description { margin: 14px 0; color: var(--muted); }
.routine-exercises { display: grid; gap: 1px; margin: 14px 0; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--line); }
.routine-exercises > div { display: grid; grid-template-columns: minmax(78px, auto) 1fr auto; gap: 9px; align-items: center; padding: 10px 12px; background: #091a2d; }
.routine-exercises span { color: var(--cyan); font-size: .68rem; font-weight: 800; text-transform: uppercase; }
.routine-exercises strong { font-size: .88rem; }
.routine-exercises small { color: var(--muted); white-space: nowrap; }
.source-link { display: inline-block; margin-bottom: 4px; color: var(--cyan); font-weight: 700; text-decoration: none; }

.workout-toolbar { display: flex; gap: 10px; position: sticky; top: 6px; z-index: 4; }
.workout-toolbar .primary-button { flex: 1; }
.exercise-card { padding: 0; overflow: hidden; }
.exercise-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px; }
.exercise-header h3 { margin: 0; }
.exercise-header-actions { display: flex; align-items: center; }
.superset-label { display: inline-block; margin-bottom: 4px; color: var(--cyan); font-size: .68rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.exercise-target { margin: 3px 0 0; color: var(--green); font-size: .78rem; font-weight: 700; }
.exercise-note { margin: 0; padding: 0 16px 10px; color: var(--muted); font-size: .82rem; }
.set-grid { display: grid; grid-template-columns: 34px 1fr 1fr 44px; gap: 8px; align-items: center; padding: 7px 14px; }
.set-grid.header { color: var(--muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; }
.set-grid input { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 10px; background: #08192b; color: var(--text); padding: 10px 7px; text-align: center; }
.set-number { color: var(--muted); text-align: center; font-weight: 700; }
.done-check { width: 38px; height: 38px; accent-color: var(--green); }
.exercise-actions { display: flex; gap: 8px; padding: 10px 14px 15px; }

dialog { width: min(92vw, 480px); padding: 0; border: 0; border-radius: 22px; color: var(--text); background: var(--surface); }
dialog::backdrop { background: rgba(0, 6, 13, .76); backdrop-filter: blur(4px); }
.dialog-card { display: grid; gap: 15px; padding: 20px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; }
.dialog-heading h2 { margin: 0; }
label { display: grid; gap: 7px; color: var(--muted); font-size: .85rem; font-weight: 650; }
input, select { border: 1px solid var(--line); border-radius: 12px; background: #08192b; color: var(--text); padding: 13px; }
.file-button input { display: none; }
.version { margin: 4px 0 0; text-align: center; color: var(--muted); font-size: .78rem; }

.empty { text-align: center; padding: 32px 18px; }
.empty-icon { font-size: 2.2rem; }
#toast { position: fixed; z-index: 30; left: 50%; bottom: 100px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 11px 16px; border-radius: 999px; background: var(--text); color: var(--bg); font-weight: 700; transition: .2s; white-space: nowrap; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.guide-intro { background: linear-gradient(145deg, #14385b, #0d2238); }
.guide-intro h2 { margin-bottom: 6px; }
.guide-intro p { color: var(--muted); }
.guide-intro .guide-safety { margin-bottom: 0; color: #ffd47f; }
.guide-search input { font-size: 1rem; }
.filter-row { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 5px; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); padding: 8px 13px; }
.filter-chip.active { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 750; }
.guide-count { margin: -4px 2px 0; color: var(--muted); font-size: .8rem; }
.guide-list { display: grid; gap: 12px; }
.guide-card { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(13, 34, 56, .92); }
.guide-card[hidden] { display: none; }
.guide-card summary { display: grid; grid-template-columns: 112px 1fr 24px; gap: 12px; align-items: center; padding: 12px; cursor: pointer; list-style: none; }
.guide-card summary::-webkit-details-marker { display: none; }
.guide-card h3 { margin: 2px 0; font-size: 1rem; }
.guide-card summary p { margin: 0; color: var(--muted); font-size: .76rem; }
.guide-category { color: var(--cyan); font-size: .65rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.guide-visual { display: grid; place-items: center; min-height: 82px; border-radius: 14px; background: #08192b; color: var(--text); }
.guide-art { display: block; width: 108px; height: 74px; }
.guide-art .figure { fill: none; stroke: #dce9f7; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.guide-art .motion { stroke: var(--accent); stroke-width: 4; }
.guide-chevron { color: var(--muted); font-size: 1.25rem; transition: transform .2s; }
.guide-card[open] .guide-chevron { transform: rotate(180deg); }
.guide-body { padding: 2px 16px 18px; border-top: 1px solid var(--line); }
.guide-body h4 { margin: 16px 0 5px; color: var(--cyan); font-size: .76rem; letter-spacing: .06em; text-transform: uppercase; }
.guide-body p, .guide-body li { color: #d7e2ee; }
.guide-body ol { margin: 6px 0 15px; padding-left: 21px; }
.guide-body li + li { margin-top: 6px; }
.cue-box, .mistake-box { display: grid; gap: 3px; margin-top: 10px; padding: 12px; border-radius: 12px; }
.cue-box { background: rgba(82, 226, 174, .1); border: 1px solid rgba(82, 226, 174, .35); }
.cue-box strong { color: var(--green); }
.mistake-box { background: rgba(255, 107, 107, .08); border: 1px solid rgba(255, 107, 107, .28); }
.mistake-box strong { color: #ff9a9a; }
.source-note p { margin: 7px 0 12px; color: var(--muted); font-size: .86rem; }
.source-note div { display: flex; flex-wrap: wrap; gap: 12px; }
.source-note a { color: var(--cyan); font-weight: 700; text-decoration: none; }

@media (max-width: 390px) {
  .guide-card summary { grid-template-columns: 92px 1fr 18px; gap: 9px; }
  .guide-art { width: 90px; }
  .nav-button { font-size: .68rem; }
}

@media (min-width: 700px) {
  body { padding-bottom: 40px; }
  .bottom-nav { position: static; max-width: 680px; margin: 0 auto 24px; border: 1px solid var(--line); border-radius: 18px; order: -1; }
  body { display: flex; flex-direction: column; }
  .app-header { width: 100%; }
  #app { width: 100%; }
}
