@font-face {font-family: "M PLUS Rounded 1c"; src: url("./assets/brand/rounded-japanese-bold.woff") format("woff"); font-weight: 700 900; font-style:normal; font-display:swap;}
@font-face {
  font-family: "M PLUS Rounded 1c";
  src: url("./assets/brand/rounded-japanese.woff") format("woff");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --yellow: #ffda45;
  --cream: #fff9f0;
  --ink: #302b2b;
  --mint: #76ddbd;
  --mint-light: #bbf2de;
  --coral: #f4a49a;
  --sky: #aee5f7;
  --muted: #675c50;
  --line: rgba(86, 102, 86, .15);
  --surface: rgba(255, 249, 240, .96);
  --radius: 24px;
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  color: var(--ink);
  background: var(--sky);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

*, *::before, *::after { box-sizing: border-box; }
html { min-width: 320px; min-height: 100%; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100svh;
  background: var(--sky) url("./assets/brand/background.webp") center bottom / cover no-repeat fixed;
  font-size: 15px;
  line-height: 1.65;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button, a { touch-action: manipulation; }
a { color: inherit; }
img { display: block; max-width: 100%; }
svg { display: block; width: 22px; height: 22px; flex: 0 0 auto; }
h1, h2, h3, p { margin: 0; }
button { border: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #256965; outline-offset: 4px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 12px 20px;
  background: var(--cream);
  border-radius: 12px;
  transform: translateY(-160%);
}
.skip-link:focus { transform: none; }

.site-shell {
  position: relative;
  width: min(1120px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: 16px 24px 32px;
  isolation: isolate;
}
.site-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 80px;
  margin-bottom: 16px;
  z-index: 5;
}
.brand { display: block; width: 188px; flex: 0 0 auto; text-decoration: none; }
.brand img { width: 100%; height: auto; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  background: rgba(255, 249, 240, .9);
  border: 1px solid rgba(255, 255, 255, .8);
  border-radius: 50%;
}
.quiet-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px;
  background: rgba(255, 249, 240, .85);
  border-radius: 16px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 56px;
  padding: 12px 28px;
  border: 2px solid transparent;
  border-radius: 18px;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.4;
  text-decoration: none;
  transition: transform 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}
.button.primary { background: var(--yellow); box-shadow: 0 4px 0 rgba(172, 125, 29, .2); }
.button.secondary { background: var(--cream); border-color: var(--coral); }
.button:active { transform: translateY(2px); box-shadow: none; }
.button:disabled { opacity: .55; box-shadow: none; }
.screen { position: relative; z-index: 2; }

/* The open sky and the original friends form the front door. */
.home-screen { min-height: calc(100svh - 144px); text-align: center; }
.home-copy { padding-top: 12px; }
.eyebrow {
  display: inline-block;
  margin-bottom: 12px;
  padding: 4px 16px;
  background: rgba(255, 249, 240, .87);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
}
.home-copy h1 { font-size: clamp(24px, 3.2vw, 36px); line-height: 1.45; font-weight: 800; }
.home-copy p { margin-top: 12px; font-size: 15px; font-weight: 600; }
.hero-friends {
  position: relative;
  overflow: clip;
  padding-bottom: 16px;
  padding-top: 32px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 0;
  width: min(750px, 100%);
  height: clamp(240px, 43svh, 390px);
  margin: 0 auto;
}
.hero-friends .friend {
  width: 31%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  transform-origin: 50% 85%;
}
.hero-friends .friend-one { transform: rotate(-5deg) translateY(12px); }
.hero-friends .friend-two { position: relative; z-index: 2; width: 35%; transform: scale(1.05); }
.hero-friends .friend-three { transform: rotate(5deg) translateY(10px); }
.speech-bubble {
  position: absolute;
  top: 4px;
  z-index: 3;
  right: 6%;
  padding: 10px 18px;
  border-radius: 20px 20px 20px 4px;
  background: var(--cream);
  font-size: 14px;
  font-weight: 700;
  transform: rotate(4deg);
}
.home-actions { display: flex; justify-content: center; align-items: center; flex-direction: column; width: min(360px, 100%); gap: 12px; margin: 16px auto 0; }
.home-actions .button { min-width: 248px; }
.school-gallery-link { min-height: 48px; text-decoration: none; background: var(--cream); padding: 8px 20px; }
.school-gallery-entry { display: flex; justify-content: center; margin-top: 24px; }
.school-gallery-entry .button { text-decoration: none; }
.home-footnote { width: fit-content; margin: 20px auto 0; padding: 4px 12px; border-radius: 12px; background: rgba(255, 249, 240, .84); font-size: 12px; }
.intro-controls { display: flex; justify-content: center; gap: 12px; margin-top: 12px; }
.intro-controls .quiet-button { background: rgba(255, 249, 240, .8); font-size: 12px; }

.scene-train {
  position: fixed;
  left: 0;
  bottom: 24px;
  z-index: 0;
  width: max-content;
  pointer-events: none;
  transform: translateX(-120%);
}
.train-cars { display: flex; gap: 8px; }
.train-car {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 124px;
  height: 96px;
  padding: 8px 12px 24px;
  background: var(--cream);
  border: 5px solid var(--yellow);
  border-bottom-width: 16px;
  border-radius: 18px 18px 8px 8px;
}
.train-car::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -7px; height: 5px; background: var(--mint); }
.train-car img { width: 100%; height: 72px; object-fit: contain; object-position: 50% 25%; }
.train-wheels { position: absolute; left: 14px; right: 14px; bottom: -24px; display: flex; justify-content: space-between; }
.train-wheels span { display: block; width: 22px; height: 22px; border: 5px solid #587f78; border-radius: 50%; background: var(--cream); }
.intro-playing .scene-train { animation: train-arrival 6s cubic-bezier(.28, .6, .46, 1) both; }
.intro-playing .friend-one { animation: friend-hello 800ms 700ms ease both; }
.intro-playing .friend-two { animation: friend-hello 800ms 1.05s ease both; }
.intro-playing .friend-three { animation: friend-hello 800ms 1.4s ease both; }
@keyframes train-arrival { 0% { transform: translateX(-120%); } 40% { transform: translateX(calc(50vw - 50%)); } 68% { transform: translateX(calc(50vw - 50%)); } 100% { transform: translateX(calc(100vw + 32px)); } }
@keyframes friend-hello { 0% { opacity: 0; translate: 0 16px; } 100% { opacity: 1; translate: 0 0; } }

.section-heading { text-align: center; margin: 24px 0 32px; }
.section-heading h1 { font-size: clamp(24px, 3vw, 32px); font-weight: 800; }
.section-heading p { margin-top: 8px; font-size: 15px; }
.choose-screen { max-width: 780px; margin: 0 auto; }
.age-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.age-card { display: flex; flex-direction: column; align-items: center; padding: 20px 20px 24px; background: var(--surface); border: 3px solid rgba(255, 255, 255, .75); border-radius: 28px; }
.age-card img { width: 100%; height: clamp(190px, 34svh, 320px); object-fit: contain; }
.age-card strong { display: block; margin-top: 12px; font-size: 23px; font-weight: 800; }
.age-card small { display: block; margin-top: 4px; font-size: 13px; color: var(--muted); }
.age-card:first-child { border-bottom: 8px solid var(--mint); }
.age-card:last-child { border-bottom: 8px solid var(--yellow); }
.age-card:active { transform: translateY(2px); }

/* A large preview stays beside the few controls currently needed. */
.maker-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin: 0 4px 16px; }
.maker-heading h1 { font-size: 24px; font-weight: 800; }
.maker-heading p { font-size: 13px; color: var(--ink); }
.editor-layout { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); gap: 20px; height: min(660px, calc(100dvh - 190px)); min-height: 500px; }
.preview-panel, .controls-panel { min-width: 0; min-height: 0; border-radius: var(--radius); }
.preview-panel { position: relative; display: flex; flex-direction: column; padding: 16px; background: rgba(255, 249, 240, .84); overflow: hidden; }
.preview-topbar { position: relative; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.age-badge { display: inline-flex; align-items: center; min-height: 32px; padding: 4px 12px; background: var(--mint-light); border-radius: 999px; font-size: 12px; font-weight: 700; }
.undo-button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 12px; background: var(--cream); border: 1px solid var(--line); border-radius: 14px; font-size: 12px; font-weight: 700; }
.undo-button:disabled { opacity: .45; }
.undo-button svg { width: 18px; height: 18px; }
.avatar-stage { position: relative; flex: 1; width: 100%; min-height: 0; overflow: hidden; }
.avatar-stage .avatar-canvas { position: absolute; left: 50%; top: 48%; width: auto; max-width: none; height: 150%; transform: translate(-50%, -50%); }
.preview-message { margin-top: 8px; text-align: center; font-size: 13px; font-weight: 600; }
.finish-button { width: 100%; margin-top: 12px; }
.controls-panel { display: flex; flex-direction: column; padding: 16px; background: var(--surface); border: 1px solid rgba(255, 255, 255, .75); }
#part-controls { flex-shrink: 0; }
#choice-controls { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.choices-count { display: flex; align-items: center; font-size: 11px; color: var(--muted); white-space: nowrap; padding: 0 4px; }
.selection-check, .color-swatch > svg { display: none; }
.none-mark { font-size: 32px !important; color: #69817a; }
.header-spacer { width: 48px; }
.preview-loading { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); border-radius: 12px; padding: 6px 12px; background: var(--cream); white-space: nowrap; font-size: 12px; }
.parent-link > span { display: block; font-size: 11px; }
.completion-spark { position: absolute; font-size: 36px; color: #c28d17; }
.spark-one { top: 16%; left: 10%; transform: rotate(-10deg); }
.spark-two { top: 36%; right: 7%; font-size: 24px; }
.gallery-card > span { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 10px; font-size: 13px; }
.empty-gallery > img { height: 180px; width: 100%; object-fit: contain; margin-bottom: 16px; }
.train-window { width: 74px; height: 52px; border-radius: 8px; background: #ccecf8; overflow: hidden; }
.train-window img { width: 100%; height: 154px; max-width: none; object-fit: cover; object-position: top; }
.category-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; flex-shrink: 0; }
.category-tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-width: 0; min-height: 66px; padding: 8px 4px; border: 2px solid transparent; background: #f2eee3; border-radius: 16px; font-size: 15px; font-weight: 800; line-height: 1.35; }
.category-tab svg { width: 25px; height: 25px; }
.category-tab.is-selected, .category-tab[aria-selected="true"], .category-tab[aria-pressed="true"] { border-color: #32866b; background: var(--mint-light); }
.part-selector { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.part-selector label { flex-shrink: 0; font-size: 12px; font-weight: 700; }
.part-selector select { width: min(100%, 240px); min-width: 0; min-height: 44px; padding: 8px 36px 8px 12px; border: 1px solid var(--line); border-radius: 12px; background-color: #fff; font-size: 14px; font-weight: 700; }
.mode-tabs { display: flex; gap: 8px; flex-shrink: 0; margin: 16px 0 12px; }
.mode-tab { position: relative; flex: 1; min-height: 44px; padding: 8px 12px; border: 2px solid transparent; border-radius: 12px; background: #f2eee3; font-size: 14px; font-weight: 700; }
.mode-tab.is-selected, .mode-tab[aria-selected="true"], .mode-tab[aria-pressed="true"] { background: var(--yellow); border-color: #bd8a29; }
.choices-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #9bcbb8 transparent; padding: 4px 4px 8px; scroll-padding-block: 8px; }
.shape-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; align-content: start; }
.shape-card { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; min-height: 116px; padding: 8px 6px; border: 3px solid transparent; border-radius: 16px; background: #fff; }
.shape-card img { width: 100%; height: 76px; object-fit: contain; }
.shape-card span { display: block; margin-top: 4px; max-width: 100%; font-size: 11px; line-height: 1.4; overflow-wrap: anywhere; }
.shape-card .shape-label-word { display: inline-block; margin: 0; white-space: nowrap; }
.shape-card.is-selected, .shape-card[aria-pressed="true"] { border-color: #32866b; background: #e9faf3; }
.shape-card.is-selected::after, .shape-card[aria-pressed="true"]::after { content: "✓"; position: absolute; top: 4px; right: 4px; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: #32866b; color: white; font-size: 13px; font-weight: 800; }
.empty-choice { gap: 8px; }
.empty-choice svg { width: 32px; height: 32px; opacity: .65; }
.color-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; align-content: start; }
.color-card { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 102px; padding: 10px 4px; border: 3px solid transparent; border-radius: 16px; background: #fff; font-size: 12px; font-weight: 600; }
.color-swatch { position: relative; display: block; width: 42px; height: 42px; border: 1px solid rgba(48, 43, 43, .2); border-radius: 50%; background: var(--swatch, var(--cream)); }
.color-card.is-selected, .color-card[aria-pressed="true"] { border-color: #32866b; background: #e9faf3; }
.color-card.is-selected .color-swatch::after, .color-card[aria-pressed="true"] .color-swatch::after { content: "✓"; position: absolute; bottom: -5px; right: -5px; display: grid; place-items: center; width: 22px; height: 22px; border: 2px solid white; border-radius: 50%; background: #32866b; color: white; font-size: 12px; }
.panel-hint { flex-shrink: 0; margin: 8px 0 0; font-size: 11px; text-align: center; color: var(--muted); }

.completion-heading { text-align: center; margin: 16px auto; }
.completion-heading h1 { font-size: clamp(26px, 4vw, 36px); font-weight: 800; }
.completion-heading p { margin-top: 6px; font-size: 14px; }
.completion-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .9fr); align-items: center; gap: 40px; max-width: 860px; margin: 0 auto; }
.completion-stage { position: relative; width: 100%; height: min(60svh, 510px); overflow: hidden; }
.completion-stage canvas { position: absolute; left: 50%; top: 48%; width: auto; height: 150%; max-width: none; transform: translate(-50%, -50%); }
.completion-actions { display: flex; flex-direction: column; gap: 12px; }
.completion-actions .button { width: 100%; }
.save-note { margin-top: 4px; font-size: 12px; line-height: 1.8; text-align: center; }
.parent-link { margin-top: 12px; text-align: center; }
.parent-link .quiet-button { font-size: 12px; text-decoration: underline; text-underline-offset: 4px; }
.gallery-screen { max-width: 920px; margin: 0 auto; }
.gallery-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.gallery-card { position: relative; display: flex; flex-direction: column; align-items: center; padding: 16px; min-width: 0; border-radius: 24px; background: var(--surface); }
.gallery-card canvas { width: 100%; height: 270px; object-fit: contain; }
.gallery-card h2, .gallery-card strong { margin-top: 8px; font-size: 16px; }
.gallery-card p, .gallery-card small { margin-top: 4px; font-size: 12px; }
.gallery-card .quiet-button { margin-top: 8px; background: var(--mint-light); }
.empty-gallery { max-width: 480px; margin: 48px auto; padding: 40px 24px; border-radius: 24px; background: var(--surface); text-align: center; }
.empty-gallery p { margin-bottom: 24px; }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 30; width: max-content; max-width: calc(100% - 32px); padding: 12px 24px; border: 1px solid rgba(48, 43, 43, .15); border-radius: 18px; background: var(--cream); box-shadow: 0 4px 20px rgba(56, 91, 76, .12); transform: translateX(-50%); font-size: 13px; font-weight: 700; text-align: center; }

dialog {
  width: min(460px, calc(100% - 32px));
  max-height: calc(100dvh - 40px);
  margin: auto;
  padding: 32px 24px 24px;
  border: 0;
  border-radius: 28px;
  color: var(--ink);
  background: var(--cream);
  overflow: auto;
}
dialog::backdrop { background: rgba(42, 76, 77, .35); backdrop-filter: blur(3px); }
.dialog-overlay { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(42, 76, 77, .35); }
.dialog-overlay dialog[open] { position: relative; }
.parent-dialog h2, .new-dialog h2 { padding-right: 28px; font-size: 22px; font-weight: 800; }
.parent-dialog p, .new-dialog p { margin-top: 16px; font-size: 14px; }
.parent-dialog label, .new-dialog label { display: block; margin-top: 20px; font-size: 13px; font-weight: 700; }
.parent-dialog input, .new-dialog input { width: 100%; min-height: 48px; margin-top: 8px; padding: 10px 12px; border: 1px solid #b8cabe; border-radius: 12px; background: #fff; font-size: 16px; }
.dialog-close { position: absolute; top: 12px; right: 12px; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--mint-light); }
.dialog-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 24px; }
.dialog-actions .button { width: 100%; font-size: 15px; }

@media (hover: hover) {
  .button.primary:hover { background: #ffe36f; transform: translateY(-1px); }
  .button.secondary:hover, .quiet-button:hover, .icon-button:hover { background: #fff; }
  .age-card:hover { background: #fff; }
  .shape-card:hover, .color-card:hover { border-color: #76b49d; }
  .category-tab:hover, .mode-tab:hover { filter: brightness(1.025); }
}

@media (min-width: 1200px) {
  body { background-size: 100% auto; }
  .home-screen { min-height: calc(100svh - 154px); }
  .home-copy { padding-top: 24px; }
}

@media (max-width: 767px) {
  .site-shell { padding: 12px 16px 24px; }
  .site-header { min-height: 64px; margin-bottom: 12px; gap: 8px; }
  .brand { width: 148px; }
  .header-actions { gap: 4px; }
  .header-actions .quiet-button { padding: 8px 10px; font-size: 11px; }
  .header-actions svg { width: 18px; height: 18px; }
  .icon-button { width: 44px; height: 44px; }
  .home-screen { min-height: calc(100svh - 120px); }
  .home-copy { padding-top: 12px; }
  .home-copy h1 { font-size: 25px; }
  .home-copy p { max-width: 290px; margin: 10px auto 0; font-size: 13px; }
  .hero-friends { height: clamp(240px, 37svh, 330px); width: calc(100% + 24px); margin-left: -12px; }
  .speech-bubble { top: 4%; right: 10px; padding: 8px 12px; font-size: 12px; }
  .home-actions { flex-direction: column; width: min(312px, 100%); gap: 12px; margin-top: 12px; }
  .home-actions .button { width: 100%; min-width: 0; }
  .home-footnote { margin-top: 16px; max-width: 320px; font-size: 11px; }
  .intro-controls { margin-top: 8px; }
  .train-car { width: 100px; height: 80px; padding-bottom: 16px; }
  .train-car img { height: 58px; }
  .section-heading { margin: 24px 0; }
  .section-heading h1 { font-size: 24px; }
  .section-heading p { font-size: 13px; }
  .age-options { gap: 12px; }
  .age-card { padding: 12px 8px 20px; border-radius: 22px; }
  .age-card img { height: clamp(180px, 30svh, 270px); }
  .age-card strong { font-size: 19px; }
  .age-card small { font-size: 11px; }
  body[data-screen="maker"] .site-shell { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  body[data-screen="maker"] .site-header { min-height: 56px; margin-bottom: 8px; }
  body[data-screen="maker"] .brand { width: 126px; }
  .maker-heading { margin: 0 4px 8px; gap: 8px; }
  .maker-heading h1 { font-size: 18px; }
  .maker-heading p { font-size: 11px; }
  .editor-layout { grid-template-columns: 1fr; grid-template-rows: minmax(200px, .86fr) minmax(270px, 1.14fr); gap: 12px; height: calc(100dvh - 124px - env(safe-area-inset-bottom)); min-height: 500px; }
  .preview-panel { padding: 8px 12px; border-radius: 20px; }
  .preview-topbar { align-items: flex-start; }
  .age-badge { min-height: 28px; padding: 3px 10px; font-size: 11px; }
  .undo-button { min-height: 40px; padding: 6px 10px; font-size: 11px; }
  .avatar-stage { position: absolute; inset: 20px 12px 8px; width: auto; }
  .avatar-stage .avatar-canvas { top: 46%; height: 145%; }
  .preview-message { position: absolute; bottom: 12px; left: 12px; max-width: 45%; margin: 0; font-size: 11px; }
  .finish-button { position: absolute; right: 12px; bottom: 12px; z-index: 3; width: auto; min-width: 132px; min-height: 48px; margin: 0; padding: 10px 20px; font-size: 16px; }
  .controls-panel { padding: 12px; border-radius: 20px; }
  .category-tabs { gap: 6px; }
  .category-tab { min-height: 52px; padding: 5px 4px; border-radius: 12px; font-size: 13px; gap: 2px; }
  .category-tab svg { width: 21px; height: 21px; }
  .part-selector { margin-top: 8px; gap: 8px; }
  .part-selector label { font-size: 11px; }
  .part-selector select { min-height: 40px; padding-block: 6px; font-size: 13px; }
  .mode-tabs { margin: 8px 0; gap: 6px; }
  .mode-tab { min-height: 40px; padding: 6px 8px; font-size: 12px; }
  .shape-grid { gap: 8px; }
  .shape-card { min-height: 96px; padding: 6px 4px; border-radius: 12px; }
  .shape-card img { height: 60px; }
  .shape-card span { font-size: 10px; }
  .color-grid { gap: 8px; }
  .color-card { min-height: 88px; padding: 8px 3px; gap: 6px; border-radius: 12px; font-size: 11px; }
  .color-swatch { width: 34px; height: 34px; }
  .panel-hint { margin-top: 4px; font-size: 10px; }
  .completion-heading { margin-top: 20px; }
  .completion-heading h1 { font-size: 28px; }
  .completion-heading p { font-size: 12px; }
  .completion-layout { grid-template-columns: 1fr; gap: 12px; }
  .completion-stage { height: clamp(250px, 37svh, 370px); width: min(360px, 100%); margin: 0 auto; }
  .completion-actions { width: min(320px, 100%); margin: 0 auto; gap: 12px; }
  .completion-actions .button { min-height: 52px; font-size: 15px; }
  .save-note { font-size: 11px; }
  .parent-link { margin-top: 4px; }
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .gallery-card { padding: 12px 8px; border-radius: 20px; }
  .gallery-card canvas { height: 190px; }
  .gallery-card h2, .gallery-card strong { font-size: 13px; }
  .gallery-card .quiet-button { font-size: 11px; padding: 8px 10px; }
}

@media (max-width: 359px) {
  .site-shell { padding-inline: 12px; }
  .brand { width: 126px; }
  .header-actions .quiet-button { max-width: 94px; gap: 4px; font-size: 10px; }
  .header-actions .quiet-button svg { display: none; }
  .maker-heading p { display: none; }
  .controls-panel { padding: 10px; }
  .category-tab { font-size: 12px; }
  .shape-grid, .color-grid { gap: 6px; }
  .shape-card img { height: 54px; }
  .shape-card { min-height: 90px; }
  .home-copy h1 { font-size: 22px; }
  .color-card { font-size: 10px; }
}

@media (max-height: 720px) and (max-width: 767px) {
  .home-copy { padding-top: 0; }
  .eyebrow { margin-bottom: 8px; }
  .hero-friends { height: 220px; }
  .home-actions { margin-top: 8px; gap: 8px; }
  .home-actions .button { min-height: 52px; }
  .editor-layout { grid-template-rows: 200px minmax(270px, 1fr); height: calc(100dvh - 120px); min-height: 482px; }
  .completion-stage { height: 250px; }
}

@media (orientation: landscape) and (max-height: 600px) {
  .site-shell { padding-top: 8px; }
  .site-header { min-height: 48px; margin-bottom: 8px; }
  .brand { width: 120px; }
  .home-copy { padding-top: 0; }
  .hero-friends { height: 180px; }
  .home-actions { flex-direction: row; width: auto; }
  .home-actions .button { width: auto; min-width: 200px; }
  .maker-heading { margin-bottom: 8px; }
  .maker-heading h1 { font-size: 18px; }
  .editor-layout { grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); grid-template-rows: 1fr; gap: 12px; height: calc(100dvh - 116px); min-height: 270px; }
  .preview-panel { padding: 8px 12px; }
  .preview-topbar { align-items: flex-start; }
  .avatar-stage { position: absolute; inset: 32px 8px 8px; width: auto; }
  .preview-message { display: none; }
  .finish-button { position: absolute; right: 12px; bottom: 12px; width: auto; min-width: 120px; min-height: 44px; margin: 0; padding: 8px 16px; font-size: 14px; }
  .controls-panel { padding: 8px; }
  .category-tab { min-height: 44px; flex-direction: row; gap: 4px; font-size: 12px; }
  .category-tab svg { width: 19px; height: 19px; }
  .part-selector { margin-top: 6px; }
  .part-selector select { min-height: 36px; padding-block: 4px; }
  .mode-tabs { margin: 6px 0; }
  .mode-tab { min-height: 36px; padding-block: 4px; }
  .panel-hint { display: none; }
  .shape-card { min-height: 92px; }
  .shape-card img { height: 54px; }
  .completion-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
  .completion-stage { height: 260px; }
  .completion-actions { gap: 8px; }
  .completion-heading { margin: 8px auto; }
  .completion-heading h1 { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .intro-playing .scene-train { display: none; }
  .intro-playing .friend { opacity: 1; translate: none; }
}

/* Keep the illustration and the controls inside the editor's fixed row. */
@media (min-width: 768px) {
  .editor-layout { grid-template-rows: minmax(0, 1fr); }
}
.screen:focus { outline: none; }
.undo-button, .mode-tab, .part-selector select { min-height: 44px; }
.shape-card .selection-check { display: none; }
body[data-screen="home"] .brand { width: 230px; }
@media (max-width: 767px) {
  body[data-screen="home"] .brand { width: 190px; }
  .maker-heading p { display: none; }
  .maker-heading h1 { font-size: 17px; }
  .train-window img { height: 154px; }
}

.mobile-break { display: none; }
@media (max-width:767px) { .mobile-break { display: inline; } .completion-heading h1 {font-size:26px;line-height:1.5;} }

/* Allow tall hairstyles and lower shoes to stay inside the original safe area. */
.avatar-stage .avatar-canvas[data-age="kids"], .completion-stage .avatar-canvas[data-age="kids"] { height: 125%; top: 50%; }
.avatar-stage .avatar-canvas[data-age="baby"], .completion-stage .avatar-canvas[data-age="baby"] { height: 150%; top: 44%; }
@media (max-width: 767px), (orientation: landscape) and (max-height: 600px) {
  .avatar-stage { inset: 44px 12px 66px; }
  .preview-message { white-space: nowrap; max-width: none; font-size: 10px; bottom: 26px; }
}
@media (max-width: 359px) { .preview-message { display: none; } }

/* One editor grid, with shape selection first and color revealed on request. */
.gallery-link { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; width: 72px; min-height: 56px; padding: 4px; border-radius: 16px; background: var(--cream); font-size: 11px; font-weight: 700; line-height: 1.2; }
.gallery-link svg { width: 18px; height: 18px; }
.gallery-link br { display: initial; }
.maker-screen { --editor-inset: 12px; --editor-gap: 8px; --editor-control-height: 44px; --editor-control-radius: 12px; display: flex; flex-direction: column; gap: var(--editor-gap); }
.maker-screen .editor-layout { height: min(700px, calc(100dvh - 200px)); min-height: 520px; gap: var(--editor-gap); }
.maker-screen .preview-panel, .maker-screen .controls-panel { padding: 6px var(--editor-inset); border: 0; gap: var(--editor-gap); }
.preview-topbar { min-height: 24px; flex-shrink: 0; align-items: center; }
#preview-caption { flex: 1; text-align: right; font-size: 12px; font-weight: 700; }
.age-badge { min-height: 24px; padding: 2px 10px; }
.avatar-stage { position: relative; inset: auto; flex: 1; width: 100%; min-height: 0; border-radius: 16px; background: rgba(255,255,255,.58); cursor: default; }
.avatar-stage .avatar-canvas { pointer-events: none; }
.preview-pan-hint { display: none; position: absolute; bottom: 6px; left: 8px; padding: 2px 8px; border-radius: 8px; background: var(--cream); font-size: 12px; pointer-events: none; }
.preview-tools { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: var(--editor-gap); flex-shrink: 0; }
.preview-view-button, .preview-expand { display: flex; align-items: center; justify-content: center; gap: 6px; min-width: 44px; min-height: 44px; padding: 6px 4px; border-radius: var(--editor-control-radius); background: var(--cream); border: 1px solid var(--line); font-size: 13px; font-weight: 700; white-space: nowrap; }
.preview-expand svg { width: 17px; height: 17px; }
.zoom-controls { display: none; grid-template-columns: 44px minmax(28px,1fr) 44px; align-items: center; gap: 8px; }
.zoom-controls button { display: grid; place-items: center; width: 44px; height: 44px; border-radius: var(--editor-control-radius); background: var(--cream); border: 1px solid var(--line); }
.zoom-controls button:disabled { opacity: .4; }
.zoom-controls output { text-align: center; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.parts-heading { display: flex; align-items: center; justify-content: space-between; margin: 0; min-height: 24px; gap: var(--editor-gap); }
.parts-heading h2 { font-size: 20px; line-height: 1.3; font-weight: 800; }
.parts-heading > span { font-size: 12px; color: var(--muted); }
.selection-toolbar { display: grid; grid-template-columns: minmax(0,1fr) 96px; gap: 8px; align-items: center; min-height: 44px; flex-shrink: 0; }
.selection-toolbar #part-controls { min-width: 0; }
.selection-toolbar #mode-controls { width: 96px; }
.selection-toolbar .part-buttons { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(44px,1fr); gap: 8px; padding: 0; overflow: visible; }
.part-buttons button { min-width: 44px; min-height: 44px; padding: 6px 2px; border: 2px solid var(--line); border-radius: var(--editor-control-radius); background: white; font-size: 13px; font-weight: 700; white-space: nowrap; }
.part-buttons button[aria-pressed="true"] { background: var(--mint-light); border-color: #32866b; }
.part-buttons button:focus-visible { outline-offset: -4px; }
.part-context { display: flex; align-items: center; min-height: 44px; margin: 0; font-size: 13px; font-weight: 700; }
.color-action { width: 96px; min-height: 44px; padding: 6px 2px; border: 2px solid #32866b; border-radius: var(--editor-control-radius); background: white; font-size: 13px; font-weight: 700; white-space: nowrap; }
.color-action[aria-expanded="true"] { background: var(--mint-light); }
.mode-static { display: flex; align-items: center; justify-content: center; width: 96px; min-height: 44px; color: var(--muted); font-size: 12px; }
#choice-controls { position: relative; }
.choices-scroll { padding: 0 0 24px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.choices-scroll::-webkit-scrollbar { display: none; }
.choices-more { position: absolute; bottom: 3px; right: 4px; padding: 2px 8px; border-radius: 8px; background: var(--cream); color: var(--muted); font-size: 11px; font-weight: 700; pointer-events: none; }
.shape-grid, .color-grid, .category-tabs { display: grid; grid-template-columns: repeat(12,minmax(0,1fr)); gap: var(--editor-gap); }
.category-tab { grid-column: span 3; min-height: 44px; }
.shape-card { grid-column: span 4; }
.color-card { grid-column: span 3; }
.maker-footer { display: flex; align-items: center; gap: var(--editor-gap); padding: 6px var(--editor-inset); background: var(--surface); border-radius: 20px; flex-shrink: 0; }
.maker-footer .finish-button { position: static; flex: 1; min-height: 48px; width: auto; margin: 0; }
.maker-footer .undo-button { min-height: 48px; font-size: 13px; }
.preview-dialog { width: min(680px, calc(100vw - 24px)); height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); max-height: none; max-width: none; padding: 12px; border-radius: 24px; background: var(--cream); overflow: hidden; }
.preview-dialog[open] { display: flex; flex-direction: column; gap: 8px; }
.preview-dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-shrink: 0; }
.preview-dialog-heading h2 { font-size: 18px; }
.preview-dialog .preview-panel { flex: 1; min-height: 0; padding: 8px 12px; gap: 8px; background: #eff8f4; }
.preview-dialog .preview-expand { display: none; }
.preview-dialog .zoom-controls { display: grid; }
.preview-dialog .preview-pan-hint { display: block; }
.preview-dialog .avatar-stage { touch-action: none; cursor: grab; }
.preview-dialog .avatar-stage:active { cursor: grabbing; }
.details-dialog { width: min(420px,calc(100vw - 24px)); padding: 20px; border-radius: 24px; }
.details-dialog > p { margin: 12px 0; }
.details-options { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.details-options button { display: flex; flex-direction: column; align-items: center; gap: 8px; min-height: 100px; padding: 12px; border-radius: 16px; background: white; border: 2px solid var(--line); font-size: 16px; font-weight: 700; }
.details-options img { object-fit: contain; }
@media (max-width: 767px) {
  .site-header { gap: 8px; }
  body[data-screen="home"] .brand { width: min(190px,calc(100vw - 160px)); }
  .gallery-link { min-height: 48px; width: 72px; }
  body[data-screen="maker"] { overflow: hidden; background-attachment: scroll; }
  body[data-screen="maker"] .site-shell { display: flex; flex-direction: column; height: 100dvh; min-height: 0; padding: max(8px,env(safe-area-inset-top)) 12px max(8px,env(safe-area-inset-bottom)); }
  body[data-screen="maker"] .site-header { flex-shrink: 0; min-height: 52px; height: 52px; margin-bottom: 8px; }
  body[data-screen="maker"] .brand { width: 112px; }
  .maker-screen { flex: 1; min-height: 0; }
  .maker-screen .editor-layout { flex: 1; height: auto; min-height: 0; grid-template-columns: 1fr; grid-template-rows: minmax(196px,1fr) minmax(252px,1.08fr); }
  .maker-screen .preview-panel, .maker-screen .controls-panel { border-radius: 20px; }
  .avatar-stage { position: relative; inset: auto; width: 100%; }
  .parts-heading h2 { font-size: 18px; }
  .category-tab { flex-direction: row; padding: 6px 2px; gap: 4px; font-size: 14px; }
  .category-tab svg { width: 18px; height: 18px; }
  .category-tab span { white-space: nowrap; }
  .shape-card { min-height: 104px; padding: 6px 4px; border-radius: var(--editor-control-radius); }
  .shape-card img { height: 64px; }
  .shape-card span { font-size: 12px; }
  .color-card { min-height: 94px; font-size: 12px; border-radius: var(--editor-control-radius); }
  .panel-hint { display: none; }
  .completion-heading { margin: 8px auto; }
  .completion-heading h1 { font-size: 24px; }
  .completion-stage { height: clamp(210px,32svh,300px); }
  .save-note { font-size: 12px; }
}
@media (max-width: 374px) {
  .selection-toolbar { row-gap: 8px; }
  .selection-toolbar #part-controls { grid-column: 1 / -1; }
  .selection-toolbar #mode-controls { grid-column: 2; }
  .preview-view-button { font-size: 12px; }
}
@media (max-width: 767px) and (max-height: 720px) {
  .shape-card { min-height: 98px; }
  .shape-card img { height: 60px; }
  .selection-toolbar[data-editor-category="hair"] ~ #choice-controls .shape-card img { height: 52px; }
  .selection-toolbar[data-editor-category="hair"] ~ #choice-controls .shape-card:not(.empty-choice) > span { min-height: 2.8em; }
}
@media (max-width: 359px) {
  .category-tab { font-size: 13px; }
  .category-tab svg { width: 16px; height: 16px; }
  .preview-dialog .preview-tools { grid-template-columns: 1fr; }
}
@media (max-width: 767px) and (max-height: 640px) and (orientation: portrait) {
  .maker-screen .editor-layout { grid-template-rows: minmax(170px,.85fr) minmax(232px,1.15fr); }
}
@media (orientation: landscape) and (max-height: 600px) {
  body[data-screen="maker"] .site-shell { height: 100dvh; min-height: 0; display: flex; flex-direction: column; padding-block: 6px; }
  body[data-screen="maker"] .site-header { min-height: 44px; height: 44px; margin-bottom: 4px; flex-shrink: 0; }
  .maker-screen { flex: 1; min-height: 0; }
  .maker-screen .editor-layout { flex: 1; height: auto; min-height: 0; grid-template-columns: minmax(0,1fr) minmax(0,1.15fr); grid-template-rows: minmax(0,1fr); }
  .maker-screen .preview-panel, .maker-screen .controls-panel, .maker-footer { padding: 8px; }
  .parts-heading h2 { font-size: 16px; }
  .maker-footer .finish-button, .maker-footer .undo-button { min-height: 44px; }
  .selection-toolbar #part-controls { grid-column: 1 / -1; }
  .selection-toolbar #mode-controls { grid-column: 2; }
  .preview-tools { grid-template-columns: 1fr; }
  .gallery-link { min-height: 44px; }
}
@media (max-width: 767px) and (max-height: 600px), (orientation: landscape) and (max-height: 600px) {
  .maker-screen .controls-panel { overflow-y: auto; overscroll-behavior: contain; }
  .maker-screen #choice-controls { flex: 0 0 auto; min-height: 144px; }
  .maker-screen .choices-scroll { flex: none; overflow: visible; }
  .maker-screen .choices-more { display: none; }
}
