:root {
  color-scheme: dark;
  --page-bg: #0f1419;
  --card-bg: #182028;
  --bg-elevated: #182028;
  --bg-panel: #202a33;
  --bg-muted: #26323d;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-strong: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f6f5ef;
  --text-dim: #b6c0cb;
  --accent: #e7a33e;
  --accent-soft: rgba(231, 163, 62, 0.2);
  --danger: #ef5a5a;
  --warn: #d7b445;
  --good: #39b36d;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --radius: 22px;
  --radius-sm: 14px;
  --bottom-safe: calc(env(safe-area-inset-bottom, 0px) + 16px);
  --top-safe: calc(env(safe-area-inset-top, 0px) + 16px);
  --font-heading: "Avenir Next", "SF Pro Display", "Helvetica Neue", sans-serif;
  --font-body: "Avenir", "SF Pro Text", "Helvetica Neue", sans-serif;
  --subject-rgb: 231, 163, 62;
}

html[data-theme="light"] {
  color-scheme: light;
  --page-bg: #eef4fb;
  --card-bg: #ffffff;
  --bg-elevated: #ffffff;
  --bg-panel: #f6faff;
  --bg-muted: #eaf2fb;
  --surface: rgba(23, 38, 56, 0.05);
  --surface-strong: rgba(23, 38, 56, 0.1);
  --line: rgba(23, 38, 56, 0.14);
  --text: #16202b;
  --text-dim: #526273;
  --accent: #e18618;
  --accent-soft: rgba(225, 134, 24, 0.22);
  --danger: #e05252;
  --warn: #cb9812;
  --good: #229a5f;
  --shadow: 0 16px 32px rgba(27, 52, 84, 0.1);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--page-bg);
  color: var(--text);
  font-family: var(--font-body);
}

body {
  min-height: 100dvh;
}

button,
 a,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
}

.app-shell {
  width: min(100vw, 430px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: var(--top-safe) 16px calc(var(--bottom-safe) + 88px);
  position: relative;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.screen-header h1,
.card-title,
.section-title {
  margin: 0;
  font-family: var(--font-heading);
  letter-spacing: 0.02em;
}

.hero h1 {
  font-size: 2rem;
}

.hero p,
.muted,
.hint,
.empty-state p,
.screen-header p {
  margin: 0;
  color: var(--text-dim);
  line-height: 1.45;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card,
.panel,
.empty-state,
.history-row,
.template-row,
.exercise-row {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card,
.panel,
.empty-state {
  padding: 18px;
}

.screen-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.subject-card {
  --subject-rgb: 231, 163, 62;
  background:
    linear-gradient(rgba(var(--subject-rgb), 0.08), rgba(var(--subject-rgb), 0.08)),
    var(--card-bg);
  border-color: rgba(var(--subject-rgb), 0.24);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    var(--shadow);
}

.subject-start {
  --subject-rgb: 239, 125, 84;
}

.subject-history {
  --subject-rgb: 87, 163, 232;
}

.subject-admin {
  --subject-rgb: 161, 121, 228;
}

.subject-progress {
  --subject-rgb: 231, 163, 62;
}

.subject-recent {
  --subject-rgb: 78, 190, 162;
}

.subject-exercises {
  --subject-rgb: 87, 163, 232;
}

.subject-templates {
  --subject-rgb: 239, 125, 84;
}

.subject-data {
  --subject-rgb: 78, 190, 162;
}

.subject-theme {
  --subject-rgb: 161, 121, 228;
}

.active-workout-meta {
  min-width: 0;
  max-width: 240px;
}

.active-workout-subheader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.active-workout-subheader .badge {
  justify-self: end;
}

.section-header .hint {
  font-size: 0.84rem;
}

.grid-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn,
.icon-btn,
.nav-pill,
.tab {
  border-radius: 16px;
  min-height: 48px;
  padding: 0 16px;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.btn:active,
.icon-btn:active,
.nav-pill:active,
.tab:active {
  transform: translateY(1px) scale(0.99);
}

.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-primary {
  background: var(--accent);
  color: #23190a;
  font-weight: 700;
  border-color: transparent;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
}

.btn-danger {
  background: rgba(239, 90, 90, 0.15);
  color: #ffb1b1;
  border-color: rgba(239, 90, 90, 0.25);
}

.btn-ghost {
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--text-dim);
}

.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.icon-btn {
  width: 48px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.pill-row,
.toolbar,
.inline-actions,
.chips {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar {
  align-items: center;
  justify-content: space-between;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
  border: 1px solid var(--line);
  font-size: 0.86rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.theme-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.theme-chip {
  min-height: 46px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-dim);
}

.theme-chip.active {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(161, 121, 228, 0.45);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(161, 121, 228, 0.18);
}

.status-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.exercise-list-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.legend-badge {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.8rem;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
}

.mini-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
}

.mini-status-not-started {
  background: var(--danger);
}

.mini-status-in-progress {
  background: var(--warn);
}

.mini-status-complete {
  background: var(--good);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(239, 90, 90, 0.15);
}

.status-not-started .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(239, 90, 90, 0.15);
}

.status-in-progress .status-dot {
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(215, 180, 69, 0.15);
}

.status-complete .status-dot {
  background: var(--good);
  box-shadow: 0 0 0 4px rgba(57, 179, 109, 0.15);
}

.list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.list-row {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px;
}

.list-row h3,
.list-row h2,
.mini-card h3 {
  margin: 0;
  font-size: 1rem;
}

.list-row p,
.mini-card p {
  margin: 6px 0 0;
  color: var(--text-dim);
  font-size: 0.92rem;
  line-height: 1.4;
}

.list-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.list-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.input-grid {
  display: grid;
  gap: 12px;
}

.input-grid.two {
  grid-template-columns: 1fr 1fr;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field label {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  padding: 14px 16px;
  outline: none;
}

.field textarea {
  min-height: 120px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: rgba(231, 163, 62, 0.7);
  box-shadow: 0 0 0 4px rgba(231, 163, 62, 0.12);
}

.template-builder {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.exercise-select-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.ordered-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ordered-item {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.ordered-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ordered-meta strong {
  font-size: 0.96rem;
}

.ordered-meta span {
  color: var(--text-dim);
  font-size: 0.86rem;
}

.mini-actions {
  display: flex;
  gap: 8px;
}

.exercise-status-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.exercise-status-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  padding: 16px;
  align-items: center;
  border-radius: 22px;
}

.exercise-status-card .status-dot {
  margin-top: 2px;
}

.exercise-status-card strong {
  display: block;
  font-size: 1rem;
}

.exercise-status-card span {
  margin-top: 0;
}

.exercise-status-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.exercise-status-meta span {
  display: block;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.exercise-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 82px;
  min-height: 52px;
  padding: 0 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  justify-self: end;
  align-self: center;
}

.exercise-status-card.current {
  border-color: rgba(231, 163, 62, 0.45);
  background: rgba(231, 163, 62, 0.08);
}

.exercise-detail {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.set-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.set-row {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}

.set-row strong {
  color: var(--text-dim);
  font-size: 0.88rem;
}

.set-row input {
  min-width: 0;
  width: 100%;
  padding: 14px 16px;
  text-align: center;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  outline: none;
}

.history-toggle {
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}

.tab {
  min-width: 124px;
  background: transparent;
  color: var(--text-dim);
}

.tab.active {
  background: var(--accent);
  color: #23190a;
  font-weight: 700;
}

.history-table-wrap {
  overflow-x: auto;
  border-radius: 18px;
  border: 1px solid var(--line);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
  background: rgba(255, 255, 255, 0.03);
}

.history-table th,
.history-table td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 0.88rem;
}

.history-table th {
  color: var(--text-dim);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.04);
}

.history-table td small {
  display: block;
  color: var(--text-dim);
  line-height: 1.35;
}

.sticky-nav {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  transform: translateX(-50%);
  width: min(calc(100vw - 24px), 406px);
  padding: 10px;
  border-radius: 24px;
  background: rgba(14, 18, 23, 0.9);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: var(--shadow);
}

.sticky-nav-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.nav-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--line);
}

.nav-pill.primary {
  background: var(--accent);
  color: #23190a;
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 24, 0.38);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 30;
}

.modal {
  width: min(100%, 390px);
  padding: 20px;
  border-radius: 24px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.modal h2 {
  margin: 0 0 8px;
}

.modal p {
  margin: 0;
  color: var(--text-dim);
  line-height: 1.45;
}

.modal .toolbar {
  margin-top: 18px;
  justify-content: flex-end;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 104px);
  transform: translateX(-50%);
  width: min(calc(100vw - 48px), 360px);
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--card-bg);
  border: 1px solid rgba(231, 163, 62, 0.25);
  box-shadow: var(--shadow);
  text-align: center;
  z-index: 35;
}

.toast.success {
  border-color: rgba(57, 179, 109, 0.28);
}

.toast.error {
  border-color: rgba(239, 90, 90, 0.28);
}

.empty-state {
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 6px;
}

.home-shortcuts {
  display: grid;
  gap: 12px;
}

.shortcut-card {
  padding: 18px;
  border-radius: 24px;
  box-shadow: var(--shadow);
  text-align: left;
}

.shortcut-card h2 {
  margin: 0;
}

.shortcut-card p {
  margin: 8px 0 0;
  color: var(--text-dim);
}

.subtle-separator {
  width: 100%;
  height: 1px;
  background: var(--line);
}

.fine-print {
  font-size: 0.82rem;
  color: var(--text-dim);
}

.hidden {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
