:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --ink: #17211d;
  --muted: #66746e;
  --line: #dfe5df;
  --green: #276749;
  --mint: #dff3e5;
  --blue: #2364aa;
  --amber: #b7791f;
  --red: #b42318;
  --shadow: 0 14px 38px rgba(23, 33, 29, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 20px 12px 110px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 2px 18px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 2.75rem;
  line-height: 1;
}

h2 {
  font-size: 1.75rem;
  line-height: 1.2;
}

h3 {
  font-size: 1.42rem;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

.icon-button,
.close-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(23, 33, 29, 0.08);
}

.today-panel,
.safety-panel,
.routine-summary,
.record-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.today-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 24px 18px;
}

.today-panel p:last-child {
  margin-top: 10px;
  color: var(--muted);
  font-size: 1.22rem;
  line-height: 1.4;
}

.progress-ring {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: conic-gradient(var(--green) var(--progress, 0%), #e7ece7 0);
}

.progress-ring span {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--surface);
  font-weight: 800;
  font-size: 1.1rem;
}

.safety-panel {
  margin-top: 14px;
  padding: 16px;
}

.safety-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.safety-grid span {
  min-height: 44px;
  padding: 10px;
  border-radius: 8px;
  color: #173c2c;
  background: var(--mint);
  font-size: 0.86rem;
  font-weight: 700;
}

.routine-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 18px 0;
}

.routine-tabs button {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
  font-weight: 800;
  font-size: 1.18rem;
}

.routine-tabs button[aria-selected="true"] {
  color: #ffffff;
  border-color: var(--green);
  background: var(--green);
}

.routine-summary {
  padding: 18px;
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1.35;
}

.summary-row strong {
  color: var(--ink);
}

.blocked-note {
  margin-top: 12px;
  padding: 11px;
  border: 1px solid #f2c7c2;
  border-radius: 8px;
  color: var(--red);
  background: #fff1ef;
  font-weight: 700;
  font-size: 1.08rem;
  line-height: 1.4;
}

.exercise-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.exercise-card {
  display: grid;
  grid-template-columns: 34px 1fr 24px;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 108px;
  padding: 18px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  text-align: left;
  background: var(--surface);
}

.exercise-card.is-done {
  border-color: #a8d5b5;
  background: #f0fbf3;
}

.exercise-status {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid #b8c5be;
  border-radius: 50%;
  color: #ffffff;
  font-size: 1rem;
  font-weight: 900;
}

.is-done .exercise-status {
  border-color: var(--green);
  background: var(--green);
}

.exercise-main {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.exercise-main strong {
  font-size: 1.32rem;
  line-height: 1.18;
}

.exercise-main strong,
.exercise-main small {
  overflow-wrap: anywhere;
}

.exercise-main small {
  color: var(--muted);
  font-size: 1.12rem;
  line-height: 1.35;
}

.exercise-chevron {
  color: var(--muted);
  font-size: 2.2rem;
  line-height: 1;
}

.record-panel {
  margin-top: 18px;
  padding: 16px;
}

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

.record-stats {
  display: grid;
  justify-items: end;
  color: var(--muted);
  font-size: 0.78rem;
}

.record-stats strong {
  color: var(--ink);
  font-size: 1.35rem;
}

.month-controls {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  gap: 8px;
  margin-top: 16px;
}

.month-controls button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #f9fbf8;
  font-weight: 850;
}

.next-session {
  margin-top: 12px;
  padding: 11px;
  border-radius: 8px;
  color: #173c2c;
  background: var(--mint);
  font-weight: 800;
}

.sync-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbf8;
}

.sync-panel div {
  display: grid;
  gap: 2px;
}

.sync-panel span {
  color: var(--muted);
  font-size: 0.83rem;
}

.sync-panel button,
.secondary-action {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  font-weight: 850;
}

.weekday-grid,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.weekday-grid {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 850;
  text-align: center;
}

.calendar-grid {
  margin-top: 6px;
}

.day-cell {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 3px;
  min-height: 54px;
  padding: 5px 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #f9fbf8;
  font-weight: 800;
}

.day-cell .day-number {
  font-size: 0.82rem;
}

.day-cell .day-session {
  min-height: 18px;
  padding: 2px 6px;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-size: 0.68rem;
  font-weight: 900;
}

.day-cell.outside {
  opacity: 0.35;
}

.day-cell.session-s1 .day-session {
  color: #ffffff;
  background: var(--green);
}

.day-cell.session-s2 .day-session {
  color: #ffffff;
  background: var(--blue);
}

.day-cell.session-s3 .day-session {
  color: #ffffff;
  background: var(--amber);
}

.day-cell.session-s4 .day-session {
  color: #ffffff;
  background: #5b4aa0;
}

.day-cell.rest .day-session {
  color: #51605a;
  background: #e5eae5;
}

.day-cell.today {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.history-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbf8;
}

.history-item span {
  color: var(--muted);
  font-size: 0.83rem;
}

.date-dialog {
  width: min(100% - 18px, 520px);
  max-height: calc(100dvh - 18px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(23, 33, 29, 0.28);
}

.date-dialog::backdrop {
  background: rgba(23, 33, 29, 0.48);
}

.date-dialog form {
  display: flex;
  justify-content: flex-end;
  padding: 10px;
}

#dateDetail {
  display: grid;
  gap: 12px;
  padding: 0 16px 18px;
}

.date-options {
  display: grid;
  gap: 8px;
}

.date-options button {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  min-height: 52px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #f9fbf8;
  text-align: left;
  font-weight: 850;
}

.date-options button.is-selected {
  border-color: var(--green);
  background: var(--mint);
}

.date-options span {
  color: var(--muted);
  font-weight: 700;
}

.sync-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

.sync-field input {
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #f9fbf8;
}

.secondary-action {
  width: 100%;
}

.close-button {
  font-size: 1.5rem;
}

.exercise-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  width: 100%;
  min-height: 100dvh;
  overflow-y: auto;
  background: var(--bg);
}

.exercise-screen.is-open {
  display: block;
}

.exercise-screen-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  min-height: 62px;
  padding: env(safe-area-inset-top) 12px 0;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 244, 0.96);
  backdrop-filter: blur(10px);
  font-weight: 900;
  font-size: 1.2rem;
  text-align: center;
}

.back-button {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  background: var(--surface);
  font-size: 3.2rem;
  line-height: 1;
}

#exerciseDetail {
  display: grid;
  gap: 20px;
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 18px 14px 120px;
}

.detail-header {
  display: grid;
  gap: 10px;
}

.detail-header h2 {
  font-size: 2.25rem;
  line-height: 1.08;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  padding: 10px 12px;
  border-radius: 999px;
  color: #173c2c;
  background: var(--mint);
  font-size: 1.08rem;
  font-weight: 800;
}

.warning {
  padding: 14px;
  border-radius: 8px;
  color: #6c3f00;
  background: #fff6df;
  font-weight: 750;
  font-size: 1.16rem;
  line-height: 1.4;
}

.danger {
  color: var(--red);
  background: #fff1ef;
}

.media-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 78%;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 2px;
  scroll-snap-type: x mandatory;
}

.media-strip img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  scroll-snap-align: start;
  background: #eef1ee;
}

.description {
  display: grid;
  gap: 10px;
  padding-left: 18px;
  color: #2c3733;
  font-size: 1.35rem;
  line-height: 1.48;
}

.video-link,
.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--blue);
  font-weight: 850;
  font-size: 1.18rem;
  text-decoration: none;
}

.primary-action {
  width: 100%;
  background: var(--green);
}

.timer {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.timer strong {
  font-size: 2.25rem;
}

.timer button {
  min-height: 56px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--green);
  font-weight: 800;
  font-size: 1.08rem;
}

.feedback {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.feedback label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
  font-size: 1.18rem;
}

.feedback input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.toggle-row input {
  width: 34px;
  height: 34px;
  accent-color: var(--green);
}

@media (max-width: 430px) {
  .app-shell {
    padding-inline: 10px;
  }

  .today-panel {
    align-items: flex-start;
    padding: 20px 16px;
  }

  .safety-grid {
    grid-template-columns: 1fr;
  }

  .day-cell {
    min-height: 58px;
  }
}

@media (max-width: 760px) {
  .topbar {
    padding-bottom: 22px;
  }

  h1 {
    font-size: 3.2rem;
  }

  h2 {
    font-size: 2.05rem;
  }

  .eyebrow {
    font-size: 1.08rem;
  }

  .today-panel {
    padding: 28px 20px;
  }

  .today-panel p:last-child,
  .summary-row,
  .blocked-note {
    font-size: 1.45rem;
  }

  .routine-tabs button {
    min-height: 76px;
    font-size: 1.45rem;
  }

  .exercise-card {
    grid-template-columns: 46px 1fr 32px;
    min-height: 132px;
    padding: 22px 16px;
  }

  .exercise-status {
    width: 46px;
    height: 46px;
    font-size: 1.25rem;
  }

  .exercise-main strong {
    font-size: 1.68rem;
  }

  .exercise-main small {
    font-size: 1.38rem;
  }

  .exercise-screen-header {
    grid-template-columns: 78px 1fr 78px;
    min-height: 92px;
    padding-inline: 14px;
    font-size: 1.55rem;
  }

  .back-button {
    width: 70px;
    height: 70px;
    font-size: 3.6rem;
  }

  #exerciseDetail {
    gap: 24px;
    padding: 24px 18px 140px;
  }

  .detail-header h2 {
    font-size: 3.05rem;
  }

  .pill-row {
    gap: 10px;
  }

  .pill {
    padding: 12px 14px;
    font-size: 1.35rem;
  }

  .warning {
    padding: 16px;
    font-size: 1.5rem;
  }

  .media-strip {
    grid-auto-columns: 66%;
  }

  .media-strip img {
    aspect-ratio: 4 / 3;
    object-fit: cover;
  }

  .description {
    gap: 16px;
    padding-left: 28px;
    font-size: 1.82rem;
    line-height: 1.42;
  }

  .video-link,
  .primary-action {
    min-height: 78px;
    font-size: 1.5rem;
  }

  .timer {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 18px;
  }

  .timer strong {
    font-size: 3rem;
  }

  .timer button {
    min-height: 68px;
    font-size: 1.45rem;
  }

  .feedback {
    padding: 18px;
  }

  .feedback label {
    font-size: 1.55rem;
  }

  .feedback input[type="range"] {
    min-height: 44px;
  }

  .toggle-row input {
    width: 48px;
    height: 48px;
  }
}
