:root {
  color-scheme: light;
  --ink: #151712;
  --muted: #687064;
  --paper: #f4f5ef;
  --surface: #ffffff;
  --line: #d9ddd3;
  --accent: #b9f348;
  --accent-strong: #85c900;
  --accent-ink: #213000;
  --dark: #121510;
  --warning: #c46c21;
  --danger: #b33333;
  --radius: 8px;
  --shadow: 0 20px 60px rgba(25, 32, 20, 0.12);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
}

button, input, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; }

[hidden] { display: none !important; }

.loading-screen {
  display: grid;
  min-height: 100svh;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
}

.setup-screen {
  display: flex;
  min-height: 100svh;
  overflow-x: hidden;
  background: var(--dark);
}

.setup-panel {
  display: flex;
  width: min(100%, 760px);
  align-items: center;
  flex-direction: column;
  justify-content: flex-start;
  margin: auto;
  padding: clamp(36px, 8vw, 104px) clamp(24px, 7vw, 72px);
  color: #f5f7f0;
}

.setup-panel > * {
  width: 100%;
  max-width: 440px;
}

.brand, .wordmark { font-weight: 800; }
.brand {
  margin: 0 0 28px;
  font-size: 58px;
  line-height: 1;
  letter-spacing: 0;
}

.setup-copy {
  margin: 24px 0 36px;
  color: #bdc4b8;
  font-size: 17px;
  line-height: 1.7;
}

.setup-form { max-width: 440px; }
label { display: block; margin-bottom: 8px; color: inherit; font-size: 13px; font-weight: 700; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
}

input:focus, textarea:focus { border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(185, 243, 72, 0.2); }
.setup-form input { margin-bottom: 12px; border-color: #43493f; background: #20241d; color: #fff; color-scheme: dark; }

.primary-button, .secondary-button, .danger-button, .text-button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 17px;
  font-weight: 750;
}

.primary-button { width: 100%; color: var(--accent-ink); background: var(--accent); }
.primary-button:hover { background: #c9ff5e; transform: translateY(-1px); }
.primary-button:active { transform: translateY(0); }
.secondary-button { border: 1px solid var(--line); color: var(--ink); background: transparent; }
.secondary-button:hover { border-color: #aeb5a8; background: #f8faf5; }
.danger-button { border: 1px solid #ebc5c5; color: var(--danger); background: #fff6f6; }
.text-button { width: 100%; max-width: 440px; margin-top: 14px; padding: 0; color: #dbe1d4; background: transparent; text-align: center; }
.text-button:hover { color: var(--accent); }
.primary-button svg, .secondary-button svg, .danger-button svg { width: 18px; height: 18px; }

.app-shell { min-height: 100vh; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  height: 68px;
  align-items: center;
  border-bottom: 1px solid rgba(217, 221, 211, 0.9);
  padding: 0 clamp(20px, 4vw, 64px);
  background: rgba(244, 245, 239, 0.92);
  backdrop-filter: blur(18px);
}

.wordmark { display: inline-flex; width: max-content; align-items: center; gap: 9px; text-decoration: none; }
.wordmark-mark { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 50%; color: var(--accent-ink); background: var(--accent); }
.desktop-nav { display: flex; height: 100%; align-items: stretch; gap: 36px; }
.desktop-nav a { display: flex; position: relative; align-items: center; color: var(--muted); font-size: 14px; font-weight: 700; text-decoration: none; }
.desktop-nav a.active { color: var(--ink); }
.desktop-nav a.active::after { position: absolute; right: 0; bottom: 0; left: 0; height: 3px; background: var(--ink); content: ""; }
.topbar > .icon-button { justify-self: end; }

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--ink);
  background: transparent;
}
.icon-button:hover { background: rgba(21, 23, 18, 0.07); }
.icon-button svg { width: 20px; height: 20px; }

.view { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 50px 0 90px; outline: none; }
.page-enter { animation: page-in 320ms ease both; }
@keyframes page-in { from { opacity: 0; transform: translateY(8px); } }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; margin-bottom: 34px; }
.eyebrow { margin: 0 0 8px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.page-header h1, .dialog-header h2 { margin: 0; font-size: clamp(30px, 4vw, 52px); line-height: 1.08; letter-spacing: 0; }
.page-header p:last-child { max-width: 560px; margin: 12px 0 0; color: var(--muted); line-height: 1.6; }

.sync-badge { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #aab0a6; }
.status-dot.synced { background: var(--accent-strong); }
.status-dot.syncing { background: #e4a235; animation: pulse 1s infinite; }
.status-dot.offline, .status-dot.error { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.35; } }

.today-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.65fr); gap: clamp(28px, 5vw, 72px); }
.session-workspace { min-width: 0; }
.date-line { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.date-line .today-tag { border-radius: 999px; padding: 4px 9px; color: var(--accent-ink); background: var(--accent); font-size: 11px; font-weight: 800; }

.session-title-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 14px 0 28px; }
.session-title-row h2 { margin: 0; font-size: clamp(34px, 5vw, 64px); line-height: 1; }
.session-duration { color: var(--muted); font-weight: 700; }

.adaptation-note { display: flex; align-items: flex-start; gap: 12px; margin: 0 0 24px; border-left: 3px solid var(--warning); padding: 10px 0 10px 16px; color: #72502f; line-height: 1.55; }
.adaptation-note svg { width: 18px; flex: 0 0 auto; margin-top: 3px; }

.exercise-list { border-top: 1px solid var(--line); }
.exercise-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto 42px;
  min-height: 76px;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  transition: opacity 180ms ease, background 180ms ease;
}
.exercise-row.checked { opacity: 0.48; }
.exercise-row.checked .exercise-name { text-decoration: line-through; }
.exercise-check { display: grid; width: 28px; height: 28px; place-items: center; border: 1.5px solid #aeb5a8; border-radius: 50%; color: transparent; background: transparent; }
.exercise-check.checked { border-color: var(--accent-strong); color: var(--accent-ink); background: var(--accent); }
.exercise-check svg { width: 16px; }
.exercise-name { display: block; font-weight: 800; }
.exercise-meta { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; }
.exercise-target { color: var(--ink); font-size: 13px; font-weight: 800; text-align: right; white-space: nowrap; }
.video-button { color: var(--muted); text-decoration: none; }
.video-button:hover { color: var(--ink); background: rgba(21, 23, 18, 0.07); }

.complete-area { display: flex; align-items: center; gap: 14px; margin-top: 28px; }
.complete-area .primary-button { width: auto; min-width: 220px; }
.skip-button { min-height: 46px; border: 0; padding: 0 12px; color: var(--muted); background: transparent; font-weight: 700; }
.skip-button:hover { color: var(--warning); }

.today-aside { border-left: 1px solid var(--line); padding-left: clamp(24px, 4vw, 52px); }
.progress-ring { position: relative; display: grid; width: 172px; height: 172px; margin-bottom: 34px; place-items: center; }
.progress-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.progress-ring circle { fill: none; stroke-width: 8; }
.progress-ring .ring-track { stroke: #dfe2d9; }
.progress-ring .ring-value { stroke: var(--accent-strong); stroke-linecap: round; transition: stroke-dashoffset 500ms ease; }
.progress-ring strong { font-size: 36px; }
.progress-ring span { display: block; color: var(--muted); font-size: 12px; text-align: center; }
.aside-stat { display: flex; align-items: baseline; justify-content: space-between; border-top: 1px solid var(--line); padding: 17px 0; }
.aside-stat span { color: var(--muted); font-size: 13px; }
.aside-stat strong { font-size: 22px; }
.next-up { margin-top: 28px; }
.next-up h3 { margin: 0 0 12px; font-size: 14px; }
.next-up p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }

.rest-state { position: relative; min-height: 520px; overflow: hidden; border-radius: var(--radius); color: white; background: var(--dark); }
.rest-image { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(10, 12, 9, .85), rgba(10, 12, 9, .15)), url("https://images.unsplash.com/photo-1552674605-db6ffd4facb5?auto=format&fit=crop&w=1600&q=85") center / cover; }
.rest-copy { position: relative; z-index: 1; display: flex; min-height: 520px; max-width: 560px; flex-direction: column; justify-content: flex-end; padding: clamp(30px, 6vw, 72px); }
.rest-copy h2 { margin: 0 0 14px; font-size: clamp(42px, 7vw, 84px); line-height: 0.95; }
.rest-copy p { color: #d5dbd0; line-height: 1.7; }

.week-switcher { display: flex; align-items: center; gap: 6px; }
.week-switcher strong { min-width: 76px; text-align: center; }
.calendar-strip { display: grid; grid-template-columns: repeat(7, 1fr); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.day-cell { position: relative; min-height: 142px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 14px; background: rgba(255, 255, 255, 0.32); }
.day-cell.today { box-shadow: inset 0 0 0 2px var(--ink); }
.day-cell.completed { background: rgba(185, 243, 72, 0.18); }
.day-cell.outside-plan { color: var(--muted); background: rgba(255, 255, 255, 0.14); }
.day-cell.outside-plan .day-session { opacity: 0.58; }
.day-number { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }
.day-number strong { color: var(--ink); font-size: 15px; }
.day-session { display: block; width: 100%; margin-top: 22px; border: 0; padding: 0; color: var(--ink); background: transparent; text-align: left; }
.day-session strong { display: block; font-size: 16px; }
.day-session span { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }
.cell-status { position: absolute; right: 12px; bottom: 12px; }
.cell-status svg { width: 18px; height: 18px; color: var(--accent-strong); }
.plan-legend { display: flex; flex-wrap: wrap; gap: 20px; margin-top: 18px; color: var(--muted); font-size: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; background: #d9ddd3; }
.legend-swatch.strength { background: var(--ink); }
.legend-swatch.run { background: #d58a4c; }
.legend-swatch.done { background: var(--accent-strong); }

.progress-grid { display: grid; grid-template-columns: minmax(240px, .72fr) minmax(0, 1.5fr); gap: clamp(36px, 7vw, 90px); }
.big-progress { padding-top: 14px; }
.big-progress strong { display: block; font-size: clamp(72px, 12vw, 150px); line-height: .85; }
.big-progress span { display: block; margin-top: 18px; color: var(--muted); }
.metric-list { margin-top: 42px; }
.metric-list .aside-stat strong { font-size: 28px; }
.week-bars { display: grid; grid-template-columns: repeat(8, 1fr); height: 310px; align-items: end; gap: 12px; border-bottom: 1px solid var(--line); padding-top: 30px; }
.week-bar-wrap { display: flex; height: 100%; flex-direction: column; justify-content: flex-end; gap: 9px; text-align: center; }
.week-bar { min-height: 4px; background: var(--accent-strong); transition: height 600ms cubic-bezier(.2,.8,.2,1); }
.week-bar-wrap span { color: var(--muted); font-size: 11px; }
.history-title { margin: 48px 0 14px; font-size: 16px; }
.history-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) auto; align-items: center; border-top: 1px solid var(--line); padding: 16px 0; gap: 20px; }
.history-row:last-child { border-bottom: 1px solid var(--line); }
.history-row time, .history-row span { color: var(--muted); font-size: 13px; }

dialog { color: var(--ink); }
dialog::backdrop { background: rgba(12, 15, 10, 0.58); backdrop-filter: blur(4px); }
.sheet-dialog { width: min(680px, calc(100% - 24px)); max-height: calc(100svh - 36px); border: 0; border-radius: var(--radius); padding: 0; box-shadow: var(--shadow); }
.sheet-dialog[open] { animation: dialog-in 220ms ease both; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(14px) scale(.99); } }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 28px 30px 22px; }
.dialog-header h2 { font-size: 30px; }
.settings-body { padding: 0 30px 30px; }
.settings-body section { border-bottom: 1px solid var(--line); padding: 26px 0; }
.settings-body section:last-child { border: 0; }
.settings-body h3 { margin: 0 0 10px; font-size: 15px; }
.settings-body p { margin: 8px 0 16px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.sync-line { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 700; }
.secret-row { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 6px 4px 14px; background: #f7f8f4; }
.secret-row code { min-width: 0; flex: 1; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }
.file-button { cursor: pointer; }
.file-button input { display: none; }
.danger-zone p { max-width: 520px; }

.confirm-dialog { width: min(420px, calc(100% - 24px)); border: 0; border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.confirm-dialog[open] { animation: dialog-in 180ms ease both; }
.confirm-dialog h2 { margin: 0; font-size: 28px; }
.confirm-dialog > p:not(.eyebrow) { margin: 14px 0 0; color: var(--muted); font-size: 14px; line-height: 1.65; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 26px; }
.confirm-actions .primary-button { width: auto; }

.restore-dialog { width: min(440px, calc(100% - 24px)); border: 0; border-radius: var(--radius); padding: 32px; box-shadow: var(--shadow); }
.restore-close { position: absolute; top: 12px; right: 12px; }
.restore-dialog h2 { margin: 0; font-size: 30px; }
.restore-dialog > p:not(.eyebrow) { color: var(--muted); font-size: 14px; }
.restore-dialog form { margin-top: 24px; }
.restore-dialog input { margin-bottom: 8px; }
.form-error { min-height: 18px; margin: 0 0 8px; color: var(--danger); font-size: 12px; }

.session-detail { padding: 28px 30px 30px; }
.session-detail .dialog-header { margin: -28px -30px 20px; }
.session-detail-list { margin: 20px 0; }
.session-detail-row { display: grid; grid-template-columns: 1fr auto; border-top: 1px solid var(--line); padding: 15px 0; gap: 14px; }
.session-detail-row:last-child { border-bottom: 1px solid var(--line); }
.session-detail-row strong { font-size: 14px; }
.session-detail-row span { color: var(--muted); font-size: 12px; }

.toast { position: fixed; z-index: 100; right: 24px; bottom: 24px; max-width: min(380px, calc(100% - 48px)); border-radius: var(--radius); padding: 13px 17px; color: white; background: var(--dark); box-shadow: var(--shadow); opacity: 0; transform: translateY(14px); pointer-events: none; transition: 180ms ease; }
.toast.show { opacity: 1; transform: translateY(0); }

.mobile-nav { display: none; }

@media (max-width: 820px) {
  .setup-panel { margin: 0 auto; padding: 34px 24px 48px; }
  .brand { margin-bottom: 24px; font-size: 46px; }
  .setup-copy { margin: 18px 0 26px; font-size: 15px; }

  .topbar { grid-template-columns: 1fr auto; height: 58px; padding: 0 18px; }
  .desktop-nav { display: none; }
  .view { width: min(100% - 28px, 680px); padding: 32px 0 104px; }
  .page-header { align-items: flex-start; flex-direction: column; margin-bottom: 26px; }
  .page-header h1 { font-size: 34px; }
  .today-layout, .progress-grid { grid-template-columns: 1fr; }
  .today-aside { border-top: 1px solid var(--line); border-left: 0; padding-top: 30px; padding-left: 0; }
  .progress-ring { width: 140px; height: 140px; }
  .exercise-row { grid-template-columns: 36px minmax(0, 1fr) 42px; gap: 10px; }
  .exercise-target { grid-column: 2; grid-row: 2; padding-bottom: 10px; text-align: left; }
  .video-button { grid-column: 3; grid-row: 1 / span 2; }
  .complete-area { align-items: stretch; flex-direction: column; }
  .complete-area .primary-button { width: 100%; }

  .calendar-strip { grid-template-columns: 1fr; border: 0; }
  .day-cell { display: grid; grid-template-columns: 64px 1fr; min-height: 82px; align-items: center; border: 0; border-top: 1px solid var(--line); padding: 10px 6px; }
  .day-cell:last-child { border-bottom: 1px solid var(--line); }
  .day-cell.today { box-shadow: inset 3px 0 var(--ink); }
  .day-number { display: block; }
  .day-number strong { display: block; margin-top: 3px; }
  .day-session { margin: 0; }
  .cell-status { position: static; justify-self: end; }
  .week-bars { height: 240px; gap: 7px; }
  .history-row { grid-template-columns: 90px 1fr; }
  .history-row span:last-child { grid-column: 2; }

  .mobile-nav {
    position: fixed;
    z-index: 30;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    min-height: 70px;
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--line);
    background: rgba(250, 251, 247, .96);
    backdrop-filter: blur(18px);
  }
  .mobile-nav a { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 3px; color: var(--muted); font-size: 10px; font-weight: 700; text-decoration: none; }
  .mobile-nav a.active { color: var(--ink); }
  .mobile-nav svg { width: 19px; height: 19px; }
  .toast { right: 14px; bottom: 86px; left: 14px; max-width: none; }

  .confirm-dialog { padding: 24px; }
  .confirm-actions { align-items: stretch; flex-direction: column-reverse; }
  .confirm-actions button { width: 100%; }
}

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