:root {
  --bg: #E3EAE2;          /* sage: the calm, un-inflamed baseline */
  --surface: #F1F5EF;
  --surface-2: #FAFCF8;
  --ink: #1C2A24;
  --muted: #52625B;
  --line: #C3CFC5;
  --crimson: #A8122A;     /* the heart, and the top of the heat scale */
  --heat-max: #9A0F27;

  --display: 'Unbounded', ui-sans-serif, system-ui, sans-serif;
  --body: 'Onest', ui-sans-serif, system-ui, sans-serif;

  --r: 14px;
  --gutter: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.45 var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
[hidden] { display: none !important; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
}

h1, h2 {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

/* ---------- Lock ---------- */

.lock {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(var(--safe-t) + 64px) var(--gutter) calc(var(--safe-b) + 28px);
}
.wordmark {
  font: 600 13px/1 var(--display);
  letter-spacing: 0.04em;
  margin: 0 0 18px;
  color: var(--muted);
}
.lock h1 { font-size: 30px; }
.dots { display: flex; gap: 16px; margin-top: 30px; }
.dots span {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--ink);
  transition: background .12s;
}
.dots span.on { background: var(--ink); }
.dots.shake { animation: shake .35s; }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
.lock-msg { min-height: 1.45em; margin: 18px 0 0; color: var(--crimson); font-weight: 500; }
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.keypad button {
  height: 68px;
  border-radius: var(--r);
  background: var(--surface);
  font: 500 24px/1 var(--display);
}
.keypad button:active { background: var(--line); }
.keypad .del { font-family: var(--body); font-size: 15px; font-weight: 500; color: var(--muted); background: transparent; }

/* ---------- Home ---------- */

.home { padding: calc(var(--safe-t) + 22px) var(--gutter) calc(var(--safe-b) + 150px); }

.month-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 22px;
}
.month-head h1 { font-size: 34px; line-height: 1; }
.month-head .year { display: block; font: 500 14px/1 var(--body); color: var(--muted); margin-top: 8px; letter-spacing: 0; }
.month-nav { display: flex; gap: 6px; }
.icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface);
}
.icon-btn:disabled { opacity: .35; }
.icon-btn svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }

.weekdays, .cal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}
.weekdays span {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding-bottom: 6px;
}
.cell {
  aspect-ratio: 1 / 1.08;
  border-radius: 10px;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 6px 7px;
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--muted);
}
.cell.logged {
  background: var(--c);
  color: var(--t);
  box-shadow: none;
}
.cell.future { opacity: .4; }
.cell.today { box-shadow: inset 0 0 0 2px var(--ink); color: var(--ink); font-weight: 700; }
.cell.today.logged { color: var(--t); box-shadow: inset 0 0 0 2px var(--ink), inset 0 0 0 4px var(--surface-2); }
.cell .drop {
  position: absolute;
  right: 6px; bottom: 6px;
  width: 7px; height: 9px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: var(--crimson);
}
/* On dark heat the crimson drop disappears, so it takes the cell's text colour. */
.cell.logged .drop { background: var(--drop, var(--crimson)); }

.legend {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
  font-size: 13px;
  color: var(--muted);
}
.legend .scale { display: flex; gap: 3px; }
.legend .scale i { width: 16px; height: 10px; border-radius: 3px; }
.legend .drop-key { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.legend .drop-key i {
  width: 7px; height: 9px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: var(--crimson);
}
.summary {
  margin: 26px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 28px;
}
.summary div { display: flex; flex-direction: column; gap: 4px; }
.summary b { font: 600 24px/1 var(--display); }
.summary span { font-size: 13px; color: var(--muted); }

.heart-dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  padding: 26px 0 calc(var(--safe-b) + 14px);
  background: linear-gradient(to bottom, transparent, var(--bg) 40%);
  pointer-events: none;
}
.heart {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.heart svg {
  width: 96px; height: 88px;
  fill: var(--crimson);
  filter: drop-shadow(0 8px 14px rgba(168, 18, 42, .28));
  transition: transform .15s;
  animation: breathe 4.5s ease-in-out infinite;
}
.heart span { font-size: 13px; font-weight: 600; letter-spacing: .02em; }
.heart:active svg { transform: scale(.92); animation: none; }
@keyframes breathe { 50% { transform: scale(1.045); } }

/* ---------- Flow ---------- */

.flow {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.flow-top {
  position: sticky; top: 0; z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(var(--safe-t) + 10px) var(--gutter) 10px;
  background: var(--bg);
}
.progress { flex: 1; display: flex; gap: 5px; }
.progress span { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.progress span.on { background: var(--ink); }

.flow-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 18px var(--gutter) 0;
}
.eyebrow {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--muted);
}
.flow-body h1 { font-size: 26px; line-height: 1.18; }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 15px; }
.block { margin-top: 26px; }
.label { display: block; font-weight: 600; margin-bottom: 10px; }

.actions {
  position: sticky; bottom: 0;
  margin-top: auto;
  padding: 22px 0 calc(var(--safe-b) + 16px);
  background: linear-gradient(to bottom, transparent, var(--bg) 22px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.primary, .big {
  width: 100%;
  min-height: 58px;
  border-radius: var(--r);
  font-weight: 600;
  font-size: 17px;
}
.primary { background: var(--ink); color: var(--surface-2); }
.primary:disabled { background: var(--line); color: var(--muted); }
.big { background: var(--surface-2); box-shadow: inset 0 0 0 1.5px var(--ink); }
.primary:active:not(:disabled), .big:active { transform: scale(.985); }

/* The heat strip: drag across to rate 0–10. Same scale as the calendar. */
.strips { display: flex; flex-direction: column; gap: 8px; margin-top: 22px; }
.strip {
  position: relative;
  height: 56px;
  border-radius: 12px;
  background: var(--surface-2);
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.strip .fill {
  position: absolute; inset: 0 auto 0 0;
  width: 0;
  background: var(--fill, transparent);
  transition: width .08s linear, background-color .08s linear;
}
.strip.dragging .fill { transition: none; }
.strip .name, .strip .val { position: relative; pointer-events: none; }
.strip .name { font-weight: 500; font-size: 16px; color: var(--name-ink, var(--ink)); }
.strip .val {
  font: 600 22px/1 var(--display);
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
  text-align: right;
  color: var(--val-ink, var(--ink));
}
.strip .val.zero { color: var(--line); }
.strip .ticks {
  position: absolute; inset: auto 0 0 0;
  height: 6px;
  display: flex;
  pointer-events: none;
}
.strip .ticks i { flex: 1; border-right: 1px solid var(--line); }
.strip .ticks i:last-child { border-right: 0; }

.choices { display: grid; gap: 8px; }
.choices.five { grid-template-columns: repeat(5, 1fr); margin-top: 30px; }
.choices.four { grid-template-columns: repeat(4, 1fr); }
.choices.three { grid-template-columns: repeat(3, 1fr); }
.choices.two { grid-template-columns: repeat(2, 1fr); margin-top: 24px; }
.choice {
  min-height: 58px;
  border-radius: var(--r);
  background: var(--surface-2);
  font-weight: 600;
  font-size: 16px;
}
.choices.five .choice { aspect-ratio: 1; font: 600 24px/1 var(--display); }
.choices.two .choice { min-height: 76px; font: 600 20px/1 var(--display); }
.choice[aria-pressed="true"] { background: var(--ink); color: var(--surface-2); }

textarea {
  width: 100%;
  min-height: 108px;
  resize: vertical;
  border: 0;
  border-radius: var(--r);
  background: var(--surface-2);
  padding: 14px 16px;
  font-size: 16px;
  line-height: 1.45;
  box-shadow: inset 0 0 0 1.5px var(--line);
}
textarea:focus { outline: none; box-shadow: inset 0 0 0 2px var(--ink); }
textarea::placeholder { color: #8A9891; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 14px;
  font-weight: 500;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Colour slider */
.color-track {
  position: relative;
  height: 56px;
  border-radius: 12px;
  background: linear-gradient(90deg, #F5F2EC, #F0A3B5 20%, #C41E30 40%, #E57A2E 60%, #77482A 80%, #1B1716);
  box-shadow: inset 0 0 0 1px var(--line);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.color-track .thumb {
  position: absolute;
  top: 50%;
  width: 34px; height: 68px;
  margin-left: -17px;
  transform: translateY(-50%);
  border-radius: 12px;
  background: var(--sw, transparent);
  box-shadow: 0 0 0 3px var(--surface-2), 0 0 0 4.5px var(--ink), 0 6px 14px rgba(0,0,0,.18);
  pointer-events: none;
}
.color-track.unset .thumb { display: none; }
.color-names {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}
.color-pick { margin-top: 14px; display: flex; align-items: center; gap: 10px; font-weight: 600; min-height: 26px; }
.color-pick i { width: 22px; height: 22px; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.color-pick.empty { color: var(--muted); font-weight: 400; }

/* Done */
.done {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 18px;
  padding: 0 var(--gutter) 80px;
}
.done svg { width: 84px; height: 78px; fill: var(--crimson); animation: pop .5s cubic-bezier(.3, 1.6, .5, 1); }
.done h1 { font-size: 26px; }
.done p { margin: 0; color: var(--muted); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }

/* ---------- Day sheet ---------- */

.sheet { position: fixed; inset: 0; z-index: 10; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(28, 42, 36, .35); animation: fade .2s; }
.sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  padding: 10px var(--gutter) calc(var(--safe-b) + 18px);
  animation: rise .25s cubic-bezier(.2, .9, .3, 1);
}
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 16px; }
.sheet-panel h2 { font-size: 22px; margin-bottom: 16px; }
.sheet-panel .weekday { display: block; font: 500 14px/1 var(--body); color: var(--muted); margin-top: 6px; }
.empty { color: var(--muted); margin: 0 0 18px; }
.entry {
  background: var(--surface-2);
  border-radius: var(--r);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.entry header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.entry time { font: 600 15px/1 var(--display); }
.entry .pending { font-size: 12px; font-weight: 600; color: var(--crimson); }
.entry .del { margin-left: auto; font-size: 14px; color: var(--muted); padding: 6px 0 6px 10px; text-decoration: underline; text-underline-offset: 3px; }
.entry dl { margin: 0; display: grid; gap: 8px; }
.entry dl div { display: grid; grid-template-columns: 112px 1fr; gap: 10px; }
.entry dt { color: var(--muted); font-size: 14px; }
.entry dd { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
.pill {
  display: inline-block;
  padding: 2px 8px;
  margin: 0 4px 4px 0;
  border-radius: 6px;
  background: var(--c);
  color: var(--t);
  font-size: 13px;
  font-weight: 600;
}
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 5px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.sheet-panel .primary { margin-top: 8px; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(100%); } }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 24px);
  transform: translateX(-50%);
  z-index: 20;
  width: calc(100% - 2 * var(--gutter));
  max-width: 440px;
  padding: 14px 16px;
  border-radius: var(--r);
  background: var(--ink);
  color: var(--surface-2);
  font-weight: 500;
}

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