:root {
  --bg: #f3f5f5; --panel: #fff; --ink: #1d2427; --muted: #5f6b70; --line: #d9e0e2; --accent: #4f6f79; --accent-ink: #fff;
  --accent-soft: #e3ecee; --brand: #587a85; --danger: #b3261e; --radius: 10px; --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161b1d; --panel: #20272a; --ink: #e8eef0; --muted: #9eabb0; --line: #34403f; --accent: #8fb3bd; --accent-ink: #12181a;
    --accent-soft: #2a3a3f; --brand: #3d5860; --shadow: 0 1px 3px rgba(0,0,0,.4); color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', sans-serif; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; font-family: 'Libre Baskerville', Georgia, serif; font-weight: 400; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
button, .button { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: .45em .95em;
  border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .4em; min-height: 40px; }
button:hover, .button:hover { border-color: var(--accent); }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--danger); }
button.small, .button.small { min-height: 32px; padding: .2em .6em; font-size: .9rem; }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: .5em .7em; width: 100%; }
textarea { resize: vertical; min-height: 8em; line-height: 1.5; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-weight: 600; font-size: .92rem; margin: .7em 0 .25em; }
.hint { color: var(--muted); font-size: .88rem; font-weight: normal; }

.topbar { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .inner { max-width: 1200px; margin: 0 auto; padding: .5rem 1rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topbar { background: var(--brand); border-bottom: 0; color: #fff; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; line-height: 1; }
.brand img { height: 22px; display: block; }
.brand span { font-family: 'Libre Baskerville', Georgia, serif; font-size: 1.05rem; border-left: 1px solid rgba(255,255,255,.5); padding-left: .6rem; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; margin-left: auto; align-items: center; }
.topbar nav a, .topbar nav button { text-decoration: none; color: #fff; padding: .35em .7em; border-radius: 8px; border: 0; background: none; min-height: 36px; }
.topbar nav a.active, .topbar nav a:hover, .topbar nav button:hover { background: rgba(255,255,255,.16); }
main { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 700px) { .grid2 { grid-template-columns: 1fr; } }
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: .6em 1.1em;
  border-radius: 8px; z-index: 100; box-shadow: var(--shadow); max-width: calc(100% - 2rem); }
.error { color: var(--danger); }
.muted { color: var(--muted); }

body.auth-page { min-height: 100vh; background: linear-gradient(rgba(20,30,34,.55), rgba(20,30,34,.7)), url(/static/brand-hero.jpg) center/cover fixed #2c3b40; }
.auth { max-width: 420px; margin: 0 auto; padding: 8vh 1rem 2rem; }
.auth .hero-logo { display: block; height: 34px; margin: 0 auto .9rem; }
.auth .hero-line { color: #fff; text-align: center; font: 1.7rem/1.25 'Libre Baskerville', Georgia, serif; margin: 0 0 .3rem; text-shadow: 0 2px 8px rgba(0,0,0,.4); }
.auth .hero-sub { color: #e3ecee; text-align: center; margin: 0 0 1.4rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.card .thumb { aspect-ratio: 5.5 / 8.5; background: var(--accent-soft) center/cover no-repeat; position: relative; display: block; text-decoration: none; }
.card .thumb .mast { position: absolute; top: 8%; left: 0; right: 0; text-align: center; color: #fff; font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 1.6rem; text-shadow: 0 2px 6px rgba(0,0,0,.6); }
.card .thumb.empty .mast { color: var(--accent); text-shadow: none; }
.card .meta { padding: .6rem .75rem; flex: 1; }
.card .meta strong { display: block; }
.card .actions { display: flex; flex-wrap: wrap; gap: .3rem; padding: 0 .6rem .7rem; }

.editor { display: grid; grid-template-columns: 320px 1fr; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .editor { grid-template-columns: 1fr; } .tray-panel { position: static !important; max-height: none !important; } }
.tray-panel { position: sticky; top: 70px; max-height: calc(100vh - 85px); overflow: auto; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 1rem; text-align: center; color: var(--muted); cursor: pointer; transition: .15s; }
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.tray { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin-top: .75rem; }
.tray .ph { position: relative; aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: var(--line); cursor: grab; border: 3px solid transparent; padding: 0; min-height: 0; }
.tray .ph img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.tray .ph.selected { border-color: var(--accent); }
.tray .ph .used { position: absolute; bottom: 2px; right: 2px; background: rgba(0,0,0,.7); color: #fff; font-size: .7rem; border-radius: 4px; padding: 0 4px; }
.tray .ph.uploading { display: flex; align-items: center; justify-content: center; font-size: .75rem; color: var(--muted); cursor: default; }
.photo-menu { margin-top: .6rem; padding: .6rem; border-radius: 8px; background: var(--accent-soft); }
.photo-menu .row { gap: .35rem; margin-top: .3rem; }
.photo-menu select { padding: .3em .4em; }
.slot { border: 2px dashed var(--line); border-radius: var(--radius); min-height: 90px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); text-align: center; padding: .6rem; transition: .15s; font-size: .9rem; }
.slot.over { border-color: var(--accent); background: var(--accent-soft); }
.cover-slot { display: grid; grid-template-columns: 140px 1fr; gap: 1rem; align-items: start; }
@media (max-width: 500px) { .cover-slot { grid-template-columns: 1fr; } .cover-slot .slot { max-width: 160px; } }
.cover-slot .slot { aspect-ratio: 5.5 / 8.5; min-height: 0; padding: 0; overflow: hidden; }
.cover-slot .slot img { width: 100%; height: 100%; object-fit: cover; }
.story { border-left: 4px solid var(--accent); }
.story-head { display: flex; gap: .4rem; align-items: center; }
.story-head input { font-weight: 700; font-size: 1.05rem; }
.story-photos { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: .4rem; }
.story-photo { width: 160px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .35rem; }
.story-photo img { width: 100%; height: 105px; object-fit: cover; border-radius: 5px; display: block; }
.story-photo input, .story-photo select { padding: .3em .4em; font-size: .85rem; margin-top: .3rem; }
.story-photo .row { gap: .2rem; margin-top: .25rem; }
.story .slot { min-height: 60px; width: 160px; }
.templates { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; }
@media (max-width: 700px) { .templates { grid-template-columns: repeat(2, 1fr); } }
.tpl { border: 2px solid var(--line); border-radius: 8px; padding: .5rem; cursor: pointer; text-align: center; background: var(--panel); display: block; min-height: 0; width: 100%; }
.tpl.on { border-color: var(--accent); background: var(--accent-soft); }
.tpl .sw { height: 54px; border-radius: 5px; margin-bottom: .35rem; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; }
.tpl.classic .sw { background: #f4ece2; color: #7a4a24; font-family: 'Dancing Script'; font-weight: 700; }
.tpl.modern .sw { background: #1f3a5f; color: #fff; font-family: 'Montserrat'; font-weight: 800; letter-spacing: .12em; font-size: 1rem; text-transform: uppercase; }
.tpl.mission .sw { background: #3f5a36; color: #f6efe0; font-family: 'Caveat'; font-size: 1.7rem; }
.tpl.simple .sw { background: #fff; color: #111; border: 1px solid #ccc; font-family: 'Playfair Display'; font-weight: 700; }
.savestate { font-size: .88rem; color: var(--muted); }
details > summary { cursor: pointer; font-weight: 700; font-size: 1.1rem; }
.pagecount { font-size: .9rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .85rem; color: var(--muted); font-weight: 600; }
.linkbox { display: flex; gap: .4rem; margin-top: .5rem; }
.linkbox input { font-size: .85rem; }
@media (max-width: 700px) { .hide-sm { display: none; } }

/* design studio */
.designer { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 1rem; align-items: start; }
@media (max-width: 950px) { .designer { grid-template-columns: 1fr; } .preview-col { position: static !important; } }
.preview-col { position: sticky; top: 70px; }
.design-preview { overflow: hidden; }
.design-preview .scaler { transform-origin: top left; width: calc(11in + 14px); }
.design-preview .nl { display: flex; flex-wrap: wrap; gap: 14px; }
.design-preview .pg { box-shadow: 0 2px 10px rgba(0,0,0,.2); }
.choices { display: flex; flex-wrap: wrap; gap: .4rem; }
.choice { flex-direction: column; min-height: 0; padding: .4rem .55rem; font-size: .85rem; text-align: center; max-width: 150px; }
.choice.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.dg { width: 44px; height: 62px; border: 1px solid var(--muted); border-radius: 3px; position: relative; background: #fff; }
.dg i { position: absolute; display: block; }
.dg .h { left: 6px; right: 6px; top: 5px; height: 4px; background: #9aa; }
.dg .p { background: #7fa3ad; }
.dg .t { background: repeating-linear-gradient(#c8cfd1 0 2px, transparent 2px 5px); }
.dg-photo-top .p { left: 6px; right: 6px; top: 12px; height: 20px; } .dg-photo-top .t { left: 6px; right: 6px; top: 36px; bottom: 5px; }
.dg-photo-bottom .p { left: 6px; right: 6px; bottom: 5px; height: 20px; } .dg-photo-bottom .t { left: 6px; right: 6px; top: 12px; bottom: 28px; }
.dg-photo-left .p { left: 6px; width: 15px; top: 12px; height: 26px; } .dg-photo-left .t { left: 24px; right: 6px; top: 12px; bottom: 5px; }
.dg-photo-right .p { right: 6px; width: 15px; top: 12px; height: 26px; } .dg-photo-right .t { left: 6px; right: 24px; top: 12px; bottom: 5px; }
.dg-cover-full-top .p, .dg-cover-full-bottom .p, .dg-cover-full-left .p { inset: 3px; }
.dg .m { background: #fff; border: 1px solid #456; }
.dg-cover-full-top .m { left: 10px; right: 10px; top: 7px; height: 6px; }
.dg-cover-full-bottom .m { left: 10px; right: 10px; bottom: 7px; height: 6px; }
.dg-cover-full-left .m { left: 6px; top: 10px; bottom: 10px; width: 6px; }
.dg-cover-band .p { left: 3px; right: 3px; top: 3px; height: 38px; } .dg-cover-band .m { left: 3px; right: 3px; bottom: 3px; height: 16px; background: #456; }
.dg-cover-framed .m { left: 8px; right: 8px; top: 5px; height: 6px; } .dg-cover-framed .p { left: 6px; right: 6px; top: 16px; bottom: 6px; }

.env-badge { background: #f2c14e; color: #2a2100; font-weight: 700; font-size: .75rem; letter-spacing: .1em; text-transform: uppercase; padding: .2em .55em; border-radius: 5px; }
