:root {
  --bg: #f5f4ef;
  --panel: #ffffff;
  --panel-2: #f0f5f7;
  --ink: #111827;
  --muted: #64707d;
  --line: #d9dedf;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #dff4ef;
  --accent-panel: #effaf8;
  --blue: #2563eb;
  --gold: #b7791f;
  --danger: #b91c1c;
  --danger-soft: #f0c6c6;
  --input-bg: #ffffff;
  --nav-bg: rgba(255, 255, 255, 0.94);
  --topbar-bg: rgba(245, 244, 239, 0.92);
  --hero-tint: rgba(15, 118, 110, 0.08);
  --modal-backdrop: rgba(17, 24, 39, 0.5);
  --active-bg: #111827;
  --active-fg: #ffffff;
  --active-muted: rgba(255, 255, 255, 0.72);
  --export-bg: #111827;
  --export-ink: #e5e7eb;
  --shadow: 0 16px 36px rgba(17, 24, 39, 0.1);
  color-scheme: light dark;
}

:root[data-theme="dark"] {
  --bg: #0b1120;
  --panel: #111827;
  --panel-2: #1f2937;
  --ink: #f8fafc;
  --muted: #a7b0be;
  --line: #2f3b4b;
  --accent: #14b8a6;
  --accent-dark: #5eead4;
  --accent-soft: #123f3d;
  --accent-panel: #0f2f30;
  --blue: #60a5fa;
  --gold: #fbbf24;
  --danger: #fca5a5;
  --danger-soft: #7f1d1d;
  --input-bg: #0f172a;
  --nav-bg: rgba(15, 23, 42, 0.94);
  --topbar-bg: rgba(11, 17, 32, 0.92);
  --hero-tint: rgba(20, 184, 166, 0.12);
  --modal-backdrop: rgba(2, 6, 23, 0.72);
  --active-bg: #f8fafc;
  --active-fg: #0b1120;
  --active-muted: rgba(11, 17, 32, 0.72);
  --export-bg: #020617;
  --export-ink: #d1d5db;
  --shadow: 0 16px 36px rgba(0, 0, 0, 0.32);
  color-scheme: dark;
}

:root[data-theme="light"] {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, var(--hero-tint), transparent 260px),
    var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 820px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px 14px 88px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: -14px -14px 12px;
  padding: calc(14px + env(safe-area-inset-top)) 14px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 1.35rem;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  font-size: 1.45rem;
  line-height: 1.15;
  letter-spacing: 0;
}

h3 {
  font-size: 1.02rem;
  line-height: 1.22;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-head {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  margin: 18px 0 12px;
}

.icon-button,
.secondary-button,
.ghost-button,
.primary-button,
.danger-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.icon-button {
  width: 42px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
}

.secondary-button,
.ghost-button {
  padding: 0 12px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
}

.primary-button {
  width: 100%;
  color: #fff;
  background: var(--accent);
  box-shadow: var(--shadow);
}

.danger-button {
  width: 100%;
  color: var(--danger);
  background: var(--panel);
  border: 1px solid var(--danger-soft);
}

.day-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  margin: 12px 0;
}

.day-button {
  min-height: 56px;
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
}

.day-button strong {
  display: block;
  font-size: 0.78rem;
}

.day-button span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.7rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.day-button.active {
  color: var(--active-fg);
  background: var(--active-bg);
  border-color: var(--active-bg);
}

.day-button.active span {
  color: var(--active-muted);
}

.session-card,
.exercise-card,
.progress-panel,
.program-block,
.library-card,
.coach-hero,
.coach-recommendation,
.coach-method {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.session-card {
  padding: 14px;
  margin: 12px 0;
}

.history-load-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -2px 0 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--panel);
}

.history-load-status[hidden] {
  display: none;
}

.history-load-status div {
  display: grid;
  gap: 3px;
}

.history-load-status span {
  color: var(--muted);
  font-size: 0.8rem;
}

.history-load-status[data-state="error"] {
  border-left-color: var(--danger);
}

.session-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.pill {
  display: inline-flex;
  flex: 0 0 auto;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.session-note {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.45;
}

.readiness,
.field,
.flex-controls {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.flex-cue {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

select,
input,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: var(--input-bg);
}

textarea {
  min-height: 112px;
  padding: 10px;
  resize: vertical;
  line-height: 1.35;
}

.exercise-list,
.program-days,
.library-list,
.history-list,
.volume-bars {
  display: grid;
  gap: 10px;
}

.exercise-card {
  overflow: hidden;
}

.exercise-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.exercise-prescription {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.last-session {
  display: grid;
  gap: 3px;
  margin-top: 10px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  color: var(--muted);
  background: var(--accent-panel);
  font-size: 0.75rem;
}

.last-session strong {
  color: var(--accent-dark);
}

.sync-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}

.sync-panel h4 {
  margin: 0 0 3px;
}

.sync-panel p,
.sync-status {
  color: var(--muted);
  font-size: 0.78rem;
}

.sync-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.device-enrollment {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.device-enrollment h5 {
  margin: 0 0 4px;
}

.device-enrollment p {
  margin: 0;
}

.enrollment-code {
  padding: 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-align: center;
}

.sync-status[data-state="ok"] {
  color: var(--accent-dark);
  font-weight: 800;
}

.sync-status[data-state="error"] {
  color: var(--danger);
  font-weight: 800;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel-2);
  font-size: 0.74rem;
  font-weight: 800;
}

.info-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-dark);
  background: var(--accent-panel);
  font-weight: 900;
}

.set-table {
  width: 100%;
  border-collapse: collapse;
}

.set-table th,
.set-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 0.78rem;
}

.set-table th {
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.set-table input {
  min-height: 36px;
  padding: 0 7px;
  border-radius: 7px;
}

.set-table td:first-child {
  width: 40px;
  color: var(--muted);
  font-weight: 900;
}

.check-cell {
  width: 42px;
  text-align: center;
}

.set-done {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.exercise-footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 0.78rem;
}

.session-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin: 14px 0;
}

.draft-status {
  margin: -6px 0 14px;
  color: var(--muted);
  font-size: 0.76rem;
}

.draft-status[data-state="saved"] {
  color: var(--accent-dark);
  font-weight: 800;
}

.program-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.summary-tile,
.stat-tile {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.summary-tile strong,
.stat-tile strong {
  display: block;
  margin-top: 4px;
  font-size: 1.12rem;
}

.program-block {
  padding: 14px;
}

.program-block h3 {
  margin-bottom: 8px;
}

.program-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.program-row:first-of-type {
  border-top: 0;
}

.program-row p {
  color: var(--muted);
  font-size: 0.82rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.progress-panel {
  padding: 14px;
  margin-bottom: 12px;
}

.progress-panel h3 {
  margin-bottom: 10px;
}

.history-item {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.history-item:first-child {
  border-top: 0;
}

.history-item summary {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  list-style: none;
}

.history-item summary::-webkit-details-marker {
  display: none;
}

.history-item summary > span:first-child {
  display: grid;
  gap: 4px;
}

.history-item small,
.history-item p {
  color: var(--muted);
  font-size: 0.82rem;
}

.history-toggle {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
}

.history-item[open] .history-toggle {
  font-size: 0;
}

.history-item[open] .history-toggle::after {
  content: "Hide sets";
  font-size: 0.75rem;
}

.history-details {
  display: grid;
  gap: 12px;
  padding: 14px 0 4px;
}

.history-exercise {
  padding: 10px;
  border-radius: 12px;
  background: var(--panel-2);
}

.history-exercise h4 {
  margin-bottom: 7px;
  font-size: 0.88rem;
}

.history-exercise ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-exercise li {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.78rem;
}

.history-exercise li strong {
  color: var(--text);
  text-align: right;
}

.bar-row {
  display: grid;
  grid-template-columns: 96px 1fr 36px;
  gap: 8px;
  align-items: center;
  min-height: 28px;
  font-size: 0.78rem;
  font-weight: 800;
}

.volume-progress {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: var(--panel-2);
}

.volume-progress::-webkit-progress-bar {
  border-radius: 999px;
  background: var(--panel-2);
}

.volume-progress::-webkit-progress-value {
  border-radius: 999px;
  background: var(--accent);
}

.volume-progress::-moz-progress-bar {
  border-radius: 999px;
  background: var(--accent);
}

.coach-summary {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.coach-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
}

.coach-hero p:not(.eyebrow) {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.confidence-badge {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel-2);
  font-size: 0.72rem;
  font-weight: 900;
}

.confidence-badge.building,
.confidence-badge.high {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.goal-priorities {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.goal-priority {
  display: flex;
  gap: 8px;
  min-width: 0;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.goal-priority > span {
  display: grid;
  width: 25px;
  height: 25px;
  flex: 0 0 25px;
  place-items: center;
  border-radius: 50%;
  color: var(--active-fg);
  background: var(--active-bg);
  font-size: 0.72rem;
  font-weight: 900;
}

.goal-priority div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.goal-priority strong {
  font-size: 0.78rem;
}

.goal-priority small {
  color: var(--muted);
  font-size: 0.68rem;
}

.coach-recommendation {
  margin-bottom: 12px;
  padding: 14px;
  border-left: 4px solid var(--accent);
  background: var(--accent-panel);
}

.coach-recommendation h3 {
  margin-top: 4px;
  color: var(--accent-dark);
}

.coach-recommendation > p:not(.eyebrow) {
  margin-top: 7px;
  color: var(--ink);
  line-height: 1.45;
}

.coach-rule {
  display: block;
  margin-top: 9px;
  color: var(--muted);
  font-size: 0.74rem;
}

.coach-volume,
.coach-evidence {
  display: grid;
  gap: 12px;
}

.coach-window {
  color: var(--muted);
  font-size: 0.75rem;
}

.coach-volume-row {
  display: grid;
  gap: 6px;
}

.coach-volume-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.8rem;
}

.coach-volume-head span,
.coach-volume-row small {
  color: var(--muted);
}

.coach-volume-row small {
  font-size: 0.72rem;
  line-height: 1.35;
}

.evidence-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.evidence-grid div {
  display: grid;
  gap: 3px;
  padding: 10px;
  border-radius: 8px;
  background: var(--panel-2);
}

.evidence-grid span {
  color: var(--muted);
  font-size: 0.7rem;
}

.evidence-grid strong {
  font-size: 1rem;
}

.evidence-callout,
.coach-gate {
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.evidence-callout p,
.coach-gate p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.coach-gate.locked {
  border-color: var(--danger-soft);
}

.coach-gate.open {
  border-color: var(--accent);
}

.coach-method {
  margin-bottom: 12px;
  padding: 13px 14px;
}

.coach-method summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 800;
}

.coach-method-body {
  display: grid;
  gap: 9px;
  margin-top: 11px;
}

.coach-method-body p {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.search-input {
  margin: 4px 0 12px;
}

.library-card {
  padding: 14px;
}

.library-card p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.library-open-button {
  margin-top: 10px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  display: grid;
  width: min(100%, 820px);
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  border-top: 1px solid var(--line);
  background: var(--nav-bg);
  backdrop-filter: blur(14px);
}

.nav-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 900;
}

.nav-button.active {
  color: var(--active-fg);
  background: var(--active-bg);
}

.dialog {
  width: min(94vw, 620px);
  max-height: 84vh;
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: var(--modal-backdrop);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.dialog-body {
  display: grid;
  gap: 14px;
  padding: 14px;
  overflow: auto;
}

.dialog-body h4 {
  margin: 0 0 5px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.dialog-body p,
.dialog-body li {
  color: var(--muted);
  line-height: 1.48;
}

.dialog-body ul {
  margin: 0;
  padding-left: 20px;
}

.export-box,
.import-box {
  max-height: 180px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  border-radius: 8px;
}

.export-box {
  background: var(--export-bg);
  color: var(--export-ink);
  font-size: 0.72rem;
  white-space: pre-wrap;
}

.import-box {
  color: var(--ink);
  background: var(--input-bg);
  font-size: 0.78rem;
}

@media (min-width: 720px) {
  .app-shell {
    padding-left: 22px;
    padding-right: 22px;
  }

  .topbar {
    margin-left: -22px;
    margin-right: -22px;
    padding-left: 22px;
    padding-right: 22px;
  }

  .exercise-list,
  .program-days,
  .library-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .session-card,
  .progress-panel {
    grid-column: 1 / -1;
  }
}
