:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  color-scheme: light;
  font-family: ui-rounded, "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  color: #344f58;
  background: #edf7f5;
  font-synthesis: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  background: radial-gradient(ellipse at 48% 22%, #ffffffad 0%, transparent 48%), linear-gradient(165deg, #e8f5f8 0%, #eef8f3 56%, #faf5e9 100%);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
button { font: inherit; cursor: pointer; border: 0; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
button, canvas { -webkit-tap-highlight-color: transparent; }
button:focus-visible, canvas:focus-visible { outline: 4px solid #427f9a; outline-offset: 5px; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
.svg-definitions { position: absolute; width: 0; height: 0; overflow: hidden; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.app-shell { --tool-size: clamp(72px, calc(60px + 2vw), 82px); --tool-gap: clamp(6px, .8vw, 10px); --header-height: 84px; --rail-width: calc(var(--tool-size) + 20px); width: 100%; min-width: 0; height: 100%; height: 100dvh; padding: 0 0 var(--safe-bottom) var(--safe-left); display: grid; grid-template-columns: var(--rail-width) minmax(0, 1fr) calc(var(--rail-width) + var(--safe-right)); grid-template-rows: calc(var(--header-height) + var(--safe-top)) minmax(0, 1fr); grid-template-areas: "header header header" "palette scene tools"; position: relative; }
.app-shell > * { min-width: 0; min-height: 0; }
.topbar { grid-area: header; position: relative; display: flex; min-width: 0; align-items: center; gap: 12px; padding: calc(6px + var(--safe-top)) calc(12px + var(--safe-right)) 6px 12px; z-index: 6; }
.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand-mark { width: 42px; height: 48px; display: block; transform: rotate(-8deg); }
.brand-mark svg { width: 100%; height: 100%; filter: drop-shadow(0 5px 0 #c4e9db); }
.brand-copy { display: flex; min-width: 0; flex-direction: column; gap: 4px; }
.brand-name { font-size: 25px; font-weight: 900; letter-spacing: -1.1px; line-height: 1.1; color: #345e59; }
.brand-name > span { color: #3cae93; }
.brand-tagline { color: #7a928d; font-size: 10px; letter-spacing: .25px; }
.app-shell[data-layout="sides"] .topbar { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
.app-shell[data-layout="sides"] .brand { grid-column: 2; position: relative; justify-content: center; text-align: center; }
.app-shell[data-layout="sides"] .brand-mark { position: absolute; right: calc(100% + 13px); }
.icon-button {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 78px;
  height: 78px;
  min-width: 72px;
  min-height: 72px;
  border-radius: 25px;
  color: #638a8c;
  background: #ffffffed;
  border: 2px solid #fff;
  box-shadow: 0 5px 0 #d4e7e2, 0 9px 20px #527c7710;
  transition: transform .18s ease, box-shadow .18s ease, background .2s ease;
}
.icon-button > svg { width: 35px; height: 35px; position: relative; pointer-events: none; }
.icon-button:active { transform: translateY(4px) scale(.96); box-shadow: 0 1px 0 #cfe1dc, 0 2px 8px #527c7710; }
.sound-button { color: #7c9e96; }
.sound-button .sound-off { display: none; }
.sound-button.is-muted .sound-off { display: block; }
.sound-button.is-muted .sound-waves { display: none; }
.sound-button.is-muted { color: #91a6a1; background: #f6faf8; }
.music-button { color: #a08aba; background: #fbf7ff; box-shadow: 0 5px 0 #e0d5e9, 0 8px 25px #8161940a; }
.music-button .music-off { display: none; }
.music-button.is-muted .music-off { display: block; }
.music-button.is-muted { color: #aaa0b3; background: #f8f5fa; }
.music-button.is-playing:not(.is-muted) > svg { animation: music-sway 5s ease-in-out infinite; }
@keyframes music-sway { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
.clear-button { background: #fff8e8; color: #ba9157; box-shadow: 0 5px 0 #eadbbd, 0 9px 20px #9876530a; overflow: hidden; }
.clear-button > svg { margin-top: -7px; }
.button-caption { font-size: 9px; font-weight: 700; letter-spacing: .15px; position: absolute; bottom: 8px; pointer-events: none; }
.hold-progress { position: absolute; inset: 0; background: conic-gradient(from 0deg, #ffda86 var(--hold, 0deg), transparent var(--hold, 0deg)); opacity: .6; pointer-events: none; }
.clear-button.is-holding { box-shadow: 0 3px 0 #eadbbd, 0 0 0 5px #ffdf924f; }

#scene-wrap { grid-area: scene; min-height: 0; min-width: 0; position: relative; overflow: hidden; }
#world { display: block; width: 100%; height: 100%; touch-action: none; outline-offset: -6px; }
.scene-hint { position: absolute; top: 9px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; max-width: calc(100% - 20px); padding: 10px 18px; border: 1px solid #ffffffb3; border-radius: 30px; background: #ffffff8c; font-size: 13px; color: #728f86; text-align: center; pointer-events: none; z-index: 1; }
.scene-hint span { color: #d3b85e; font-size: 17px; }
.side-tools { grid-area: tools; display: grid; grid-template-columns: var(--tool-size); grid-auto-rows: max-content; align-items: start; align-content: start; justify-content: center; gap: var(--tool-gap); min-width: 0; min-height: 0; padding: 4px calc(4px + var(--safe-right)) 8px 4px; border-left: 1px solid #ffffffa3; background: linear-gradient(90deg, #f5fbf358, #eef7f181); overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; touch-action: pan-y; scrollbar-gutter: stable; scrollbar-width: thin; scrollbar-color: #99baa9 #e6f0e9; z-index: 2; }
.side-tools > .icon-button { width: var(--tool-size); height: var(--tool-size); }
.side-tools::-webkit-scrollbar { width: 8px; }
.side-tools::-webkit-scrollbar-track { background: #e6f0e9; border-radius: 8px; }
.side-tools::-webkit-scrollbar-thumb { background: #99baa9; border: 2px solid #e6f0e9; border-radius: 8px; }
.tool-button { width: var(--tool-size, 82px); height: var(--tool-size, 82px); border-radius: 27px; }
.tool-button > svg { width: 42px; height: 42px; }
.rotate-button { color: #aa8cc8; background: #fbf7ff; box-shadow: 0 5px 0 #e1d5ed, 0 8px 25px #8161940a; }
.view-button { color: #69a0c2; background: #f5fbff; box-shadow: 0 5px 0 #d2e4ef, 0 8px 25px #6182940a; }
.base-button { color: #6b9f88; background: #f1fbf5; box-shadow: 0 5px 0 #cfe6d9, 0 8px 25px #618c730a; }
.base-button.is-selected, .base-button[aria-expanded="true"] { background: #dff5e8; box-shadow: 0 5px 0 #c4decf, 0 0 0 4px #dcefe380; }
.trash-button { color: #80a68f; background: #f7fcf6; box-shadow: 0 5px 0 #d7e7d4, 0 8px 25px #7294610a; }
.base-panel {
  position: fixed;
  z-index: 20;
  display: flex;
  flex-direction: row-reverse;
  gap: var(--tool-gap);
  width: max-content;
  --base-slide-x: 6px;
  --base-slide-y: 0px;
}
.base-panel:not([hidden]) > button { animation: reveal-base-control .16s ease-out; }
@keyframes reveal-base-control {
  from { opacity: 0; translate: var(--base-slide-x) var(--base-slide-y); }
  to { opacity: 1; translate: 0 0; }
}
.base-size-button { width: var(--tool-size, 82px); height: var(--tool-size, 82px); border-radius: 21px; color: #60947d; background: #fff; box-shadow: 0 4px 0 #cfe3d7; }
.base-size-button[aria-disabled="true"] { color: #9eb4a8; background: #eaf4ee; box-shadow: 0 4px 0 #dbe8df; }
.basket-smile { display: none; }
.has-selection .rotate-button { background: #f3eaff; box-shadow: 0 5px 0 #dac5ec, 0 0 0 5px #ede2f952; }
.has-selection .trash-button { background: #ecf9e9; }
.trash-button.is-over { background: #d9f5cd; transform: scale(1.12); box-shadow: 0 5px 0 #bfdcb7, 0 0 0 8px #e4f6da; }
.trash-button.is-over .basket-smile { display: block; }
.scene-sticker { position: absolute; pointer-events: none; color: #ead992; font-size: 35px; opacity: .7; }
.sticker-flower { left: 5%; bottom: 15%; transform: rotate(-15deg); }

.toy-shelf { grid-area: palette; display: flex; min-width: 0; min-height: 0; flex-direction: column; align-items: center; z-index: 2; padding: 4px 0 8px; }
.shelf-caption, .shelf-footnote { display: none; }
.palette { display: grid; grid-template-columns: var(--tool-size); grid-auto-rows: var(--tool-size); align-items: start; align-content: start; justify-content: center; gap: var(--tool-gap); width: 100%; height: 100%; min-height: 0; padding: 6px 5px 10px; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; scrollbar-gutter: stable; scrollbar-width: thin; scrollbar-color: #aec7b6 transparent; }
.palette::-webkit-scrollbar { width: 8px; height: 6px; }
.palette::-webkit-scrollbar-track { background: transparent; }
.palette::-webkit-scrollbar-thumb { background: #aec7b6; border-radius: 8px; }
.brick-choice {
  position: relative;
  display: flex;
  flex-shrink: 0;
  justify-content: center;
  align-items: center;
  width: var(--tool-size);
  height: var(--tool-size);
  min-width: 72px;
  min-height: 72px;
  color: var(--brick);
  border-radius: 25px;
  background: var(--tile);
  border: 2px solid transparent;
  box-shadow: inset 0 -4px 0 #00000003;
  transition: transform .18s ease, background .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.brick-choice > svg { width: 100%; height: calc(var(--tool-size) - 3px); overflow: visible; pointer-events: none; }
.brick-art { transform-origin: 60px 75px; animation: breathe 4.8s ease-in-out infinite; animation-delay: var(--delay); }
.brick-choice:active { transform: translateY(3px) scale(.95); }
.brick-choice.is-selected { border-color: var(--brick); background: #fff; box-shadow: 0 0 0 3px var(--tile), inset 0 -4px 0 var(--tile); }
.choice-dot { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: var(--brick); bottom: 7px; opacity: .65; pointer-events: none; }
.brick-choice.is-selected .choice-dot { width: 17px; border-radius: 5px; opacity: 1; }

.sky-decoration { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.sky-spark { position: absolute; color: #dec77b; font-size: 24px; opacity: .65; }
.spark-one { left: 18%; top: 17%; transform: rotate(10deg); }
.spark-two { right: 18%; top: 53%; font-size: 32px; }

.state-card { position: absolute; left: 50%; top: 48%; transform: translate(-50%, -50%); width: min(340px, calc(100% - 36px)); padding: 32px 25px; background: #fffffff2; border: 3px solid #fff; border-radius: 30px; box-shadow: 0 9px 0 #d7e8df, 0 20px 70px #44695b14; text-align: center; z-index: 5; }
.state-card p { margin: 20px 0 0; font-size: 15px; line-height: 1.5; color: #6a8e81; }
.loading-brick { display: inline-flex; position: relative; margin-top: 12px; width: 65px; height: 42px; border-radius: 10px; background: #70d5b6; box-shadow: inset 0 -8px 0 #00000008; animation: unpack 1.6s ease-in-out infinite; }
.loading-brick i { position: absolute; top: -12px; width: 17px; height: 18px; background: #91e3c8; border-radius: 6px 6px 0 0; }
.loading-brick i:first-child { left: 10px; }
.loading-brick i:last-child { right: 10px; }
.fallback-cloud { font-size: 48px; color: #9fc6d6; }
.state-card .adult-note { font-size: 12px; margin-top: 12px; color: #8c9d98; }
.retry-button { margin-top: 20px; min-height: 72px; min-width: 160px; padding: 14px 22px; background: #e0f5ea; color: #568573; border-radius: 22px; font-size: 14px; font-weight: bold; }
.retry-button span { display: inline-block; margin-right: 7px; font-size: 23px; vertical-align: middle; }
.is-celebrating .brand-mark { animation: happy-wiggle .7s ease; }

@keyframes breathe { 0%, 100% { transform: translateY(1px) rotate(-1deg); } 50% { transform: translateY(-3px) rotate(1deg); } }
@keyframes unpack { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-7px) rotate(4deg); } }
@keyframes happy-wiggle { 0%,100% { transform: rotate(-8deg); } 30% { transform: rotate(8deg) translateY(-5px); } 65% { transform: rotate(-14deg); } }
@media (hover: hover) {
  .icon-button:hover { transform: translateY(-3px); }
  .brick-choice:hover { transform: translateY(-4px); box-shadow: 0 5px 0 var(--tile); }
}

.layout-button { color: #6f9a8b; background: #f8fdf9; }
.layout-panel { position: fixed; z-index: 20; display: grid; grid-template-columns: repeat(2, minmax(72px, 1fr)); gap: 8px; width: 260px; max-width: calc(100% - 16px); overflow: auto; padding: 12px; border: 2px solid #fff; border-radius: 26px; background: #f3fbf6; box-shadow: 0 6px 0 #d3e7d9, 0 18px 40px #527e6426; }
.layout-choice { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-width: 72px; min-height: 96px; padding: 8px; border: 2px solid #fff; border-radius: 20px; background: #fff; color: #79998b; box-shadow: 0 3px 0 #dfebe3; }
.layout-choice > svg { width: 64px; height: 48px; pointer-events: none; }
.layout-choice > span { font-size: 12px; font-weight: 700; pointer-events: none; }
.layout-choice[aria-pressed="true"] { color: #507e68; border-color: #a6d8bc; background: #e5f5eb; box-shadow: 0 3px 0 #c3dfce; }
.layout-note { grid-column: 1 / -1; margin: 2px 4px 0; color: #7c9486; font-size: 11px; line-height: 1.4; text-align: center; }

/* Each horizontal bar gains a second row only when its buttons need one. */
.app-shell[data-layout="stacked"] { --tool-size: 72px; --tool-gap: 6px; --palette-bar-height: calc((var(--tool-size) + var(--tool-gap)) * var(--palette-rows, 1) - var(--tool-gap) + 14px); --tools-bar-height: calc((var(--tool-size) + var(--tool-gap)) * var(--tools-rows, 1) - var(--tool-gap) + 14px); padding-right: var(--safe-right); grid-template-columns: 44px minmax(0, 1fr); grid-template-rows: calc(var(--header-height) + var(--safe-top)) var(--palette-bar-height) minmax(0, 1fr) var(--tools-bar-height); grid-template-areas: "header header" ". palette" ". scene" "tools tools"; }
.app-shell[data-layout="stacked"] { --header-height: 8px; }
.app-shell[data-layout="stacked"] .topbar { padding: 0; }
/* Reserve a slim left margin so upright letters never cover the play area. */
.app-shell[data-layout="stacked"] .brand {
  position: absolute;
  top: 50vh;
  top: 50dvh;
  left: 8px;
  width: 28px;
  transform: translateY(-50%);
  flex-direction: column;
  pointer-events: none;
}
.app-shell[data-layout="stacked"] .brand-mark { position: absolute; bottom: calc(100% + 8px); width: 28px; height: 32px; }
.app-shell[data-layout="stacked"] .brand-copy { display: block; }
.app-shell[data-layout="stacked"] .brand-name { display: block; writing-mode: vertical-rl; text-orientation: upright; font-size: 20px; line-height: 1.1; letter-spacing: 0; white-space: nowrap; }
.app-shell[data-layout="stacked"] .brand-tagline { display: none; }
.app-shell[data-layout="stacked"] .toy-shelf { padding: 0 2px; }
.app-shell[data-layout="stacked"] .palette { grid-template-columns: repeat(var(--palette-columns, 8), var(--tool-size)); grid-template-rows: repeat(var(--palette-rows, 1), var(--tool-size)); grid-auto-flow: row; grid-auto-rows: var(--tool-size); justify-content: start; width: max-content; max-width: 100%; padding: 4px; overflow-x: auto; overflow-y: hidden; touch-action: pan-x; scrollbar-gutter: auto; }
.app-shell[data-layout="stacked"] .side-tools { grid-template-columns: none; grid-template-rows: repeat(var(--tools-rows, 1), var(--tool-size)); grid-auto-columns: var(--tool-size); grid-auto-rows: var(--tool-size); grid-auto-flow: column; justify-content: start; justify-content: safe center; padding: 2px 4px 4px; border-left: 0; border-top: 1px solid #ffffffb3; overflow-x: auto; overflow-y: hidden; touch-action: pan-x; scrollbar-gutter: auto; }
.app-shell[data-layout="stacked"] .base-panel { flex-direction: column-reverse; --base-slide-x: 0px; --base-slide-y: 6px; }
.app-shell[data-layout="stacked"] .side-tools::-webkit-scrollbar { height: 6px; }

/* Two independent side rails leave the whole middle cell for the building. */
@media (max-width: 900px), (max-height: 600px) {
  .app-shell { --tool-size: 72px; --tool-gap: 6px; --header-height: 84px; }
  .topbar { padding: calc(4px + var(--safe-top)) calc(8px + var(--safe-right)) 4px 8px; }
  .brand { gap: 7px; }
  .brand-mark { width: 30px; height: 34px; }
  .brand-name { font-size: 21px; letter-spacing: -.7px; }
  .brand-tagline { display: none; }
  .icon-button { border-radius: 22px; }
  .icon-button > svg { width: 33px; height: 33px; }
  .tool-button > svg { width: 37px; height: 37px; }
  .scene-hint, .sticker-flower { display: none; }
  .brick-choice { border-radius: 20px; }
  .choice-dot { bottom: 4px; width: 5px; height: 5px; }
  .state-card { width: min(320px, calc(100% - 16px)); padding: 20px 12px; }
  .state-card p { font-size: 13px; }
  .retry-button { min-width: 140px; padding: 12px; }
}

/* Keep the brand compact in narrow windows. */
@media (max-width: 540px) {
  .brand-name { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}

@font-face {font-family:Newsreader;src:url('../assets/fonts/newsreader-latin.woff2') format('woff2');font-weight:400 600;font-display:swap}
:root {--paper:var(--home-paper);--ink:var(--home-ink);--soft:var(--home-blue-wash);--tile-bg:var(--home-surface);--edge:var(--home-line);font-family:var(--font);color:var(--ink)}
:root[data-theme=dim] {--paper:var(--home-dim-paper);--ink:var(--home-dim-ink);--soft:var(--home-dim-blue-wash);--tile-bg:var(--home-dim-surface);--edge:var(--home-dim-line)}
body {background:var(--paper);color:var(--ink)}
.sky-decoration,.scene-sticker {display:none}
.app-shell .topbar {border-bottom:1px solid var(--edge);background:var(--paper)}
.app-shell .topbar .brand-name {grid-column:2;margin:0;font:500 clamp(25px, 4vw, 38px)/1 Newsreader,Georgia,serif;letter-spacing:-.035em;color:var(--ink);text-align:center;writing-mode:horizontal-tb}
.topbar .back {display:inline-flex;align-items:center;gap:9px;justify-self:start;margin-left:10px;min-height:44px;padding:0 12px;color:var(--ink);font-size:15px;text-decoration:none}
.topbar .back span:first-child {font-size:25px}
.back:hover {text-decoration:underline}
:focus-visible {outline:3px solid var(--ink);outline-offset:2px}
.app-shell[data-layout=stacked] {--header-height:52px;grid-template-columns:minmax(0,1fr);grid-template-areas:"header" "palette" "scene" "tools"}
.app-shell[data-layout=stacked] .topbar {display:grid;grid-template-columns:minmax(0,1fr) auto minmax(0,1fr)}
.app-shell .side-tools,.toy-shelf {background:var(--soft);border:0}
.app-shell .tool-button,.app-shell .brick-choice,.app-shell .layout-choice,.app-shell .base-size-button {
  color:var(--ink);background:var(--tile-bg);border:1px solid var(--edge);border-radius:16px;box-shadow:none
}
.app-shell .is-selected,.app-shell .tool-button[aria-expanded=true],.app-shell .layout-choice[aria-pressed=true] {outline:2px solid var(--ink);outline-offset:-3px}
.app-shell .is-muted {opacity:.7}
.layout-panel,.state-card {background:var(--tile-bg);color:var(--ink);border:1px solid var(--edge);border-radius:16px;box-shadow:0 6px 18px #243f3b18}
.scene-hint {border:0;background:var(--paper);color:var(--ink);font-size:15px}
@media(max-width:540px){.topbar .back span:last-child{position:absolute;clip-path:inset(50%);width:1px;height:1px;overflow:hidden}.topbar .back{min-width:44px;justify-content:center;margin-left:0}}
.app-shell .brick-choice {color:var(--brick)}
.brick-art {animation:none}
.app-shell .icon-button:not(.tool-button) {background:var(--tile-bg);color:var(--ink);border:1px solid var(--edge);border-radius:16px;box-shadow:none}
html[data-motion=none] *,html[data-motion=none] *::before {transition:none!important;animation:none!important}
