:root {
  --paper: #f4f2ed;
  --surface: #fbfaf7;
  --ink: #1c1c1a;
  --muted: #706f69;
  --line: #d9d6ce;
  --clay: #c86f52;
  --moon: #5365b5;
  --moss: #4f745f;
  --danger: #9d4b45;
  --shadow: 0 16px 48px rgba(36, 33, 28, 0.07);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 92% 3%, rgba(83, 101, 181, 0.09), transparent 23rem),
    var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(100%, 700px);
  margin: 0 auto;
  padding: 0 18px calc(34px + var(--safe-bottom));
}

.masthead { padding: 28px 4px 14px; }

.brand-line,
.day-meta,
.card-heading,
.daily-overview,
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.eyebrow,
.mono-label,
.card-heading > div > p,
.panel-label,
.save-state {
  margin: 0;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.eyebrow { color: var(--muted); }

.text-button,
.icon-button {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.text-button {
  margin-right: -12px;
  color: var(--muted);
  font-size: 13px;
}

.hero-copy { padding: 34px 0 30px; }

.hero-copy h1 {
  max-width: 430px;
  margin: 0;
  font-size: clamp(43px, 12vw, 70px);
  font-weight: 580;
  letter-spacing: -0.065em;
  line-height: 0.94;
}

.hero-copy h1 span {
  color: var(--clay);
  font-family: "Iowan Old Style", "Songti SC", serif;
  font-style: italic;
  font-weight: 500;
  letter-spacing: -0.045em;
}

.hero-copy > p {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.day-meta {
  padding: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.day-meta > div { display: grid; grid-template-columns: auto auto; gap: 4px 12px; align-items: baseline; }
.day-meta .mono-label { grid-column: 1 / -1; color: var(--muted); }
.day-meta strong { font-size: 22px; letter-spacing: -0.03em; }
.day-meta #current-date-label { color: var(--muted); font-size: 13px; }

.summary-button {
  display: grid;
  min-width: 84px;
  min-height: 52px;
  place-content: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(251, 250, 247, 0.68);
  cursor: pointer;
}

.summary-button span { font-size: 15px; font-weight: 700; }
.summary-button small { margin-top: 2px; color: var(--muted); font-size: 10px; }

.day-strip {
  display: flex;
  gap: 5px;
  margin-top: 14px;
}

.day-button {
  position: relative;
  flex: 0 0 calc(14.285714% - 4.285714px);
  width: calc(14.285714% - 4.285714px);
  min-width: 0;
  min-height: 51px;
  padding: 6px 2px;
  border: 1px solid transparent;
  border-radius: 13px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.day-button b,
.day-button small { display: block; }
.day-button b { font-family: ui-monospace, "SFMono-Regular", monospace; font-size: 12px; }
.day-button small { margin-top: 3px; font-size: 9px; }
.day-button.is-selected { border-color: var(--ink); color: var(--ink); background: var(--surface); }
.day-button.is-closed::after {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--moss);
  content: "";
}

.daily-overview {
  gap: 14px;
  margin: 20px 0 12px;
  padding: 17px 18px;
  border-radius: 18px;
  color: #f8f7f2;
  background: var(--ink);
  box-shadow: var(--shadow);
}

.overview-count { min-width: 66px; }
.overview-count span { font-size: 33px; font-weight: 650; letter-spacing: -0.06em; }
.overview-count small { color: #a5a49e; font-size: 14px; }
.daily-overview > div:nth-child(2) { flex: 1; }
.daily-overview strong { font-size: 13px; }
.daily-overview p { margin: 3px 0 0; color: #aaa9a2; font-size: 11px; }
.save-state { max-width: 74px; color: #9c9b95; line-height: 1.45; text-align: right; }

.protocol-stack {
  position: relative;
  display: grid;
  gap: 14px;
}

.protocol-stack::before {
  position: absolute;
  z-index: 0;
  top: 40px;
  bottom: 40px;
  left: 28px;
  width: 1px;
  background: linear-gradient(var(--clay), var(--moon), var(--moss));
  content: "";
  opacity: 0.36;
}

.protocol-card {
  position: relative;
  z-index: 1;
  overflow: hidden;
  border: 1px solid rgba(83, 80, 72, 0.16);
  border-radius: 22px;
  background: rgba(251, 250, 247, 0.92);
  box-shadow: 0 9px 30px rgba(35, 32, 28, 0.045);
}

.protocol-card::after {
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--card-accent);
  content: "";
}

.sleep-card { --card-accent: var(--clay); }
.energy-card { --card-accent: var(--moon); }
.company-card { --card-accent: var(--moss); }

.card-heading { gap: 12px; padding: 20px 18px 17px; }
.chapter-mark {
  display: grid;
  flex: 0 0 43px;
  height: 43px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--card-accent);
  background: var(--surface);
  font-family: ui-monospace, "SFMono-Regular", monospace;
  font-size: 12px;
  font-weight: 750;
}

.card-heading > div { flex: 1; }
.card-heading > div > p { color: var(--card-accent); }
.card-heading h2 { margin: 4px 0 0; font-size: 19px; font-weight: 650; letter-spacing: -0.035em; }
.action-badge { color: var(--muted); font-family: ui-monospace, "SFMono-Regular", monospace; font-size: 11px; }
.action-badge b { color: var(--ink); font-size: 16px; }

.rule-list { padding: 0 14px; }

.rule-row {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  min-height: 58px;
  padding: 12px 4px;
  border-top: 1px solid var(--line);
  cursor: pointer;
}

.rule-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.check-ui {
  position: relative;
  width: 24px;
  height: 24px;
  margin-top: 1px;
  border: 1px solid #bbb8af;
  border-radius: 8px;
  background: var(--surface);
  transition: 160ms ease;
}

.check-ui::after {
  position: absolute;
  top: 5px;
  left: 7px;
  width: 7px;
  height: 4px;
  border-bottom: 2px solid white;
  border-left: 2px solid white;
  content: "";
  opacity: 0;
  transform: rotate(-45deg) scale(0.65);
  transition: 160ms ease;
}

.rule-row input:checked + .check-ui { border-color: var(--card-accent); background: var(--card-accent); }
.rule-row input:checked + .check-ui::after { opacity: 1; transform: rotate(-45deg) scale(1); }
.rule-row input:focus-visible + .check-ui { outline: 3px solid color-mix(in srgb, var(--card-accent) 22%, transparent); outline-offset: 2px; }
.rule-row b, .rule-row small { display: block; }
.rule-row b { font-size: 14px; font-weight: 620; }
.rule-row small { margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.5; }

.weekly-row { background: color-mix(in srgb, var(--card-accent) 5%, transparent); }
.conditional-rule { cursor: default; }
.condition-mark {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px dashed var(--card-accent);
  border-radius: 7px;
  color: var(--card-accent);
  font-family: ui-monospace, "SFMono-Regular", monospace;
  font-size: 8px;
  font-weight: 800;
}

.effect-panel {
  margin-top: 8px;
  padding: 16px 18px 19px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--card-accent) 5%, var(--surface));
}

.panel-label { margin-bottom: 15px; color: var(--card-accent); }
.rating-field { margin: 0; padding: 0; border: 0; }
.rating-field + .rating-field { margin-top: 18px; }
.rating-field legend { display: flex; width: 100%; align-items: baseline; justify-content: space-between; padding: 0; }
.rating-field legend span { font-size: 13px; font-weight: 620; }
.rating-field legend small { color: var(--muted); font-size: 10px; }

.rating-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin-top: 9px; }
.rating-choice { position: relative; }
.rating-choice input { position: absolute; opacity: 0; }
.rating-choice span {
  display: grid;
  min-height: 43px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.48);
  font-family: ui-monospace, "SFMono-Regular", monospace;
  font-size: 12px;
  cursor: pointer;
  transition: 140ms ease;
}

.rating-choice input:checked + span { border-color: var(--card-accent); color: white; background: var(--card-accent); transform: translateY(-1px); }
.rating-choice input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--card-accent) 22%, transparent); outline-offset: 2px; }
.delta-caption { display: flex; justify-content: space-between; margin-top: 6px; color: var(--muted); font-size: 9px; }

.finish-zone { padding: 25px 4px 8px; text-align: center; }
.finish-zone > p:first-child { margin: 0 0 12px; color: var(--muted); font-size: 11px; }
.finish-button,
.secondary-button {
  width: 100%;
  min-height: 54px;
  border-radius: 15px;
  cursor: pointer;
  font-weight: 650;
}

.finish-button { border: 1px solid var(--ink); color: var(--surface); background: var(--ink); }
.finish-button.is-closed { border-color: var(--moss); background: var(--moss); }
.privacy-note { margin: 12px 0 0 !important; color: #88867f !important; font-size: 9px !important; }

.sheet {
  width: min(calc(100% - 24px), 620px);
  max-height: min(82vh, 760px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 24px 24px 0 0;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 -24px 80px rgba(24, 23, 20, 0.22);
}

.sheet::backdrop { background: rgba(28, 28, 26, 0.42); backdrop-filter: blur(4px); }
.sheet[open] { animation: sheet-up 220ms ease-out; }
.sheet-inner { padding: 22px 20px calc(24px + var(--safe-bottom)); }
.sheet-header { padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.sheet-header h2 { margin: 4px 0 0; font-size: 25px; letter-spacing: -0.04em; }
.icon-button { margin-right: -8px; font-size: 28px; font-weight: 300; }

.summary-list { display: grid; gap: 0; margin: 6px 0 18px; }
.summary-day {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 66px;
  border-bottom: 1px solid var(--line);
}
.summary-day strong { font-family: ui-monospace, "SFMono-Regular", monospace; font-size: 12px; }
.summary-day p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.summary-status { color: var(--muted); font-size: 11px; }
.summary-day.is-closed .summary-status { color: var(--moss); font-weight: 650; }
.secondary-button { border: 1px solid var(--line); background: var(--paper); }

.date-field,
.text-field { display: grid; gap: 8px; margin: 20px 0; font-size: 12px; font-weight: 620; }
.date-field input,
.text-field input {
  min-height: 50px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: white;
}
.form-note { margin: -4px 0 20px; color: var(--muted); font-size: 10px; line-height: 1.55; }

.toast {
  position: fixed;
  z-index: 20;
  right: 18px;
  bottom: calc(20px + var(--safe-bottom));
  left: 18px;
  width: fit-content;
  max-width: calc(100% - 36px);
  margin: auto;
  padding: 11px 15px;
  border-radius: 12px;
  color: white;
  background: var(--ink);
  box-shadow: var(--shadow);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: 180ms ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

button:focus-visible,
input:focus-visible { outline: 3px solid rgba(83, 101, 181, 0.28); outline-offset: 2px; }

@keyframes sheet-up {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 720px) {
  .app-shell { padding-top: 18px; }
  .protocol-card { border-radius: 26px; }
  .sheet { margin-bottom: auto; border-radius: 24px; }
}

/* iPhone 17 Pro Max daily view: all three protocols and their metrics fit in one screen. */
@media (min-width: 420px) and (min-height: 760px) and (max-width: 480px) {
  body {
    min-height: 100svh;
    overflow: hidden;
  }

  .app-shell {
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    width: 100%;
    height: 100svh;
    padding: 0 12px calc(5px + var(--safe-bottom));
    overflow: hidden;
  }

  .masthead { padding: 8px 2px 5px; }
  .brand-line { min-height: 30px; }
  .eyebrow { font-size: 8px; }
  .text-button { min-height: 32px; font-size: 11px; }

  .hero-copy {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 3px 0 6px;
  }

  .hero-copy h1 {
    flex: 0 0 auto;
    font-size: 25px;
    line-height: 1;
    letter-spacing: -0.055em;
  }

  .hero-copy h1 span {
    display: inline;
    font-size: 23px;
  }

  .hero-copy > p {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 9px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .day-meta {
    min-height: 40px;
    padding: 4px 0;
  }

  .day-meta > div {
    display: flex;
    gap: 7px;
    align-items: baseline;
  }

  .day-meta .mono-label { display: none; }
  .day-meta strong { font-size: 15px; }
  .day-meta #current-date-label { font-size: 10px; }
  .summary-button {
    display: flex;
    min-width: auto;
    min-height: 30px;
    align-items: center;
    gap: 5px;
    padding: 4px 9px;
    border-radius: 10px;
  }
  .summary-button span { font-size: 11px; }
  .summary-button small { margin: 0; font-size: 8px; }

  .day-strip { gap: 4px; margin-top: 5px; }
  .day-button {
    flex-basis: calc(14.285714% - 3.428571px);
    width: calc(14.285714% - 3.428571px);
    min-height: 32px;
    padding: 3px 1px;
    border-radius: 9px;
  }
  .day-button b { font-size: 9px; }
  .day-button small { margin-top: 1px; font-size: 7px; }
  .day-button.is-closed::after { top: 4px; right: 4px; width: 4px; height: 4px; }

  .daily-overview {
    gap: 9px;
    min-height: 43px;
    margin: 4px 0 5px;
    padding: 5px 11px;
    border-radius: 13px;
  }
  .overview-count { min-width: 47px; }
  .overview-count span { font-size: 23px; }
  .overview-count small { font-size: 10px; }
  .daily-overview strong { font-size: 10px; }
  .daily-overview p { margin-top: 1px; font-size: 8px; }
  .save-state { max-width: 61px; font-size: 7px; }

  .protocol-stack {
    min-height: 0;
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }
  .protocol-stack::before { display: none; }
  .protocol-card {
    display: grid;
    grid-template-columns: minmax(0, 1.48fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    min-height: 0;
    border-radius: 15px;
  }

  .card-heading {
    grid-column: 1 / -1;
    min-height: 38px;
    gap: 8px;
    padding: 5px 9px 4px 11px;
  }
  .chapter-mark {
    flex-basis: 27px;
    width: 27px;
    height: 27px;
    font-size: 9px;
  }
  .card-heading > div > p { font-size: 7px; }
  .card-heading h2 { margin-top: 1px; font-size: 13px; }
  .action-badge { font-size: 8px; }
  .action-badge b { font-size: 12px; }

  .rule-list {
    grid-column: 1;
    min-height: 0;
    padding: 0 7px 2px 10px;
    border-top: 1px solid var(--line);
  }
  .rule-row {
    grid-template-columns: 19px 1fr;
    gap: 6px;
    min-height: 0;
    padding: 4px 1px;
    border-top: 0;
  }
  .rule-row + .rule-row { border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent); }
  .check-ui,
  .condition-mark {
    width: 18px;
    height: 18px;
    border-radius: 6px;
  }
  .check-ui::after { top: 3px; left: 5px; }
  .condition-mark { font-size: 6px; }
  .rule-row b { font-size: 9px; line-height: 1.15; }
  .rule-row small {
    margin-top: 1px;
    font-size: 7px;
    line-height: 1.24;
  }
  .weekly-row { background: transparent; }

  .effect-panel {
    grid-column: 2;
    grid-row: 2;
    min-height: 0;
    margin: 0;
    padding: 5px 7px;
    border-top: 1px solid var(--line);
    border-left: 1px solid var(--line);
  }
  .panel-label { margin-bottom: 4px; font-size: 7px; }
  .rating-field + .rating-field { margin-top: 6px; }
  .rating-field legend { display: block; }
  .rating-field legend span { display: block; font-size: 8px; }
  .rating-field legend small { display: none; }
  .rating-row { gap: 3px; margin-top: 3px; }
  .rating-choice span {
    min-height: 24px;
    border-radius: 7px;
    font-size: 8px;
  }
  .delta-caption { margin-top: 2px; font-size: 6px; }
  .delta-caption span:nth-child(2) { display: none; }

  .finish-zone { padding: 5px 0 0; }
  .finish-zone > p:first-child,
  .privacy-note { display: none; }
  .finish-button { min-height: 38px; border-radius: 12px; font-size: 11px; }
}

@media (max-width: 390px) {
  .app-shell { padding-right: 13px; padding-left: 13px; }
  .hero-copy { padding-top: 29px; }
  .daily-overview { padding-right: 14px; padding-left: 14px; }
  .save-state { display: none; }
  .card-heading { padding-right: 14px; padding-left: 14px; }
  .effect-panel { padding-right: 14px; padding-left: 14px; }
  .rating-field legend { align-items: flex-start; flex-direction: column; gap: 2px; }
}

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