:root {
  --night: #0b1230;
  --night-2: #1a2456;
  --ink: #eef0ff;
  --muted: #9aa3c7;
  --line: rgba(255, 255, 255, .14);
  --panel: rgba(22, 30, 72, .88);
  --gold: #ffd27a;
  --warm: #ffb36b;
  --calm: #8ecbff;
  --joy: #ffe066;
  --quiet: #c8b6ff;
  --gutter: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  /* faint town glow on the horizon over the night gradient */
  background: linear-gradient(to top, rgba(255, 150, 120, .08), transparent 28%) fixed,
    radial-gradient(120% 70% at 50% 0%, var(--night-2), var(--night) 70%) fixed var(--night);
  color: var(--ink);
  font: 16px/1.45 Inter, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
/* Slowly drifting nebula behind everything (transform-only animation = cheap, GPU composited). */
body::before {
  content: ""; position: fixed; inset: -25%; z-index: -1; pointer-events: none;
  background:
    radial-gradient(35% 25% at 25% 30%, rgba(140, 110, 255, .16), transparent 70%),
    radial-gradient(30% 22% at 75% 60%, rgba(80, 170, 255, .12), transparent 70%),
    radial-gradient(28% 20% at 55% 85%, rgba(255, 150, 200, .08), transparent 70%);
  animation: drift 60s ease-in-out infinite alternate;
}

button { font: inherit; color: inherit; cursor: pointer; }
/* Type roles: Fraunces (soft serif) for headings and numbers, Inter for controls, Caveat only for your own notes. */
h1 { font: 400 26px/1.25 Fraunces, Georgia, serif; text-align: center; margin: 0 0 18px; text-wrap: balance; letter-spacing: -.01em; }
h2 { font-size: 18px; font-weight: 600; margin: 0; }
small { color: var(--muted); font-size: 13px; }
.hand { font-family: Caveat, cursive; font-size: 26px; line-height: 1.2; }

.screen {
  position: relative;
  max-width: 480px;
  min-height: 100vh; /* fallback for browsers without dvh */
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(var(--gutter), env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right))
           max(var(--gutter), env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: screen-in .45s ease both; /* opacity only: a transform here would break the fixed sky */
}
/* Content of Add/Year floats up in a short cascade each time the screen opens. */
#add-screen > *, #year-screen > * { animation: fade-in .5s ease both; }
#add-screen > :nth-child(2), #year-screen > :nth-child(2) { animation-delay: .06s; }
#add-screen > :nth-child(3), #year-screen > :nth-child(3) { animation-delay: .12s; }
#add-screen > :nth-child(4), #year-screen > :nth-child(4) { animation-delay: .18s; }
#add-screen > :nth-child(n+5), #year-screen > :nth-child(n+5) { animation-delay: .24s; }

.top { position: relative; z-index: 1; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.tally { display: flex; align-items: center; gap: 12px; }
.count { font: 400 26px/1.1 Fraunces, Georgia, serif; letter-spacing: -.01em; }
.count b { font-weight: 600; color: var(--gold); text-shadow: 0 0 14px rgba(255, 210, 122, .55); }
.streak { color: var(--muted); font-size: 14px; min-height: 1.4em; margin-top: 2px; }

/* Tonight's moon: the one quiet signature in the header. Tap it for a meteor shower. */
.moon-btn { flex: none; background: none; border: 0; padding: 0; border-radius: 50%; }
.moon { display: block; width: 52px; height: 52px; overflow: visible; filter: drop-shadow(0 0 14px rgba(255, 240, 205, .35)); transition: transform .3s cubic-bezier(.3, 1.8, .5, 1); }
.moon-btn:active .moon { transform: scale(.92); }
@media (hover: hover) { .moon-btn:hover .moon { transform: scale(1.06); } }
.actions { display: flex; gap: 8px; }
.round { width: 44px; padding: 0; font-size: 20px; line-height: 1; }

.ghost { background: rgba(255, 255, 255, .07); border: 1px solid var(--line); border-radius: 999px; padding: 10px 16px; min-height: 44px; white-space: nowrap; }
.link { background: none; border: 0; padding: 8px 4px; color: var(--gold); text-decoration: underline; cursor: pointer; font-size: inherit; }

.primary {
  position: relative; z-index: 1;
  margin-top: auto;
  align-self: center;
  width: 100%;
  max-width: 440px;
  padding: 16px;
  border: 0;
  border-radius: 999px;
  background: var(--gold);
  color: #1d1733;
  font-weight: 600;
  font-size: 17px;
  background: linear-gradient(180deg, #ffe0a0, var(--gold));
  box-shadow: 0 0 32px rgba(255, 210, 122, .35), inset 0 1px 0 rgba(255, 255, 255, .6);
  transition: transform .15s, filter .2s;
}
.primary:active { transform: scale(.98); }
.primary.invite { animation: invite 3.2s ease-in-out infinite; }
.ghost { transition: background .2s; }
@media (hover: hover) {
  .ghost:hover, .moods span:hover { background: rgba(255, 255, 255, .13); }
  .primary:hover { filter: brightness(1.06); }
}
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.card {
  position: relative; z-index: 2;
  display: block; width: 100%; text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 16px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .28), inset 0 1px 0 rgba(255, 255, 255, .07);
}
.card small { display: block; }
.card p { margin: 4px 0 0; }

/* Sky */
/* The sky fills the whole window (wide on tablets/desktop); text and buttons stay in the centered column. */
.sky { position: fixed; inset: 0; width: 100%; height: 100%; }
#sky { will-change: transform; transition: opacity .6s ease, transform 1.2s cubic-bezier(.2, .7, .2, 1); }
#sky { transform: translate(calc(var(--px, 0) * -6px), calc(var(--py, 0) * -4px)); }
#dust { transform: translate(calc(var(--px, 0) * -18px), calc(var(--py, 0) * -12px)); transition: transform 1.2s cubic-bezier(.2, .7, .2, 1); }
.hills { position: fixed; left: 0; bottom: 0; width: 100%; height: min(12vh, 100px); pointer-events: none; } /* own layer: twinkling dust doesn't repaint the glowing stars */
/* Behind Add and Year the sky stays, dimmed: it fills the sides on wide screens and keeps you "under your sky". */
body:not([data-screen="sky-screen"]) #sky { opacity: .22; }
body:not([data-screen="sky-screen"]) #sky :is(.line, .spot, .hint-dot) { display: none; } /* just stars back there, no lines */
/* The sky sits behind the screen's box now, so let taps pass through the empty parts of the sky screen. */
#sky-screen { pointer-events: none; }
#sky-screen > * { pointer-events: auto; }
.tw2 { animation: twinkle 5s ease-in-out infinite alternate; }
.line { fill: none; stroke: var(--gold); stroke-width: 1.2; opacity: .6; }
.draw { stroke-dasharray: 1; animation: draw 2.4s .3s ease-out both; } /* constellation traces itself in */
.dashed, .spot { stroke-dasharray: 3 5; }
.spot { fill: none; stroke: var(--gold); stroke-width: 1.2; opacity: .85; transform-box: fill-box; transform-origin: center; animation: pulse 3s ease-in-out infinite; }
.star { cursor: pointer; outline: none; }
.tw { pointer-events: none; animation: star-twinkle 5s ease-in-out infinite; }
.star:focus-visible .core { stroke: #fff; stroke-width: 1.5; }
.rise { animation: rise 1.6s cubic-bezier(.2, .7, .2, 1) both; }
.hint { stroke-dasharray: 2 6; opacity: .35; }
.hint-dot { fill: none; stroke: var(--gold); stroke-width: 1; opacity: .45; }
.pick { fill: none; stroke: var(--gold); stroke-width: 1.2; transform-box: fill-box; transform-origin: center; animation: pick 1.8s ease-out infinite; pointer-events: none; }
.burst { opacity: 0; stroke-width: 1.5; transform-box: fill-box; transform-origin: center; animation: burst 1.2s 1.3s ease-out both; }

/* Shooting stars (spawned by app.js): bright head at the front, fading tail. Padding = a bigger tap target to catch one. */
.meteor {
  position: fixed; height: 2px; padding: 16px 0; box-sizing: content-box; opacity: 0; cursor: pointer;
  background: linear-gradient(90deg, transparent, rgba(200, 220, 255, .35) 60%, #fff) content-box;
}
.meteor::after { content: ""; position: absolute; right: -2px; top: 50%; width: 4px; height: 4px; margin-top: -2px; border-radius: 50%; background: #fff; box-shadow: 0 0 8px 3px rgba(210, 225, 255, .8); }
body:not([data-screen="sky-screen"]) .meteor { pointer-events: none; }
/* Tap sparkles: a four-point star. */
.spark {
  position: fixed; z-index: 5; width: 28px; height: 28px; pointer-events: none;
  background: radial-gradient(circle, #fff 15%, var(--gold) 45%, transparent 70%);
  clip-path: polygon(50% 0, 58% 42%, 100% 50%, 58% 58%, 50% 100%, 42% 58%, 0 50%, 42% 42%);
}
.toast {
  position: fixed; z-index: 10; left: 50%; top: calc(max(var(--gutter), env(safe-area-inset-top)) + 72px);
  max-width: min(420px, calc(100% - 2 * var(--gutter))); width: max-content;
  padding: 10px 18px; border-radius: 999px; text-align: center; font-size: 15px;
  background: rgba(22, 30, 72, .92); border: 1px solid rgba(255, 210, 122, .35); box-shadow: 0 0 24px -6px rgba(255, 210, 122, .5);
  opacity: 0; transform: translate(-50%, -8px); transition: opacity .35s, transform .35s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.memory { animation: fade-in .8s ease both; }
.note { position: absolute; left: var(--gutter); right: var(--gutter); bottom: calc(max(var(--gutter), env(safe-area-inset-bottom)) + 76px); width: auto; animation: fade-in .25s ease both; }
.empty {
  position: absolute; left: var(--gutter); right: var(--gutter); bottom: calc(max(var(--gutter), env(safe-area-inset-bottom)) + 84px);
  max-width: 340px; margin: 0 auto; text-align: center; color: var(--muted); font-size: 15px; line-height: 1.55; text-wrap: balance;
}

/* Add */
.preview-wrap { display: grid; place-items: center; height: 140px; }
.preview-star {
  --c: var(--warm);
  position: relative;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 16px 8px var(--c), 0 0 60px 24px var(--c);
  transition: box-shadow .5s;
  animation: pulse 3s ease-in-out infinite;
}
/* Four-point sparkle rays, slowly turning. */
.preview-star::before, .preview-star::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 2px; height: 76px; margin: -38px 0 0 -1px;
  background: linear-gradient(transparent, rgba(255, 255, 255, .9), transparent);
  animation: spin 14s linear infinite;
}
.preview-star::after { height: 52px; margin-top: -26px; animation-name: spin-90; }
form { display: flex; flex-direction: column; gap: 8px; flex: 1; }
textarea {
  width: 100%; resize: none;
  background: rgba(16, 22, 56, .72);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  padding: 12px 14px;
  transition: border-color .25s, box-shadow .25s, background .25s;
}
textarea:focus-visible { outline: none; border-color: var(--gold); background: rgba(22, 30, 72, .8); box-shadow: 0 0 0 4px rgba(255, 210, 122, .14), 0 0 28px rgba(255, 210, 122, .12); }
textarea::placeholder { color: var(--muted); }
.chars { text-align: right; color: var(--muted); font-size: 13px; }
.moods { border: 0; padding: 0; margin: 8px 0 16px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.moods legend { color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.moods label { position: relative; }
.moods input { position: absolute; inset: 0; opacity: 0; margin: 0; }
.moods span { display: block; text-align: center; padding: 10px 0; border-radius: 12px; border: 1px solid var(--line); cursor: pointer; background: rgba(16, 22, 56, .6); transition: border-color .25s, background .25s, box-shadow .25s; }
.moods span::before { content: ""; display: block; width: 8px; height: 8px; margin: 0 auto 4px; border-radius: 50%; background: var(--c); box-shadow: 0 0 8px var(--c); transition: transform .3s cubic-bezier(.3, 1.8, .5, 1); }
.moods input:checked + span { border-color: var(--c); background: rgba(255, 255, 255, .08); box-shadow: 0 0 20px -6px var(--c); }
.moods input:checked + span::before { transform: scale(1.5); }
.moods input:focus-visible + span { outline: 2px solid var(--gold); }
.fine { text-align: center; color: var(--muted); font-size: 13px; margin: 0; }

/* Year */
.months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
#year-title { font: italic 400 26px/1.1 Fraunces, Georgia, serif; color: var(--gold); text-shadow: 0 0 16px rgba(255, 210, 122, .35); }
.tile {
  background: linear-gradient(160deg, rgba(34, 44, 98, .8), rgba(16, 22, 56, .8));
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 8px 10px;
  animation: fade-in .5s calc(var(--i) * 45ms) ease both; /* months appear one after another */
}
.tile.now { border-color: var(--gold); box-shadow: 0 0 18px -6px var(--gold); }
.mhead { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--muted); }
.mhead b { font: 600 15px Fraunces, Georgia, serif; color: var(--gold); }
/* Month calendar: 7 columns, day 1 starts on its weekday. */
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; margin-top: 8px; }
.days i:first-child { grid-column-start: var(--first); }
.days i { width: 100%; max-width: 7px; aspect-ratio: 1; justify-self: center; border-radius: 50%; background: rgba(255, 255, 255, .13); }
.days i.later { background: none; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1); }
.days i.lit { background: var(--c); box-shadow: 0 0 5px var(--c); animation: pop .4s calc(var(--i) * 45ms + .25s) cubic-bezier(.3, 1.8, .5, 1) both; }
.brightest { border-color: rgba(255, 210, 122, .35); box-shadow: 0 0 30px -10px rgba(255, 210, 122, .5), 0 12px 32px rgba(0, 0, 0, .28); }
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; padding: 6px 0; }
.totals b { display: block; font: 600 28px/1.15 Fraunces, Georgia, serif; color: var(--gold); overflow-wrap: anywhere; }
.totals span { font-size: 12px; color: var(--muted); }
/* The top word is a word, not a number: italic, and sized so ~10 letters fit a third of a phone screen. */
#total-word { font-style: italic; font-weight: 400; font-size: clamp(16px, calc((100vw - 48px) / 15), 26px); line-height: 1.6; }

@keyframes twinkle { to { opacity: .06; } }
@keyframes rise { from { transform: translateY(420px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes pulse { 50% { transform: scale(1.15); } }
@keyframes star-twinkle { 18% { opacity: .7; } 30% { opacity: .95; } 55% { opacity: .5; } 72% { opacity: .9; } 85% { opacity: .65; } }
@keyframes pick { from { transform: scale(.6); opacity: 1; } to { transform: scale(1.7); opacity: 0; } }
@keyframes draw { from { stroke-dashoffset: 1; } }
@keyframes burst { from { opacity: 1; transform: scale(.3); } to { opacity: 0; transform: scale(3.2); } }
@keyframes drift { to { transform: translate(6%, -4%) rotate(8deg) scale(1.08); } }
@keyframes screen-in { from { opacity: 0; } }
@keyframes invite { 50% { box-shadow: 0 0 52px rgba(255, 210, 122, .6), inset 0 1px 0 rgba(255, 255, 255, .6); } }
@keyframes pop { from { transform: scale(0); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes spin-90 { from { transform: rotate(90deg); } to { transform: rotate(450deg); } }

/* Small phones */
@media (max-width: 360px) {
  :root { --gutter: 12px; }
  .hand { font-size: 23px; }
  .moods { gap: 6px; }
  .totals b { font-size: 22px; }
  .count, h1 { font-size: 23px; }
  .moon { width: 44px; height: 44px; }
}
/* Short screens: landscape phones, small Androids with the keyboard open */
@media (max-height: 640px) {
  .preview-wrap { height: 72px; }
  h1 { font-size: 19px; margin-bottom: 8px; }
  .moods { margin: 4px 0 8px; }
}
/* Tablets and desktop: give the year view room */
@media (min-width: 760px) {
  #year-screen { max-width: 720px; }
  .months { grid-template-columns: repeat(4, 1fr); gap: 10px; }
  .tile { padding: 10px 12px 12px; }
  .days i { max-width: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .preview-star::after { transform: rotate(90deg); }
  #sky, #dust { transform: none; }
}
