/* ============ Sweet Pi ============ */
:root {
  --bg: #fff5f9;
  --bg-2: #ffe9f2;
  --surface: #ffffff;
  --pink-50: #fff0f6;
  --pink-100: #ffe3ef;
  --pink-200: #ffc9df;
  --pink-300: #ffa6c9;
  --pink-400: #ff85b5;
  --pink-500: #ff5fa2;
  --pink-600: #ec3f8a;
  --pink-650: #d42f80; /* candy press: top of white-text fills (white 4.65:1) */
  --pink-700: #b8256a; /* raspberry: small pink text + bottom of white-text fills (white 5.98:1, pink-100 4.98:1) */
  --pink-800: #8e1d50; /* candy ledge under pink-650/700 faces */
  --ink: #5b2346;
  --ink-soft: #87536f; /* 5.0:1 on pink-100 */
  --lilac: #c9a7ff;
  --lilac-soft: #f1e8ff;
  --mint: #2fb98f;
  --mint-soft: #ddf8ee;
  --coral: #ff6b7d;
  --coral-soft: #ffe6ea;
  --gold: #ffc94d;
  /* figure series: validated as a categorical set (CVD + contrast) on white */
  --fig-1: #d42f80;
  --fig-2: #2f7fd0;
  --fig-3: #1f9a75;
  --fig-4: #c27c00;
  --radius: 26px;
  --radius-sm: 16px;
  --shadow: 0 10px 30px -12px rgba(220, 70, 140, 0.35), 0 2px 6px rgba(220, 70, 140, 0.08);
  --shadow-sm: 0 4px 14px -6px rgba(220, 70, 140, 0.35);
  --chat-w: 380px;
  --topbar-h: 68px;
  --font-display: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(255, 95, 162, 0.13) 1.5px, transparent 0),
    radial-gradient(1200px 600px at 10% -10%, #ffe0ee 0%, transparent 60%),
    radial-gradient(900px 600px at 110% 110%, #f3e6ff 0%, transparent 60%);
  background-size: 26px 26px, auto, auto;
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.15; margin: 0 0 0.4em; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.6rem, 3.5vw, 2.2rem); }
h2 { font-size: 1.35rem; }
p { margin: 0 0 0.75em; }
a { color: var(--pink-700); }
code { background: var(--pink-50); padding: 0.1em 0.35em; border-radius: 6px; font-size: 0.9em; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--pink-650); outline-offset: 3px; border-radius: 12px; }
::selection { background: var(--pink-200); color: var(--ink); }
input, textarea { caret-color: var(--pink-650); }
::placeholder { color: var(--ink-soft); opacity: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-soft); }
.small { font-size: 0.9rem; }
.eyebrow { font-family: var(--font-display); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.78rem; color: var(--pink-700); margin-bottom: 0.35em; }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4em;
  min-height: 48px; padding: 0.6em 1.2em;
  border: 0; border-radius: 999px;
  font-family: var(--font-display); font-weight: 600; font-size: 1.02rem;
  text-decoration: none; color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s;
  user-select: none;
}
.btn:active:not(:disabled) { transform: translateY(2px) scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
/* White text sits only on pink-650 or deeper (Contrast Floor Rule). */
.btn--primary {
  color: #fff;
  background: linear-gradient(180deg, var(--pink-650), var(--pink-700));
  box-shadow: 0 5px 0 var(--pink-800), 0 10px 20px -8px rgba(212, 47, 128, 0.6);
}
.btn--primary:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--pink-800); }
.btn--ghost { background: var(--surface); border: 2px solid var(--pink-200); box-shadow: none; }
.btn--soft { background: var(--pink-100); box-shadow: none; }
.btn--danger { color: var(--ink); background: var(--coral-soft); border: 2px solid var(--coral); box-shadow: none; }
.btn--big { min-height: 56px; padding: 0.7em 1.6em; font-size: 1.12rem; }
.btn--small { min-height: 44px; padding: 0.35em 1.05em; font-size: 0.95rem; }
.btn--wide { width: 100%; }
@media (hover: hover) {
  .btn--ghost:hover { background: var(--pink-50); }
  .btn--soft:hover { background: var(--pink-200); }
  .btn--danger:hover { background: #ffd6dc; }
  .icon-btn:hover { background: var(--pink-200); }
  .chip:hover { background: var(--pink-50); border-color: var(--pink-300); }
  .nav a:hover { background: var(--pink-50); color: var(--ink); }
}

.icon-btn {
  display: inline-grid; place-items: center;
  width: 48px; height: 48px; flex: none;
  border: 0; border-radius: 50%;
  background: var(--pink-100); color: var(--ink);
  font-size: 1.15rem; text-decoration: none; cursor: pointer;
  transition: background 0.2s, transform 0.12s;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn--small { width: 44px; height: 44px; font-size: 1rem; }
/* One stroke icon family for every control (public/js/icons.js); emoji are for content only. */
.icon { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn--small .icon { width: 20px; height: 20px; }

.chip {
  display: inline-flex; align-items: center; gap: 0.3em;
  min-height: 44px; padding: 0.45em 0.95em;
  border: 2px solid var(--pink-200); border-radius: 999px;
  background: var(--surface);
  font-weight: 700; font-size: 0.95rem;
  transition: background 0.15s, transform 0.12s, border-color 0.15s;
}
.chip:active { transform: scale(0.96); }
.chip--tiny { min-height: 44px; padding: 0.25em 0.8em; font-size: 0.85rem; white-space: nowrap; }
.chip--idea { font-size: 0.88rem; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(18px, 3vw, 28px);
  border: 2px solid rgba(255, 166, 201, 0.35);
}

.notice { background: var(--lilac-soft); border-radius: var(--radius-sm); padding: 0.8em 1em; margin-bottom: 1em; font-size: 0.95rem; }

/* ---------- layout ---------- */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--chat-w);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas: 'top chat' 'main chat';
  height: 100dvh;
}

.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 12px;
  padding: 0 clamp(12px, 3vw, 28px);
  padding-top: env(safe-area-inset-top);
  background: rgba(255, 245, 249, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--pink-100);
  z-index: 5;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); flex: none; }
.brand__pip { width: 46px; height: 46px; display: block; }
.brand__pip svg { width: 100%; height: 100%; }
.brand__name { font-family: var(--font-display); font-weight: 700; font-size: 1.45rem; letter-spacing: -0.02em; }
.brand__name em { font-style: normal; color: var(--pink-600); } /* large text: the brightest pink in the mark */

.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 14px; border-radius: 999px;
  text-decoration: none; color: var(--ink-soft); font-weight: 800; font-size: 0.95rem;
}
.nav__icon { font-size: 1.1em; line-height: 1; }
.nav a.is-active { background: var(--pink-100); color: var(--ink); }

.hud { display: flex; align-items: center; gap: 8px; margin-left: auto; min-width: 0; }

.lang-toggle { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--pink-100); gap: 2px; flex: none; }
.lang-toggle button {
  position: relative;
  min-width: 44px; min-height: 36px; padding: 0 10px; border: 0; border-radius: 999px;
  background: transparent; color: var(--ink-soft);
  font-family: var(--font-display); font-weight: 600; font-size: 0.9rem; letter-spacing: 0.03em;
}
.lang-toggle button.is-on { background: var(--surface); color: var(--pink-700); box-shadow: var(--shadow-sm); }
.lang-toggle button::after { content: ''; position: absolute; inset: -6px 0; } /* 48px tall touch target */
.login__lang { position: fixed; top: calc(14px + env(safe-area-inset-top)); right: 16px; }
.hud__item { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border: 2px solid transparent; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow-sm); font-weight: 800; }
/* Streak: custard once today is secured; until then a dashed blush pill, dimmed by colour (No-Grey Rule). */
.hud__streak.is-lit { background: #fff1d6; border-color: #ffe0a3; }
.hud__streak:not(.is-lit) { background: var(--pink-50); border-style: dashed; border-color: var(--pink-300); color: var(--ink-soft); box-shadow: none; }
.hud__ring {
  --pct: 0%;
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: conic-gradient(var(--pink-600) var(--pct), var(--pink-100) 0);
  font-family: var(--font-display); font-weight: 700;
  position: relative;
}
.hud__ring::before { content: ''; position: absolute; inset: 5px; background: var(--surface); border-radius: 50%; }
.hud__ring b { position: relative; }
.hud__item, .hud__ring { flex: none; white-space: nowrap; }

.view {
  grid-area: main;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(14px, 3vw, 32px);
  padding-bottom: calc(110px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 22px;
  outline: none;
}
.view > * { width: 100%; max-width: 920px; margin-inline: auto; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 6px 4px 12px; }
.section-head h2 { margin: 0; }

/* ---------- chat ---------- */
.chat {
  grid-area: chat;
  display: flex; flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-left: 2px solid var(--pink-100);
  box-shadow: -10px 0 30px -20px rgba(220, 70, 140, 0.4);
  z-index: 20;
}
.chat__head {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 16px 16px 12px; padding-top: calc(16px + env(safe-area-inset-top));
  background: linear-gradient(180deg, var(--pink-100), var(--pink-50));
  border-bottom: 2px solid var(--pink-100);
}
.chat__head > div { flex: 1; }
.chat__head h2 { margin: 0; font-size: 1.25rem; }
.chat__head p { margin: 2px 0 0; font-size: 0.85rem; color: var(--ink-soft); }
.chat__close { display: none; }
.chat__headtext { min-width: 0; }
.chat__thread { display: flex; flex-direction: column; gap: 1px; margin: 4px 0 0 !important; min-width: 0; }
.chat__thread-lesson { font-size: 0.75rem; font-weight: 800; color: var(--pink-700); text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat__thread-title { font-size: 0.9rem; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn.is-on { background: var(--pink-650); color: #fff; }

/* thread list replaces the messages while open */
.chat__threads { display: none; flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 12px 14px 20px; }
.chat.is-list .chat__threads { display: block; }
.chat.is-list .chat__list, .chat.is-list .chat__suggest, .chat.is-list .chat__form { display: none; }
.threads__back { min-height: 44px; border: 0; background: none; color: var(--pink-700); font-weight: 800; padding: 6px 2px; margin-bottom: 4px; font-size: 0.92rem; }
.threads__group { margin-bottom: 18px; }
.threads__group h3 { font-size: 1rem; margin: 2px 2px 8px; overflow-wrap: anywhere; }
.threads__here { display: inline-block; font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: #fff; background: var(--pink-700); border-radius: 999px; padding: 2px 9px; margin: 0 0 6px 2px; }
.threads__group.is-current { background: var(--pink-50); border-radius: 20px; padding: 10px 10px 12px; }
.threads__empty { color: var(--ink-soft); font-size: 0.9rem; margin: 4px 4px 8px; }
.threads__new { margin-top: 4px; }
.thread { display: flex; flex-wrap: wrap; align-items: stretch; gap: 4px; margin-bottom: 8px; }
.thread__open {
  flex: 1; min-width: 0; text-align: left; display: flex; flex-direction: column; gap: 2px;
  padding: 10px 12px; border-radius: 16px; border: 2px solid var(--pink-100); background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
}
@media (hover: hover) {
  .thread__open:hover { border-color: var(--pink-300); }
  .thread__del:hover { background: var(--coral-soft); border-color: var(--coral); color: var(--ink); }
}
.thread.is-current .thread__open { border-color: var(--pink-500); }
.thread__open strong { font-size: 0.95rem; line-height: 1.25; overflow-wrap: anywhere; }
.thread__preview { font-size: 0.82rem; color: var(--ink-soft); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.thread__meta { font-size: 0.75rem; color: var(--pink-700); font-weight: 700; }
/* Delete: a labelled icon button in berry ink (3:1+), confirmed inline before anything is lost. */
.thread__del { display: grid; place-items: center; width: 44px; flex: none; border: 2px solid var(--pink-100); border-radius: 16px; background: var(--surface); color: var(--ink-soft); transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.12s; }
.thread__del .icon { width: 20px; height: 20px; }
.thread__del:active { transform: scale(0.96); }
.thread.is-confirming .thread__del { background: var(--coral-soft); border-color: var(--coral); color: var(--ink); }
.thread__confirm {
  flex-basis: 100%;
  padding: 12px 14px; border-radius: 16px;
  background: var(--coral-soft);
  box-shadow: 0 6px 18px -10px rgba(220, 70, 140, 0.45);
  animation: confirm-in 0.25s cubic-bezier(.2, .8, .2, 1);
}
.thread__confirm p { margin: 0 0 10px; font-weight: 700; font-size: 0.92rem; }
.thread__confirm-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.thread__confirm-yes { border-color: var(--coral); }
@keyframes confirm-in { from { opacity: 0; transform: translateY(-6px); } }
.lesson__threads { margin: 0 auto 6px; display: inline-flex; }
.chat__list { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
/* suggestions wrap onto a second line rather than hiding off-screen */
.chat__suggest { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; }
.chat__form { padding: 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); border-top: 2px solid var(--pink-100); background: var(--pink-50); }
.chat__row { display: flex; align-items: flex-end; gap: 8px; }
.chat__row textarea {
  flex: 1; resize: none; min-height: 48px; max-height: 140px;
  padding: 12px 14px; border-radius: 22px;
  border: 2px solid var(--pink-600); background: var(--surface);
  font-size: 16px; line-height: 1.35;
}
.btn--send { width: 48px; min-height: 48px; padding: 0; flex: none; }
.chat__preview { position: relative; display: flex; align-items: center; gap: 10px; margin-bottom: 8px; padding-right: 52px; min-width: 0; }
.chat__preview img { width: 64px; height: 84px; flex: none; object-fit: cover; object-position: top; border-radius: 12px; border: 2px solid var(--pink-200); background: var(--pink-100); }
.chat__preview img:not([src]) { visibility: hidden; }
.chat__preview-label { font-size: 0.85rem; font-weight: 700; color: var(--ink-soft); overflow-wrap: anywhere; }
.chat__preview .icon-btn { position: absolute; top: 0; right: 0; }

.msg { display: flex; gap: 8px; max-width: 100%; }
.msg__avatar { width: 36px; height: 36px; flex: none; }
.msg__avatar svg { width: 100%; height: 100%; }
.msg__body { padding: 10px 14px; border-radius: 20px; font-size: 1em; overflow-wrap: anywhere; min-width: 0; }
.msg--assistant .msg__body { flex: 0 1 auto; max-width: 100%; }
/* Crisp Plate Rule: maths never smaller than the body text around it */
.msg__body .katex { font-size: 1.12em; overflow-wrap: normal; }
.msg__body > :last-child { margin-bottom: 0; }
.msg__body p { margin: 0 0 0.5em; }
.msg__body ul, .msg__body ol { margin: 0.2em 0 0.5em; padding-left: 1.2em; }
.msg--assistant .msg__body { background: var(--pink-50); border-top-left-radius: 6px; }
.msg--user { justify-content: flex-end; }
.msg--user .msg__body { background: linear-gradient(180deg, var(--pink-650), var(--pink-700)); color: #fff; border-top-right-radius: 6px; max-width: 85%; }
.msg--user .msg__body .katex { color: #fff; }
.msg__img { display: block; max-width: 200px; max-height: 180px; object-fit: cover; object-position: top; border-radius: 12px; margin-bottom: 6px; background: #fff; }
.msg__imgnote { font-size: 0.85rem; }
.msg .katex-display { overflow-x: auto; overflow-y: hidden; max-width: 100%; margin: 0.4em 0; padding: 4px 2px 6px; scrollbar-width: thin; scrollbar-color: var(--pink-300) transparent; }
.msg .katex-display > .katex { white-space: nowrap; }
.msg .katex-display.is-scrollable {
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
  border-radius: 8px;
}
.msg .katex-display.is-scrollable.is-end { -webkit-mask-image: none; mask-image: none; }
.msg .katex-display.is-scrollable:focus-visible { outline-offset: 0; }

.dots { display: inline-flex; gap: 4px; padding: 4px 2px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--pink-400); animation: dot 1s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 80%, 100% { transform: translateY(0); opacity: 0.5; } 40% { transform: translateY(-6px); opacity: 1; } }

.chat-fab, .chat-scrim { display: none; }

/* ---------- home ---------- */
/* Tonight's door: greeting, streak, one primary action, compact level line. */
.today {
  display: grid; grid-template-columns: clamp(84px, 13vw, 128px) minmax(0, 1fr); align-items: center;
  gap: clamp(12px, 2.5vw, 26px);
  background: linear-gradient(135deg, #fff 0%, var(--pink-50) 100%);
}
.today__pip { animation: bob 3.2s ease-in-out infinite; align-self: start; }
.today__pip svg { width: 100%; display: block; }
.today__main { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.today__greet { font-size: clamp(1.45rem, 2.8vw, 1.9rem); margin: 0; text-wrap: balance; }
.today__streak {
  align-self: flex-start; margin: 0;
  display: inline-flex; align-items: center; gap: 0.35em;
  padding: 0.4em 0.95em; border-radius: 999px;
  background: var(--pink-50); border: 2px solid var(--pink-100);
  font-weight: 800; font-size: 0.95rem; line-height: 1.3;
}
.today__streak.is-lit { background: #fff1d6; border-color: #ffe0a3; }

.go {
  display: flex; align-items: center; gap: clamp(12px, 2vw, 18px);
  padding: 16px 18px; border-radius: 22px;
  background: var(--surface); border: 2px solid var(--pink-200);
  box-shadow: 0 8px 22px -12px rgba(220, 70, 140, 0.45);
  color: var(--ink); text-decoration: none;
  transition: transform 0.18s cubic-bezier(.2,.8,.2,1), border-color 0.18s, box-shadow 0.18s;
}
.go:active { transform: scale(0.985); }
.go--loading { min-height: 96px; justify-content: center; border-style: dashed; box-shadow: none; }
.go__emoji { font-size: 2.4rem; line-height: 1; flex: none; }
.go__text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.go__label { font-family: var(--font-display); font-weight: 600; font-size: 0.98rem; color: var(--pink-700); }
.go__title { font-family: var(--font-display); font-weight: 600; font-size: clamp(1.2rem, 2.2vw, 1.4rem); line-height: 1.2; overflow-wrap: anywhere; }
.go__why { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; font-size: 0.9rem; color: var(--ink-soft); }
.go__why .mini-stars { margin: 0; padding: 0; font-size: 1rem; }
.go__cta { flex: none; pointer-events: none; }

.today__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 0.9rem; font-weight: 700; color: var(--ink-soft); }
.today__level { font-family: var(--font-display); font-weight: 600; color: var(--ink); }
.today__xp { font-variant-numeric: tabular-nums; }
.today__chip {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: 999px;
  background: var(--pink-50); color: var(--ink); text-decoration: none; font-weight: 800;
  transition: background 0.15s, transform 0.12s;
}
.today__chip:active { transform: scale(0.96);
}

.xpbar { position: relative; height: 26px; border-radius: 999px; background: var(--pink-100); overflow: hidden; }
.xpbar__fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--pink-400), var(--pink-500), var(--lilac)); background-size: 200% 100%; animation: shimmer 3s linear infinite; min-width: 26px; transition: width 0.6s cubic-bezier(.2,.8,.2,1); }
.xpbar span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 0.85rem; color: var(--ink); }
.xpbar--slim { height: 10px; width: clamp(90px, 16vw, 170px); flex: none; }
.xpbar--slim .xpbar__fill { min-width: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Bake a new lesson: two equal doors (type / photo), settings folded into one chip. */
.bake__head h2 { margin-bottom: 0.2em; }
.bake__head p { max-width: 62ch; }
.bake__doors { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 14px; margin-top: 6px; }
.door { min-width: 0; display: flex; flex-direction: column; }
.door__label { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; margin: 0 0 8px 4px; }
.bake textarea {
  width: 100%; resize: vertical; min-height: 76px;
  padding: 14px 16px; border-radius: 20px;
  border: 2px solid var(--pink-600); background: var(--pink-50);
  font-size: 16px; line-height: 1.4;
}
.ideas { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip--more { border-style: dashed; color: var(--pink-700); }

.door__photo {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 120px; padding: 18px 16px; border-radius: 22px;
  border: 2px dashed var(--pink-300); background: var(--pink-50); color: var(--ink);
  text-align: center;
  transition: background 0.18s, border-color 0.18s, transform 0.12s;
}
.door__photo:active:not(:disabled) { transform: scale(0.98); }
.door__photo:disabled { opacity: 0.7; cursor: progress; }
.door__icon { font-size: 2.3rem; line-height: 1; margin-bottom: 6px; }
.door__title { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; }
.door__sub { font-size: 0.88rem; color: var(--ink-soft); font-weight: 700; }

.photo-preview { flex: 1; display: flex; align-items: center; gap: 14px; min-width: 0; padding: 12px; border-radius: 22px; background: var(--pink-50); border: 2px solid var(--pink-200); }
.photo-preview img { width: 76px; height: 96px; flex: none; object-fit: cover; object-position: top; border-radius: 14px; border: 2px solid var(--pink-200); display: block; background: #fff; }
.photo-preview__info { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.photo-preview__label { font-size: 0.92rem; font-weight: 800; color: var(--ink); overflow-wrap: anywhere; }
.photo-preview__actions { display: flex; align-items: center; gap: 6px; }

.bake__go { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 14px; margin-top: 18px; }
.chip--prefs { max-width: 100%; min-width: 0; gap: 0.5em; font-size: 0.92rem; }
.chip--prefs__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip--prefs .icon { width: 18px; height: 18px; color: var(--pink-700); }
.chip--prefs[aria-expanded='true'] { background: var(--pink-100); border-color: var(--pink-300); }
.prefs { display: flex; flex-wrap: wrap; gap: 14px 18px; margin-top: 14px; padding: 16px; border-radius: 20px; background: var(--pink-50); }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-weight: 800; font-size: 0.85rem; color: var(--ink-soft); padding-left: 4px; }
.field select {
  min-height: 46px; padding: 0 36px 0 14px; border-radius: 999px;
  border: 2px solid var(--pink-600); background: var(--surface);
  appearance: none; max-width: 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23ec3f8a' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
  font-weight: 700;
}
.seg { display: inline-flex; padding: 4px; border-radius: 999px; background: var(--pink-100); gap: 2px; }
.seg button { border: 0; background: transparent; min-height: 44px; padding: 0 14px; border-radius: 999px; font-weight: 800; font-size: 0.9rem; white-space: nowrap; }
.seg button.is-on { background: var(--surface); box-shadow: var(--shadow-sm); color: var(--pink-700); }

/* My lessons: newest first, delete only in edit mode. */
.my-lessons .section-head { align-items: center; }
.lessons { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.lesson-card { position: relative; }
.lesson-card__link {
  display: flex; flex-direction: column; gap: 4px; height: 100%;
  padding: 18px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  border: 2px solid rgba(255, 166, 201, 0.35);
  text-decoration: none; color: var(--ink);
  transition: transform 0.15s, box-shadow 0.2s, border-color 0.15s;
}
.lesson-card__link:active { transform: scale(0.98); }
.lesson-card__emoji { font-size: 2.2rem; line-height: 1; margin-bottom: 4px; }
.lesson-card__title { font-family: var(--font-display); font-weight: 600; font-size: 1.12rem; line-height: 1.2; overflow-wrap: anywhere; }
.lesson-card__meta { font-size: 0.85rem; color: var(--ink-soft); }
.mini-stars { margin-top: auto; padding-top: 6px; letter-spacing: 2px; color: var(--pink-50); -webkit-text-stroke: 1.5px var(--pink-600); font-size: 1.1rem; }
.mini-stars .on { color: var(--gold); -webkit-text-stroke: 0; text-shadow: 0 1px 0 #e0a420; }
.lesson-card__del {
  display: none; position: absolute; top: 8px; right: 8px; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid var(--coral); background: var(--coral-soft); color: var(--ink);
  transition: background 0.15s, transform 0.12s;
}
.lesson-card__del .icon { width: 20px; height: 20px; }
.lesson-card__del:active { transform: scale(0.94); }
.lessons.is-editing .lesson-card__del { display: grid; animation: popIn 0.25s cubic-bezier(.3,1.5,.5,1); }
.lessons.is-editing .lesson-card__link { border-style: dashed; border-color: var(--pink-300); cursor: default; }
.lessons.is-editing .lesson-card__title { padding-right: 40px; }

@media (hover: hover) {
  .go:hover { border-color: var(--pink-400); transform: translateY(-2px); box-shadow: 0 14px 28px -14px rgba(220, 70, 140, 0.55); }
  .door__photo:hover:not(:disabled) { background: var(--pink-100); border-style: solid; }
  .today__chip:hover { background: var(--pink-100); }
  .lessons:not(.is-editing) .lesson-card__link:hover { transform: translateY(-3px) rotate(-0.5deg); }
  .lesson-card__del:hover { background: #ffd6dc; }
}

.empty { text-align: center; color: var(--ink-soft); }
.loading-card { display: grid; place-items: center; padding: 40px; }

/* ---------- lesson ---------- */
.lesson { display: flex; flex-direction: column; gap: 16px; max-width: 760px !important; }
.lesson__top { display: flex; align-items: center; gap: 12px; }
.bar { flex: 1; height: 18px; border-radius: 999px; background: var(--pink-100); overflow: hidden; }
.bar__fill { width: 100%; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--pink-400), var(--pink-500)); transform: scaleX(0); transform-origin: left center; transition: transform 0.5s cubic-bezier(.2,.8,.2,1); box-shadow: inset 0 -4px 0 rgba(196,42,110,0.12), inset 0 4px 0 rgba(255,255,255,0.35); }
.combo { font-family: var(--font-display); font-weight: 700; padding: 6px 12px; border-radius: 999px; background: var(--pink-50); color: var(--ink-soft); box-shadow: var(--shadow-sm); transition: background 0.2s; }
.combo[hidden] { display: none; }
.combo.is-hot { background: #fff1d6; color: var(--ink); }
.combo.pop { animation: pop 0.4s; }

.step { position: relative; }
.step h1, .step h2 { color: var(--ink); }
.step--intro, .step--done { text-align: center; }
.step__emoji { font-size: 3.6rem; line-height: 1; margin-bottom: 8px; animation: bob 3s ease-in-out infinite; }
.step__actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; align-items: center; margin-top: 20px; }
.step--intro .step__actions, .step__actions--center { justify-content: center; }
.step--intro .btn--big { margin-top: 10px; }
.question { font-size: 1.2rem; font-weight: 700; margin-bottom: 18px; }
.question .katex { font-size: 1.15em; }
.rich .katex-display { overflow-x: auto; overflow-y: hidden; padding: 6px 0; }
.rich ul, .rich ol { padding-left: 1.3em; }
.rich table { border-collapse: collapse; margin: 0.5em 0; }
.rich td, .rich th { border: 1px solid var(--pink-200); padding: 4px 10px; }

/* ---------- figures (graphs, sketches, tree diagrams, number lines, bar charts) ---------- */
.fig { margin: 0.75em auto; max-width: 520px; font-family: var(--font-body); }
.fig__board, .fig__canvas { position: relative; width: 100%; background: var(--surface); border: 2px solid var(--pink-100); border-radius: var(--radius-sm); overflow: hidden; }
.fig.is-interactive .fig__board { border-color: var(--pink-200); }
.fig__caption { margin-top: 6px; text-align: center; font-size: 0.9rem; color: var(--ink-soft); }
.fig__caption .katex { font-size: 1.05em; }
/* JSXGraph text (labels, tick numbers); colour and size come from board.js */
.fig__txt { font-family: var(--font-body); font-weight: 700; line-height: 1.1; white-space: nowrap; padding: 1px 3px; text-shadow: 0 0 3px var(--surface), 0 0 3px var(--surface), 0 0 2px var(--surface); }
.fig__txt .katex { font-size: 1.05em; }
.fig__txt--tick { font-weight: 600; }
.fig__txt--fn { font-weight: 800; }
/* sliders under an interactive graph */
.fig__sliders { display: grid; gap: 2px; margin-top: 8px; padding: 4px 12px; background: var(--pink-50); border-radius: var(--radius-sm); }
.fig__slider { display: grid; grid-template-columns: minmax(2.2em, auto) 1fr 3.6em; align-items: center; gap: 12px; min-height: 44px; font-weight: 700; }
.fig__slider input[type='range'] { width: 100%; accent-color: var(--pink-650); min-height: 32px; margin: 0; }
.fig__slider-value { font-family: var(--font-display); font-variant-numeric: tabular-nums; text-align: right; color: var(--pink-700); }
/* tree diagrams are plain SVG with HTML labels laid over them */
.fig__canvas svg { display: block; width: 100%; height: 100%; overflow: visible; }
.fig__canvas svg * { vector-effect: non-scaling-stroke; }
.fig__branch { stroke: var(--ink-soft); stroke-width: 1.75; fill: none; }
.fig__point { fill: var(--pink-700); stroke: var(--surface); stroke-width: 2; }
.fig .is-dashed { stroke-dasharray: 7 5; }
.fig__labels { position: absolute; inset: 0; pointer-events: none; }
.fig__lbl {
  position: absolute; white-space: nowrap; line-height: 1.1; font-size: 0.92rem; font-weight: 700; color: var(--ink);
  text-shadow: 0 0 3px var(--surface), 0 0 3px var(--surface), 0 0 2px var(--surface);
  transform: translate(-50%, -50%);
}
.fig__lbl .katex { font-size: 1.05em; }
.fig__lbl--n { transform: translate(-50%, -100%); }
.fig__lbl--s { transform: translate(-50%, 0); }
.fig__lbl--e { transform: translate(0, -50%); }
.fig__lbl--w { transform: translate(-100%, -50%); }
.fig__lbl--ne { transform: translate(0, -100%); }
.fig__lbl--nw { transform: translate(-100%, -100%); }
.fig__lbl--se { transform: translate(0, 0); }
.fig__lbl--sw { transform: translate(-100%, 0); }
.fig__lbl--tick { font-size: 0.74rem; font-weight: 600; color: var(--ink-soft); }
.fig__lbl--axis { font-size: 0.85rem; color: var(--ink-soft); }
.fig__lbl--small, .fig__lbl--prob { font-size: 0.82rem; }
.fig__lbl--area { color: var(--ink); font-size: 0.85rem; }
.fig__lbl--result { font-size: 0.85rem; color: var(--pink-700); }
.fig__node { background: var(--pink-50); border: 2px solid var(--pink-200); border-radius: 999px; padding: 2px 8px; text-shadow: none; }
.fig--error { display: flex; gap: 8px; align-items: center; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--pink-50); color: var(--ink-soft); font-size: 0.9rem; }
.msg__body .fig { margin: 0.5em 0; }
.msg__body .fig__lbl, .msg__body .fig__txt { font-size: 0.82rem !important; }
.msg__body .fig__lbl--tick, .msg__body .fig__txt--tick { font-size: 0.68rem !important; }
.msg--user .msg__body .fig__lbl, .msg--user .msg__body .fig .katex, .msg--user .msg__body .fig__caption, .msg--user .msg__body .fig__slider { color: var(--ink); }

.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.options--tf { grid-template-columns: 1fr 1fr; }
.option {
  min-height: 60px; padding: 12px 16px;
  border: 3px solid var(--pink-100); border-radius: 20px;
  background: var(--surface);
  font-weight: 700; font-size: 1.08rem; text-align: left;
  box-shadow: 0 4px 0 var(--pink-100);
  transition: transform 0.1s, border-color 0.15s, background 0.15s, box-shadow 0.1s;
}
.option--tf { text-align: center; font-family: var(--font-display); font-size: 1.2rem; min-height: 72px; }
@media (hover: hover) {
  .option:hover:not(:disabled) { border-color: var(--pink-300); background: var(--pink-50); }
  .key:hover { background: var(--pink-200); }
}
.option:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--pink-100); }
.option.is-selected { border-color: var(--pink-500); background: var(--pink-50); box-shadow: 0 4px 0 var(--pink-400); }
.option.is-wrong { border-color: var(--coral); background: var(--coral-soft); box-shadow: 0 4px 0 #f5b5be; color: var(--ink-soft); text-decoration: line-through; text-decoration-color: var(--coral); }
.option.is-right { border-color: var(--mint); background: var(--mint-soft); box-shadow: 0 4px 0 #9fe3cc; }
.option:disabled { cursor: default; }
.option .katex, .chip .katex { font-size: 1.15em; }
/* Maths is set in display style (see disp() in lesson.js); give tall fractions room in the line. */
.option, .order-pool .chip, .chip--placed, .question { line-height: 1.6; }
.option .katex .mfrac, .chip .katex .mfrac, .question .katex .mfrac { padding: 0 0.1em; }

.answer__input {
  width: 100%; min-height: 64px; padding: 12px 20px;
  border: 3px solid var(--pink-600); border-radius: 20px;
  background: var(--pink-50);
  font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; text-align: center;
}
.keypad { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; justify-content: center; }
.key { min-width: 48px; min-height: 44px; padding: 0 10px; border: 0; border-radius: 14px; background: var(--pink-100); font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; }
.key:active { transform: scale(0.93); background: var(--pink-200); }

.order-slots { list-style: none; counter-reset: slot; padding: 12px; margin: 0 0 12px; min-height: 64px; border-radius: 20px; border: 3px dashed var(--pink-200); background: var(--pink-50); display: flex; flex-direction: column; gap: 8px; }
.order-slots:empty::before { content: attr(data-empty); color: var(--ink-soft); font-size: 0.95rem; text-align: center; padding: 8px; }
.order-slots li { counter-increment: slot; display: flex; align-items: center; gap: 8px; }
.order-slots li::before { content: counter(slot); width: 28px; height: 28px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--pink-700); color: #fff; font-weight: 800; font-size: 0.85rem; }
.order-pool { display: flex; flex-wrap: wrap; gap: 8px; }
.chip--placed { border-color: var(--pink-400); flex: 1; justify-content: flex-start; text-align: left; }
.order-pool .chip, .chip--placed { border-radius: 16px; min-height: 52px; text-align: left; }

.hints { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.hint { display: flex; gap: 10px; padding: 12px 14px; border-radius: 16px; background: #fff8e1; border: 2px solid #ffe7a3; font-size: 0.98rem; }
.hint.is-new { animation: slideIn 0.35s ease; }
.explain { margin-top: 14px; padding: 14px 16px; border-radius: 18px; background: var(--mint-soft); border: 2px solid #a6ead2; animation: slideIn 0.35s ease; }
.explain > :last-child { margin-bottom: 0; }
.step.is-correct { border-color: #a6ead2; }
.wiggle { animation: wiggle 0.6s ease 2; }

.lesson__pip { display: flex; align-items: center; gap: 12px; min-height: 84px; }
.pip-wrap { width: 84px; flex: none; }
.pip-wrap svg { width: 100%; display: block; }
.pip-wrap--bounce { animation: pop 0.45s ease; }
.speech { position: relative; padding: 10px 16px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow-sm); font-family: var(--font-display); font-weight: 600; animation: slideIn 0.3s ease; }
.speech::before { content: ''; position: absolute; left: -8px; top: 50%; transform: translateY(-50%) rotate(45deg); width: 16px; height: 16px; background: var(--surface); }

.stars { display: flex; justify-content: center; gap: 10px; margin: 6px 0 18px; }
.star { font-size: clamp(3rem, 10vw, 4.4rem); line-height: 1; color: var(--pink-50); -webkit-text-stroke: 2.5px var(--pink-600); }
.star.is-on { color: var(--gold); -webkit-text-stroke: 0; text-shadow: 0 4px 0 #e0a420; animation: starIn 0.5s var(--d) both cubic-bezier(.3,1.6,.5,1); }
.tally { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; }
.tally > div { min-width: 96px; padding: 12px 14px; border-radius: 18px; background: var(--pink-50); display: flex; flex-direction: column; align-items: center; }
.tally strong { font-family: var(--font-display); font-size: 1.6rem; color: var(--pink-600); line-height: 1.1; }
.tally span { font-size: 0.82rem; color: var(--ink-soft); font-weight: 700; }

.lesson [data-step-head]:focus { outline: none; }
.lesson [data-step-head]:focus-visible { outline: 3px solid var(--pink-650); outline-offset: 4px; border-radius: 8px; }
.answer__formats { margin: 8px 0 0; text-align: center; font-size: 0.95rem; color: var(--ink-soft); font-weight: 600; }
.key[data-key="·"] { font-size: 1.6rem; line-height: 1; }
.key__var { font-family: 'Times New Roman', 'Cambria Math', serif; font-size: 1.25rem; font-weight: 600; }
.gate { margin: 14px 0 0; padding: 10px 14px; border-radius: 16px; background: var(--pink-50); border: 2px dashed var(--pink-200); font-weight: 700; text-align: center; }
.explain__note { margin: 10px 0 0; font-weight: 700; color: var(--ink-soft); }
.walk { margin-top: 14px; padding: 16px 18px; border-radius: 20px; background: var(--pink-50); border: 2px solid var(--pink-100); }
.walk__loading { display: flex; align-items: center; gap: 10px; margin: 0; color: var(--ink-soft); font-weight: 700; }
.walk ol { margin: 0.6em 0; }
.walk li + li { margin-top: 0.35em; }
.step__sub { max-width: 46ch; margin: 4px auto 12px; color: var(--ink-soft); font-weight: 600; text-wrap: balance; }
.streak-note { display: inline-block; margin: 0 0 16px; padding: 8px 16px; border-radius: 999px; background: var(--pink-50); font-family: var(--font-display); font-weight: 700; }
.streak-note.is-secured { background: #fff1d6; box-shadow: var(--shadow-sm); animation: pop 0.4s; }
.review { margin-top: 22px; text-align: left; }
.review h2 { font-size: 1.12rem; margin: 0 0 10px; }
.review__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.review__item { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-radius: 18px; background: var(--pink-50); }
.review__q { flex: 1; min-width: 0; font-weight: 600; }
.review__q > :last-child { margin-bottom: 0; }
.review__q > :first-child { margin-top: 0; }
.review__tag { flex: none; padding: 4px 10px; border-radius: 999px; background: var(--surface); font-size: 0.82rem; font-weight: 800; color: var(--ink-soft); white-space: nowrap; }
.lesson__pip--inline { min-height: 0; margin-top: 14px; }

@media (max-width: 600px) {
  .lesson { gap: 12px; }
  .lesson__pip--inline .pip-wrap { width: 52px; }
  .lesson__pip--inline .speech { font-size: 0.95rem; padding: 8px 12px; }
  .keypad { gap: 6px; }
  .key { flex: 1 0 calc(25% - 6px); min-width: 0; }
  .review__item { flex-direction: column; gap: 6px; }
  .step--done .step__actions .btn--big { order: -1; }
}

/* Form fields: pink-600 stroke (3:1); focus deepens it, turns the fill white and adds a soft halo. */
.chat__row textarea:focus,
.bake textarea:focus,
.answer__input:focus,
.login__card input:focus,
.field select:focus { outline: none; border-color: var(--pink-700); background-color: #fff; box-shadow: 0 0 0 4px var(--pink-100); }

/* ---------- stickers & shop ---------- */
.shop-hero { display: flex; align-items: center; gap: 20px; }
.shop-hero__pip { width: clamp(100px, 20vw, 150px); flex: none; animation: bob 3s ease-in-out infinite; }
.shop-hero__pip svg { width: 100%; display: block; }
.sweets-big { font-family: var(--font-display); font-weight: 700; font-size: 1.8rem; margin: 0; }
.sweets-big span { font-size: 1rem; color: var(--ink-soft); font-weight: 600; }
.shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.shop-item { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 12px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); border: 3px solid transparent; text-align: center; }
.shop-item.is-on { border-color: var(--pink-400); }
.shop-item__pip { width: 84px; }
.shop-item .btn { min-height: 44px; width: 100%; }
.stickers { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.sticker { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; padding: 16px 10px; border-radius: var(--radius); background: rgba(255, 255, 255, 0.6); border: 3px dashed var(--pink-200); color: var(--ink-soft); }
.sticker__emoji { width: 64px; height: 64px; display: grid; place-items: center; border-radius: 50%; background: var(--pink-100); font-size: 2rem; font-family: var(--font-display); font-weight: 700; color: var(--pink-650); margin-bottom: 6px; }
.sticker small { font-size: 0.78rem; line-height: 1.3; }
.sticker.is-got { background: var(--surface); border: 3px solid var(--pink-200); color: var(--ink); box-shadow: var(--shadow-sm); transform: rotate(-1.5deg); }
.sticker.is-got:nth-child(even) { transform: rotate(1.5deg); }
.sticker.is-got .sticker__emoji { background: linear-gradient(135deg, var(--pink-100), var(--lilac-soft)); box-shadow: 0 0 0 4px #fff, 0 0 0 6px var(--pink-200); }
.stats .tally { justify-content: flex-start; }

/* ---------- modal, toast, float ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(91, 35, 70, 0.35); backdrop-filter: blur(4px); animation: fadeIn 0.2s; }
.modal__card { width: min(420px, 100%); text-align: center; background: var(--surface); border-radius: 32px; padding: 28px 24px; box-shadow: 0 30px 60px -20px rgba(91, 35, 70, 0.5); animation: popIn 0.4s cubic-bezier(.3,1.5,.5,1); }
.modal__pip { width: 130px; margin: -70px auto 6px; }
.modal__pip svg { width: 100%; display: block; }
.modal__title { font-size: 1.1rem; margin-bottom: 18px; }
.modal h2 { font-size: 2rem; color: var(--pink-600); }
.modal--baking .modal__pip { margin-top: 0; width: 120px; }
.pip-wrap--bob { animation: bob 1.4s ease-in-out infinite; }
.baking-line { font-weight: 800; min-height: 1.5em; }
.oven { height: 14px; border-radius: 999px; background: var(--pink-100); overflow: hidden; margin: 14px 0 10px; }
/* Indeterminate but honest: JS eases the width toward (never to) the end; a soft glaze drifts inside it. */
.oven__fill {
  height: 100%; width: 6%; border-radius: 999px;
  background: linear-gradient(90deg, var(--pink-300), var(--pink-500) 60%, var(--pink-300)) 0 0 / 200% 100%;
  transition: width 1s linear;
  animation: glaze 2.4s ease-in-out infinite alternate;
}
@keyframes glaze { from { background-position: 0 0; } to { background-position: 100% 0; } }
.modal--baking .btn { margin-top: 6px; }
.baking-time { font-variant-numeric: tabular-nums; }

/* confirm dialogs (logout, delete) */
.modal--confirm .modal__card { padding-top: 22px; }
.modal__pip--small { width: 92px; margin: -64px auto 4px; }
.modal h2.modal__q { font-size: 1.5rem; color: var(--ink); text-wrap: balance; }
.modal__body { color: var(--ink-soft); max-width: 36ch; margin: 0 auto 20px; }
.modal__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.modal__actions .btn { flex: 1 1 140px; }
.modal__card:focus { outline: none; }

.toasts { position: fixed; top: calc(var(--topbar-h) + 10px + env(safe-area-inset-top)); right: calc(var(--chat-w) + 16px); z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 12px; max-width: 340px; padding: 12px 16px; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); border: 2px solid var(--pink-200); animation: toastIn 0.4s cubic-bezier(.3,1.5,.5,1); pointer-events: auto; font-size: 0.95rem; }
.toast.is-leaving { animation: toastOut 0.4s forwards; }
.toast__emoji { font-size: 2rem; line-height: 1; }
.float-text { position: fixed; z-index: 130; transform: translate(-50%, 0); font-family: var(--font-display); font-weight: 700; font-size: 1.6rem; color: var(--pink-600); text-shadow: 0 2px 0 #fff, 0 0 12px #fff; pointer-events: none; animation: floatUp 1.4s ease-out forwards; }
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 140; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; padding: 20px; }
.login { width: min(400px, 100%); text-align: center; }
.login__pip { width: 150px; margin: 0 auto -6px; animation: bob 3s ease-in-out infinite; }
.login__pip svg { width: 100%; display: block; }
.login__title { font-size: 3rem; margin: 0; }
.login__title em { font-style: normal; color: var(--pink-600); }
.login__tag { color: var(--ink-soft); font-weight: 700; margin-bottom: 22px; }
.login__card { text-align: left; display: flex; flex-direction: column; gap: 10px; }
.login__card label { font-weight: 800; padding-left: 6px; }
.login__card input { min-height: 56px; padding: 0 20px; border-radius: 999px; border: 3px solid var(--pink-600); background: var(--pink-50); font-size: 1.1rem; }
.login__error { color: var(--pink-700); font-weight: 700; min-height: 1.5em; margin: 0; padding-left: 6px; }

/* ---------- animations ---------- */
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
@keyframes pop { 0% { transform: scale(0.8); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes popIn { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideIn { from { transform: translateY(8px); opacity: 0; } }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } to { transform: scale(1) rotate(0); } }
@keyframes toastIn { from { transform: translateX(40px) scale(0.9); opacity: 0; } }
@keyframes toastOut { to { transform: translateX(40px); opacity: 0; } }
@keyframes floatUp { 0% { transform: translate(-50%, 0) scale(0.6); opacity: 0; } 20% { transform: translate(-50%, -20px) scale(1.1); opacity: 1; } 100% { transform: translate(-50%, -90px) scale(1); opacity: 0; } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }
.shake { animation: shake 0.45s; }
@keyframes shake { 20% { transform: translateX(-10px); } 40% { transform: translateX(9px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  :root { --chat-w: 330px; }
  /* emoji-only links, but the label stays in the accessibility tree */
  .nav__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* Tablet portrait & phones: chat becomes a slide-over panel */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: 'top' 'main'; }
  .chat {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: min(420px, 100%);
    transform: translateX(105%);
    transition: transform 0.3s cubic-bezier(.2,.8,.2,1);
    border-radius: 28px 0 0 28px;
    overflow: hidden;
    visibility: hidden;
  }
  body.chat-open .chat { transform: none; visibility: visible; }
  .chat__close { display: inline-grid; }
  .chat-scrim { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(91, 35, 70, 0.3); opacity: 0; pointer-events: none; transition: opacity 0.3s; }
  body.chat-open .chat-scrim { opacity: 1; pointer-events: auto; }
  .chat-fab {
    display: inline-flex; align-items: center; gap: 8px;
    position: fixed; z-index: 10;
    right: calc(16px + env(safe-area-inset-right)); bottom: calc(16px + env(safe-area-inset-bottom));
    min-height: 60px; padding: 0 22px 0 18px;
    border: 0; border-radius: 999px;
    background: linear-gradient(180deg, var(--pink-650), var(--pink-700));
    color: #fff; font-family: var(--font-display); font-weight: 600; font-size: 1.1rem;
    box-shadow: 0 5px 0 var(--pink-800), 0 14px 26px -8px rgba(212, 47, 128, 0.7);
  }
  .chat-fab:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--pink-800); }
  .toasts { right: 12px; left: 12px; align-items: center; }
}

@media (max-width: 600px) {
  :root { --topbar-h: 60px; }
  body { font-size: 16px; }
  .brand__name { display: none; }
  .brand__pip { width: 42px; height: 42px; }
  .nav { margin-left: 0; }
  .nav a { padding: 0 10px; font-size: 1.15rem; }
  .hud { gap: 5px; }
  .lang-toggle button { min-width: 40px; padding: 0 6px; font-size: 0.8rem; }
  .field, .field select { width: 100%; }
  .hud__item { padding: 5px 9px; font-size: 0.9rem; }
  .hud__ring { width: 38px; height: 38px; }
  .today { grid-template-columns: 64px minmax(0, 1fr); align-items: start; gap: 12px; }
  .today__main { display: contents; }
  .today__pip { grid-column: 1; grid-row: 1; }
  .today__greet { grid-column: 2; grid-row: 1; align-self: center; font-size: 1.4rem; }
  .today__streak, .today__go, .today__meta { grid-column: 1 / -1; }
  .today__streak { font-size: 0.86rem; padding: 0.4em 0.8em; }
  .today__meta { gap: 6px 10px; }
  .go { flex-wrap: wrap; gap: 6px 12px; padding: 14px; }
  .go__emoji { font-size: 2rem; }
  .go__label { font-size: 0.88rem; }
  .go__cta { flex: 1 1 100%; margin-top: 6px; }
  .bake__head p { display: none; } /* the two doors say it */
  .bake__doors { grid-template-columns: 1fr; gap: 12px; }
  .door--photo { order: -1; } /* on a phone, snapping the worksheet comes first */
  /* photo is a first-class phone action: solid, filled, full width */
  .door__photo {
    display: grid; grid-template-columns: auto 1fr; align-items: center; justify-items: start; column-gap: 14px; row-gap: 0;
    min-height: 80px; padding: 14px 18px; text-align: left;
    border-style: solid; border-color: var(--pink-300); background: var(--pink-100);
  }
  .door__photo .door__icon { grid-row: 1 / span 2; margin: 0; font-size: 2.1rem; }
  .bake__go .btn--primary { flex: 1 1 100%; order: 2; }
  .chip--prefs { flex: 1 1 100%; justify-content: space-between; order: 1; }
  .prefs { flex-direction: column; order: 1; }
  .seg { width: 100%; }
  .seg button { flex: 1; padding: 0 8px; }
  .options { grid-template-columns: 1fr; }
  .options--tf { grid-template-columns: 1fr 1fr; }
  .step__actions { justify-content: stretch; }
  .step__actions .btn { flex: 1 1 auto; }
  .step__actions .btn--big { flex-basis: 100%; order: 10; }
  .lessons { grid-template-columns: 1fr 1fr; gap: 10px; }
  .lesson-card__link { padding: 14px; }
  .shop-hero { flex-direction: column; text-align: center; }
  .chat { border-radius: 0; }
  .chat-fab span { display: none; }
  .chat-fab { padding: 0; width: 60px; justify-content: center; font-size: 1.5rem; }
  .pip-wrap { width: 64px; }
}

/* Small phones: the streak is the reason to come back, so it stays; sweets (also on home) and the
   brand mark (the 🏠 link goes home too) give way so the logout button is never clipped. */
@media (max-width: 420px) {
  .brand, .hud__sweets { display: none; }
  .topbar { gap: 6px; padding-inline: 10px; }
  .nav a { padding: 0 9px; }
  .hud { gap: 4px; }
  .hud__item { padding: 5px 8px; }
  .lang-toggle button { min-width: 40px; padding: 0 5px; }
}
@media (max-width: 380px) {
  .lessons { grid-template-columns: 1fr; }
}

/* in a lesson on phones, keep the floating button clear of the action buttons */
@media (max-width: 900px) {
  /* lesson steps have their own "Pip fragen" button (#ask), so the floating one would only cover the
     actions. Intro and finish screens have none, so the FAB stays there. */
  body.in-lesson .chat-fab { bottom: calc(16px + env(safe-area-inset-bottom)); }
  body.in-lesson:has(#view #ask) .chat-fab { display: none; }
}
