:root {
  color-scheme: dark;
  --bg: #0a0a0b;
  --surface: #151518;
  --surface-2: #202024;
  --surface-3: #29292e;
  --text: #f5f5f6;
  --muted: #a3a3ad;
  --orange: #ff6a00;
  --orange-soft: #ff9b55;
  --green: #38d88a;
  --yellow: #ffd166;
  --red: #ff626b;
  --line: #33333a;
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 90% -10%, rgba(255,106,0,.16), transparent 32rem),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button, select { -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }

.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 99; background: white; color: black; padding: .75rem; }
.skip-link:focus { top: 1rem; }
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(1.15rem + env(safe-area-inset-top, 0px)) 1rem .9rem;
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(10,10,11,.9);
  border-bottom: 1px solid rgba(255,255,255,.06);
  backdrop-filter: blur(18px);
}
.app-header h1 { margin: .2rem 0 0; font-size: 1.9rem; line-height: 1; letter-spacing: -.06em; }
.app-header h1 span { color: var(--orange); }
.eyebrow { margin: 0; color: var(--muted); font-size: .52rem; font-weight: 800; line-height: 1.15; letter-spacing: .12em; }
.offline-indicator { margin-top: .3rem; color: var(--green); border: 1px solid color-mix(in srgb, var(--green), transparent 65%); background: color-mix(in srgb, var(--green), transparent 90%); border-radius: 99px; padding: .4rem .6rem; font-size: .72rem; white-space: nowrap; }
.offline-indicator.is-offline { color: var(--yellow); border-color: color-mix(in srgb, var(--yellow), transparent 65%); background: color-mix(in srgb, var(--yellow), transparent 90%); }

main { width: min(100%, 720px); margin: 0 auto; padding: 1rem 1rem calc(6.4rem + var(--safe-bottom)); }
.page-heading { margin: .35rem 0 1rem; }
.page-heading h2 { margin: 0; font-size: clamp(1.65rem, 8vw, 2.4rem); letter-spacing: -.045em; }
.page-heading p { margin: .35rem 0 0; color: var(--muted); line-height: 1.45; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.4rem 0 .7rem; }
.section-title h3 { margin: 0; font-size: 1rem; letter-spacing: .01em; }
.section-title span { color: var(--muted); font-size: .82rem; }

.card, .workout-tile, .set-card, .history-card, .manage-card, .empty-card, .loading-card {
  background: linear-gradient(145deg, rgba(255,255,255,.025), transparent), var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(0,0,0,.2);
}
.workout-grid { display: grid; gap: .8rem; }
.workout-tile { width: 100%; padding: 1.1rem; color: var(--text); text-align: left; cursor: pointer; }
.workout-tile:active { transform: scale(.99); }
.workout-tile-top { display: flex; align-items: center; justify-content: space-between; }
.workout-tile h3 { margin: .25rem 0; font-size: 1.35rem; }
.workout-tile p { margin: 0; color: var(--muted); }
.arrow { color: var(--orange); font-size: 1.5rem; }
.tiny-label, .status-pill { font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.tiny-label { color: var(--orange-soft); }

.primary-button, .secondary-button, .danger-button, .small-button, .icon-button {
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 14px;
  padding: .78rem 1rem;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}
.primary-button { background: var(--orange); color: #17100b; }
.secondary-button { background: var(--surface-2); border-color: var(--line); }
.danger-button { background: color-mix(in srgb, var(--red), transparent 84%); border-color: color-mix(in srgb, var(--red), transparent 55%); color: #ff9ba1; }
.small-button { min-height: 38px; padding: .45rem .7rem; background: var(--surface-2); border-color: var(--line); font-size: .8rem; }
.icon-button { min-width: 42px; min-height: 42px; padding: .35rem; background: transparent; border-color: var(--line); color: var(--muted); }
.primary-button:disabled, button:disabled { opacity: .48; cursor: not-allowed; }
.button-row { display: flex; flex-wrap: wrap; gap: .55rem; }
.button-row > .primary-button, .button-row > .secondary-button, .button-row > .danger-button { flex: 1 1 130px; }

.active-banner { padding: 1rem; margin-bottom: 1rem; border-color: color-mix(in srgb, var(--orange), transparent 55%); }
.active-banner h3 { margin: .2rem 0; }
.active-banner p { margin: .25rem 0 1rem; color: var(--muted); }
.progress-track { overflow: hidden; height: 6px; margin: .8rem 0; background: var(--surface-3); border-radius: 99px; }
.progress-track span { display: block; height: 100%; background: var(--orange); border-radius: inherit; transition: width .2s ease; }

.workout-toolbar { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: 1rem; }
.workout-toolbar h2 { margin: 0; font-size: 1.55rem; }
.workout-toolbar p { margin: .2rem 0 0; color: var(--muted); font-size: .86rem; }
.set-list { display: grid; gap: .7rem; }
.set-card { overflow: hidden; }
.set-card.is-confirmed { border-color: color-mix(in srgb, var(--green), transparent 55%); }
.set-card.is-skipped { opacity: .7; }
.set-card.is-skipped.is-open { opacity: 1; }
.set-summary { display: flex; align-items: center; width: 100%; min-height: 74px; border: 0; padding: .8rem .9rem; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.set-index { display: grid; place-items: center; flex: 0 0 38px; height: 38px; margin-right: .75rem; border-radius: 12px; background: var(--surface-2); color: var(--muted); font-weight: 900; }
.is-confirmed .set-index { background: color-mix(in srgb, var(--green), transparent 80%); color: var(--green); }
.set-summary-text { min-width: 0; flex: 1; }
.set-summary-text strong, .set-summary-text span { display: block; }
.set-summary-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-summary-text span { margin-top: .2rem; color: var(--muted); font-size: .8rem; }
.status-pill { margin-left: .5rem; color: var(--yellow); }
.is-confirmed .status-pill { color: var(--green); }
.is-skipped .status-pill { color: var(--muted); }
.set-details { padding: 0 .9rem 1rem; border-top: 1px solid var(--line); }
.prefill-note { margin: .8rem 0; padding: .7rem .8rem; border-radius: 12px; background: color-mix(in srgb, var(--yellow), transparent 90%); color: #ffe39a; font-size: .82rem; line-height: 1.35; }
.prefill-note.confirmed { background: color-mix(in srgb, var(--green), transparent 91%); color: #91efbd; }
.field { display: grid; gap: .4rem; margin: .8rem 0; }
.field > span, .field label { color: var(--muted); font-size: .78rem; font-weight: 750; }
input, select, textarea { width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 12px; padding: .72rem .8rem; background: var(--surface-2); color: var(--text); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(255,106,0,.14); }
textarea { min-height: 82px; resize: vertical; }
.rep-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin: .9rem 0; }
.rep-control { padding: .75rem .55rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 15px; text-align: center; }
.rep-control > label { display: block; color: var(--muted); font-size: .75rem; font-weight: 800; }
.rep-entry { display: grid; grid-template-columns: 42px minmax(48px,1fr) 42px; align-items: center; gap: .25rem; margin-top: .55rem; }
.rep-entry button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-3); color: var(--text); font-size: 1.25rem; font-weight: 700; }
.rep-entry input { min-width: 0; height: 44px; min-height: 44px; padding: 0; border: 0; background: transparent; text-align: center; font-size: 1.55rem; font-weight: 900; box-shadow: none; appearance: textfield; }
.rep-entry input::-webkit-inner-spin-button { display: none; }
.set-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; margin-top: .9rem; }
.set-actions .primary-button { grid-column: 1 / -1; }
.reorder-row { display: flex; gap: .45rem; margin-top: .7rem; }

.history-list, .manage-list { display: grid; gap: .7rem; }
.history-card, .manage-card { padding: 1rem; }
.history-card summary { cursor: pointer; list-style: none; }
.history-card summary::-webkit-details-marker { display: none; }
.history-title { display: flex; justify-content: space-between; gap: .8rem; }
.history-title h3, .manage-card h3 { margin: 0; }
.history-title p, .manage-card p { margin: .3rem 0 0; color: var(--muted); font-size: .84rem; }
.history-sets { display: grid; gap: .45rem; margin-top: .9rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.history-set { display: grid; grid-template-columns: 1fr auto; gap: .6rem; padding: .6rem; background: var(--surface-2); border-radius: 11px; }
.history-set span { color: var(--muted); font-size: .76rem; }
.history-set strong { text-align: right; }
.manage-card .button-row { margin-top: .8rem; }
.nested-list { display: grid; gap: .45rem; margin-top: .8rem; }
.nested-item { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .6rem; background: var(--surface-2); border-radius: 11px; }
.nested-item-text { min-width: 0; }
.nested-item-text strong, .nested-item-text span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nested-item-text span { margin-top: .15rem; color: var(--muted); font-size: .74rem; }
.nested-actions { display: flex; flex: 0 0 auto; gap: .3rem; }
.inline-form { display: grid; gap: .6rem; padding: .9rem; margin: .8rem 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.inline-form h3 { margin: 0; }
.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }

.backup-card { padding: 1rem; margin-bottom: .8rem; }
.backup-card h3 { margin: 0; }
.backup-card p, .helper-text { color: var(--muted); line-height: 1.45; font-size: .88rem; }
.file-input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
.empty-card, .loading-card { padding: 2rem 1.2rem; text-align: center; color: var(--muted); }
.empty-card h3 { color: var(--text); }
.spinner { width: 30px; height: 30px; margin: 0 auto; border: 3px solid var(--line); border-top-color: var(--orange); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.bottom-nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); padding: .45rem max(.55rem, env(safe-area-inset-right)) calc(.45rem + var(--safe-bottom)) max(.55rem, env(safe-area-inset-left)); border-top: 1px solid var(--line); background: rgba(17,17,19,.94); backdrop-filter: blur(20px); }
.bottom-nav button { display: grid; justify-items: center; gap: .2rem; min-height: 50px; border: 0; background: transparent; color: var(--muted); font-size: .68rem; font-weight: 750; }
.bottom-nav button span { font-size: 1.1rem; }
.bottom-nav button[aria-current="page"] { color: var(--orange); }
.toast { position: fixed; z-index: 80; left: 50%; bottom: calc(5.4rem + var(--safe-bottom)); max-width: calc(100% - 2rem); padding: .7rem 1rem; transform: translate(-50%, 2rem); opacity: 0; pointer-events: none; border: 1px solid var(--line); border-radius: 99px; background: #29292e; color: var(--text); box-shadow: 0 8px 30px rgba(0,0,0,.45); transition: .2s ease; white-space: nowrap; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

@media (min-width: 620px) {
  .workout-grid { grid-template-columns: 1fr 1fr; }
  .app-header { padding-inline: max(1rem, calc((100% - 720px) / 2)); }
}
@media (max-width: 440px) {
  .rep-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
