:root {
  --bg: oklch(0.982 0.007 150);
  --surface: oklch(0.995 0.004 150);
  --ink: oklch(0.28 0.024 155);
  --muted: oklch(0.47 0.022 152);
  --faint: oklch(0.52 0.02 150);
  --line: oklch(0.912 0.014 150);
  --hairline: oklch(0.87 0.02 150);
  --sage: oklch(0.56 0.085 155);
  --sage-ink: oklch(0.42 0.08 156);
  --sage-soft: oklch(0.955 0.022 152);
  --sage-wash: oklch(0.972 0.014 151);
  --gold: oklch(0.52 0.09 84);
  --danger: oklch(0.5 0.15 27);
  --ring-track: oklch(0.93 0.012 150);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  min-height: 100dvh;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }
:focus-visible { outline: 2px solid var(--sage); outline-offset: 2px; border-radius: 2px; }
[tabindex="-1"]:focus-visible { outline: none; }

/* ---------- gate ---------- */

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card { text-align: center; max-width: 320px; width: 100%; }

.gate-card h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.9rem, 6vw, 2.4rem);
  letter-spacing: 0.01em;
}

.gate-sub { color: var(--muted); font-size: 0.92rem; margin: 6px 0 34px; }

.gate-card input {
  width: 100%;
  text-align: center;
  font-size: 1.35rem;
  letter-spacing: 0.35em;
  padding: 13px 8px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
}

.gate-card input:focus { outline: 2px solid var(--sage); border-color: var(--sage); }

.gate-card button[type="submit"] {
  width: 100%;
  margin-top: 14px;
  padding: 13px;
  border-radius: 10px;
  background: var(--sage-ink);
  color: var(--bg);
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: background 0.2s var(--ease);
}

.gate-card button[type="submit"]:hover { background: var(--sage); }

#gate-err { color: var(--danger); font-size: 0.9rem; margin-top: 14px; min-height: 1.3em; }

/* ---------- shell ---------- */

#app { max-width: 1060px; margin: 0 auto; padding: clamp(18px, 4vw, 44px) clamp(16px, 3.5vw, 40px) 80px; }

.masthead { border-bottom: 1px solid var(--hairline); padding-bottom: 18px; }

.masthead-row { display: flex; align-items: baseline; justify-content: space-between; }

.masthead h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.7rem, 5vw, 2.3rem);
}

.period { color: var(--muted); font-size: 0.9rem; margin-top: 2px; }

.controls { margin-top: 18px; }

.seg {
  display: inline-flex;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: var(--surface);
  padding: 3px;
}

.seg button {
  padding: 7px 16px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.92rem;
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}

.seg button[aria-pressed="true"] { background: var(--sage-ink); color: var(--bg); }

.ghost { color: var(--muted); border: 1px solid transparent; border-radius: 8px; padding: 6px 10px; transition: color 0.15s var(--ease), border-color 0.15s var(--ease); }

.ghost:hover { color: var(--ink); border-color: var(--hairline); }

.ghost.small { font-size: 0.85rem; }

/* ---------- day header ---------- */

.dayhead {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin: clamp(26px, 5vw, 44px) 0 8px;
}

.dayhead-title { text-align: center; }

.weekline {
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
  min-height: 1.2em;
}

.dayhead h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.5rem, 5vw, 2rem);
  margin: 2px 0;
}

.nav-btn {
  width: 42px; height: 42px;
  border: 1px solid var(--hairline);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-size: 1.05rem;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.15s var(--ease);
}

.nav-btn:hover { color: var(--sage-ink); border-color: var(--sage); }

.nav-btn:active { transform: scale(0.94); }

/* ---------- dashboard ---------- */

.dashboard {
  display: grid;
  gap: 14px;
  margin: 18px 0 6px;
}

.dash-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 22px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 20px;
}

.dash-ring { width: 108px; height: 108px; position: relative; }

.dash-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }

.dash-ring .track { stroke: var(--ring-track); }

.dash-ring .arc {
  stroke: var(--sage);
  transition: stroke-dashoffset 0.6s var(--ease), stroke 0.3s var(--ease);
}

.dash-ring.over .arc { stroke: var(--danger); }

.ring-center {
  position: absolute; inset: 0;
  display: grid; place-content: center; text-align: center;
}

.ring-center b {
  font-family: var(--serif);
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1.1;
}

.ring-center span { font-size: 0.68rem; color: var(--faint); letter-spacing: 0.08em; text-transform: uppercase; }

.dash-body { min-width: 0; }
.dash-body h3 { font-family: var(--serif); font-weight: 600; font-size: 1.1rem; }

.dash-line { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 10px; font-size: 0.9rem; color: var(--muted); margin-top: 6px; }

.dash-line b { color: var(--ink); font-weight: 600; }

.protein-track { height: 5px; border-radius: 999px; background: var(--ring-track); overflow: hidden; margin-top: 6px; }

.protein-fill { height: 100%; border-radius: 999px; background: var(--gold); transition: width 0.5s var(--ease); }

.protein-fill.hit { background: var(--sage); }

/* ---------- meals ---------- */

.person-grid { display: grid; gap: 6px; }

.person-col > .person-label {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 600;
  margin: 22px 0 0;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--hairline);
}

.slot { margin-top: 26px; }

.slot-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.slot-head h4 {
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--sage-ink);
  font-weight: 700;
}

.slot-head .slot-note { font-size: 0.8rem; color: var(--faint); }

.variant {
  position: relative;
  display: block;
  width: 100%;
  text-align: left;
  margin-top: 10px;
  padding: 14px 16px 14px 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}

.variant:hover { border-color: var(--faint); }

.variant .box {
  position: absolute;
  left: 14px; top: 17px;
  width: 20px; height: 20px;
  border: 1.5px solid var(--hairline);
  border-radius: 50%;
  display: grid; place-content: center;
  color: transparent;
  font-size: 0.75rem;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.variant.on { border-color: var(--sage); background: var(--sage-wash); }

.variant.on .box { background: var(--sage-ink); border-color: var(--sage-ink); color: var(--surface); }

.variant .v-name { font-family: var(--serif); font-size: 1.05rem; font-weight: 600; }

.variant .v-kcal { float: right; font-size: 0.85rem; color: var(--muted); margin-left: 10px; }

.variant .v-kcal b { color: var(--sage-ink); }

.variant .v-desc { font-size: 0.9rem; color: var(--muted); margin-top: 4px; clear: both; }

.variant .v-qty { font-size: 0.85rem; color: var(--faint); margin-top: 4px; }

.variant .v-items { margin: 8px 0 0 16px; font-size: 0.88rem; color: var(--muted); }

.variant .v-items li::marker { color: var(--sage); }

.search-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 9px;
  font-size: 0.82rem;
  color: var(--sage-ink);
  background: var(--sage-soft);
  border-radius: 999px;
  padding: 4px 12px;
}

.search-chip::before { content: "⌕"; font-size: 0.95rem; }

.prep-chip { font-size: 0.8rem; color: var(--faint); margin-left: 8px; }

/* ---------- week strip ---------- */

.weekstrip-wrap { margin-top: 44px; }

.section-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.2rem;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 14px;
}

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

.wday {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 8px 4px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  transition: border-color 0.15s var(--ease);
}

.wday:hover { border-color: var(--faint); }

.wday .d { display: block; font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); }

.wday .n { display: block; font-family: var(--serif); font-size: 1rem; font-weight: 600; color: var(--ink); }

.wday .dots { display: block; min-height: 0.9em; letter-spacing: 2px; color: var(--sage); font-size: 0.62rem; }

.wday.today { border-color: var(--sage); background: var(--sage-wash); }

.wday.selected { outline: 2px solid var(--sage-ink); outline-offset: -1px; }

/* ---------- weigh-ins ---------- */

.weighins { margin-top: 44px; }

.protocol { font-size: 0.9rem; color: var(--muted); margin-bottom: 14px; }

.weighin-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }

.weighin-form label { display: grid; gap: 4px; font-size: 0.82rem; color: var(--muted); }

.weighin-form input,
.weighin-form select {
  padding: 9px 12px;
  border: 1px solid var(--hairline);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.weighin-form button {
  padding: 10px 20px;
  border-radius: 9px;
  background: var(--sage-ink);
  color: var(--bg);
  font-weight: 600;
  transition: background 0.2s var(--ease);
}

.weighin-form button:hover { background: var(--sage); }

.weighin-lists { display: grid; gap: 20px; margin-top: 20px; }

.weighin-list h4 { font-family: var(--serif); font-size: 1rem; margin-bottom: 6px; }

.weighin-list table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

.weighin-list td { padding: 7px 4px; border-bottom: 1px solid var(--line); }

.weighin-list td.kg { font-family: var(--serif); font-weight: 600; }

.weighin-list td.diff { color: var(--muted); font-size: 0.84rem; }

.weighin-list td.actions { text-align: right; }

.weighin-list .del { color: var(--faint); font-size: 0.8rem; }

.weighin-list .del:hover { color: var(--danger); }

.weighin-empty { color: var(--faint); font-size: 0.88rem; }

/* ---------- notes ---------- */

.notes { margin-top: 44px; }

.warning {
  border-left: 2px solid var(--gold);
  padding: 10px 16px;
  background: var(--sage-wash);
  border-radius: 0 10px 10px 0;
  font-size: 0.92rem;
  color: var(--muted);
  margin-bottom: 18px;
}

.notes details { border-bottom: 1px solid var(--line); padding: 12px 2px; }

.notes summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.notes summary::-webkit-details-marker { display: none; }

.notes summary::after { content: "+"; color: var(--sage); font-size: 1.1rem; transition: transform 0.2s var(--ease); }

.notes details[open] summary::after { transform: rotate(45deg); }

.notes ol, .notes ul { margin: 10px 0 4px 18px; font-size: 0.9rem; color: var(--muted); display: grid; gap: 8px; }

.notes li b { color: var(--ink); }

.colophon { margin-top: 56px; padding-top: 16px; border-top: 1px solid var(--hairline); }

.colophon p { font-size: 0.82rem; color: var(--faint); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translateX(-50%);
  max-width: min(90vw, 420px);
  background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 10px;
  font-size: 0.9rem; text-align: center;
  box-shadow: 0 6px 24px oklch(0.3 0.02 155 / 0.25);
}

/* ---------- reveal ---------- */

.reveal { animation: rise 0.45s var(--ease) both; }

.reveal:nth-child(2) { animation-delay: 0.05s; }

.reveal:nth-child(3) { animation-delay: 0.1s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- desktop ---------- */

@media (min-width: 900px) {
  .dashboard.both { grid-template-columns: 1fr 1fr; }
  .person-grid.both { grid-template-columns: 1fr 1fr; gap: 0 40px; }
  .weighin-lists { grid-template-columns: 1fr 1fr; }
}
