:root {
  --red: #b4252a; --red-dark: #7f1418; --green: #1f5b3a; --green-dark: #123a24; --gold: #e6b84a; --cream: #fff8ec; --ink: #2b2b2b;
  --panel: #fffdf8; --line: #e8dcc8; --radius: 14px; --shadow: 0 10px 30px rgba(40, 10, 10, .25);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-family: 'Lato', system-ui, sans-serif; color: var(--ink); background: linear-gradient(160deg, #0f3b26 0%, #164b31 45%, #7f1418 100%) fixed; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--red); }
h1, h2, h3 { font-family: 'Mountains of Christmas', cursive; font-weight: 700; margin: 0; }
.hidden { display: none !important; }

/* snow */
.snow { position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: radial-gradient(3px 3px at 20px 30px, #fff 50%, transparent 55%), radial-gradient(2px 2px at 90px 140px, #fff 50%, transparent 55%),
    radial-gradient(2.5px 2.5px at 160px 60px, #fff 50%, transparent 55%), radial-gradient(1.5px 1.5px at 230px 200px, #fff 50%, transparent 55%),
    radial-gradient(3px 3px at 300px 110px, #fff 50%, transparent 55%), radial-gradient(2px 2px at 60px 260px, #fff 50%, transparent 55%);
  background-size: 340px 340px; opacity: .55; animation: snowfall 18s linear infinite; }
@keyframes snowfall { from { background-position: 0 0; } to { background-position: 40px 340px; } }
@media (prefers-reduced-motion: reduce) { .snow { animation: none; } }

#app { position: relative; z-index: 1; min-height: 100vh; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 999px; border: 2px solid transparent; background: #fff; color: var(--ink); font-weight: 700; box-shadow: 0 2px 6px rgba(0,0,0,.12); transition: transform .08s, box-shadow .12s; white-space: nowrap; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.18); }
.btn:disabled { opacity: .55; cursor: wait; transform: none; }
.btn.primary { background: var(--red); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.gold { background: var(--gold); color: #3a2a00; }
.btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.5); box-shadow: none; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.danger { color: var(--red); }
.btn.icon { padding: 6px 10px; }

/* login + home */
.center { max-width: 1100px; margin: 0 auto; padding: 32px 20px 80px; }
.hero { text-align: center; color: #fff; padding: 24px 0 18px; }
.hero h1 { font-size: clamp(38px, 7vw, 68px); text-shadow: 0 3px 0 rgba(0,0,0,.25); line-height: 1; }
.hero p { font-size: 18px; opacity: .92; max-width: 640px; margin: 10px auto 0; }
.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.panel h2 { font-size: 30px; color: var(--red); margin-bottom: 6px; }
.panel .sub { color: #666; margin: 0 0 14px; }
.lights { height: 10px; background: repeating-linear-gradient(90deg, var(--red) 0 20px, var(--green) 20px 40px, var(--gold) 40px 60px); border-radius: var(--radius) var(--radius) 0 0; margin: -22px -22px 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }
label.field { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 700; color: #555; }
label.field input, label.field select, label.field textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 11px; border: 1px solid #d8ccb6; border-radius: 10px; background: #fff; font-weight: 400; color: var(--ink); }
label.field textarea { min-height: 70px; resize: vertical; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; margin: 6px 0 14px; }
.cat { border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 6px; text-align: center; font-size: 13px; font-weight: 700; color: #444; }
.cat .e { font-size: 26px; display: block; margin-bottom: 4px; }
.cat.on { border-color: var(--red); background: #fff1f0; color: var(--red); }
.style-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 14px; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px #ccc; padding: 0; }
.swatch.on { box-shadow: 0 0 0 3px var(--red); }
.book-list { display: grid; gap: 10px; }
.book-row { display: flex; align-items: center; gap: 12px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.book-row .e { font-size: 30px; }
.book-row .t { flex: 1; min-width: 0; }
.book-row .t b { display: block; font-size: 16px; }
.book-row .t span { color: #777; font-size: 13px; }
.book-row .acts { display: flex; gap: 6px; }
.empty { color: #777; text-align: center; padding: 20px; }
.login { max-width: 420px; margin: 12vh auto; text-align: center; }
.login input { text-align: center; font-size: 20px; letter-spacing: .1em; }
.err { color: var(--red); font-weight: 700; margin-top: 8px; }

/* editor */
.editor { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: rgba(0,0,0,.28); backdrop-filter: blur(6px); color: #fff; }
.topbar h2 { font-size: 26px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .status { font-size: 12px; opacity: .75; }
.workspace { display: grid; grid-template-columns: 170px 1fr 340px; min-height: 0; }
@media (max-width: 1000px) { .workspace { grid-template-columns: 120px 1fr; } .inspector { grid-column: 1 / -1; max-height: 45vh; } }
.strip { overflow-y: auto; padding: 12px 10px; background: rgba(0,0,0,.18); display: flex; flex-direction: column; gap: 10px; }
.thumb { position: relative; width: 100%; aspect-ratio: 5/7; border-radius: 6px; overflow: hidden; border: 3px solid transparent; background: #fff; cursor: pointer; }
.thumb.on { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(0,0,0,.3); }
.thumb .scaled { position: absolute; top: 0; left: 0; transform-origin: top left; pointer-events: none; }
.thumb .num { position: absolute; bottom: 4px; left: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 8px; }
.strip .add { margin-top: 4px; }
.stage { display: flex; align-items: center; justify-content: center; padding: 20px; overflow: auto; min-width: 0; }
.preview { position: relative; width: 5in; height: 7in; transform-origin: top left; box-shadow: 0 20px 50px rgba(0,0,0,.45); border-radius: 4px; }
.preview-wrap { position: relative; }
.inspector { background: var(--panel); overflow-y: auto; padding: 16px; border-left: 1px solid rgba(0,0,0,.1); }
.inspector h3 { font-size: 24px; color: var(--green); margin-bottom: 8px; }
.inspector .sec { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.inspector .sec > b { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: #888; margin-bottom: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row .btn { flex: none; }
.seg { display: flex; border: 1px solid #d8ccb6; border-radius: 999px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 7px 12px; font-size: 13px; font-weight: 700; color: #666; }
.seg button.on { background: var(--green); color: #fff; }
.emoji-picks { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.emoji-picks button { border: 1px solid var(--line); background: #fff; border-radius: 8px; font-size: 20px; padding: 2px 5px; line-height: 1.2; }
.ai-box { background: #f3f7f1; border: 1px dashed #9fb897; border-radius: 12px; padding: 10px; margin-top: 8px; }
.ai-box .hint { font-size: 12px; color: #666; margin: 0 0 6px; }
.img-preview { width: 100%; max-height: 140px; object-fit: contain; background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0/16px 16px; border-radius: 8px; margin-top: 6px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 6px 0; }
.check input { width: 18px; height: 18px; }
.page-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* modal */
#modal-root:empty { display: none; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); width: min(1000px, 100%); max-height: 92vh; display: flex; flex-direction: column; overflow: hidden; }
.modal header { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal header h2 { font-size: 28px; color: var(--red); flex: 1; }
.modal .body { padding: 16px 18px; overflow-y: auto; }
.modal footer { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); background: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { border: 1px solid #d8ccb6; background: #fff; border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 700; color: #555; }
.chip.on { background: var(--green); color: #fff; border-color: var(--green); }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.pick { position: relative; border: 3px solid transparent; border-radius: 10px; overflow: hidden; cursor: pointer; background: #fff; aspect-ratio: 5/7; }
.pick .scaled { position: absolute; top: 0; left: 0; transform-origin: top left; pointer-events: none; }
.pick.on { border-color: var(--gold); }
.pick .tick { position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%; background: var(--green); color: #fff; display: none; align-items: center; justify-content: center; font-weight: 700; }
.pick.on .tick { display: flex; }
.pick .cap { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; padding: 3px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.idea { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fff; margin-bottom: 8px; }
.idea .e { font-size: 28px; }
.idea .t { flex: 1; } .idea .t small { color: #777; display: block; }
.dl-menu { display: grid; gap: 10px; }
.dl-menu .opt { display: flex; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fff; cursor: pointer; }
.dl-menu .opt:hover { border-color: var(--green); }
.dl-menu .opt .e { font-size: 30px; }
.dl-menu .opt b { display: block; }
.dl-menu .opt span { color: #666; font-size: 13px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: grid; gap: 6px; }
#toast div { background: #222; color: #fff; padding: 10px 16px; border-radius: 999px; box-shadow: 0 6px 20px rgba(0,0,0,.4); font-weight: 700; animation: pop .2s; }
#toast div.err { background: var(--red); }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
