@font-face { font-family: "Fredoka"; src: url("/fonts/fredoka.woff2") format("woff2"); font-weight: 300 700; font-display: swap; }
@font-face { font-family: "Nunito"; src: url("/fonts/nunito.woff2") format("woff2"); font-weight: 200 1000; font-display: swap; }

:root {
  color-scheme: only light;
  --ink: #1f2440;
  --ink-soft: #565d7e;
  --line: #dfe3f0;
  --surface: #f3f5fb;
  --primary: #5b3fe0;
  --primary-dark: #4429c2;
  --primary-soft: #ece8ff;
  --danger: #c0392b;
  --radius: 20px;
  --display: "Fredoka", "Nunito", system-ui, sans-serif;
  --body: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: #fff; color: var(--ink); font-family: var(--body); font-size: 18px; line-height: 1.45; }
h1, h2, h3, p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); }
.icon { width: 24px; height: 24px; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }

/* ---------- top bar ---------- */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 1120px; margin: 0 auto; padding: 14px 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-family: var(--display); font-weight: 600; font-size: 26px; letter-spacing: 0.2px; }
.brand img { width: 36px; height: 36px; display: block; }
.bar-link { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border: 2px solid var(--line); border-radius: 999px; text-decoration: none; color: var(--ink); font-weight: 800; font-size: 16px; background: #fff; }
.bar-link { white-space: nowrap; }
@media (max-width: 480px) { .brand { font-size: 22px; gap: 8px; } .brand img { width: 32px; height: 32px; } .bar-link { padding: 0 12px; font-size: 15px; gap: 6px; } }
.bar-link:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 56px; padding: 0 24px; border-radius: 999px; border: 2px solid var(--line); background: #fff; font-family: var(--display); font-weight: 600; font-size: 20px; text-decoration: none; color: var(--ink); }
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 0 var(--primary-dark); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--primary-dark); }
.btn[disabled] { opacity: 0.55; cursor: default; }
.btn-round { width: 48px; min-height: 48px; height: 48px; padding: 0; }
.btn-small { min-height: 44px; font-size: 17px; padding: 0 18px; }

/* ---------- home ---------- */
.home { max-width: 1120px; margin: 0 auto; padding: 8px 16px 48px; }
.hero { padding: 12px 0 24px; }
.hero h1 { font-family: var(--display); font-weight: 600; font-size: clamp(30px, 6vw, 46px); line-height: 1.1; }
.hero p { margin-top: 8px; color: var(--ink-soft); font-size: 19px; font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; list-style: none; margin: 0; padding: 0; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; } }
@media (min-width: 1000px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.card { display: flex; flex-direction: column; height: 100%; border: 2px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; text-decoration: none; color: var(--ink); transition: transform 0.15s ease, border-color 0.15s ease; }
.card:hover { transform: translateY(-3px); border-color: var(--primary); }
.card .thumb { aspect-ratio: 4 / 3; background: var(--surface); }
.card .thumb svg { display: block; width: 100%; height: 100%; }
.card h2 { padding: 12px 14px 16px; font-family: var(--display); font-weight: 600; font-size: clamp(17px, 2.600vw, 21px); line-height: 1.2; }
.foot { max-width: 1120px; margin: 0 auto; padding: 24px 16px 40px; color: var(--ink-soft); font-size: 15px; border-top: 2px solid var(--surface); display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: space-between; }

/* ---------- player ---------- */
.player { max-width: 920px; margin: 0 auto; padding: 10px 16px 24px; min-height: 100dvh; display: flex; flex-direction: column; }
.player-top { display: flex; align-items: center; gap: 12px; }
.dots { flex: 1; display: flex; justify-content: center; gap: 8px; list-style: none; margin: 0; padding: 0; }
.dots li { width: 100%; max-width: 44px; height: 10px; border-radius: 999px; background: var(--line); }
.dots li.done { background: var(--primary); }
.read-btn { gap: 6px; padding: 0 16px; }
.read-btn[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.player h1 { font-family: var(--display); font-weight: 600; font-size: clamp(22px, 4.500vw, 30px); line-height: 1.15; margin: 14px 0 12px; text-align: center; }
.stage-wrap { position: relative; width: 100%; max-width: min(100%, calc((100dvh - 440px) * 4 / 3)); min-width: min(100%, 300px); margin: 0 auto; }
.stage { aspect-ratio: 4 / 3; border-radius: 24px; overflow: hidden; border: 2px solid var(--line); background: var(--surface); }
.stage svg { display: block; width: 100%; height: 100%; }
.hint-row { height: 56px; display: flex; align-items: flex-end; justify-content: center; }
.tap-hint { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 999px; border: 2px solid var(--ink); background: #fff; font-weight: 800; font-size: 16px; white-space: nowrap; animation: hint-bob 1.600s ease-in-out infinite; }
.tap-hint[hidden] { display: none; }
@keyframes hint-bob { 50% { transform: translateY(-5px); } }
.caption { margin: 12px auto 0; max-width: 720px; min-height: 5.200em; text-align: center; font-size: clamp(21px, 4.600vw, 28px); font-weight: 800; line-height: 1.3; }
.caption small { display: block; font-family: var(--display); font-weight: 600; font-size: 0.8em; color: var(--primary); margin-bottom: 4px; }
.controls { margin-top: auto; padding-top: 16px; display: flex; gap: 12px; justify-content: center; }
.controls .btn { flex: 1; max-width: 260px; }
.controls .btn-back { flex: 0 1 150px; }

/* ---------- scenes (shared rules for every animated story) ---------- */
.scene { font-family: var(--display); font-weight: 600; user-select: none; -webkit-user-select: none; }
.scene [data-from] { opacity: 0; pointer-events: none; transition: opacity 0.7s ease; }
.scene [data-from].on { opacity: 1; pointer-events: auto; }
.scene .tap-target { cursor: pointer; }
.frozen *, .frozen *::before, .frozen *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- ideas (grown-ups) ---------- */
.ideas { max-width: 760px; margin: 0 auto; padding: 8px 16px 56px; }
.ideas h1 { font-family: var(--display); font-weight: 600; font-size: clamp(28px, 5.500vw, 40px); line-height: 1.1; }
.ideas .lead { margin-top: 8px; color: var(--ink-soft); font-weight: 600; }
.panel { margin-top: 20px; padding: 20px; border: 2px solid var(--line); border-radius: var(--radius); background: #fff; }
.panel h2 { font-family: var(--display); font-weight: 600; font-size: 22px; }
.panel .hint { color: var(--ink-soft); font-size: 16px; margin-top: 4px; }
.field { display: block; margin-top: 14px; }
.field span { display: block; font-weight: 800; font-size: 16px; margin-bottom: 6px; }
.field input, .field textarea { width: 100%; min-height: 52px; padding: 12px 14px; border: 2px solid var(--line); border-radius: 14px; background: #fff; font-size: 18px; }
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--primary); }
.code-input { font-family: var(--display); font-size: 28px !important; letter-spacing: 10px; text-align: center; }
.form-row { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.form-error { margin-top: 12px; color: var(--danger); font-weight: 800; font-size: 16px; }
.form-error:empty { display: none; }
.linkish { background: none; border: 0; padding: 0; min-height: 44px; color: var(--primary); font-weight: 800; text-decoration: underline; font-size: 16px; }
.signed { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; color: var(--ink-soft); font-size: 16px; font-weight: 700; }
.list-head { margin-top: 32px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.list-head h2 { font-family: var(--display); font-weight: 600; font-size: 24px; }
.tabs { display: inline-flex; border: 2px solid var(--line); border-radius: 999px; padding: 2px; }
.tabs button { min-height: 44px; padding: 0 16px; border: 0; border-radius: 999px; background: none; font-weight: 800; font-size: 16px; color: var(--ink-soft); }
.tabs button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.idea-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 12px; }
.idea { display: flex; gap: 14px; align-items: flex-start; padding: 14px; border: 2px solid var(--line); border-radius: var(--radius); background: #fff; }
.vote { flex: none; width: 60px; min-height: 68px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 2px solid var(--line); border-radius: 16px; background: #fff; font-family: var(--display); font-weight: 600; font-size: 19px; }
.vote:hover { border-color: var(--primary); }
.vote[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.idea-body { min-width: 0; flex: 1; }
.idea-body h3 { font-family: var(--display); font-weight: 600; font-size: 20px; line-height: 1.25; overflow-wrap: anywhere; }
.idea-body p { margin-top: 4px; color: var(--ink-soft); font-size: 16px; overflow-wrap: anywhere; }
.idea-meta { margin-top: 6px; font-size: 14px !important; font-weight: 700; }
.badge { display: inline-block; margin-left: 8px; padding: 2px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 13px; font-weight: 800; vertical-align: middle; }
.empty { margin-top: 14px; padding: 28px 20px; border: 2px dashed var(--line); border-radius: var(--radius); text-align: center; color: var(--ink-soft); font-weight: 700; }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); max-width: calc(100vw - 32px); padding: 12px 20px; border-radius: 14px; background: var(--ink); color: #fff; font-weight: 800; font-size: 16px; opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease; z-index: 10; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
