:root {
  --bg: #F4EEE8;
  --ink: #3A2E28;
  --muted: #8C7D73;
  --paper: #FFFEFB;                     /* lighter, closer to a fresh sheet */
  --sheet: #FFFEFB;                     /* the writing sheet itself */
  --line: #D9CEC4;
  --soft: #E9E0D7;
  /* writing sheet */
  --pen: #1F2B4D;                       /* blue-black pen ink */
  --rule: rgba(70, 110, 170, 0.24);     /* ruled lines */
  --margin-line: rgba(205, 85, 85, 0.38);
  --hand: "Bradley Hand", "Noteworthy", "Ink Free", "Segoe Print", casual, system-ui, sans-serif;
  --lh: 1.875rem;                       /* one ruled line */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1A1614;
    --ink: #E8DFD6;
    --muted: #9A8D83;
    --paper: #2A2421;
    /* real paper is light even in a dim room: a dimmed ivory sheet, dark pen ink */
    --sheet: #E3DACB;
    --line: #463B35;
    --soft: #2F2825;
    --pen: #1F2B4D;
    --rule: rgba(70, 110, 170, 0.26);
    --margin-line: rgba(190, 80, 80, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; }
button { font: inherit; color: inherit; }

main {
  flex: 1;
  overflow-x: hidden;
  overflow-x: clip;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 16px 24px;
}

.screen {
  width: 100%;
  max-width: 34rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1.25rem;
}

/* every screen arrives gently; nothing snaps (SPEC §4 Motion) */
.screen { animation: fade-in 0.55s ease backwards; }
.screen.leaving { opacity: 0; transition: opacity 0.6s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes reveal { from { opacity: 0; visibility: hidden; } to { opacity: 1; visibility: visible; } }

.line { font-size: 1.4rem; line-height: 1.4; margin: 0; }
.sub { font-size: 1rem; line-height: 1.5; margin: 0; }
.sub.muted { color: var(--muted); }
[data-screen="checkin"] .sub.muted { margin-bottom: -0.6rem; }
/* the writing prompt changes layer by layer: let each new question settle in */
.line.swap { animation: fade-in 0.7s ease; }
.echo { margin: 0 0 -0.75rem; font-size: 0.95rem; color: var(--muted); text-transform: lowercase; }

/* × wipe */
.wipe {
  position: fixed; top: 10px; left: 10px;
  width: 40px; height: 40px;
  border: 0; background: none;
  font-size: 1.5rem; line-height: 1;
  color: var(--muted); cursor: pointer;
}

/* quiet links */
.skip, .quiet {
  border: 0; background: none; padding: 8px 12px;
  color: var(--muted); cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
  text-decoration-color: var(--line);
}
.skip { font-size: 0.9rem; }

.primary {
  border: 1px solid var(--line); background: var(--paper);
  border-radius: 999px; padding: 10px 28px; cursor: pointer;
}

/* 1–5 scale */
.scale { display: flex; gap: 10px; justify-content: center; }
.scale-item { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 56px; }
.circle {
  width: 56px; height: 56px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--soft);
  cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
/* each circle holds a weight that grows heavier from 1 to 5: people rate weight, not mood */
.weight { display: block; border-radius: 50%; background: var(--ink); }
.circle[data-value="1"] .weight { width: 12px; height: 12px; opacity: 0.22; }
.circle[data-value="2"] .weight { width: 18px; height: 18px; opacity: 0.34; }
.circle[data-value="3"] .weight { width: 24px; height: 24px; opacity: 0.48; }
.circle[data-value="4"] .weight { width: 31px; height: 31px; opacity: 0.64; }
.circle[data-value="5"] .weight { width: 38px; height: 38px; opacity: 0.82; }
.circle[aria-pressed="true"] { background: var(--paper); border-color: var(--muted); }
.scale-num { font-size: 0.85rem; }
.scale-cap { font-size: 0.72rem; color: var(--muted); white-space: nowrap; min-height: 1em; }
.helpline-note { font-size: 0.95rem; line-height: 1.5; color: var(--muted); margin: 0; max-width: 26rem; }

/* name chips */
.chips {
  display: grid; gap: 10px; width: 100%; max-width: 26rem;
  grid-template-columns: repeat(3, 1fr);
}
.chip {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--soft);
  border-radius: 16px; padding: 14px 6px 12px; cursor: pointer;
}
.chip:active { background: var(--paper); }
.chip-emoji { font-size: 2rem; line-height: 1; }
.chip-word { font-size: 0.9rem; }
/* "something else" sits centred on its own row */
.chip:last-child:nth-child(3n + 1) { grid-column: 2; }

/* ---------- the sheet of paper ---------- */
.paper {
  width: 100%;
  position: relative;
  background-color: var(--sheet);
  background-image:
    radial-gradient(ellipse at 50% 40%, rgba(255,255,255,0.35), rgba(255,255,255,0) 70%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.4 0 0 0 0 0.3 0 0 0 0.035 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  border-radius: 2px;
  box-shadow:
    0 1px 1px rgba(60, 40, 30, 0.08),
    0 3px 6px rgba(60, 40, 30, 0.06),
    0 14px 24px -10px rgba(60, 40, 30, 0.22);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
@media (prefers-color-scheme: dark) {
  .paper {
    box-shadow: 0 1px 1px rgba(0,0,0,0.3), 0 14px 26px -10px rgba(0,0,0,0.6);
  }
}

/* the writing surface: ruled notebook page, pen ink, handwriting where the device has it */
.paper textarea {
  display: block; width: 100%;
  min-height: calc(var(--lh) * 9);
  border: 0; outline: none; resize: none; border-radius: 0;
  color: var(--pen); caret-color: var(--pen);
  font-family: var(--hand); font-size: 1.15rem; line-height: var(--lh);
  text-shadow: 0 0 0.6px var(--pen);     /* a little ink bleed */
  padding: var(--lh) 1rem 0.5rem 3rem;
  text-align: left;
  background-color: transparent;
  background-image:
    linear-gradient(to right, transparent 2.25rem, var(--margin-line) 2.25rem,
      var(--margin-line) calc(2.25rem + 1.5px), transparent calc(2.25rem + 1.5px)),
    linear-gradient(to bottom, transparent calc(var(--rule-y, 22px) - 0.5px), var(--rule) calc(var(--rule-y, 22px) - 0.5px),
      var(--rule) calc(var(--rule-y, 22px) + 0.6px), transparent calc(var(--rule-y, 22px) + 0.6px));
  background-size: 100% 100%, 100% var(--lh);
  background-repeat: no-repeat, repeat-y;
  background-position: 0 0, 0 var(--lh);
  background-attachment: local, local;
}
.paper textarea::placeholder { color: var(--pen); opacity: 0.38; text-shadow: none; }
.ink-canvas { position: absolute; left: 0; top: 0; pointer-events: none; }

body[data-state="crumple"] .paper { cursor: pointer; }
body[data-state="crumple"] .paper textarea { pointer-events: none; }
/* while crumpling, the canvas draws the sheet; the textarea keeps the layout */
.paper.crumpling { background: none; box-shadow: none; }
.paper.crumpling textarea { visibility: hidden; }
.paper.crumpling .ink-canvas { display: none; }
.paper-canvas { position: absolute; pointer-events: none; }

/* ---------- how to crumple: a tiny sheet that a fingertip presses and holds until it crumples ---------- */
.crumple-demo {
  position: relative; width: 104px; height: 80px; margin: -0.4rem 0 -0.2rem;
  pointer-events: none;
}
.cd-sheet {
  position: absolute; left: 50%; top: 50%; width: 66px; height: 50px; margin: -25px 0 0 -33px;
  background-color: var(--sheet);
  background-image: repeating-linear-gradient(to bottom, transparent 0 6px, var(--rule) 6px 7px);
  box-shadow: 0 2px 5px rgba(40, 25, 15, 0.2);
  clip-path: polygon(0% 0%, 50% 0%, 100% 0%, 100% 50%, 100% 100%, 50% 100%, 0% 100%, 0% 50%);
  animation: cd-crumple 3s ease-in-out 0.4s infinite;
}
.cd-finger {
  position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px 0 0 -13px;
  border-radius: 50%; background: var(--ink); opacity: 0;
  animation: cd-finger 3s ease-in-out 0.4s infinite;
}
@keyframes cd-crumple {
  0%, 16% {
    clip-path: polygon(0% 0%, 50% 0%, 100% 0%, 100% 50%, 100% 100%, 50% 100%, 0% 100%, 0% 50%);
    transform: none; filter: none; opacity: 1;
  }
  62%, 80% {
    clip-path: polygon(30% 16%, 54% 8%, 76% 24%, 84% 50%, 70% 82%, 46% 90%, 22% 74%, 16% 44%);
    transform: rotate(18deg) scale(0.95); filter: brightness(0.9) contrast(1.15); opacity: 1;
  }
  90% { opacity: 0; transform: rotate(18deg) scale(0.9); }
  91% { clip-path: polygon(0% 0%, 50% 0%, 100% 0%, 100% 50%, 100% 100%, 50% 100%, 0% 100%, 0% 50%); transform: none; filter: none; opacity: 0; }
  100% { opacity: 1; }
}
@keyframes cd-finger {
  0% { opacity: 0; transform: translate(14px, -16px) scale(1.15); }
  14% { opacity: 0.32; transform: none; }
  18%, 62% { opacity: 0.4; transform: scale(0.8); }   /* pressed, and held */
  72%, 100% { opacity: 0; transform: translate(10px, -14px) scale(1.1); }
}

/* ---------- write: quiet nudge + "is that all of it?" ---------- */
.hint {
  margin: -0.4rem 0 0; min-height: 1.5em;
  font-size: 0.95rem; line-height: 1.5; color: var(--muted);
  opacity: 0; transform: translateY(-3px);
  transition: opacity 0.9s ease, transform 0.9s ease;
}
.hint.on { opacity: 1; transform: none; }
.check { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
.check .options { gap: 12px; margin: 0; }

/* ---------- throw: ball on the floor, bin a little further away at the lower right ---------- */
.throw-area {
  position: relative; width: min(calc(100vw - 32px), 50rem); flex-shrink: 0;
  height: min(56vh, 440px); min-height: 300px;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.aim { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; opacity: 0; transition: opacity 0.6s ease; }
.aim.on { opacity: 1; }
.aim path {
  fill: none; stroke: var(--muted); stroke-opacity: 0.45; stroke-width: 2;
  stroke-linecap: round; stroke-dasharray: 2 10;
  animation: aim-flow 1.4s linear infinite;
}
@keyframes aim-flow { to { stroke-dashoffset: -24; } }
.ball-shadow {
  position: absolute; left: 0; top: 0; width: 84px; height: 10px; margin-top: -5px;
  border-radius: 50%; background: radial-gradient(closest-side, rgba(40, 25, 15, 0.45), rgba(40, 25, 15, 0));
  transform-origin: 50% 50%; pointer-events: none; opacity: 0;
}
.ball {
  position: absolute; left: 0; top: 0; z-index: 3;
  cursor: grab; touch-action: none;
  filter: drop-shadow(0 2px 2px rgba(50, 32, 20, 0.18));
}
.ball.held { cursor: grabbing; filter: drop-shadow(0 10px 10px rgba(50, 32, 20, 0.22)); }
.ball.inside { z-index: 1; }
.bin { position: absolute; display: block; overflow: visible; pointer-events: none; transform-origin: 50% 96%; }
.bin-back { z-index: 0; }
.bin-front { z-index: 2; }
.bin.wobble { animation: bin-wobble 0.7s cubic-bezier(.3, .6, .4, 1); }
@keyframes bin-wobble {
  0% { transform: rotate(0); }
  20% { transform: rotate(-2.6deg) translateY(1px); }
  45% { transform: rotate(1.6deg); }
  70% { transform: rotate(-0.7deg); }
  100% { transform: rotate(0); }
}

/* ---------- breathe ---------- */
.breath { width: 200px; height: 200px; display: flex; align-items: center; justify-content: center; margin: 0.5rem 0; }
.breath-circle {
  width: 200px; height: 200px; border-radius: 50%;
  background: radial-gradient(circle at 42% 38%, rgba(232, 150, 115, 0.55), rgba(194, 100, 63, 0.32) 60%, rgba(194, 100, 63, 0.16));
  box-shadow: 0 0 40px rgba(194, 100, 63, 0.18);
  transform: scale(0.46); will-change: transform;
}
.breath-cap { margin: 0; min-height: 1.5em; font-size: 1.05rem; color: var(--muted); }
/* the circle rises from where the bin was, then "Breathe with it." appears */
[data-screen="breathe"] .line { animation: reveal 0.9s ease 0.9s backwards; }
/* why we breathe, in one short line, before the first breath */
[data-screen="breathe"] .breath-why { margin-top: -0.6rem; max-width: 22rem; animation: reveal 0.9s ease 1.4s backwards; }

/* ---------- the ending, in stages ---------- */
.r1 { animation: reveal 0.9s ease 0.3s backwards; }
.r2 { animation: reveal 0.9s ease 1.5s backwards; }
.r3 { animation: reveal 0.9s ease 1.9s backwards; }
.r4 { animation: reveal 0.9s ease 3.4s backwards; }
.brand-bar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: center;
  padding: calc(18px + env(safe-area-inset-top)) 16px 0;
  pointer-events: none;
}
.logo { display: block; opacity: 0.9; }
.logo img { display: block; height: 28px; width: auto; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.sr-only:focus { position: static; width: auto; height: auto; margin: 0; clip: auto; overflow: visible; }

.options { display: flex; gap: 4px; align-items: center; color: var(--muted); margin: 0.5rem 0 0; }
.test-code { font-family: ui-monospace, Consolas, monospace; font-size: 0.8rem; color: var(--muted); margin: 0; }

/* footer */
.footer {
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  text-align: center; font-size: 0.75rem; line-height: 1.5; color: var(--muted);
}
.footer p { margin: 2px 0; }
