:root {
  --bg: #fbf6ef;
  --paper: #ffffff;
  --ink: #2b2420;
  --muted: #7a6e66;
  --line: #e8ddd1;
  --accent: #d9534f;
  --accent-ink: #ffffff;
  --accent-soft: #fbe3e1;
  --green: #25d366;
  --green-ink: #0b3d1f;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(60, 40, 20, .10);
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
* { box-sizing: border-box; }

/* ---------- Scrollbars ----------
   Thin, rounded, warm-toned. Firefox and current Chrome/Edge use the standard
   properties; older Chrome and Safari fall back to the ::-webkit-scrollbar rules. */
:root { --scroll-thumb: #d9c9b8; --scroll-thumb-hover: #c2ab95; --scroll-track: transparent; }
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) var(--scroll-track); }
@supports not (scrollbar-color: auto) {
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-track { background: var(--scroll-track); }
  ::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
  ::-webkit-scrollbar-thumb:hover { background-color: var(--scroll-thumb-hover); }
  ::-webkit-scrollbar-corner { background: transparent; }
}
/* The book has a dark background: lighter thumb on a dark track */
html:has(.book-app) { --scroll-thumb: rgba(247, 238, 228, .35); --scroll-thumb-hover: rgba(247, 238, 228, .55); background: #2c1d14; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0 0 .5em; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  padding: .7em 1.2em; border-radius: 999px; border: 1px solid var(--line);
  background: var(--paper); cursor: pointer; text-decoration: none; color: var(--ink);
  font-weight: 600; transition: transform .08s ease, background .15s ease;
  white-space: nowrap;
}
.btn:hover { background: #f6efe6; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.whatsapp { background: var(--green); border-color: var(--green); color: var(--green-ink); }
.btn.small { padding: .4em .8em; font-size: .875rem; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--accent); }

input[type=text], input[type=password], textarea, select {
  width: 100%; padding: .75em 1em; border: 1px solid var(--line); border-radius: 10px;
  background: var(--paper); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.card { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; }
.muted { color: var(--muted); }
.error { color: var(--accent); min-height: 1.5em; font-size: .925rem; margin: .5em 0 0; }
.hidden { display: none !important; }

/* ---------- Landing ---------- */
.landing {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(circle at 15% 20%, #fde2d4 0, transparent 40%),
    radial-gradient(circle at 85% 80%, #e3ecd9 0, transparent 40%),
    var(--bg);
}
.landing .card { width: 100%; max-width: 440px; text-align: center; }
.landing .emoji { font-size: 48px; line-height: 1; margin-bottom: 12px; }
.landing h1 { font-size: clamp(1.8rem, 6vw, 2.4rem); }
.landing form { display: grid; gap: 12px; margin-top: 20px; }
.landing input { text-align: center; font-size: 1.25rem; letter-spacing: .15em; text-transform: uppercase; }
.landing .divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .875rem; margin: 22px 0 14px; }
.landing .divider::before, .landing .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- Editor ---------- */
.editor-app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--paper); border-bottom: 1px solid var(--line);
}
.topbar .title { font-family: var(--serif); font-weight: 600; font-size: 1.1rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .status { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.editor-body { flex: 1; display: flex; min-height: 0; }
.tools {
  width: 280px; flex: none; background: var(--paper); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 18px;
}
.tools h3 { font-family: var(--sans); font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; }
.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 6px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--paper); cursor: pointer; font-size: .8rem; font-weight: 600;
}
.tool-btn:hover { background: #f6efe6; }
.tool-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Drawing bar: sits between the top bar and the page, so it never covers the drawing area */
.draw-bar {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px 14px;
  padding: 8px 12px; background: #fff8f0; border-bottom: 1px solid var(--line);
}
.draw-bar .draw-label { font-weight: 700; font-size: .85rem; }
.draw-bar .swatch { width: 26px; height: 26px; }
.pen-sizes { display: flex; gap: 4px; }
.pen-sizes button { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: var(--paper); cursor: pointer; padding: 0; }
.pen-sizes button i { display: block; border-radius: 50%; background: var(--ink); }
.pen-sizes button.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.tool-btn .ico { font-size: 1.4rem; line-height: 1; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.swatch.active { box-shadow: 0 0 0 2px var(--accent); }
.swatch.custom { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); position: relative; overflow: hidden; }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.stickers { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.stickers button { font-size: 1.4rem; background: none; border: 0; padding: 4px; cursor: pointer; border-radius: 8px; }
.stickers button:hover { background: #f6efe6; }
.stickers h4 { grid-column: 1 / -1; margin: 10px 0 2px; font-size: .8rem; font-weight: 600; color: var(--muted); }
.stickers h4:first-child { margin-top: 0; }
.row { display: flex; gap: 6px; align-items: center; }
.row > * { flex: 1; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--paper); padding: 8px 0; cursor: pointer; font-weight: 700; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.placement { margin-top: 18px; text-align: left; }
.placement h3 { font-family: var(--sans); font-size: .85rem; margin: 0 0 8px; }
.placement .seg button { font-size: .8rem; padding: 8px 4px; }
.placement .name-row { display: flex; gap: 8px; }
.placement .name-row input { flex: 1; min-width: 0; padding: .5em .8em; }
.placement .hint { font-size: .78rem; color: var(--muted); margin: 6px 0 0; }
.placement .saved-note { color: #1d6b34; font-weight: 600; }
label.slider { display: grid; gap: 4px; font-size: .8rem; color: var(--muted); }
input[type=range] { width: 100%; accent-color: var(--accent); }

.stage { flex: 1; display: grid; place-items: center; overflow: auto; padding: 24px; background: #efe7dc; }
.canvas-wrap { box-shadow: 0 20px 50px rgba(60,40,20,.25); background: #fff; line-height: 0; }

.selection-panel { border-top: 1px dashed var(--line); padding-top: 16px; display: flex; flex-direction: column; gap: 12px; }

.mobile-tabs { display: none; }

@media (max-width: 820px) {
  .editor-body { flex-direction: column-reverse; }
  .tools {
    width: 100%; border-right: 0; border-top: 1px solid var(--line);
    max-height: 42vh; padding: 12px 16px;
  }
  .tools .panel { display: none; }
  .tools .panel.active { display: flex; flex-direction: column; gap: 14px; }
  .mobile-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; position: sticky; top: -12px; background: var(--paper); padding: 4px 0 8px; z-index: 1; }
  .mobile-tabs::-webkit-scrollbar { display: none; }
  .mobile-tabs button { flex: 1; border: 1px solid var(--line); background: var(--paper); border-radius: 999px; padding: 6px 10px; font-weight: 600; font-size: .85rem; white-space: nowrap; cursor: pointer; }
  .mobile-tabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
  .stage { padding: 12px; }
  .topbar .status { display: none; }
  .tool-grid { grid-template-columns: repeat(5, 1fr); }
  .draw-bar .draw-label { display: none; }
  .stickers { grid-template-columns: repeat(8, 1fr); }
}
@media (max-width: 480px) {
  /* Too narrow for the title to show more than "D…": keep it only as a spacer */
  .topbar { gap: 8px; padding: 10px 12px; }
  .topbar .title { visibility: hidden; }
}
@media (max-width: 360px) {
  .topbar { gap: 4px; padding: 10px 8px; }
  .topbar .btn.small { padding: .4em .6em; }
}
@media (min-width: 821px) {
  .tools .panel { display: flex; flex-direction: column; gap: 14px; }
  /* Desktop shows every panel at once: keep the selected item's options right under
     "Add to your page", above the long sticker list */
  .tools .panel[data-panel="add"] { order: 1; }
  .tools .panel[data-panel="edit"] { order: 2; border-top: 1px dashed var(--line); padding-top: 14px; }
  .tools .panel[data-panel="stickers"] { order: 3; }
  .tools .panel[data-panel="background"] { order: 4; }
}

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(30,20,10,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal .card { max-width: 420px; width: 100%; text-align: center; }

/* ---------- Book ---------- */
.book-app {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 20px 16px 32px;
  background: radial-gradient(ellipse at center, #5a3d2b 0%, #2c1d14 100%); color: #f7eee4;
}
.book-app h1 { color: #f7eee4; font-size: clamp(1.4rem, 4vw, 2rem); text-align: center; margin: 0; }
.book-wrap { width: 100%; max-width: 1100px; flex: 1; display: flex; align-items: center; justify-content: center; }
#book { margin: 0 auto; }
.page { background: #fffdf9; overflow: hidden; }
.page img { width: 100%; height: 100%; object-fit: contain; display: block; background: #fff; }
.page .caption { position: absolute; bottom: 8px; right: 12px; font-size: 12px; color: rgba(0,0,0,.45); font-family: var(--serif); font-style: italic; }
.page.cover {
  background: linear-gradient(135deg, #b8473f, #7d2a25); color: #fff6ec;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 32px;
}
.page.cover .inner { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 2px solid rgba(255,246,236,.5); padding: 24px; }
.page.cover h2 { font-size: clamp(1.6rem, 4vw, 3rem); color: #fff6ec; }
.page.cover p { opacity: .85; }
.page.blank { background: #fffdf9; display: flex; align-items: center; justify-content: center; color: #b9a99a; font-family: var(--serif); font-style: italic; }
.book-controls { display: flex; gap: 12px; align-items: center; }
.book-controls .btn, .book-downloads .btn { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.25); color: #f7eee4; }
.book-controls .btn:hover, .book-downloads .btn:hover { background: rgba(255,255,255,.2); }
.book-downloads { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; max-width: 100%; }
.book-downloads .dl-label { font-size: .85rem; opacity: .75; }
.book-downloads .dl-current { display: contents; }
.book-downloads .dl-current .btn { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.preview-banner { background: #f0ad4e; color: #3a2400; padding: 6px 14px; border-radius: 999px; font-size: .85rem; font-weight: 600; }

/* ---------- Admin ---------- */
/* minmax(0, 1fr): stop wide content (button rows) from stretching the page past the screen */
.admin { max-width: 1000px; margin: 0 auto; padding: 24px 16px 60px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.admin header h1 { font-size: clamp(1.5rem, 6vw, 2rem); }
.book-code-row { flex: 0 1 auto; flex-wrap: wrap; gap: 10px; min-width: 0; }
.book-code-row > * { flex: none; }
.admin header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { background: var(--paper); border-radius: 12px; padding: 14px 16px; border: 1px solid var(--line); }
.stat b { display: block; font-size: 1.6rem; font-family: var(--serif); }
.stat span { color: var(--muted); font-size: .85rem; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; letter-spacing: .08em; background: #f6efe6; padding: .15em .5em; border-radius: 6px; white-space: nowrap; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.pill { display: inline-block; padding: .15em .6em; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.pill.done { background: #dff3e4; color: #1d6b34; }
.pill.draft { background: #fff1d6; color: #8a5a00; }
.pill.none { background: #eee; color: #777; }
.pill.warn { background: var(--accent-soft); color: #a3302c; }
tr.is-disabled td:first-child, tr.is-disabled .code { opacity: .55; }
tr.is-disabled .code { text-decoration: line-through; }
.actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.my-page-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.book-key { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.toggle input { width: 44px; height: 24px; appearance: none; background: #ccc; border-radius: 999px; position: relative; cursor: pointer; transition: background .2s; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .2s; }
.toggle input:checked { background: var(--green); }
.toggle input:checked::after { left: 23px; }
@media (max-width: 640px) {
  .admin table thead { display: none; }
  .admin table tr { display: grid; grid-template-columns: 1fr auto; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .admin table td { border: 0; padding: 4px 0; }
  .admin table td:last-child { grid-column: 1 / -1; } /* the actions cell gets its own full row */
  .admin .actions { justify-content: flex-start; }
  .admin .card { padding: 20px; }
}
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: .9rem; z-index: 100; box-shadow: var(--shadow);
}

/* ---------- Privacy ---------- */
.privacy-note { font-size: .85rem; color: var(--muted); margin: 14px 0 0; }
.privacy-card { max-width: 480px !important; text-align: left !important; max-height: calc(100dvh - 32px); overflow-y: auto; }
.privacy-card > div:first-child, .privacy-card h2 { text-align: center; }
.privacy-card h2 { font-size: 1.35rem; }
.privacy-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 12px; font-size: .95rem; }
.privacy-list li { display: flex; gap: 12px; align-items: flex-start; }
.privacy-list li > span { font-size: 1.2rem; line-height: 1.3; flex: none; }
.prose { max-width: 680px; margin: 0 auto; padding: 32px 16px 64px; }
.prose h1 { font-size: clamp(1.8rem, 5vw, 2.4rem); }
.prose h2 { font-size: 1.25rem; margin-top: 1.8em; }
.prose li { margin-bottom: .4em; }
@media (max-width: 820px) { .hide-mobile { display: none; } }
.landing input#wa-name { text-transform: none; letter-spacing: normal; font-size: 1rem; }
