:root {
  --bg: #f6f1e7; --card: #fffdf8; --ink: #3a332c; --muted: #8a8076; --line: #e4dccd;
  --accent: #7d8f69; --accent-ink: #fff; --rose: #c98b84; --danger: #b2483e;
  --radius: 14px; --shadow: 0 2px 10px rgba(60, 45, 30, .12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #23201c; --card: #2e2a25; --ink: #efe7da; --muted: #a99d8f; --line: #433c34;
    --accent: #9fb08a; --accent-ink: #1d1a16; --shadow: 0 2px 10px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #23201c; --card: #2e2a25; --ink: #efe7da; --muted: #a99d8f; --line: #433c34;
  --accent: #9fb08a; --accent-ink: #1d1a16; --shadow: 0 2px 10px rgba(0,0,0,.4); color-scheme: dark;
}
@font-face { font-family: "Great Vibes"; src: url(../fonts/GreatVibes-Regular.ttf); font-display: swap; }
@font-face { font-family: "Cormorant SemiBold"; src: url(../fonts/Cormorant-SemiBold.ttf); font-display: swap; }
@font-face { font-family: "Montserrat Medium"; src: url(../fonts/Montserrat-Medium.ttf); font-display: swap; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.4 "Montserrat Medium", system-ui, sans-serif;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.view { min-height: 100%; padding-bottom: 96px; }
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg);
}
.bar h1 { font: 44px/1 "Great Vibes", cursive; margin: 0; font-weight: normal; }
.bar h1 span { font-family: "Cormorant SemiBold", serif; font-size: 26px; color: var(--rose); }
.bar h2 { font: 22px "Cormorant SemiBold", serif; margin: 0; }
.icon { background: none; border: 0; font-size: 26px; width: 44px; height: 44px; border-radius: 50%; }
.icon:active { background: var(--line); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 10px; scrollbar-width: none; }
.chips button {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 6px 14px; font-size: 14px;
}
.chips button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; padding: 4px 16px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border: 0; padding: 0; text-align: left; }
.card img { display: block; width: 100%; aspect-ratio: 2/3; object-fit: contain; background: #fff; }
.card .meta { padding: 8px 10px 10px; font-size: 13px; }
.card .meta b { display: block; font: 17px "Cormorant SemiBold", serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .bar-prog { height: 4px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.card .bar-prog i { display: block; height: 100%; background: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 40px 24px; }

.fab {
  position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 6;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 99px; padding: 14px 22px;
  font-size: 17px; box-shadow: var(--shadow);
}

/* ---- forms ---- */
.form { padding: 0 16px; max-width: 640px; margin: 0 auto; }
.lbl { display: block; margin: 18px 0 6px; font-size: 14px; color: var(--muted); }
.lbl small { color: var(--muted); opacity: .8; }
textarea, input:not([type=file]), select {
  width: 100%; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
}
textarea { resize: vertical; }
input[type=file] { width: 100%; }
.seg { display: flex; gap: 6px; }
.seg.wrap { flex-wrap: wrap; }
.seg button {
  flex: 1 1 auto; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 8px; font-size: 14px;
}
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px; padding: 13px 20px; font-size: 16px; }
.form .primary { width: 100%; margin-top: 24px; }
.photo-prev { max-width: 100%; max-height: 220px; margin-top: 8px; border-radius: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.row button { flex: 1; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px; }
.row button.primary { border: 0; background: var(--accent); }

.working { text-align: center; padding: 60px 24px; }
.spinner { width: 46px; height: 46px; margin: 0 auto 18px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.preview { padding: 0 16px; max-width: 640px; margin: 0 auto; }
.preview img { width: 100%; background: #fff; border-radius: 10px; box-shadow: var(--shadow); }
.qa { font-size: 13px; color: var(--muted); }
.err { color: var(--danger); padding: 0 16px; white-space: pre-wrap; }

/* ---- colouring ---- */
.view.color { height: 100dvh; padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.bar.slim { position: static; padding-top: calc(4px + env(safe-area-inset-top)); padding-bottom: 4px; }
.toggle { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 6px 12px; font-size: 14px; }
.toggle.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.viewport { flex: 1; position: relative; overflow: hidden; touch-action: none; background: #e9e3d8; }
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; box-shadow: 0 2px 16px rgba(0,0,0,.18); background: #fff; }
.stage canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
.stage canvas:nth-child(2), .stage canvas:nth-child(3) { pointer-events: none; }

.sheet { background: var(--card); padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.recent, .fams, .swatches { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px; scrollbar-width: none; }
.recent:empty { display: none; }
.fams button { flex: none; border: 0; background: none; font-size: 13px; padding: 4px 8px; border-radius: 99px; color: var(--muted); }
.fams button.on { background: var(--line); color: var(--ink); }
.sw {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 2px solid rgba(0,0,0,.08); position: relative;
  font-size: 13px; display: grid; place-items: center;
}
.recent .sw { width: 34px; height: 34px; }
.sw.on { outline: 3px solid var(--ink); outline-offset: 2px; }
.sw .n { background: rgba(255,255,255,.8); color: #333; border-radius: 99px; padding: 0 5px; font-size: 12px; }
.sw.done::after { content: "✓"; position: absolute; right: -4px; top: -4px; background: var(--accent); color: #fff; border-radius: 50%; width: 18px; height: 18px; font-size: 11px; display: grid; place-items: center; }
.swatches.cbn { flex-wrap: nowrap; }

/* ---- dialogs ---- */
dialog { border: 0; border-radius: 18px; background: var(--card); color: var(--ink); box-shadow: var(--shadow); padding: 18px; width: min(92vw, 420px); }
dialog::backdrop { background: rgba(30, 22, 14, .35); }
.menu { padding: 8px; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 14px; border-radius: 10px; }
.menu button:active { background: var(--line); }
.menu .danger { color: var(--danger); }
.menu .muted { color: var(--muted); }
.panel h3 { font: 24px "Cormorant SemiBold", serif; margin: 0 0 6px; }
.small { font-size: 12px; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: 14px; max-width: 90vw;
}
.seg button.wide { flex-basis: 100%; }

/* Happy-Color-style number swatches: progress ring around each colour */
.sw.num { border: 0; background-clip: content-box !important; padding: 4px;
  box-shadow: inset 0 0 0 4px var(--line); position: relative; }
.sw.num::before { content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(var(--accent) var(--p, 0deg), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent 60%, #000 61%); mask: radial-gradient(circle, transparent 60%, #000 61%); }
.sw.num .n { position: relative; font-size: 13px; }
.done canvas { width: 100%; border-radius: 10px; background: #fff; box-shadow: var(--shadow); }
.done h3 { text-align: center; }

/* step-by-step Gemini instructions */
.steps ol, ol.steps { padding-left: 22px; margin: 8px 0; }
.steps li, ol.steps li { margin: 10px 0; line-height: 1.45; }
.steps button, .btnlink {
  display: inline-block; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: 9px 14px; text-decoration: none; font-size: 15px;
}
.steps input[type=file] { margin-top: 6px; }

/* free mode: no AI settings */
body.free #d-settings .lbl, body.free #d-settings input, body.free #d-settings select { display: none; }
body.free #d-settings::after { content: 'Free mode: pages are made with Gemini, so there is nothing to set up here.'; display: block; color: var(--muted); font-size: 14px; }
