:root {
  color-scheme: dark;
  --bg: #0b0b0b;
  --panel: #161616;
  --panel-2: #1d1d1d;
  --line: #2b2b2b;
  --text: #f6f6f2;
  --muted: #9a9a94;
  --accent: #d8ff3e;
  --accent-ink: #101300;
  --danger: #ff6b6b;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; }
button { cursor: pointer; }
input, select { color: var(--text); background: #101010; border: 1px solid var(--line); border-radius: 10px; }

.app-shell { min-height: 100dvh; padding-bottom: calc(88px + var(--safe-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 24px 20px 12px; max-width: 760px; margin: auto; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 28px; letter-spacing: -0.04em; }
h2 { font-size: 28px; letter-spacing: -0.04em; margin-bottom: 4px; }
h3 { margin-bottom: 0; letter-spacing: -0.02em; }
.eyebrow { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: 0.14em; }
.content { max-width: 760px; margin: auto; padding: 10px 16px 30px; }
.hero-card, .program-card, .settings-card, .history-card, .exercise-card { background: var(--panel); border: 1px solid var(--line); border-radius: 22px; }
.hero-card { padding: 22px; background: linear-gradient(155deg, #1d1d1d, #121212); }
.hero-heading { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.hero-heading p, .muted { color: var(--muted); margin-bottom: 0; }
.workout-badge { display: inline-grid; place-items: center; min-width: 42px; height: 42px; border: 1px solid #4b4b4b; border-radius: 14px; color: var(--accent); font-weight: 900; }
.exercise-preview { margin: 24px 0; border-top: 1px solid var(--line); }
.preview-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.preview-row div { display: flex; flex-direction: column; gap: 3px; }
.preview-row span { color: var(--muted); font-size: 13px; }
.primary-button, .finish-button { width: 100%; border: 0; border-radius: 15px; padding: 17px 20px; background: var(--accent); color: var(--accent-ink); font-weight: 900; text-transform: uppercase; letter-spacing: 0.04em; }
.primary-button:active, .finish-button:active { transform: translateY(1px); }
.small-button, .secondary-button, .text-button { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 11px; padding: 10px 13px; font-weight: 700; }
.section-block { margin-top: 28px; }
.page-section { margin-top: 10px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.section-title h2 { margin-top: 5px; }
.empty-state { color: var(--muted); padding: 28px; text-align: center; border: 1px dashed var(--line); border-radius: 18px; }

.bottom-nav { position: fixed; z-index: 10; left: 50%; bottom: 0; transform: translateX(-50%); width: 100%; max-width: 760px; display: grid; grid-template-columns: repeat(4, 1fr); background: rgba(12,12,12,.94); backdrop-filter: blur(18px); border-top: 1px solid var(--line); padding: 8px 8px calc(8px + var(--safe-bottom)); }
.nav-button { border: 0; background: transparent; color: var(--muted); display: flex; align-items: center; flex-direction: column; gap: 4px; padding: 8px 4px; font-size: 11px; font-weight: 700; }
.nav-button span { font-size: 18px; }
.nav-button.active { color: var(--accent); }

.active-shell { min-height: 100dvh; padding-bottom: calc(94px + var(--safe-bottom)); }
.active-header { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: 46px 1fr 46px; align-items: center; gap: 12px; padding: 16px; background: rgba(11,11,11,.96); backdrop-filter: blur(14px); }
.active-header h1 { font-size: 22px; }
.icon-button { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 26px; }
.progress-label { color: var(--accent); font-size: 13px; font-weight: 900; text-align: right; }
.progress-track { height: 3px; background: #242424; position: sticky; top: 74px; z-index: 5; }
.progress-track span { display: block; height: 100%; background: var(--accent); transition: width .2s ease; }
.active-content { max-width: 760px; margin: auto; padding: 18px 14px 150px; }
.exercise-card { padding: 18px; margin-bottom: 14px; }
.exercise-card.exercise-complete { border-color: rgba(216,255,62,.5); }
.exercise-card-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.exercise-card-header h2 { margin-top: 4px; font-size: 23px; }
.weight-control { display: flex; align-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: #101010; }
.weight-control input { width: 72px; border: 0; border-radius: 0; padding: 12px 8px 12px 12px; text-align: right; font-size: 18px; font-weight: 900; }
.weight-control span { padding-right: 12px; color: var(--muted); font-weight: 700; }
.sets-table { margin-top: 16px; }
.sets-heading, .set-row { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: center; text-align: center; }
.sets-heading { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; padding: 4px 0 8px; }
.set-row { padding: 9px 0; border-top: 1px solid var(--line); }
.set-row input { width: 68px; justify-self: center; padding: 10px; text-align: center; font-weight: 800; }
.set-number { color: var(--muted); font-weight: 800; }
.set-check { justify-self: center; width: 42px; height: 42px; border-radius: 13px; border: 2px solid #454545; background: transparent; color: #101300; font-size: 22px; font-weight: 900; }
.set-row.done .set-check { background: var(--accent); border-color: var(--accent); }
.set-row.done { opacity: .78; }
.active-footer { position: fixed; bottom: 0; left: 0; right: 0; z-index: 8; padding: 12px 16px calc(12px + var(--safe-bottom)); background: rgba(11,11,11,.96); border-top: 1px solid var(--line); }
.finish-button { max-width: 728px; display: block; margin: auto; }
.finish-button:disabled { opacity: .35; cursor: not-allowed; }
.timer-card { position: fixed; z-index: 20; left: 50%; bottom: calc(92px + var(--safe-bottom)); transform: translateX(-50%); width: calc(100% - 28px); max-width: 500px; padding: 18px; border-radius: 22px; background: #f3f3ed; color: #111; box-shadow: 0 22px 80px rgba(0,0,0,.5); text-align: center; }
.timer-card .eyebrow { color: #67675f; }
.timer-card strong { display: block; font-size: 54px; letter-spacing: -0.05em; margin: 2px 0 12px; }
.timer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.timer-actions button { border: 1px solid #c9c9c2; border-radius: 12px; background: white; color: #111; padding: 12px; font-weight: 800; }
.timer-close { position: absolute; right: 12px; top: 10px; border: 0; background: transparent; font-size: 24px; color: #555; }

.history-list { display: grid; gap: 12px; }
.history-card { padding: 18px; }
.history-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.history-card-header span { color: var(--muted); font-size: 12px; }
.history-card-header h3 { margin-top: 3px; }
.history-card-header b { color: var(--accent); }
.history-exercises { margin-top: 14px; display: grid; gap: 9px; }
.history-exercises div { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13px; }
.history-exercises strong { color: var(--text); text-align: right; }
.danger-link { margin-top: 14px; padding: 0; border: 0; background: transparent; color: var(--danger); font-size: 12px; }

.program-list { display: grid; gap: 18px; margin-top: 18px; }
.program-card { padding: 18px; }
.program-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.program-name-input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 4px 0; font-size: 22px; font-weight: 900; }
.program-exercises { display: grid; gap: 12px; margin: 18px 0; }
.exercise-editor { background: #101010; border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.editor-name-row { display: flex; gap: 8px; align-items: center; }
.editor-name-row input { flex: 1; min-width: 0; padding: 11px; font-weight: 800; }
.remove-button { flex: 0 0 38px; height: 38px; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--danger); font-size: 22px; }
.editor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 10px; }
.editor-grid label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
.editor-grid input { width: 100%; padding: 10px; }

.settings-card { padding: 18px; margin-bottom: 14px; }
.setting-row { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-row select, .setting-row input[type="number"] { max-width: 150px; padding: 10px; text-align: right; }
.setting-number { display: flex; align-items: center; gap: 7px; color: var(--muted); }
.toggle { appearance: none; width: 46px; height: 27px; border-radius: 99px; background: #353535; border: 0; position: relative; transition: .2s; }
.toggle::after { content: ""; position: absolute; width: 21px; height: 21px; top: 3px; left: 3px; background: white; border-radius: 50%; transition: .2s; }
.toggle:checked { background: var(--accent); }
.toggle:checked::after { transform: translateX(19px); background: #111; }
.backup-card p, .danger-zone p { color: var(--muted); line-height: 1.5; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
.file-button input { display: none; }
.danger-zone { border-color: rgba(255,107,107,.25); }
.danger-button { border: 1px solid rgba(255,107,107,.4); border-radius: 11px; background: rgba(255,107,107,.08); color: var(--danger); padding: 11px 14px; font-weight: 800; }
.fatal-error { max-width: 600px; margin: 80px auto; padding: 24px; }

@media (min-width: 620px) {
  .content { padding-left: 24px; padding-right: 24px; }
  .editor-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .active-content { padding-left: 24px; padding-right: 24px; }
}
