:root {
  --bg: #f4f1ea; --panel: #ffffff; --ink: #2b2d42; --muted: #6c757d;
  --accent: #3a86ff; --danger: #e63946; --radius: 14px;
  --shadow: 0 2px 10px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: Fredoka, system-ui, sans-serif; }
#app { height: 100%; display: flex; flex-direction: column; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }
.spacer { flex: 1; }

.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); box-shadow: var(--shadow); z-index: 2; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; margin: 0; }
.btn { font: inherit; font-size: 15px; border: none; border-radius: 12px; padding: 8px 14px; background: #eceae3; color: var(--ink); cursor: pointer; }
.btn:hover { filter: brightness(.95); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .4; cursor: default; }
.title-input, .select { font: inherit; font-size: 17px; font-weight: 600; border: 2px solid transparent; border-radius: 10px; padding: 6px 10px; background: #f4f1ea; min-width: 180px; }
.title-input:focus, .select:focus { outline: none; border-color: var(--accent); }

/* Site: login, home, library pages */
.center { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; }
.login-box { background: var(--panel); border-radius: 18px; box-shadow: var(--shadow); padding: 28px; width: 360px; max-width: 100%; display: flex; flex-direction: column; gap: 8px; }
.login-box h2 { margin: 0 0 8px; }
.login-box input, .modal-box input[type=password], .modal-box select, .modal-box input[type=text] { font: inherit; padding: 9px 12px; border-radius: 10px; border: 2px solid #ddd; width: 100%; }
.login-box label, .modal-box label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.btn.big { font-size: 18px; padding: 12px; margin-top: 8px; }
.btn.link { background: transparent; color: var(--accent); text-decoration: underline; }
.bar { display: flex; gap: 8px; align-items: center; }
.page-main { flex: 1; overflow: auto; padding: 20px 24px 40px; }
.page-main h2 { font-size: 20px; margin: 22px 0 10px; }
.section-head { display: flex; align-items: center; gap: 12px; }
.section-head h2 { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 18px; align-content: start; }
.hero { background: var(--panel); border-radius: 18px; padding: 32px; text-align: center; box-shadow: var(--shadow); }
.hero h2 { margin: 0 0 8px; font-size: 28px; }
.lib-card { text-decoration: none; color: inherit; }
.lib-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.14); }
.lib-icon { font-size: 54px; }
.lib-title { font-size: 20px; margin: 0; }
.badge { background: #e5d4ff; color: #4a2a8a; border-radius: 999px; padding: 3px 10px; font-size: 13px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.list-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #f4f1ea; border-radius: 10px; flex-wrap: wrap; }
.list-row select { width: auto; }
.menu { display: flex; flex-direction: column; gap: 6px; }
.menu .btn { text-align: left; }
.check { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--ink); }
.check input { width: auto; }
code.url { font-size: 12px; background: #f4f1ea; padding: 6px 8px; border-radius: 8px; word-break: break-all; flex: 1; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2b2d42; color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 100; box-shadow: 0 4px 16px rgba(0,0,0,.3); max-width: 90vw; }
.toast.error { background: var(--danger); }
body.busy { cursor: progress; }
body.busy::after { content: 'Saving…'; position: fixed; right: 16px; bottom: 16px; background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 999px; z-index: 100; }
a.btn { text-decoration: none; display: inline-block; }

/* Library */
.library { padding: 24px; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 20px; overflow: auto; align-content: start; }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.card .cover { width: 170px; height: 170px; display: flex; align-items: center; justify-content: center; }
.card .cover-inner { position: relative; }
.card h3 { margin: 0; font-size: 17px; text-align: center; }
.card .row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.card .btn { padding: 6px 10px; font-size: 13px; }
.empty { grid-column: 1/-1; text-align: center; padding: 60px 20px; color: var(--muted); font-size: 20px; }

/* Editor layout */
.editor-body { flex: 1; display: grid; grid-template-columns: 90px 1fr 250px; min-height: 0; }
.toolbar { display: flex; flex-direction: column; gap: 6px; padding: 10px 8px; background: var(--panel); overflow: auto; }
.toolbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; border: none; background: transparent; border-radius: 12px; padding: 8px 4px; font: inherit; font-size: 26px; cursor: pointer; }
.toolbar button span { font-size: 12px; }
.toolbar button:hover { background: #eef4ff; }
.toolbar.locked button { pointer-events: none; opacity: .35; }
#stage { position: relative; display: flex; align-items: center; justify-content: center; gap: 12px; padding: 16px; overflow: hidden; min-height: 0; }
#page-wrap { position: relative; touch-action: none; flex: none; }
.nav-arrow { width: 48px; height: 48px; border-radius: 50%; border: none; background: var(--panel); box-shadow: var(--shadow); font-size: 30px; cursor: pointer; flex: none; color: var(--ink); }
.nav-arrow.light { background: rgba(255,255,255,.15); color: #fff; }
.nav-arrow:disabled { opacity: .25; cursor: default; }
.props { background: var(--panel); padding: 14px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.props h3 { margin: 0 0 4px; font-size: 17px; }
.props label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.props .row { display: flex; gap: 6px; flex-wrap: wrap; }
.props .row .btn { flex: 1; padding: 8px 6px; font-size: 14px; }
.props .btn.on { outline: 3px solid var(--accent); }
.props select, .props input[type=range] { width: 100%; font: inherit; padding: 6px; border-radius: 8px; border: 1px solid #ddd; }
.layers { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }
.layer { display: flex; align-items: center; gap: 2px; padding: 5px 8px; border-radius: 8px; background: #f4f1ea; cursor: pointer; font-size: 14px; border: 2px solid transparent; user-select: none; }
.layer.on { border-color: var(--accent); background: #eef4ff; }
.layer.over { border-color: var(--accent); border-style: dashed; }
.layer-name { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.layer-btn { border: none; background: transparent; cursor: pointer; font-size: 12px; padding: 2px 5px; color: var(--muted); border-radius: 6px; }
.layer-btn:hover { background: #e3e0d8; }
.layer-btn:disabled { opacity: .25; cursor: default; }
.hint { font-size: 13px; color: var(--muted); line-height: 1.4; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid #ddd; cursor: pointer; padding: 0; }
.swatch.on { outline: 3px solid var(--accent); }
.swatches input[type=color] { width: 32px; height: 32px; border: none; padding: 0; background: none; cursor: pointer; }

/* Page strip */
.page-strip { display: flex; gap: 10px; padding: 10px 16px; background: var(--panel); overflow-x: auto; align-items: center; height: 130px; flex: none; }
.thumb { display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; padding: 4px; border-radius: 10px; border: 3px solid transparent; flex: none; }
.thumb.active { border-color: var(--accent); }
.thumb-inner { position: relative; overflow: hidden; }
.thumb .page { pointer-events: none; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.thumb-label { font-size: 12px; color: var(--muted); }
.thumb-add { width: 60px; height: 84px; border-radius: 10px; border: 2px dashed #bbb; background: transparent; font-size: 30px; cursor: pointer; color: var(--muted); flex: none; }

/* Page and elements (shared by editor, reader, print) */
.page { position: relative; overflow: hidden; background: #fff; transform-origin: 0 0; box-shadow: 0 4px 24px rgba(0,0,0,.18); border-radius: 4px; user-select: none; font-family: Fredoka, system-ui, sans-serif; }
.page .el { position: absolute; }
.page .el-text .text-content { width: 100%; height: 100%; padding: 6px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.25; outline: none; overflow: hidden; }
.page .el.editing .text-content { outline: 2px solid var(--accent); background: rgba(255,255,255,.35); user-select: text; cursor: text; }
.page .el img { width: 100%; height: 100%; object-fit: fill; display: block; pointer-events: none; }
.page .el-drawing svg { width: 100%; height: 100%; display: block; }
.page .el-shape svg { width: 100%; height: 100%; display: block; overflow: visible; }
.page .el-shape svg * { vector-effect: non-scaling-stroke; }
.page .audio-btn { width: 100%; height: 100%; border-radius: 50%; border: none; background: #ffb703; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.page .el.anim-wobble > * { animation: wobble 1.4s ease-in-out infinite; }
.page .el.anim-bounce > * { animation: bounce 1.2s ease-in-out infinite; }
.page .el.anim-spin > * { animation: spin 3s linear infinite; }
.page .el.anim-pulse > * { animation: pulse 1.2s ease-in-out infinite; }
.page .el.anim-float > * { animation: floaty 3s ease-in-out infinite; }
@keyframes wobble { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-14%); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
@keyframes floaty { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
.page .el-sticker .sticker { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; line-height: 1; }
.page .el-link .link-chip { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: #3a86ff; color: #fff; font-size: 20px; text-decoration: none; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.page .el-link iframe { width: 100%; height: 100%; border: 0; display: block; }

/* Bubbles, text effects, picture looks */
.page .el-text .bubble { position: absolute; inset: 0; width: 100%; height: 100%; stroke: #111; stroke-width: 3; pointer-events: none; }
.page .el-text .bubble * { vector-effect: non-scaling-stroke; }
.page .el-text.has-bubble .text-content { position: absolute; width: auto; height: auto; display: flex; flex-direction: column; justify-content: center; }
.page .bubble-speech .text-content { inset: 10% 10% 32% 10%; }
.page .bubble-thought .text-content { inset: 10% 12% 36% 12%; }
.page .bubble-shout .text-content { inset: 22% 20% 22% 20%; }
.page .bubble-box .text-content { inset: 6%; }
.page .fx-comic .text-content { -webkit-text-stroke: .06em #111; paint-order: stroke fill; text-shadow: .08em .08em 0 #111; letter-spacing: .02em; }
.page .fx-outline .text-content { -webkit-text-stroke: .04em #111; paint-order: stroke fill; }
.page .fx-shadow .text-content { text-shadow: .12em .12em 0 rgba(0,0,0,.35); }
.page .fx-glow .text-content { text-shadow: 0 0 .25em currentColor, 0 0 .6em currentColor; }
.page .fx-rainbow .text-content { background: linear-gradient(90deg, #e63946, #fb8500, #ffd60a, #2a9d8f, #3a86ff, #8338ec); -webkit-background-clip: text; background-clip: text; color: transparent !important; -webkit-text-fill-color: transparent; }
.page .fx-wobble .text-content { transform: rotate(-4deg); text-shadow: .06em .06em 0 #fff, .1em .1em 0 #111; }
.page .el-image.fx-frame img { border: 6px solid #111; box-shadow: 5px 5px 0 #111; }
.page .el-image.fx-polaroid img { border: 12px solid #fff; border-bottom-width: 42px; box-shadow: 0 4px 14px rgba(0,0,0,.35); }
.page .el-image.fx-round img { border-radius: 50%; }
.page .el-image.fx-cartoon img { filter: contrast(1.5) saturate(1.9); border: 4px solid #111; }
.page .el-image.fx-old img { filter: sepia(.85) contrast(1.1) brightness(.95); border: 8px solid #f1e2b6; box-shadow: 0 3px 10px rgba(60,35,5,.5); }
.page .el-image.fx-bw img { filter: grayscale(1) contrast(1.2); }
.page .el-image.fx-sketch img { filter: grayscale(1) contrast(2.2) brightness(1.15); mix-blend-mode: multiply; }
.page .el-link .yt-thumb { width: 100%; height: 100%; background: #222 center/cover no-repeat; display: flex; align-items: center; justify-content: center; position: relative; border-radius: 6px; overflow: hidden; }
.page .el-link .yt-play { width: 22%; aspect-ratio: 1; border-radius: 50%; background: rgba(230,57,70,.95); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 300%; padding-left: 3%; }
.page .el-link .yt-label { position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 8px; background: rgba(0,0,0,.55); color: #fff; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs .btn.on { outline: 3px solid var(--accent); }
.bubble-preview { fill: #fff; stroke: #111; stroke-width: 3; }
.sound-preview { font-family: Bangers, Impact, sans-serif; font-size: 28px !important; color: #ffd60a; -webkit-text-stroke: 1.5px #111; paint-order: stroke fill; text-shadow: 3px 3px 0 #111; }

/* Themes */
.page.theme-plain { background: #ffffff; }
.page.theme-modern { background: linear-gradient(180deg, #ffffff 0 88%, #3a86ff 88%); }
.page.theme-notebook { background: linear-gradient(90deg, transparent 0 56px, #f08080 56px 58px, transparent 58px), repeating-linear-gradient(#fdfdf8 0 31px, #bcd2e8 31px 32px); }
.page.theme-parchment, .page.theme-scroll, .page.theme-leather-inner { background: radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.35), transparent 60%), radial-gradient(ellipse at 80% 90%, rgba(120,80,20,.28), transparent 55%), linear-gradient(135deg, #f3e2b8, #e8d09a 50%, #d9bd80); font-family: Lora, Georgia, serif; }
.page.theme-parchment::before, .page.theme-scroll::before, .page.theme-leather-inner::before { content: ''; position: absolute; inset: 0; box-shadow: inset 0 0 60px rgba(90,50,10,.45); pointer-events: none; }
.page.theme-scroll::before { box-shadow: inset 0 0 60px rgba(90,50,10,.45), inset 0 48px 20px -20px rgba(60,35,5,.55), inset 0 -48px 20px -20px rgba(60,35,5,.55); }
.page.theme-scroll::after { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 100%; pointer-events: none; background: linear-gradient(#8a6a30 0, #d9b870 14px, #b08a4a 30px, transparent 30px), linear-gradient(0deg, #8a6a30 0, #d9b870 14px, #b08a4a 30px, transparent 30px); }
.page.theme-leather { background: radial-gradient(ellipse at 50% 40%, rgba(255,220,150,.12), transparent 60%), linear-gradient(135deg, #5a2d16, #3a1a0c 50%, #4b2412); font-family: 'IM Fell English', Lora, serif; }
.page.theme-leather::before { content: ''; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 14px #3a1a0c, inset 0 0 0 18px #c9a227, inset 0 0 0 22px #3a1a0c, inset 0 0 90px rgba(0,0,0,.7); }
.page.theme-leather::after { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 26px; background: linear-gradient(90deg, #2a1208, #6b3a1c 40%, #2a1208); pointer-events: none; }
.page.theme-comic { background: radial-gradient(circle, rgba(230,120,0,.45) 1.4px, transparent 1.6px) 0 0 / 11px 11px, #ffe56b; font-family: Bangers, Impact, sans-serif; }
.page.theme-comic::before { content: ''; position: absolute; inset: 10px; border: 4px solid #111; pointer-events: none; }
.page.theme-newspaper { background: repeating-linear-gradient(90deg, transparent 0 136px, rgba(0,0,0,.09) 136px 137px) 24px 0, #f5f1e6; font-family: Lora, Georgia, serif; }
.page.theme-newspaper::before { content: ''; position: absolute; left: 24px; right: 24px; top: 22px; height: 74px; border-top: 4px double #111; border-bottom: 4px double #111; pointer-events: none; }
.page.theme-newspaper img { filter: grayscale(1) contrast(1.1); }
.page.theme-diary { background: radial-gradient(circle, rgba(255,120,160,.28) 0 3px, transparent 4px) 0 0 / 28px 28px, linear-gradient(180deg, #ffe6ee, #ffd1e0); font-family: 'Patrick Hand', cursive; }
.page.theme-diary::after { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 38px; background: repeating-linear-gradient(180deg, transparent 0 30px, #c2487f 30px 36px, transparent 36px 64px), #f7a8c4; border-right: 2px dashed #c2487f; pointer-events: none; }
.page.theme-diary.is-cover::before { content: '🔒'; position: absolute; right: 30px; bottom: 26px; font-size: 70px; pointer-events: none; }
.page.theme-space { background: radial-gradient(circle at 20% 30%, #fff 1px, transparent 1.8px) 0 0 / 160px 140px, radial-gradient(circle at 70% 60%, #fff 1.2px, transparent 2px) 0 0 / 230px 190px, radial-gradient(circle at 45% 85%, #fff .8px, transparent 1.5px) 0 0 / 120px 100px, radial-gradient(ellipse at 80% 20%, rgba(150,90,220,.4), transparent 50%), linear-gradient(180deg, #0b0f2b, #1a1446 60%, #2a1a5e); }
.page.theme-space::after { content: ''; position: absolute; right: -70px; bottom: -70px; width: 240px; height: 240px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffb86b, #c2410c 60%, #7c2d12); box-shadow: 0 0 50px rgba(255,160,80,.45); pointer-events: none; }
.page.theme-underwater { background: radial-gradient(circle at 15% 85%, rgba(255,255,255,.3) 0 6px, transparent 7px), radial-gradient(circle at 30% 70%, rgba(255,255,255,.25) 0 4px, transparent 5px), radial-gradient(circle at 80% 72%, rgba(255,255,255,.28) 0 8px, transparent 9px), radial-gradient(circle at 70% 92%, rgba(255,255,255,.22) 0 5px, transparent 6px), radial-gradient(circle at 88% 40%, rgba(255,255,255,.2) 0 3px, transparent 4px), repeating-linear-gradient(100deg, rgba(255,255,255,.09) 0 22px, transparent 22px 64px), linear-gradient(180deg, #6fd3ff, #1b7fd1 55%, #0b3d7a); }
.page.theme-underwater::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 64px; background: linear-gradient(#efe0b0, #d4b980); border-radius: 50% 50% 0 0 / 24px 24px 0 0; pointer-events: none; }
.page.theme-jungle { background: radial-gradient(ellipse 140px 70px at 0% 0%, #1f6b2a, transparent 70%), radial-gradient(ellipse 160px 80px at 100% 8%, #246f2e, transparent 70%), radial-gradient(ellipse 150px 90px at 10% 100%, #1a5e26, transparent 70%), radial-gradient(ellipse 170px 80px at 95% 95%, #2b7a33, transparent 70%), linear-gradient(160deg, #8fd14f, #3a9d46 50%, #1f6b2a); }
.page.theme-jungle::before { content: ''; position: absolute; inset: 0; box-shadow: inset 0 0 70px rgba(0,40,0,.5); pointer-events: none; }
.page.theme-castle { background: linear-gradient(335deg, #6d7279 23px, transparent 23px), linear-gradient(155deg, #9aa0a6 23px, transparent 23px), linear-gradient(335deg, #6d7279 23px, transparent 23px), linear-gradient(155deg, #9aa0a6 23px, transparent 23px), #858a90; background-size: 58px 58px; background-position: 0 2px, 4px 35px, 29px 31px, 34px 6px; font-family: 'IM Fell English', serif; }
.page.theme-castle::before { content: ''; position: absolute; inset: 0; box-shadow: inset 0 0 90px rgba(0,0,0,.6); pointer-events: none; }
.page.theme-pirate { background: repeating-linear-gradient(0deg, rgba(90,50,10,.12) 0 1px, transparent 1px 60px), repeating-linear-gradient(90deg, rgba(90,50,10,.12) 0 1px, transparent 1px 60px), radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.3), transparent 60%), linear-gradient(135deg, #e9d3a3, #d9bd80 50%, #c9a86a); font-family: 'IM Fell English', serif; }
.page.theme-pirate::before { content: ''; position: absolute; inset: 0; box-shadow: inset 0 0 50px 12px rgba(60,30,0,.7); pointer-events: none; }
.page.theme-pirate::after { content: '🧭'; position: absolute; right: 26px; bottom: 22px; font-size: 64px; opacity: .75; pointer-events: none; }
.page.theme-night { background: radial-gradient(circle at 20% 15%, #3b3f73, transparent 45%), #1d1f2b; }

/* Selection */
.sel-box { position: absolute; outline: var(--ow, 2px) dashed var(--accent); pointer-events: none; }
.handle { position: absolute; width: var(--hs); height: var(--hs); border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: calc(var(--hs) * .55); pointer-events: auto; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.3); user-select: none; }
.h-resize { right: calc(var(--hs) * -.5); bottom: calc(var(--hs) * -.5); cursor: nwse-resize; }
.h-del { right: calc(var(--hs) * -.5); top: calc(var(--hs) * -.5); background: var(--danger); }
.h-rotate { left: 50%; top: calc(var(--hs) * -1.7); transform: translateX(-50%); cursor: grab; background: #2a9d8f; }
.h-rotate::after { content: ''; position: absolute; left: 50%; top: 100%; width: 2px; height: calc(var(--hs) * .7); background: #2a9d8f; }
.draw-layer { position: absolute; left: 0; top: 0; cursor: crosshair; touch-action: none; }

/* Reader */
.rd { position: fixed; inset: 0; background: #1d1f2b; color: #fff; z-index: 20; }
.rd-bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; font-size: 18px; }
.rd-stage { flex: 1; display: flex; align-items: center; justify-content: center; gap: 12px; padding: 12px; min-height: 0; }
#rd-wrap { display: flex; flex: none; gap: 2px; perspective: 1800px; }
.rd-page { position: relative; flex: none; transform-style: preserve-3d; }
.rd-page.flip-next { animation: flipNext .55s ease-out; transform-origin: left center; }
.rd-page.flip-prev { animation: flipPrev .55s ease-out; transform-origin: right center; }
@keyframes flipNext { from { transform: rotateY(75deg); opacity: .2; } to { transform: rotateY(0); opacity: 1; } }
@keyframes flipPrev { from { transform: rotateY(-75deg); opacity: .2; } to { transform: rotateY(0); opacity: 1; } }
.rd-page + .rd-page .page { box-shadow: -8px 0 24px rgba(0,0,0,.35); }
.rd-page:first-child:not(:only-child) .page { box-shadow: 8px 0 24px rgba(0,0,0,.35); }
.rd-foot { text-align: center; padding: 8px; color: #bbb; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-box { background: #fff; border-radius: 18px; padding: 20px; max-width: 640px; width: 92vw; max-height: 88vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.modal-box h3 { margin: 0; }
.modal-box input[type=text], .modal-box input[type=url] { font: inherit; padding: 8px 10px; border-radius: 10px; border: 2px solid #ddd; width: 100%; }
.emoji-grid { display: flex; flex-wrap: wrap; gap: 4px; }
.shape-preview { fill: #ffd60a; stroke: #111; stroke-width: 3; }
.cam { width: 100%; max-height: 60vh; border-radius: 12px; background: #000; }
.rec-status { font-size: 18px; padding: 10px; background: #f4f1ea; border-radius: 10px; }
.emoji-grid button { font-size: 30px; border: none; background: transparent; border-radius: 10px; padding: 4px; cursor: pointer; }
.emoji-grid button:hover { background: #eef4ff; }

/* Print */
#print-area { display: none; }
@media print {
  html, body { margin: 0; background: #fff; }
  #app > *:not(#print-area) { display: none !important; }
  #print-area { display: block; }
  .print-page { break-after: page; page-break-after: always; }
  .page { box-shadow: none; border-radius: 0; }
}

@media (max-width: 820px) {
  .editor-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .toolbar { flex-direction: row; justify-content: center; }
  .props { max-height: 180px; }
  .page-strip { height: 100px; }
}

/* v3: undo, locks, word bank, drawing modes, reader social, quiz, library features */
.btn.icon { padding: 8px 10px; font-size: 18px; }
#page-wrap.page-locked { pointer-events: none; opacity: .75; }
.thumb.locked-by-other { opacity: .6; }
.page.tracing .el-image, .page.tracing .el-drawing { opacity: .3; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 15px; padding: 6px 12px; border-radius: 999px; border: none; background: #e5d4ff; color: #4a2a8a; cursor: pointer; }
.chip:hover { background: #d4bdff; }
.props textarea, .modal-box textarea { font: inherit; width: 100%; padding: 8px; border-radius: 10px; border: 2px solid #ddd; }
.emoji-grid.small button { font-size: 24px; }
.emoji-grid.small button.on { outline: 3px solid var(--accent); }
.kw.lit { background: #ffd60a; border-radius: 4px; box-shadow: 0 0 0 3px #ffd60a; }
.rd-comments { width: 320px; flex: none; background: #2b2d42; color: #fff; border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; max-height: 100%; }
.rd-c-head { display: flex; align-items: center; gap: 8px; }
.rd-c-list { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.rd-c { background: rgba(255,255,255,.08); border-radius: 10px; padding: 8px; font-size: 14px; }
.rd-c .btn.link { color: #ffb3b3; padding: 0 6px; font-size: 12px; }
.rd-c-form { display: flex; flex-direction: column; gap: 6px; }
.rd-c-form input, .rd-c-form textarea { font: inherit; padding: 8px; border-radius: 10px; border: none; }
.quiz-q { background: #f4f1ea; border-radius: 12px; padding: 10px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 6px; }
.quiz-q input[type=text] { flex: 1; }
.quiz-q.right { background: #d0f4de; }
.quiz-q.wrong { background: #ffd6e0; }
.quiz-q label.is-answer { font-weight: 700; }
.quiz-score { font-size: 24px; font-weight: 700; }
.lib-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.lib-tools input[type=search], .lib-tools select { font: inherit; padding: 8px 12px; border-radius: 10px; border: 2px solid #ddd; }
.tag { display: inline-block; font-size: 12px; background: #cde7ff; color: #1d3557; border-radius: 999px; padding: 2px 8px; margin: 2px; cursor: pointer; }
.tag.on { background: var(--accent); color: #fff; }
.featured { display: flex; gap: 20px; align-items: center; background: linear-gradient(135deg, #ffe56b, #ffb703); border-radius: 18px; padding: 18px 22px; margin-bottom: 18px; box-shadow: var(--shadow); }
.featured .cover-inner { position: relative; }
.featured h2 { margin: 0 0 6px; font-size: 24px; }
.usage { background: var(--panel); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow); font-size: 14px; display: flex; flex-direction: column; gap: 6px; min-width: 220px; }
.bar { height: 8px; background: #eee; border-radius: 999px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); border-radius: 999px; }
.bar.full > div { background: var(--danger); }
.shelf-wrap { background: linear-gradient(#5a3b1e, #3b2410); border-radius: 14px; padding: 20px 20px 0; }
.shelf { display: flex; flex-wrap: wrap; gap: 14px 18px; align-items: flex-end; padding: 0 10px 14px; border-bottom: 16px solid #8a5a2b; box-shadow: 0 18px 0 -2px #5a3b1e; margin-bottom: 26px; }
.shelf-book { position: relative; cursor: pointer; transition: transform .15s; }
.shelf-book:hover { transform: translateY(-8px) scale(1.04); }
.shelf-book .cover-inner { position: relative; box-shadow: 4px 4px 10px rgba(0,0,0,.5); }
.shelf-book .shelf-title { position: absolute; left: 0; right: 0; bottom: -4px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; padding: 2px 4px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.level-pill { display: inline-flex; align-items: center; gap: 4px; background: #ffe56b; color: #5a3b1e; border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 600; cursor: pointer; border: none; font-family: inherit; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge-card { width: 96px; text-align: center; background: #f4f1ea; border-radius: 12px; padding: 8px 4px; font-size: 12px; }
.badge-card .ic { font-size: 32px; }
.badge-card.off { opacity: .35; filter: grayscale(1); }
.city-head { font-size: 16px; color: var(--muted); margin: 14px 0 6px; }
.book-card .counts { font-size: 12px; color: var(--muted); }
.lang-switch { font: inherit; border: none; background: transparent; cursor: pointer; font-size: 18px; }
@media (max-width: 820px) { .rd-comments { position: fixed; right: 8px; bottom: 50px; top: 60px; width: min(320px, 90vw); z-index: 30; } }
.mini-lock { font-size: 14px; vertical-align: middle; margin-left: 2px; }
