:root {
  --ink: #243247;
  --muted: #667085;
  --line: rgba(36, 50, 71, 0.1);
  --paper: #f7f6f8;
  --card: #ffffff;
  --purple: #7666a8;
  --purple-deep: #5c4e8a;
  --wash: #f3f0f8;
  --stage: #efeaf6;
  --stop: #6e4a44;
  --good: #2f6b54;
  --shadow: 0 10px 30px rgba(36, 50, 71, 0.06);
  --nav: 84px;
  --safe-b: env(safe-area-inset-bottom);
  --safe-t: env(safe-area-inset-top);
  color-scheme: light;
  font-family: "Avenir Next", Avenir, "Century Gothic", system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: #e7e3ec;
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--purple-deep); }

#app {
  width: min(480px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
  position: relative;
}

.screen {
  padding: calc(18px + var(--safe-t)) 20px calc(var(--nav) + var(--safe-b) + 36px);
}

.brand {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 18px;
}
.brand b {
  font-size: 15px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.brand span { color: var(--muted); font-size: 13px; }

.date {
  margin: 0 0 4px;
  color: var(--purple-deep);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
h1 {
  margin: 0 0 6px;
  font-size: 34px;
  line-height: 1.05;
  letter-spacing: -0.035em;
  font-weight: 700;
}
.sub { margin: 0 0 16px; color: var(--muted); font-size: 16px; line-height: 1.4; }

.hero, .card, .remember, .rule, .stat, .flow, .checkin {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.hero { padding: 16px; margin-bottom: 14px; }
.hero .sub { margin-bottom: 14px; }

.btn {
  appearance: none;
  border: 0;
  width: 100%;
  min-height: 54px;
  border-radius: 16px;
  padding: 12px 16px;
  background: var(--purple);
  color: white;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.btn:active { transform: scale(0.985); }
.btn.secondary { background: var(--wash); color: var(--ink); }
.btn.quiet {
  background: transparent;
  color: var(--purple-deep);
  min-height: 44px;
}
.btn.good { background: var(--good); }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }
a.btn { display: grid; place-items: center; text-decoration: none; }

.week-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin: 8px 0 18px;
}
.week-strip a {
  text-decoration: none;
  color: var(--ink);
  text-align: center;
  padding: 8px 0 7px;
  border-radius: 12px;
  background: white;
  border: 1px solid var(--line);
  font-size: 12px;
}
.week-strip .dow { display: block; color: var(--muted); font-size: 10px; letter-spacing: 0.04em; }
.week-strip .today { background: var(--purple); color: white; border-color: transparent; }
.week-strip .today .dow { color: rgba(255,255,255,0.8); }
.week-strip .done { box-shadow: inset 0 -3px 0 var(--good); }

.list { display: flex; flex-direction: column; gap: 8px; margin: 0 0 14px; }
.row {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: white;
  min-height: 64px;
}
.row .mark {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid #c9c3d8;
  display: grid;
  place-items: center;
  color: white;
  font-size: 12px;
}
.row.done .mark { background: var(--good); border-color: var(--good); }
.row .name { font-weight: 600; letter-spacing: -0.02em; line-height: 1.25; }
.row .rx {
  color: var(--purple-deep);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  white-space: nowrap;
}

.remember, .note, .card, .flow, .checkin { padding: 14px 16px; margin: 0 0 12px; }
.remember strong, .k { display: block; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--purple-deep); margin-bottom: 4px; }
.remember p, .card p, .rule p, .flow p { margin: 0; line-height: 1.45; }
.muted { color: var(--muted); }
.stop { color: var(--stop); font-size: 14px; line-height: 1.4; margin: 8px 0 0; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.stat { padding: 12px; box-shadow: none; }
.stat b { display: block; font-size: 16px; letter-spacing: -0.02em; }
.stat span { color: var(--muted); font-size: 12px; }

.flow-row { display: grid; grid-template-columns: 92px 1fr; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.flow-row:first-of-type { border-top: 0; }
.flow-row b { font-size: 14px; }

.nav {
  position: fixed;
  z-index: 4;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(480px, 100%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 8px 12px calc(8px + var(--safe-b));
  background: rgba(247, 246, 248, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.nav a {
  text-decoration: none;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 0;
  border-radius: 12px;
}
.nav a.on { color: var(--purple-deep); background: white; }
.nav svg { display: block; margin: 0 auto 3px; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 6;
  background: rgba(36, 50, 71, 0.28);
  display: grid;
  align-items: end;
  justify-items: center;
}
.sheet .panel {
  width: min(480px, 100%);
  background: white;
  border-radius: 24px 24px 0 0;
  padding: 22px 20px calc(22px + var(--safe-b));
}
.sheet h2 { margin: 0 0 8px; font-size: 28px; letter-spacing: -0.03em; }
.sheet p { margin: 0 0 16px; line-height: 1.45; color: var(--muted); }

/* Player */
.player {
  position: fixed;
  z-index: 5;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, 100%);
  height: 100dvh;
  background: var(--paper);
  display: flex;
  flex-direction: column;
}
.player-top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: calc(10px + var(--safe-t)) 12px 8px;
}
.player-top a, .texty {
  color: var(--purple-deep);
  font-weight: 600;
  text-decoration: none;
  background: transparent;
  border: 0;
  padding: 8px;
}
.progress {
  height: 4px;
  margin: 0 16px 8px;
  background: #e4dfec;
  border-radius: 99px;
  overflow: hidden;
}
.progress span { display: block; height: 100%; background: var(--purple); }
.player h1 { font-size: 20px; line-height: 1.2; margin: 0 16px 2px; text-wrap: balance; }
.btn:disabled { opacity: 0.4; }
.brand a, .player-top a { text-decoration: none; font-weight: 600; color: var(--purple-deep); }
.row .name { min-width: 0; }
.rx-line { margin: 0 16px 8px; color: var(--purple-deep); font-weight: 600; }
.stage-wrap {
  margin: 0 16px;
  height: 42dvh;
  min-height: 230px;
  max-height: 420px;
  background: var(--stage);
  border-radius: 22px;
  position: relative;
  overflow: hidden;
}
.stage-wrap canvas { width: 100%; height: 100%; display: block; }
.stage-wrap.diagram { background: #fff; }
.stage-wrap.diagram img { width: 100%; height: 100%; object-fit: contain; display: block; }
.credit { margin: 6px 16px 0; color: var(--muted); font-size: 12px; }
.credit a { color: inherit; }
.phase {
  margin: 8px 16px 0;
  background: white;
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
}
.player-body {
  flex: 1;
  overflow: auto;
  padding: 12px 16px 8px;
}
.steps { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.steps li {
  padding: 8px 10px;
  border-radius: 12px;
  color: var(--muted);
  line-height: 1.35;
}
.steps li.on { background: white; color: var(--ink); }
.steps li b { color: var(--purple-deep); margin-right: 6px; }
.dock {
  padding: 8px 16px calc(12px + var(--safe-b));
  background: rgba(247, 246, 248, 0.96);
  border-top: 1px solid var(--line);
}
.hud {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.hud .big {
  font-size: 42px;
  font-weight: 700;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.switch {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: white;
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 8px;
  text-align: left;
}
.knob {
  width: 42px;
  height: 26px;
  border-radius: 99px;
  background: #ddd8e6;
  position: relative;
  flex: none;
}
.knob i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  transition: transform 0.15s ease;
}
.switch.on .knob { background: var(--purple); }
.switch.on .knob i { transform: translateX(16px); }
.chips { display: flex; gap: 8px; margin-bottom: 8px; }
.chip {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 40px;
}
.chip.on { background: var(--purple); color: white; border-color: transparent; }
.tiny {
  width: 44px;
  min-height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
  font-weight: 700;
  font-size: 20px;
}
.choice {
  display: block;
  width: 100%;
  text-align: left;
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 8px;
  font-weight: 600;
}
.choice.on { border-color: var(--purple); box-shadow: inset 0 0 0 1px var(--purple); }

.day-card {
  display: block;
  text-decoration: none;
  color: inherit;
  padding: 14px 14px;
  margin-bottom: 8px;
}
.day-card .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.day-card h2 { margin: 0; font-size: 20px; letter-spacing: -0.03em; }
.pill {
  font-size: 12px;
  font-weight: 700;
  color: var(--purple-deep);
  background: var(--wash);
  border-radius: 99px;
  padding: 4px 8px;
}
.pill.rest { color: var(--muted); }
.pill.ok { color: var(--good); background: #e7f3ed; }

.rule h2 { margin: 0 0 6px; font-size: 18px; letter-spacing: -0.02em; }
.checkin label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 6px; }
.checkin .chips { flex-wrap: wrap; }
.win {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--paper);
  resize: vertical;
  min-height: 72px;
}
.saved { margin: 8px 0 0; font-size: 13px; }

.help summary { cursor: pointer; font-weight: 600; color: var(--purple-deep); }
.help p { color: var(--muted); line-height: 1.45; }

.review { padding: 16px 16px 40px; }
.review h1 { font-size: 22px; }
.frame { margin-bottom: 16px; }
.frame .stage-wrap { height: 280px; }
.frame p { margin: 6px 0; font-size: 13px; color: var(--muted); }

.scrub { width: 100%; margin: 8px 0; }

@media (min-width: 880px) {
  body {
    background:
      radial-gradient(900px 420px at 50% -10%, #ece7f5, transparent 55%),
      #e4dfea;
  }
  #app { min-height: 100dvh; box-shadow: 0 24px 70px rgba(36, 50, 71, 0.14); }
}

@media (prefers-reduced-motion: reduce) {
  .btn:active { transform: none; }
  .knob i { transition: none; }
}
