/* Tokens first. The shell's slot is the one that must survive every redesign:
   inside the Second Draft shell a 48px round button floats in the bottom-right
   corner, 16px in from each edge, above everything. Nothing tappable goes
   there. Applied everywhere, shell or not, so one stylesheet stays right. */

/* The app's own face: a rounded, friendly family. There is no font file to
   download here, so this face is whichever rounded font the device already
   has; when none is present the browser falls straight through to the stack
   below and the page reads exactly the same, only in the system face. To ship
   a real web font later, put its .woff2 in public/fonts/ and add
   url('/fonts/whisker.woff2') format('woff2') first in this list — the CSP
   already allows self-hosted fonts (font-src 'self'). */
@font-face {
  font-family: 'Whisker';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: local('Avenir Next Rounded'), local('AvenirNextRounded-Bold'), local('Arial Rounded MT Bold'),
       local('ArialRoundedMTBold'), local('Varela Round'), local('Nunito'), local('Quicksand'), local('Comfortaa');
}

:root {
  --shell-switcher-size: 48px;
  --shell-switcher-inset: 16px;
  --shell-switcher-gap: 16px;
  --shell-slot: 80px; /* inset + size + gap: the corner the shell owns */

  --ink: #2a2140;
  --quiet: #6e6684;
  --paper: #fff8ee;
  --card: #ffffff;
  --line: #eee1d3;
  --accent: #ff6b57;       /* fills and decoration */
  --accent-ink: #c73e2b;   /* the same coral, dark enough to read as text */
  --accent-soft: #ffe4de;
  --pop: #6b4de6;
  --pop-soft: #e9e3ff;
  --danger: #b83a2c;
  --danger-soft: #ffe3df;

  /* One tint per mood: the fill of its drawn face, and the wash behind its button. */
  --m-happy: #ffc933;
  --m-playful: #ff7a59;
  --m-calm: #5fd3c8;
  --m-sleepy: #b39cf7;
  --m-grumpy: #93a2ba;
  --m-anxious: #f77fb0;
  --m-unknown: #d9d2c8;
  --ear: #ffb3c7;
  --eye: #fffdf8;

  --font-display: 'Whisker', ui-rounded, 'Avenir Next', 'Trebuchet MS', system-ui, sans-serif;
  --font: ui-rounded, 'Avenir Next', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --radius: 18px;
  --shadow: 0 6px 20px rgba(42, 33, 64, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; color: var(--ink); font: 16px/1.5 var(--font); }
body {
  min-height: 100dvh;
  background:
    radial-gradient(60vw 40vh at 0% 0%, var(--accent-soft) 0%, rgba(255, 228, 222, 0) 70%),
    radial-gradient(50vw 40vh at 100% 5%, var(--pop-soft) 0%, rgba(233, 227, 255, 0) 70%),
    var(--paper);
  background-repeat: no-repeat;
}
.art-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* The page fills the screen it is on: a single column on a phone, a wide
   canvas with two panels side by side on a computer. */
.page {
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px 20px calc(env(safe-area-inset-bottom, 0px) + var(--shell-slot));
}
@media (min-width: 900px) {
  .page { padding: 36px 40px calc(env(safe-area-inset-bottom, 0px) + var(--shell-slot)); }
}

h1, h2, h3, .mood-label, .nav-link, .entry-mood, .legend-label {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}
.page-heading {
  font-size: clamp(1.7rem, 1.2rem + 2vw, 2.8rem);
  line-height: 1.1;
  margin: 0;
  color: var(--pop);
}
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .page-heading {
    background: linear-gradient(95deg, var(--accent) 0%, #c04bd6 55%, var(--pop) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
}
.section-heading { font-size: 1.25rem; margin: 0 0 12px; }
.quiet { color: var(--quiet); margin: 0; }
.small { font-size: 0.875rem; }

/* Masthead: the title and the way to the other page, side by side. */
.masthead {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px 24px; margin-bottom: 20px;
}
.masthead-text { min-width: 0; }
.tagline { margin-top: 4px; }
.nav { display: flex; gap: 10px; }
.nav-link {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; min-height: 44px; border-radius: 999px;
  background: var(--ink); color: #fff; text-decoration: none; font-weight: 700;
  transition: transform 120ms ease, background-color 120ms ease;
}
.nav-link:hover { background: var(--pop); transform: translateY(-1px); }
.nav-link:focus-visible { outline: 3px solid var(--pop); outline-offset: 2px; }
.nav-link svg { width: 18px; height: 18px; }

button, input, select, textarea { font: inherit; }

/* Two panels on a wide screen; stacked on a phone. */
.layout { display: grid; gap: 24px; }
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; align-items: start; }
}
.panel {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 18px;
}
@media (min-width: 900px) {
  .panel { padding: 24px; }
  /* The picker stays in reach while a long log scrolls beside it. */
  .panel-pick { position: sticky; top: 24px; }
}
.lead { margin: 0 0 14px; font-size: 1.05rem; }

/* The mood grid: wide buttons, each a drawn face beside its name. */
.moods { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0 0 14px; }
@media (min-width: 560px) { .moods { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; } }
.mood {
  --face: var(--m-unknown);
  appearance: none; border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--ink); cursor: pointer;
  padding: 10px 12px; min-height: 68px; text-align: left;
  display: flex; align-items: center; gap: 12px;
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
.mood[data-mood="happy"] { --face: var(--m-happy); }
.mood[data-mood="playful"] { --face: var(--m-playful); }
.mood[data-mood="calm"] { --face: var(--m-calm); }
.mood[data-mood="sleepy"] { --face: var(--m-sleepy); }
.mood[data-mood="grumpy"] { --face: var(--m-grumpy); }
.mood[data-mood="anxious"] { --face: var(--m-anxious); }
@supports (background: color-mix(in srgb, red 20%, white)) {
  .mood { background: color-mix(in srgb, var(--face) 16%, white); }
}
.mood:hover { border-color: var(--face); transform: translateY(-2px); box-shadow: var(--shadow); }
.mood:active { transform: translateY(0); }
.mood:focus-visible { outline: 3px solid var(--pop); outline-offset: 2px; }
.mood:disabled { opacity: 0.6; cursor: default; transform: none; box-shadow: none; }
.mood .art { width: 44px; height: 44px; flex: none; }
.mood-label { font-size: 1.05rem; font-weight: 700; }
@media (min-width: 900px) {
  .mood { min-height: 76px; padding: 12px 14px; }
  .mood .art { width: 50px; height: 50px; }
}

/* Drawn artwork: the face's fill comes from --face on the element that shows it. */
.art { display: block; overflow: visible; }
.art[data-mood="happy"] { --face: var(--m-happy); }
.art[data-mood="playful"] { --face: var(--m-playful); }
.art[data-mood="calm"] { --face: var(--m-calm); }
.art[data-mood="sleepy"] { --face: var(--m-sleepy); }
.art[data-mood="grumpy"] { --face: var(--m-grumpy); }
.art[data-mood="anxious"] { --face: var(--m-anxious); }
.art[data-mood="unknown"] { --face: var(--m-unknown); }

.note {
  width: 100%; border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px;
  background: var(--card); color: var(--ink);
}
.note:focus { outline: none; border-color: var(--pop); box-shadow: 0 0 0 3px var(--pop-soft); }
.note::placeholder { color: var(--quiet); }

.notice {
  margin: 12px 0 0; padding: 12px 14px; border-radius: 14px;
  background: var(--danger-soft); color: var(--danger); border: 1px solid #f3c2ba;
}

/* The log: newest first. Anything tappable stays on the left, well clear of the
   shell's corner even as the list scrolls past it. */
.entries { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.entry {
  --face: var(--m-unknown);
  display: flex; gap: 12px; padding: 12px 14px 12px 12px;
  background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--face);
  border-radius: 16px;
}
.entry[data-mood="happy"] { --face: var(--m-happy); }
.entry[data-mood="playful"] { --face: var(--m-playful); }
.entry[data-mood="calm"] { --face: var(--m-calm); }
.entry[data-mood="sleepy"] { --face: var(--m-sleepy); }
.entry[data-mood="grumpy"] { --face: var(--m-grumpy); }
.entry[data-mood="anxious"] { --face: var(--m-anxious); }
.entry-mark { flex: none; }
.entry-mark .art { width: 40px; height: 40px; }
.entry-body { flex: 1; min-width: 0; }
.entry-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.entry-mood { font-size: 1.05rem; }
.entry-note { margin: 4px 0 0; overflow-wrap: anywhere; }
.entry-actions { display: flex; gap: 12px; align-items: center; margin-top: 6px; justify-content: flex-start; }
.link {
  appearance: none; border: 0; background: none; padding: 6px 0; cursor: pointer;
  color: var(--accent-ink); font-size: 0.875rem; text-decoration: underline; font-weight: 600;
}
.link.danger { color: var(--danger); }
.link:disabled { opacity: 0.6; cursor: default; }
.link:focus-visible { outline: 3px solid var(--pop); outline-offset: 2px; border-radius: 4px; }

/* History: her moods laid out day by day, one row per week, a face for every
   mood she showed that day and a dotted blank for a day with nothing logged.
   Nothing in it is tappable, so the corner the shell owns stays free. */
.history-summary { margin: 0 0 16px; }
.calendar-wrap { overflow-x: auto; }
.calendar { width: 100%; border-collapse: separate; border-spacing: 4px; table-layout: fixed; }
.calendar th { font-family: var(--font-display); font-weight: 700; font-size: 0.75rem; color: var(--quiet); text-align: left; padding: 0 2px 2px; }
.calendar th.month { width: 2.6em; vertical-align: top; padding-top: 6px; white-space: nowrap; }
.calendar td.day {
  height: 58px; vertical-align: top; padding: 4px;
  background: var(--card); border: 2px solid transparent; border-radius: 12px;
}
.calendar td.day-empty { background: transparent; border: 2px dashed var(--line); }
.calendar td.day-today { border-color: var(--pop); }
.calendar td.day-future { visibility: hidden; }
.day-num { display: block; font-size: 0.72rem; line-height: 1; color: var(--quiet); }
.day-empty .day-num { color: #b7afc6; }
.day-moods { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 4px; }
.day-moods .art { width: 18px; height: 18px; }
.day-more { font-size: 0.7rem; color: var(--quiet); align-self: center; }
.day-none { display: block; margin-top: 8px; text-align: center; color: #cfc7da; font-size: 0.9rem; line-height: 1; }
@media (min-width: 600px) {
  .calendar { border-spacing: 6px; }
  .calendar td.day { height: 76px; padding: 6px; border-radius: 14px; }
  .day-moods .art { width: 22px; height: 22px; }
}
@media (min-width: 900px) {
  .calendar td.day { height: 96px; padding: 8px; }
  .day-moods { gap: 4px; margin-top: 8px; }
  .day-moods .art { width: 30px; height: 30px; }
  .day-num { font-size: 0.8rem; }
}
.legend { list-style: none; margin: 18px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 14px; }
.legend li { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 8px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; }
.legend .art { width: 24px; height: 24px; }
.legend-label { font-weight: 700; }
.legend-count { color: var(--quiet); font-size: 0.875rem; }

@media (prefers-reduced-motion: reduce) {
  .mood, .nav-link { transition: none; }
  .mood:hover, .nav-link:hover { transform: none; }
}

/* Messages that are not the page: keep out of the shell's 80×80 corner. */
#toast {
  position: fixed; left: 16px; right: var(--shell-slot);
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--shell-switcher-inset));
  pointer-events: none;
}
#toast:empty { display: none; }
#toast > * { display: inline-block; max-width: min(100%, 520px); background: var(--ink); color: var(--paper); border-radius: 14px; padding: 12px 16px; box-shadow: var(--shadow); }

/* Spoken but not shown: a caption for screen readers. */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
