@font-face {
  font-family: 'Fredoka';
  src: url('/fonts/fredoka.woff2') format('woff2-variations'), url('/fonts/fredoka.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --paper: #f7f0e3;
  --surface: #fffdf7;
  --ink: #1d1b18;
  --muted: #6b6359;
  --line: #e4d9c3;
  --yellow: #f5c12e;
  --coral: #ee6b4d;
  --lavender: #b8a2e6;
  --good: #2f7a47;
  --warn: #9a5b0c;
  --bad: #b3301f;
  --radius: 16px;
  color-scheme: light;
  font-family: 'Fredoka', ui-rounded, 'Hiragino Maru Gothic ProN', Quicksand, system-ui, sans-serif;
  font-size: 16px;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--paper); }
[hidden] { display: none !important; }
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 2.1rem; }
h2 { font-size: 1.2rem; margin-bottom: 0.85rem; }
p { margin: 0; line-height: 1.55; }
a { color: var(--ink); text-decoration-color: var(--coral); text-decoration-thickness: 2px; text-underline-offset: 0.2em; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.shell { display: grid; grid-template-columns: 15.5rem minmax(0, 1fr); min-height: 100%; }
.sidebar { position: sticky; top: 0; align-self: start; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 1.4rem; padding: 1.4rem 1rem 1.1rem; border-right: 2px solid var(--ink); background: var(--surface); overflow-y: auto; }
.brand { display: inline-flex; align-items: flex-start; gap: 0.2rem; color: var(--ink); text-decoration: none; padding-left: 0.3rem; }
.wordmark { font-size: 2.1rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1; border-bottom: 3px solid var(--ink); padding-bottom: 0.15rem; }
.ai { display: inline-grid; place-items: center; width: 1.85rem; height: 1.85rem; margin-top: -0.3rem; border-radius: 50%; background: var(--yellow); font-size: 0.85rem; font-weight: 700; }
.nav { display: flex; flex-direction: column; gap: 0.25rem; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.6rem 0.8rem; border: 2px solid transparent; border-radius: 12px; color: var(--ink); text-decoration: none; font-size: 1rem; font-weight: 500; }
.nav a:hover { background: #f6eeda; }
.nav a[aria-current='page'] { background: var(--yellow); border-color: var(--ink); font-weight: 600; box-shadow: 2px 2px 0 var(--ink); }
.count { font-size: 0.78rem; font-weight: 600; background: var(--ink); color: var(--surface); border-radius: 999px; padding: 0.05rem 0.5rem; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 0.7rem; }
.mascot { display: block; width: 6.5rem; height: auto; margin-left: 0.3rem; }
.tagline { font-size: 1.15rem; font-weight: 600; line-height: 1.15; padding-left: 0.3rem; }
.who { display: flex; flex-direction: column; gap: 0.45rem; padding-top: 0.8rem; border-top: 2px dashed var(--line); }
.who-email { font-size: 0.85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.credits-pill { align-self: flex-start; padding: 0.25rem 0.75rem; border: 2px solid var(--ink); border-radius: 999px; background: var(--yellow); font-weight: 600; font-size: 0.92rem; text-decoration: none; font-variant-numeric: tabular-nums; }

.main { padding: clamp(1rem, 3vw, 2.25rem); min-width: 0; }
.view { display: flex; flex-direction: column; gap: 1.1rem; max-width: 82rem; margin: 0 auto; }
.view-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; }
.view-header p { margin-top: 0.3rem; color: var(--muted); max-width: 46rem; }
.header-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.section-title { margin: 0.6rem 0 0; font-size: 1.35rem; }
#account-signed-in { display: flex; flex-direction: column; gap: 0.9rem; }

.card { background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); padding: 1.2rem; }
.sticker { border-color: var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.banner { padding: 0.75rem 1rem; border-radius: 12px; background: #fdf0c4; border: 2px solid var(--ink); font-size: 0.95rem; }
.banner.bad { background: #fbe1da; }
.banner.good { background: #dff1e2; }
.hint { color: var(--muted); font-size: 0.9rem; }
.hint.bad { color: var(--bad); }
.meta { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.label, label { display: block; font-size: 0.78rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.35rem; }
.label em { font-style: normal; font-weight: 400; text-transform: none; letter-spacing: 0; }

textarea, select, input[type='email'], input[type='password'], input[type='text'] { width: 100%; font: inherit; color: var(--ink); background: #fff; border: 2px solid #d6cab2; border-radius: 12px; padding: 0.6rem 0.75rem; }
textarea { resize: vertical; min-height: 8rem; line-height: 1.5; }
:is(textarea, select, input, .button, .nav a, .reference-chip, .link, canvas):focus-visible { outline: 3px solid #2b6cb0; outline-offset: 2px; }
input[type='range'] { accent-color: var(--coral); }

.button { appearance: none; display: inline-flex; align-items: center; justify-content: center; min-height: 2.6rem; padding: 0.4rem 1rem; border: 2px solid var(--ink); border-radius: 12px; background: var(--surface); color: var(--ink); font: inherit; font-size: 0.95rem; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none; box-shadow: 2px 2px 0 var(--ink); transition: transform 0.08s, box-shadow 0.08s; }
.button:hover:not(:disabled) { background: #f6eeda; }
.button:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.button.primary { background: var(--coral); }
.button.primary:hover:not(:disabled) { background: #f27d62; }
.button.big { min-height: 3.1rem; font-size: 1.1rem; }
.button.small { min-height: 2.1rem; padding: 0.2rem 0.7rem; font-size: 0.85rem; }
.button.danger { color: var(--bad); }
.button[aria-pressed='true'].toggle { background: var(--lavender); }
.button:disabled { opacity: 0.5; cursor: default; }
.link { appearance: none; border: 0; background: none; padding: 0; font: inherit; font-weight: 600; color: var(--ink); text-decoration: underline; text-decoration-color: var(--coral); text-decoration-thickness: 2px; text-underline-offset: 0.2em; cursor: pointer; }

/* Studio */
.studio-grid { display: grid; grid-template-columns: minmax(18rem, 24rem) minmax(0, 1fr); gap: 1.1rem; align-items: start; }
.scene-card { display: flex; flex-direction: column; gap: 0.8rem; }
.scene-card h2 { margin-bottom: 0; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.field-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.field-heading .label { margin: 0; }
.field-heading a { font-size: 0.85rem; }
.reference-strip { display: flex; gap: 0.5rem; overflow-x: auto; padding: 0.2rem 0.2rem 0.45rem; }
.reference-chip { position: relative; flex: none; width: 4.6rem; height: 4.6rem; padding: 0; border: 2px solid var(--line); border-radius: 12px; background: #fff; overflow: hidden; cursor: pointer; font: inherit; font-size: 0.78rem; font-weight: 600; color: var(--ink); line-height: 1.15; }
.reference-chip img { display: block; width: 100%; height: 100%; object-fit: cover; }
.reference-chip[aria-selected='true'] { border-color: var(--ink); box-shadow: 3px 3px 0 var(--coral); }
.reference-chip.add { border-style: dashed; border-color: var(--ink); background: #fdf0c4; }
.reference-chip.add.plain { background: transparent; border-color: #cbbd9f; font-weight: 500; color: var(--muted); }
.stage-column { display: flex; flex-direction: column; gap: 1.1rem; min-width: 0; }
.stage-heading { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.8rem; }
.stage-heading h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-heading .meta { margin-left: auto; }
.badge { flex: none; font-size: 0.78rem; font-weight: 600; padding: 0.1rem 0.6rem; border-radius: 999px; background: var(--lavender); border: 2px solid var(--ink); }
.badge.live { background: var(--yellow); }
.stage { border: 2px solid var(--ink); border-radius: 12px; overflow: hidden; background: #ead8ae; display: grid; place-items: center; }
.stage canvas { display: block; width: 100%; height: auto; max-height: 66vh; object-fit: contain; }
.transport { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.9rem; }
.transport .primary { min-width: 4.8rem; }
.transport input { flex: 1; min-width: 4rem; }
.stage-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.85rem; }
.spacer { flex: 1; }
.wobble { display: inline-flex; align-items: center; gap: 0.5rem; margin: 0; }
.wobble input { width: 7rem; }
.wobble output { font-weight: 400; text-transform: none; letter-spacing: 0; min-width: 3.4rem; }
#stage-message { margin-top: 0.7rem; min-height: 1.4em; }
.steps { list-style: none; margin: 0 0 0.9rem; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; }
.steps li { display: flex; gap: 0.6rem; align-items: flex-start; opacity: 0.5; }
.steps li.active, .steps li.done, .steps li.failed { opacity: 1; }
.steps b { display: block; font-size: 0.95rem; font-weight: 600; }
.steps small { display: block; color: var(--muted); font-size: 0.83rem; line-height: 1.4; margin-top: 0.1rem; }
.step-mark { flex: none; width: 1.15rem; height: 1.15rem; margin-top: 0.1rem; border-radius: 50%; border: 2.5px solid #cbbd9f; }
.steps li.active .step-mark { border-color: var(--coral); border-top-color: transparent; animation: turn 0.9s linear infinite; }
.steps li.done .step-mark { border-color: var(--ink); background: var(--yellow); }
.steps li.failed .step-mark { border-color: var(--bad); background: var(--bad); }
@keyframes turn { to { transform: rotate(360deg); } }

/* Doodles & references */
.dropzone { border: 2px dashed transparent; border-radius: var(--radius); min-height: 12rem; }
.dropzone.over { border-color: var(--ink); background: #fdf0c4; }
.empty { text-align: center; padding: 3rem 1rem; border: 2px dashed #cbbd9f; border-radius: var(--radius); color: var(--muted); }
.empty h2 { color: var(--ink); font-size: 1.5rem; margin-bottom: 0.4rem; }
.empty .button { margin-top: 1rem; }
.reference-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr)); gap: 1rem; }
.reference-card { position: relative; background: var(--surface); border: 2px solid var(--ink); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.reference-card img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #fff; border-bottom: 2px solid var(--ink); }
.reference-card .kind { position: absolute; top: 0.5rem; left: 0.5rem; }
.reference-card .body { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.7rem; }
.reference-card input { font-size: 0.95rem; font-weight: 600; border-color: transparent; padding: 0.2rem 0.4rem; background: transparent; }
.reference-card input:hover, .reference-card input:focus { border-color: #d6cab2; background: #fff; }
.reference-card .row { display: flex; gap: 0.4rem; }
.reference-card .button { flex: 1; }

/* My creations */
.creation-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 1rem; }
.creation-card { background: var(--surface); border: 2px solid var(--ink); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.creation-thumb { appearance: none; position: relative; display: grid; place-items: center; width: 100%; height: 13rem; padding: 0; border: 0; border-bottom: 2px solid var(--ink); background: #ead8ae; cursor: pointer; overflow: hidden; }
.creation-thumb canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.creation-thumb .play-mark { position: absolute; right: 0.6rem; bottom: 0.6rem; display: grid; place-items: center; width: 2.4rem; height: 2.4rem; border: 2px solid var(--ink); border-radius: 50%; background: var(--yellow); font-size: 0.95rem; box-shadow: 2px 2px 0 var(--ink); }
.creation-thumb:hover .play-mark { background: var(--coral); }
.creation-thumb.waiting { color: var(--muted); font: inherit; font-size: 0.85rem; }
.creation-card .body { display: flex; flex-direction: column; gap: 0.45rem; padding: 0.7rem; }
.creation-card input { font-size: 1rem; font-weight: 600; border-color: transparent; padding: 0.2rem 0.4rem; background: transparent; }
.creation-card input:hover, .creation-card input:focus { border-color: #d6cab2; background: #fff; }
.creation-card .when { padding-left: 0.4rem; }
.creation-card .row { display: flex; gap: 0.4rem; }
.creation-card .row .button { flex: 1; }
.button.more { align-self: center; }
.dialog.viewer { width: min(60rem, calc(100vw - 2rem)); }
.viewer-stage { margin-top: 0.7rem; }
.viewer-stage canvas { max-height: 60vh; }
#viewer-message { min-height: 1.4em; margin-top: 0.6rem; }

/* Plans & credits */
.balance { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1.2rem; background: var(--yellow); }
.balance > div { display: flex; flex-direction: column; align-items: flex-start; gap: 0.15rem; }
.balance .label { color: var(--ink); margin: 0; }
.balance strong { font-size: 2.4rem; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.balance small { font-size: 0.9rem; line-height: 1.4; }
.balance .button { margin-top: 0.5rem; }
.offer-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 1rem; }
.offer { display: flex; flex-direction: column; gap: 0.35rem; background: var(--surface); border: 2px solid var(--ink); border-radius: var(--radius); padding: 1.1rem; }
.offer.current { background: #efe8fb; box-shadow: 4px 4px 0 var(--lavender); }
.offer h3 { margin: 0; font-size: 1.25rem; font-weight: 600; }
.offer .price { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.offer .price small { font-size: 0.9rem; font-weight: 500; color: var(--muted); }
.offer ul { list-style: none; margin: 0.3rem 0 0.7rem; padding: 0; display: grid; gap: 0.25rem; font-size: 0.93rem; }
.offer li::before { content: '✓ '; font-weight: 700; color: var(--coral); }
.offer .button { margin-top: auto; }
.packs .offer { border-style: dashed; }

/* Owner */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 1rem; }
.stat { display: flex; flex-direction: column; gap: 0.2rem; }
.stat .label { margin: 0; }
.stat strong { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat strong.good { color: var(--good); }
.stat strong.warn { color: var(--warn); }
.stat small { color: var(--muted); font-size: 0.85rem; line-height: 1.4; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 2px solid var(--line); vertical-align: top; }
th { font-size: 0.76rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.scene { max-width: 26rem; }
.pill { display: inline-block; font-size: 0.8rem; font-weight: 600; padding: 0.05rem 0.55rem; border-radius: 999px; background: #dff1e2; color: #1f5a33; white-space: nowrap; }
.pill.bad { background: #fbe1da; color: #86251a; }
.pill.run { background: #fdf0c4; color: #6d4a06; }
.plus { color: var(--good); font-weight: 600; }

/* Dialogs */
.dialog { width: min(26rem, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); padding: 1.4rem; border: 2px solid var(--ink); border-radius: 20px; background: var(--surface); color: var(--ink); box-shadow: 6px 6px 0 var(--ink); }
.dialog::backdrop { background: rgba(29, 27, 24, 0.45); }
.dialog form { display: flex; flex-direction: column; gap: 0.5rem; }
.dialog h2 { font-size: 1.5rem; margin-bottom: 0.1rem; }
.dialog label { margin: 0.4rem 0 0; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.7rem 0 0.4rem; }
#auth-message, #doodle-message { min-height: 1.4em; }
.dialog.doodle { width: min(62rem, calc(100vw - 2rem)); }
.doodle-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin: 0.8rem 0; }
.swatches, .sizes { display: flex; align-items: center; gap: 0.35rem; }
.swatch, .size { appearance: none; display: grid; place-items: center; width: 2.1rem; height: 2.1rem; padding: 0; border: 2px solid var(--ink); border-radius: 50%; background: #fff; cursor: pointer; }
.swatch[aria-checked='true'], .size[aria-checked='true'] { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--ink); }
.swatch-ink { background: #1d1b18; } .swatch-coral { background: #ee6b4d; } .swatch-yellow { background: #f5c12e; } .swatch-lavender { background: #b8a2e6; } .swatch-blue { background: #4f80c4; } .swatch-green { background: #5c9647; } .swatch-brown { background: #8a5a35; }
.size i { display: block; border-radius: 50%; background: var(--ink); }
.size-s i { width: 0.35rem; height: 0.35rem; } .size-m i { width: 0.65rem; height: 0.65rem; } .size-l i { width: 1.05rem; height: 1.05rem; }
.doodle-pad { border: 2px solid var(--ink); border-radius: 12px; overflow: hidden; background: #fffdf7; display: grid; place-items: center; }
.doodle-pad canvas { display: block; width: 100%; height: auto; max-height: 58vh; object-fit: contain; touch-action: none; cursor: crosshair; }
.noscript { padding: 2rem; text-align: center; }

@media (max-width: 64rem) {
  .studio-grid { grid-template-columns: 1fr; }
  .steps { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 48rem) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; padding: 0.8rem 1rem; border-right: 0; border-bottom: 2px solid var(--ink); }
  .wordmark { font-size: 1.6rem; }
  .nav { flex-direction: row; flex-basis: 100%; order: 3; overflow-x: auto; padding-bottom: 0.25rem; }
  .nav a { white-space: nowrap; }
  .sidebar-foot { margin: 0 0 0 auto; }
  .mascot, .tagline { display: none; }
  .who { flex-direction: row; align-items: center; padding: 0; border: 0; }
  .who-email { display: none; }
  .steps { grid-template-columns: 1fr; }
  .transport { flex-wrap: wrap; }
  .transport input { flex-basis: 100%; order: 5; }
}
@media (prefers-reduced-motion: reduce) {
  .steps li.active .step-mark { animation: none; border-top-color: var(--coral); }
  .button { transition: none; }
}

.versions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.7rem; }
.versions label { margin: 0; font-weight: 600; }
.versions select { flex: 1; min-width: 12rem; }

/* Tweak this: changing a finished creation */
.tweak-card { display: flex; flex-direction: column; gap: 0.6rem; }
.tweak-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; }
.tweak-versions { display: flex; align-items: center; gap: 0.5rem; }
.tweak-form { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.tweak-form input { flex: 1; min-width: 14rem; }
.tweak-card .hint { margin: 0; }
#tweak-message:empty, #tweak-cost:empty, #hand-note:empty { display: none; }
.hand summary { cursor: pointer; font-weight: 600; }
.hand-row { display: flex; align-items: flex-start; gap: 0.7rem; margin-top: 0.7rem; }
.hand-label { flex: 0 0 4.5rem; margin: 0.35rem 0 0; font-weight: 600; font-size: 0.9rem; }
.swatches, .chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.swatches input[type="color"] { width: 2.3rem; height: 2.3rem; padding: 0.1rem; border: 2px solid var(--ink); border-radius: 10px; background: var(--surface); cursor: pointer; }
.swatches input[type="color"].changed { box-shadow: 0 0 0 3px var(--yellow); }
.chip { appearance: none; font: inherit; font-size: 0.85rem; padding: 0.2rem 0.6rem; border: 2px solid var(--ink); border-radius: 999px; background: var(--surface); color: var(--ink); cursor: pointer; }
.chip[aria-pressed="true"] { background: #fbe1da; color: #86251a; text-decoration: line-through; }
.hand-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.8rem; }

/* Keep it going: the scenes of a film */
.film-card { display: flex; flex-direction: column; gap: 0.6rem; }
.film-card .hint { margin: 0; }
#film-message:empty, #next-cost:empty { display: none; }
.film-strip { list-style: none; margin: 0; padding: 0 0 0.2rem; display: flex; gap: 0.5rem; overflow-x: auto; }
.film-strip:empty { display: none; }
.scene-chip { appearance: none; flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 0.25rem; width: 5.6rem; padding: 0.3rem; font: inherit; font-size: 0.78rem; color: var(--ink); background: var(--surface); border: 2px solid #d6cab2; border-radius: 12px; cursor: pointer; }
.scene-chip[aria-current="true"] { border-color: var(--ink); background: #fdf0c4; box-shadow: 2px 2px 0 var(--ink); }
.scene-chip canvas { display: block; width: 100%; height: 4.2rem; object-fit: contain; background: #ead8ae; border-radius: 6px; }
.scene-chip b { font-weight: 600; }
.film-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
