:root {
  --bg: #fdf6ee;
  --card: #fffaf5;
  --ink: #3d2b4f;
  --muted: #8f8199;
  --accent: #c8602a;
  --accent-ink: #ffffff;
  --peach: #fbe3d3;
  --line: #eee2d8;
  --pill: #ffffff;
  --shadow: 0 1px 2px rgba(61, 43, 79, .06), 0 6px 18px rgba(61, 43, 79, .06);
  --radius: 18px;
  --display: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1822;
    --card: #28212f;
    --ink: #f3e9f7;
    --muted: #b1a3bc;
    --accent: #f08a4f;
    --accent-ink: #1d1822;
    --peach: #3b2a2a;
    --line: #3a3042;
    --pill: #241e2a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="dark"] {
  --bg: #1d1822; --card: #28212f; --ink: #f3e9f7; --muted: #b1a3bc; --accent: #f08a4f;
  --accent-ink: #1d1822; --peach: #3b2a2a; --line: #3a3042; --pill: #241e2a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--body);
  min-height: 100vh;
}
button, input, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.15; margin: 0; }

#app { max-width: 600px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
.screen { padding-top: 20px; animation: rise .25s ease-out; }
.screen.center { min-height: 80vh; display: grid; place-items: center; text-align: center; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .screen { animation: none; } }

.kicker { font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Banner */
.banner {
  background: var(--peach);
  border-radius: var(--radius);
  padding: 22px 20px;
  margin-bottom: 18px;
}
.banner h1 { font-size: clamp(28px, 7vw, 38px); margin: 4px 0 6px; }
.banner p { margin: 0; color: var(--muted); }
.mascot { font-size: 56px; line-height: 1; margin-bottom: 8px; }

/* Commissioned art */
figure { margin: 0; }
figure img { display: block; width: 100%; height: auto; }
.credit { font-size: 11px; color: var(--muted); font-style: italic; }
.hero-art { width: min(240px, 62vw); margin: 0 auto 10px; }
.hero-art img { filter: drop-shadow(0 8px 16px rgba(61, 43, 79, .18)); animation: bob 4s ease-in-out infinite; }
.hero-art .credit { margin-top: 2px; }
@keyframes bob { 50% { transform: translateY(-4px) rotate(-1deg); } }
@media (prefers-reduced-motion: reduce) { .hero-art img { animation: none; } }
.credit a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.welcome-art { width: min(260px, 68vw); margin: 4px auto 12px; text-align: center; }
.welcome-art img { filter: drop-shadow(0 8px 16px rgba(61, 43, 79, .18)); }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 19px; }
.card .detail { color: var(--muted); font-size: 14px; margin-top: 2px; }
.row { margin-top: 12px; }
.row-label { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }

/* Answer pills */
.pills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pills.n2, .pills.n4 { grid-template-columns: repeat(2, 1fr); }
.pills.n7 { grid-template-columns: repeat(4, 1fr); }
.pills.choice { grid-template-columns: 1fr; }
@media (min-width: 560px) {
  .pills.n6 { grid-template-columns: repeat(6, 1fr); }
  .pills.n4 { grid-template-columns: repeat(4, 1fr); }
  .pills.choice { grid-template-columns: repeat(2, 1fr); }
  .pills.n7 { grid-template-columns: repeat(7, 1fr); }
  .pills.n7 .pill { font-size: 12px; padding: 9px 2px; }
}

/* Answer key */
.key-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 7px; }
.key-list li { display: grid; grid-template-columns: 104px 1fr; gap: 10px; align-items: center; font-size: 13px; line-height: 1.3; }
.key-list .chip { text-align: center; white-space: nowrap; }
.key-list .chip.blank { background: var(--line); color: var(--ink); }
.key-list .meaning { color: var(--muted); }
.key-drawer { margin-top: 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.key-drawer summary { cursor: pointer; padding: 8px 12px; font-weight: 700; font-size: 14px; list-style: none; }
.key-drawer summary::-webkit-details-marker { display: none; }
.key-drawer summary::after { content: '▾'; float: right; color: var(--muted); }
.key-drawer[open] summary::after { content: '▴'; }
.key-drawer .key-list { margin: 0; padding: 0 12px 12px; max-height: 50vh; overflow: auto; }
.key-float { display: none; }
@media (min-width: 1100px) {
  .key-drawer { display: none; }
  .key-float {
    display: block; position: fixed; top: 96px; left: calc(50% + 320px); width: 250px;
    max-height: calc(100vh - 150px); overflow: auto;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 14px 16px; box-shadow: var(--shadow);
  }
  .key-float h3 { font-size: 16px; }
  .key-float .key-list li { grid-template-columns: 1fr; gap: 2px; }
  .key-float .key-list .chip { justify-self: start; }
}
.pill {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--pill);
  border-radius: 14px;
  padding: 9px 4px;
  min-height: 46px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.15;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: transform .08s ease, background-color .12s ease, border-color .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.pill .emo { font-size: 17px; line-height: 1; }
.pills.choice .pill { flex-direction: row; justify-content: flex-start; padding: 10px 14px; text-align: left; gap: 8px; }
.pill:active { transform: scale(.96); }
.pill[aria-pressed="true"] { border-color: transparent; color: #3d2b4f; font-weight: 700; box-shadow: inset 0 0 0 2px rgba(61, 43, 79, .18); }
.pill:focus-visible, .btn:focus-visible, input:focus-visible, textarea:focus-visible, .choice-card:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

/* Forms */
label.field { display: block; margin: 14px 0; }
label.field span { display: block; font-weight: 700; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  background: var(--pill);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 16px;
}
textarea { min-height: 96px; resize: vertical; }
.error { color: #c0392b; font-weight: 700; min-height: 24px; margin: 8px 0 0; }
@media (prefers-color-scheme: dark) { .error { color: #ff8a7a; } }

/* Buttons */
.btn {
  appearance: none; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: 16px;
  border-radius: 999px; padding: 13px 22px; min-height: 48px;
}
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

/* Welcome choices */
.choice-card {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin: 12px 0; box-shadow: var(--shadow);
}
.choice-card .emo { font-size: 32px; }
.choice-card h2 { font-size: 22px; margin: 6px 0 4px; }
.choice-card p { margin: 0; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.chip { border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 700; color: #3d2b4f; }

/* Section header + progress */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 12px 0 8px;
  margin: 0 -16px; padding-left: 16px; padding-right: 16px;
}
.progress { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s ease; }
.topbar .meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 6px; }
.section-head { margin: 10px 0 4px; }
.section-head .emo { font-size: 40px; line-height: 1; }
.section-head h2 { font-size: 28px; margin-top: 6px; }
.section-head p { margin: 4px 0 0; color: var(--muted); }

/* Sticky footer nav */
.navbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.navbar .inner { max-width: 600px; margin: 0 auto; display: flex; gap: 10px; }
.navbar .btn { flex: 1; }

/* Results */
.result-card { border-radius: var(--radius); padding: 16px; margin: 12px 0; color: #3d2b4f; }
.result-card h3 { font-size: 19px; margin-bottom: 8px; }
.result-card p { margin: 6px 0 0; font-size: 14px; }
.result-card b { font-weight: 800; }
.linkbox { display: flex; gap: 8px; margin-top: 10px; }
.linkbox input { font-size: 13px; }
.footer-note { text-align: center; color: var(--muted); font-size: 13px; margin: 28px 0 8px; font-style: italic; }
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.toggle-row { display: flex; gap: 8px; flex-wrap: wrap; }
.toggle-row .pill { flex: 1 1 140px; flex-direction: row; gap: 8px; }
.toggle-row .pill[aria-pressed="true"] { background: var(--peach); color: var(--ink); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
