/* Storybook Maker: look C "Crayon Box" (Nick's pick, 2026-10-16). White paper with a dotted grid,
   crayon-stroke borders, rainbow drawer tabs, primary colours. Fonts: Chewy for the one big title,
   Bubblegum Sans for buttons and labels, Nunito 600-700 for anything she reads. Nothing kid-facing
   under 15px, nothing tappable under 44px. The four screen corners belong to the shared buttons. */
:root {
	--ink: #222222;
	--red: #e63946;
	--yellow: #ffd60a;
	--blue: #1d8fe1;
	--green: #2dc653;
	--orange: #ff7f1e;
	--purple: #c77dff;
	--pink: #ffb6d9;
	--paper: #ffffff;
	--cream: #ffe3a8;
	--cr: 255px 18px 225px 18px / 18px 225px 18px 255px;
	--cr2: 18px 255px 18px 225px / 225px 18px 255px 18px;
	--sat: env(safe-area-inset-top, 0px);
	--sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
	font-family: 'Nunito', sans-serif;
	font-weight: 700;
	color: var(--ink);
	background-color: var(--paper);
	background-image: radial-gradient(rgba(34, 34, 34, 0.13) 1.5px, transparent 1.5px);
	background-size: 22px 22px;
	display: flex;
	flex-direction: column;
	touch-action: none;
	-webkit-user-select: none;
	user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 4px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- stickers (buttons) ---------- */
.stk {
	display: inline-flex; align-items: center; justify-content: center; gap: 8px;
	min-height: 46px; min-width: 46px; padding: 0 16px;
	background: var(--paper); border: 4px solid var(--ink); border-radius: var(--cr);
	font-family: 'Bubblegum Sans', 'Fredoka', sans-serif; font-size: 19px; line-height: 1;
	box-shadow: 3px 3px 0 var(--ink);
	transition: transform 0.08s, box-shadow 0.08s;
	white-space: nowrap;
}
.stk:nth-child(even) { border-radius: var(--cr2); }
.stk:active, .stk.down { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.stk svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.stk.red { background: var(--red); color: #fff; }
.stk.yellow { background: var(--yellow); }
.stk.blue { background: var(--blue); color: #fff; }
.stk.green { background: var(--green); }
.stk.orange { background: var(--orange); }
.stk.purple { background: var(--purple); }
.stk.pink { background: var(--pink); }
.stk.ghost { background: transparent; box-shadow: none; border-style: dashed; }
.stk.on { outline: 5px solid var(--blue); outline-offset: 2px; }
.stk.big { min-height: 56px; font-size: 22px; padding: 0 22px; }
.stk.icon { padding: 0; width: 52px; height: 52px; }
.stk.icon svg { width: 26px; height: 26px; }

/* ---------- top bar ---------- */
#top {
	height: calc(68px + var(--sat)); padding: var(--sat) 76px 0 76px;
	display: flex; align-items: center; gap: 8px; flex: none;
}
#titleBtn {
	display: flex; align-items: center; gap: 8px; min-height: 48px; min-width: 60px; max-width: 42vw;
	background: transparent; border: 0; padding: 0 6px;
	font-family: 'Chewy', cursive; font-size: clamp(22px, 2.6vw, 32px); color: var(--red);
	overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#titleBtn span { overflow: hidden; text-overflow: ellipsis; }
#titleBtn svg { width: 20px; height: 20px; stroke: var(--ink); fill: none; stroke-width: 2.6; flex: none; }
#top .sp { flex: 1; }
#top .stk { min-height: 48px; }
@media (max-width: 1000px) { #top .stk span { display: none; } #top .stk { padding: 0 12px; } }

/* ---------- main ---------- */
#main { flex: 1; display: flex; gap: 12px; padding: 4px 14px 0 14px; min-height: 0; }
#left { flex: 1 1 62%; display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; }
#stageWrap {
	position: relative; width: 100%; flex: 1; min-height: 0;
	display: flex; align-items: center; justify-content: center;
}
#frame {
	position: relative; aspect-ratio: 4 / 3; max-width: 100%; max-height: 100%;
	width: min(100%, calc((100vh - 330px) * 4 / 3));
	border-radius: 18px; overflow: visible;
	filter: drop-shadow(5px 6px 0 rgba(34, 34, 34, 0.18));
}
#stage { display: block; width: 100%; height: 100%; touch-action: none; border-radius: 18px; }
#stage .bk-item { cursor: grab; }
#textOver {
	position: absolute; left: 5%; right: 4%; top: 78.5%; height: 20%;
	border: 0; background: transparent; resize: none; padding: 0;
	font-family: 'Nunito', sans-serif; font-weight: 700; color: var(--ink);
	font-size: calc(var(--fw, 760px) * 0.0325); line-height: 1.27;
	-webkit-user-select: text; user-select: text;
}
#textOver::placeholder { color: rgba(34, 34, 34, 0.4); }
#textOver.center { left: 12%; right: 12%; top: 42%; height: 40%; text-align: center; font-family: 'Bubblegum Sans', sans-serif; font-weight: 400; font-size: calc(var(--fw, 760px) * 0.045); }
#textOver.author { top: 70%; height: 26%; text-align: center; }
/* padding-left 64: the row sits right above the strip, in the lane of the shared 📮 and 🔊 */
#chips { display: flex; align-items: center; gap: 8px; min-height: 52px; overflow-x: auto; flex: none; padding: 2px 4px 2px 64px; }
#chips .who { font-family: 'Bubblegum Sans', sans-serif; font-size: 18px; color: var(--red); white-space: nowrap; padding-right: 4px; }
#chips .stk { min-height: 44px; font-size: 17px; padding: 0 13px; flex: none; }

/* page strip, clear of the bottom-left corner (🔊 + 📮) */
#strip {
	display: flex; align-items: flex-end; gap: 12px; flex: none;
	height: 100px; padding: 0 8px 6px 64px; overflow-x: auto; overflow-y: hidden;
}
#strip .pg {
	position: relative; flex: none; width: 96px; height: 72px; padding: 0; overflow: hidden;
	background: #fff; border: 4px solid var(--ink); border-radius: 8px; box-shadow: 3px 3px 0 var(--ink);
}
#strip .pg svg { width: 100%; height: 100%; display: block; }
#strip .pg .n {
	position: absolute; left: 4px; bottom: 2px; font-family: 'Bubblegum Sans', sans-serif; font-size: 15px;
	background: #fff; border: 2px solid var(--ink); border-radius: 8px; padding: 0 6px; line-height: 20px;
}
#strip .pg:nth-child(odd) { transform: rotate(-2deg); }
#strip .pg:nth-child(even) { transform: rotate(1.5deg); }
#strip .pg.cur { width: 108px; height: 82px; border-color: var(--blue); border-width: 5px; transform: none; }
#strip .pg.drag { opacity: 0.5; }
#strip .add { flex: none; height: 72px; }

/* ---------- drawer ---------- */
#drawer { flex: 0 0 min(36%, 430px); display: flex; flex-direction: column; min-width: 300px; min-height: 0; }
#tabs { display: flex; align-items: flex-end; gap: 5px; padding: 0 6px; flex: none; }
#tabs .tab {
	min-height: 46px; padding: 0 10px; flex: 1; min-width: 0;
	border: 4px solid var(--ink); border-bottom: 0; border-radius: 14px 14px 0 0;
	font-family: 'Bubblegum Sans', sans-serif; font-size: 17px; line-height: 1;
	box-shadow: none;
}
#tabs .tab.on { min-height: 54px; font-size: 19px; }
#panel {
	flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
	background: var(--cream); border: 5px solid var(--ink);
	border-radius: 10px 22px 14px 20px / 20px 14px 22px 10px;
	padding: 12px; display: flex; flex-direction: column; gap: 10px;
	touch-action: pan-y;
}
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tile {
	display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
	min-height: 96px; padding: 6px 4px; background: #fff; border: 4px solid var(--ink); border-radius: var(--cr);
	font-family: 'Bubblegum Sans', sans-serif; font-size: 15px; line-height: 1.1; text-align: center;
	box-shadow: 3px 3px 0 var(--ink);
}
.tile:nth-child(even) { border-radius: var(--cr2); }
.tile:active { transform: translate(3px, 3px); box-shadow: none; }
.tile svg, .tile img { width: 60px; height: 60px; display: block; }
.tile.wide svg { width: 100%; height: 64px; }
.tile .em { font-size: 44px; line-height: 1; }
.tile.on { outline: 5px solid var(--blue); outline-offset: 2px; }
.tile.dash { border-style: dashed; background: var(--yellow); box-shadow: none; }
.tile.wide { grid-column: span 1; }
.tile img { object-fit: cover; border-radius: 8px; width: 100%; height: 64px; }
.sec { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.sec h3 { margin: 0; font-family: 'Chewy', cursive; font-weight: 400; font-size: 20px; color: var(--red); }
.sec .rule { flex: 1; height: 4px; background: var(--ink); border-radius: 4px; opacity: 0.4; }
.chiprow { display: flex; gap: 6px; flex-wrap: wrap; }
.chiprow .stk { min-height: 44px; font-size: 16px; padding: 0 12px; }
.hint { font-size: 16px; font-weight: 700; color: #5a4a2a; margin: 0; line-height: 1.4; }
.swatch { width: 46px; height: 46px; border: 4px solid var(--ink); border-radius: 50%; padding: 0; box-shadow: 2px 2px 0 var(--ink); }
.swatch.on { outline: 5px solid var(--blue); outline-offset: 2px; }
.input {
	width: 100%; min-height: 50px; padding: 8px 14px; border: 4px solid var(--ink); border-radius: 14px;
	font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 20px; color: var(--ink); background: #fff;
	-webkit-user-select: text; user-select: text;
}

/* ---------- sheets ---------- */
.sheet {
	position: fixed; inset: 0; z-index: 900; display: flex; align-items: center; justify-content: center;
	background: rgba(34, 34, 34, 0.45); padding: 16px;
}
.sheet .card {
	background: #fff; border: 5px solid var(--ink); border-radius: 26px 12px 22px 14px / 14px 22px 12px 26px;
	box-shadow: 6px 6px 0 var(--ink); width: min(96vw, 760px); max-height: 92vh;
	display: flex; flex-direction: column; gap: 12px; padding: 18px; overflow: auto;
	background-image: radial-gradient(rgba(34, 34, 34, 0.1) 1.5px, transparent 1.5px); background-size: 22px 22px;
}
.sheet h2 { margin: 0; font-family: 'Chewy', cursive; font-weight: 400; font-size: 30px; color: var(--red); padding-right: 56px; }
.sheet .x { position: absolute; right: 10px; top: 10px; }
.sheet .card { position: relative; }
.sheet .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.sheet .row.end { justify-content: flex-end; }
.sheet .big { font-size: 22px; min-height: 56px; }
#charPreview { width: 200px; height: 214px; margin: 0 auto; }
#charPreview svg { width: 100%; height: 100%; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.shelf .bk { display: flex; flex-direction: column; gap: 6px; align-items: stretch; background: #fff; border: 4px solid var(--ink); border-radius: 12px; padding: 8px; box-shadow: 3px 3px 0 var(--ink); }
.shelf .bk svg { width: 100%; height: auto; display: block; border-radius: 8px; }
.shelf .bk .t { font-family: 'Bubblegum Sans', sans-serif; font-size: 16px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shelf .bk.cur { border-color: var(--blue); border-width: 5px; }

/* ---------- read mode ---------- */
#reader { position: fixed; inset: 0; z-index: 800; background: #142238; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 70px 70px 80px 70px; }
#readPage { width: min(100%, calc((100vh - 160px) * 4 / 3)); aspect-ratio: 4 / 3; filter: drop-shadow(0 0 60px rgba(255, 214, 10, 0.35)); }
#readPage svg { width: 100%; height: 100%; display: block; }
#readBar { position: absolute; bottom: 12px; left: 72px; right: 72px; display: flex; justify-content: center; gap: 10px; }
#readX { position: absolute; top: 12px; right: 72px; }
#readTap { position: absolute; inset: 0; }

/* ---------- toast + coach ---------- */
#toast {
	position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%) translateY(20px); z-index: 950;
	background: var(--yellow); border: 4px solid var(--ink); border-radius: 16px; padding: 10px 18px;
	font-family: 'Bubblegum Sans', sans-serif; font-size: 19px; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
	max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast button { pointer-events: auto; margin-left: 10px; min-height: 40px; }
.recdot { width: 14px; height: 14px; border-radius: 50%; background: var(--red); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.2; } }
#meter { height: 24px; border: 4px solid var(--ink); border-radius: 12px; overflow: hidden; background: #fff; }
#meter i { display: block; height: 100%; width: 0; background: var(--green); transition: width 0.08s; }

/* ---------- portrait / phones: stack ---------- */
@media (orientation: portrait), (max-width: 760px) {
	#main { flex-direction: column; padding: 4px 8px 0 8px; }
	#left { flex: none; }
	#frame { width: min(100%, calc((100vh - 470px) * 4 / 3)); min-width: 60%; }
	/* padding-left 64: stacked, the drawer's tiles would sit under the shared 📮 and 🔊 */
	#drawer { flex: 1; min-height: 220px; min-width: 0; padding-left: 64px; }
	#top { padding: var(--sat) 66px 0 66px; }
	#titleBtn { max-width: 36vw; }
	#strip { height: 92px; }
	.grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
	.grid.two { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 500px) {
	/* phones: the title gets its own row so the five buttons never spill under the ⛶ corner */
	#top { flex-wrap: wrap; height: auto; padding: var(--sat) 70px 2px 66px; gap: 4px; row-gap: 2px; }
	/* a phone is too short for stage + strip + drawer: the whole column scrolls instead */
	#main { overflow-y: auto; touch-action: pan-y; }
	#drawer { min-height: 300px; }
	#frame { width: 100%; }
	#titleBtn { flex: 1 0 100%; max-width: none; min-height: 44px; justify-content: center; font-size: 22px; }
	#top .sp { display: none; }
	#top .stk { flex: 1; min-width: 44px; min-height: 44px; padding: 0 6px; }
	.grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
	.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- coach: one step at a time, never a gate ---------- */
#coach {
	display: flex; align-items: center; gap: 10px; flex: none; margin: 0 4px 0 64px;
	background: var(--yellow); border: 4px solid var(--ink); border-radius: 16px; padding: 6px 8px 6px 16px;
	font-family: 'Bubblegum Sans', sans-serif; font-size: 20px; line-height: 1.2;
	box-shadow: 3px 3px 0 var(--ink); animation: coachin 0.4s;
}
#coach .stk { min-height: 44px; min-width: 44px; padding: 0 10px; font-size: 16px; box-shadow: none; }
#coachText { flex: 1; }
#coachText b { color: var(--red); }
@keyframes coachin { from { transform: translateY(8px); opacity: 0; } }
#stage .bk-item.hop { animation: hop 0.5s; transform-box: fill-box; transform-origin: center bottom; }
@keyframes hop { 30% { translate: 0 -40px; } 60% { translate: 0 0; } 80% { translate: 0 -14px; } }
#stage .bk-item.pop { animation: popin 0.35s; transform-box: fill-box; transform-origin: center; }
@keyframes popin { 0% { scale: 0.2; } 70% { scale: 1.15; } 100% { scale: 1; } }
#say {
	position: absolute; z-index: 5; max-width: 60%; pointer-events: none;
	background: #fff; border: 4px solid var(--ink); border-radius: 18px; padding: 8px 14px;
	font-family: 'Bubblegum Sans', sans-serif; font-size: clamp(16px, 1.8vw, 22px); line-height: 1.2;
	box-shadow: 3px 3px 0 var(--ink); animation: coachin 0.25s; transform: translate(-50%, -100%);
}
#say::after { content: ""; position: absolute; left: 50%; bottom: -14px; margin-left: -8px; border: 8px solid transparent; border-top-color: var(--ink); }
.stk.surprise { background: var(--purple); font-size: 20px; }
.confetti { position: fixed; z-index: 980; width: 12px; height: 12px; border: 2px solid var(--ink); pointer-events: none; animation: conf 1.2s ease-out forwards; }
@keyframes conf { to { transform: translateY(70vh) rotate(540deg); opacity: 0; } }

/* ---------- draw your own ---------- */
.sheet.draw .dcard { width: min(96vw, 900px); max-height: 96vh; gap: 8px; padding: 14px; }
.dwrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.dpaper {
	max-width: 100%; max-height: min(58vh, 560px); width: auto; height: auto; display: block; touch-action: none;
	background: #fff; background-image: radial-gradient(rgba(34, 34, 34, 0.12) 1.5px, transparent 1.5px); background-size: 22px 22px;
	border: 4px solid var(--ink); border-radius: 14px 26px 12px 22px / 22px 12px 26px 14px; cursor: crosshair;
}
.drow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.dcols { gap: 6px; }
.dsizes { display: flex; gap: 6px; }
.dsz { width: 46px; height: 46px; padding: 0; display: flex; align-items: center; justify-content: center; background: #fff; border: 4px solid var(--ink); border-radius: 50%; }
.dsz i { display: block; border-radius: 50%; background: var(--ink); }
.dsz.on { outline: 5px solid var(--blue); outline-offset: 2px; }
.dtools .stk { min-height: 44px; font-size: 17px; padding: 0 12px; }
.dtools .stk.on { outline: 5px solid var(--blue); outline-offset: 2px; }
@media (max-width: 600px) { .dpaper { max-height: 46vh; } }

#coach { font-size: 18px; }
#coach .what { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
#coach .what span { white-space: nowrap; }
#coach .what .dim { color: #5a4a2a; font-size: 16px; }
#stageWrap { overflow: hidden; }
