/* =====================================================================
   CITY OF CREATIVITY — SHARED BOOK ENGINE STYLES
   Layout idea: one lamplit desk. Every page of the book is a photo of the
   same desk, so turning a page only changes the felt page in the middle.
   The words sit on a pinned felt card beside the book.
   ===================================================================== */
:root {
  --cb-walnut: #1b110a;          /* the desk at night */
  --cb-walnut-2: #2c1b10;
  --cb-ivory: #f8f3e7;           /* Warm Ivory */
  --cb-felt: #f1e8d4;            /* felt card */
  --cb-felt-edge: #e2d4b6;
  --cb-ink: #2b2118;             /* writing on felt */
  --cb-ink-soft: #6a5842;
  --cb-navy: #071a3d;            /* Midnight Navy */
  --cb-navy-2: #12295a;
  --cb-gold: #f2b82b;            /* Visionary Gold */
  --cb-gold-thread: #b9841c;     /* gold thread, readable on ivory */
  --cb-teal: #20b8d0;            /* Connection Teal */
  --cb-teal-felt: #2e6b6f;
  --cb-display: "Cormorant Garamond", "Cormorant", Garamond, "Times New Roman", serif;
  --cb-body: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --cb-hand: "Patrick Hand", "Comic Sans MS", "Segoe Print", cursive;
  --cb-stitch: repeating-linear-gradient(90deg, var(--cb-gold-thread) 0 9px, transparent 9px 15px);
  --cb-shadow: 0 18px 40px -12px rgba(0,0,0,.65), 0 2px 6px rgba(0,0,0,.35);
  color-scheme: dark;
}

.cb-sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Felt card (the pinned note beside the book) ---------- */
.cb-card {
  position: relative;
  background:
    radial-gradient(120% 90% at 20% 0%, rgba(255,255,255,.55), transparent 60%),
    var(--cb-felt);
  color: var(--cb-ink);
  border-radius: 14px;
  box-shadow: var(--cb-shadow);
  padding: 26px 24px 22px;
  font-family: var(--cb-body);
  line-height: 1.55;
}
.cb-card::before { /* hand stitching around the edge */
  content: ""; position: absolute; inset: 9px; border-radius: 9px; pointer-events: none;
  border: 2px dashed rgba(185,132,28,.75);
}
.cb-pin { position: absolute; top: -9px; left: 50%; width: 18px; height: 18px; margin-left: -9px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3c4, var(--cb-gold) 45%, #8a5f0e 100%); box-shadow: 0 3px 5px rgba(0,0,0,.45); }

.cb-eyebrow { font: 600 .72rem/1.2 var(--cb-body); letter-spacing: .14em; text-transform: uppercase; color: var(--cb-gold-thread); }
.cb-title { font: 600 clamp(1.9rem, 3.2vw, 2.6rem)/1.02 var(--cb-display); color: var(--cb-navy); margin: .2em 0 .25em; text-wrap: balance; }
.cb-question { font: italic 500 1.35rem/1.25 var(--cb-display); color: var(--cb-ink); margin: 0 0 .9rem; text-wrap: balance; }
.cb-meta { display: grid; gap: 10px; margin: 0 0 16px; font-size: .92rem; }
.cb-meta dt { font-size: .7rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--cb-ink-soft); }
.cb-meta dd { margin: 2px 0 0; }
.cb-ican { background: rgba(7,26,61,.06); border-radius: 10px; padding: 10px 12px; font-size: .92rem; }
.cb-ican strong { color: var(--cb-navy); }

.cb-piece { margin: 0 0 14px; padding: 12px 14px 12px 16px; background: var(--cb-ivory); border-radius: 4px;
  box-shadow: 0 6px 14px -8px rgba(0,0,0,.4); transform: rotate(-.6deg); font: 1.2rem/1.35 var(--cb-hand); color: #2b3a67; }
.cb-piece small { display: block; font: 600 .68rem/1.2 var(--cb-body); letter-spacing: .1em; text-transform: uppercase; color: var(--cb-ink-soft); margin-bottom: 4px; }
.cb-piece.is-new { animation: cb-glow 2.4s ease-out 1; }
@keyframes cb-glow { 0% { box-shadow: 0 0 0 0 rgba(242,184,43,.0); } 25% { box-shadow: 0 0 0 10px rgba(242,184,43,.45); } 100% { box-shadow: 0 6px 14px -8px rgba(0,0,0,.4); } }

/* State chip: always icon + words, never color alone */
.cb-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 8px; border-radius: 999px;
  font: 600 .74rem/1 var(--cb-body); letter-spacing: .04em; border: 1.5px solid currentColor; }
.cb-chip svg { width: 14px; height: 14px; }
.cb-chip[data-state="unvisited"] { color: #6a5842; }
.cb-chip[data-state="in-progress"] { color: var(--cb-navy-2); }
.cb-chip[data-state="come-back-later"] { color: var(--cb-teal-felt); }
.cb-chip[data-state="ready"] { color: #8a5f0e; background: rgba(242,184,43,.18); }
.cb-chip[data-state="revised"] { color: #8a5f0e; background: rgba(242,184,43,.18); }

/* ---------- Buttons ---------- */
.cb-btn { appearance: none; border: 0; cursor: pointer; font: 600 .98rem/1 var(--cb-body); border-radius: 999px; padding: 14px 22px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; min-height: 48px;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease; }
.cb-btn:focus-visible, .cb-iconbtn:focus-visible, .cb-dock button:focus-visible, .cb-toc button:focus-visible, .cb-choice:focus-visible { outline: 3px solid var(--cb-teal); outline-offset: 3px; }
.cb-btn-primary { background: var(--cb-navy); color: var(--cb-ivory); box-shadow: inset 0 0 0 2px var(--cb-navy), inset 0 0 0 4px rgba(242,184,43,.0), 0 6px 14px -6px rgba(7,26,61,.7); position: relative; }
.cb-btn-primary::after { content: ""; position: absolute; inset: 4px; border-radius: 999px; border: 1.5px dashed rgba(242,184,43,.75); pointer-events: none; }
.cb-btn-primary:hover { transform: translateY(-1px); background: var(--cb-navy-2); }
.cb-btn-soft { background: transparent; color: var(--cb-navy); box-shadow: inset 0 0 0 2px rgba(7,26,61,.35); }
.cb-btn-soft:hover { background: rgba(7,26,61,.06); }
.cb-btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }
.cb-row { display: flex; flex-wrap: wrap; gap: 10px; }

.cb-iconbtn { appearance: none; border: 0; background: rgba(248,243,231,.12); color: var(--cb-ivory); width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; }
.cb-iconbtn:hover { background: rgba(248,243,231,.22); }
.cb-iconbtn svg { width: 22px; height: 22px; }

/* ---------- The Storybook overlay ---------- */
.cb-book { position: fixed; inset: 0; z-index: 9000; background: radial-gradient(140% 100% at 35% 45%, var(--cb-walnut-2), var(--cb-walnut) 70%);
  color: var(--cb-ivory); display: grid; grid-template-columns: minmax(0,1fr) minmax(320px, 400px); grid-template-rows: auto minmax(0,1fr) auto;
  font-family: var(--cb-body); }
.cb-book[hidden] { display: none !important; }
.cb-book-top { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 6px; }
.cb-book-name { font: italic 500 1.2rem/1.1 var(--cb-display); color: var(--cb-felt); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cb-book-name b { font-style: normal; font-weight: 600; color: var(--cb-gold); }

.cb-stage { position: relative; overflow: hidden; min-height: 0; container-type: size; touch-action: pan-y; }
.cb-photo { position: absolute; left: 50%; top: 50%; width: max(100cqw, calc(100cqh * 16 / 9)); aspect-ratio: 16 / 9;
  transform: translate(var(--cb-px, -52.75%), var(--cb-py, -49.5%)); transition: opacity .7s ease; }
.cb-photo img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; max-width: none; }
.cb-photo .cb-color { opacity: 0; transition: opacity .6s ease; }
.cb-photo[data-state="ready"].has-finished .cb-sketch, .cb-photo[data-state="revised"].has-finished .cb-sketch { opacity: 0; }
.cb-photo[data-state="in-progress"].has-finished .cb-color { opacity: 1; -webkit-mask-image: linear-gradient(100deg, #000 30%, transparent 58%); mask-image: linear-gradient(100deg, #000 30%, transparent 58%); }
.cb-photo[data-state="in-progress"].unaligned .cb-color { opacity: 0; }
.cb-photo[data-state="ready"].has-finished .cb-color, .cb-photo[data-state="revised"].has-finished .cb-color { opacity: 1; }
.cb-photo[data-state="unvisited"] .cb-sketch { filter: saturate(.8) brightness(.93); }
.cb-photo[data-state="ready"]:not(.has-finished) .cb-sketch, .cb-photo[data-state="revised"]:not(.has-finished) .cb-sketch { filter: saturate(1.15) brightness(1.04); }
.cb-fade { opacity: 0; }
/* tall pages: whole page visible, centered on a blurred copy of the desk */
.cb-photo.tall { width: calc(100cqh * var(--cb-ratio)); height: 100cqh; aspect-ratio: auto; max-width: 100cqw; }
.cb-photo.tall .cb-backdrop { position: absolute; left: 50%; top: 50%; width: 100cqw; height: 100cqh; transform: translate(-50%, -50%) scale(1.15);
  object-fit: cover; filter: blur(18px) brightness(.55); z-index: -1; }

/* things that sit ON the felt page, positioned in % of the photo */
.cb-on { position: absolute; pointer-events: none; }
.cb-bookmark { width: 4.2%; filter: drop-shadow(0 6px 6px rgba(0,0,0,.45)); }
.cb-tab { width: 4.5%; aspect-ratio: 1 / 1.5; background: radial-gradient(120% 90% at 30% 20%, #3f8a8e, var(--cb-teal-felt)); border-radius: 0 10px 10px 0;
  box-shadow: 0 5px 8px rgba(0,0,0,.4); outline: 2px dashed rgba(242,184,43,.85); outline-offset: -5px; }
.cb-seal { width: 5.4%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #ffe9a6, var(--cb-gold) 50%, #9a6a10); box-shadow: 0 4px 8px rgba(0,0,0,.35), inset 0 0 0 3px rgba(255,255,255,.25); }
.cb-seal::after { content: ""; width: 60%; aspect-ratio: 1; border-radius: 50%; border: 2px dashed rgba(90,60,8,.6); }
.cb-seal svg { position: absolute; width: 38%; fill: #7a520c; }
.cb-pagenote { max-width: 22%; background: var(--cb-ivory); padding: .7% .9%; transform: rotate(-3deg); border-radius: 2px;
  box-shadow: 0 6px 12px -6px rgba(0,0,0,.6); font: clamp(.85rem, 1.25cqw, 1.2rem)/1.25 var(--cb-hand); color: #2b3a67; }
.cb-pagenote::before { content: ""; position: absolute; top: -6px; left: 50%; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff3c4, var(--cb-gold) 45%, #8a5f0e); }
.cb-patch { width: 7%; aspect-ratio: 1.3; background: var(--cb-teal-felt); border-radius: 6px; transform: rotate(6deg);
  box-shadow: 0 4px 8px rgba(0,0,0,.35); outline: 2px dashed rgba(242,184,43,.85); outline-offset: -6px; }
.cb-owner { font: clamp(1rem, 2.6cqw, 2.6rem)/1.2 var(--cb-hand); color: #2b3a67; text-align: center; display: grid; place-items: center; }
.cb-owner small { display: block; font: italic 500 .5em/1.3 var(--cb-display); color: #6a5842; }

.cb-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 3; }
.cb-nav.prev { left: 10px; } .cb-nav.next { right: 10px; }
.cb-nav .cb-iconbtn { background: rgba(27,17,10,.55); box-shadow: 0 4px 10px rgba(0,0,0,.4); }

.cb-side { overflow-y: auto; padding: 18px 18px 100px 6px; min-height: 0; }
.cb-side .cb-card { margin-top: 10px; }
.cb-foot { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px calc(12px + env(safe-area-inset-bottom, 0px)); flex-wrap: wrap; }
.cb-dots { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; max-width: 100%; }
.cb-dots button { width: 22px; height: 22px; border-radius: 50%; border: 0; cursor: pointer; padding: 0; display: grid; place-items: center; background: transparent; }
.cb-dots button span { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid rgba(248,243,231,.55); }
.cb-dots button[data-state="in-progress"] span, .cb-dots button[data-state="come-back-later"] span { background: rgba(32,184,208,.7); border-color: var(--cb-teal); }
.cb-dots button[data-state="ready"] span, .cb-dots button[data-state="revised"] span { background: var(--cb-gold); border-color: var(--cb-gold); }
.cb-dots button[aria-current="true"] span { outline: 2px solid var(--cb-ivory); outline-offset: 2px; }

/* table of contents */
.cb-toc { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 2px; }
.cb-toc button { width: 100%; display: grid; grid-template-columns: 2.2em minmax(0,1fr) auto; align-items: center; gap: 8px; text-align: left;
  background: transparent; border: 0; border-radius: 8px; padding: 9px 8px; cursor: pointer; color: var(--cb-ink); font: 500 .95rem/1.2 var(--cb-body); }
.cb-toc button:hover { background: rgba(7,26,61,.07); }
.cb-toc .n { font: 600 1rem/1 var(--cb-display); color: var(--cb-gold-thread); font-variant-numeric: tabular-nums; }
.cb-toc .s { font-size: .72rem; color: var(--cb-ink-soft); white-space: nowrap; }

/* "Look what you made" */
.cb-glow { position: fixed; inset: 0; z-index: 9500; display: grid; place-items: center; background: #120a05; cursor: pointer; }
.cb-glow img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; max-width: none; opacity: .92; }
.cb-glow p { position: relative; margin: 0 16px; padding: 14px 26px; text-align: center; font: italic 500 clamp(2rem, 6vw, 4rem)/1.05 var(--cb-display); color: var(--cb-ivory);
  text-shadow: 0 2px 18px rgba(0,0,0,.85), 0 0 40px rgba(242,184,43,.35); align-self: end; margin-bottom: 9vh; }
.cb-glow p small { display: block; font: 500 .9rem/1.4 var(--cb-body); font-style: normal; letter-spacing: .04em; margin-top: 8px; color: var(--cb-felt); }
.cb-glow { animation: cb-in 1.1s ease both; }
.cb-glow.out { animation: cb-out .8s ease both; }
@keyframes cb-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes cb-out { from { opacity: 1; } to { opacity: 0; } }

/* ---------- Dock: book, backpack, lightbulb ---------- */
.cb-dock { position: fixed; right: max(14px, env(safe-area-inset-right, 0px)); bottom: calc(14px + env(safe-area-inset-bottom, 0px)); z-index: 9200;
  display: flex; gap: 10px; align-items: flex-end; }
.cb-dock button { appearance: none; border: 0; cursor: pointer; width: 64px; height: 64px; border-radius: 50%; padding: 0; position: relative;
  background: radial-gradient(circle at 40% 30%, #fffaf0, var(--cb-felt) 60%, var(--cb-felt-edge)); box-shadow: var(--cb-shadow); display: grid; place-items: center; }
.cb-dock button::before { content: ""; position: absolute; inset: 4px; border-radius: 50%; border: 1.5px dashed rgba(185,132,28,.8); }
.cb-dock img { width: 74%; height: 74%; object-fit: contain; max-width: none; }
.cb-dock .lbl { position: absolute; top: 100%; left: 50%; transform: translate(-50%, 4px); font: 600 .66rem/1 var(--cb-body); color: var(--cb-ivory);
  text-shadow: 0 1px 3px #000; white-space: nowrap; letter-spacing: .03em; }
.cb-dock { padding-bottom: 14px; }
.cb-dock .count { position: absolute; top: -2px; right: -2px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; background: var(--cb-navy); color: var(--cb-gold);
  font: 700 .72rem/22px var(--cb-body); font-variant-numeric: tabular-nums; }
.cb-dock .count:empty { display: none; }
.cb-book:not([hidden]) ~ .cb-dock .cb-dock-book { display: none; }
/* while the book is open (and in worlds), the dock sits under the picture, away from the words */
@media (min-width: 821px) {
  .cb-book:not([hidden]) ~ .cb-dock, .cb-dock.left { right: auto; left: max(14px, env(safe-area-inset-left, 0px)); }
  .cb-book:not([hidden]) ~ .cb-dock { bottom: calc(58px + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- Drawer panels ---------- */
.cb-drawer { position: fixed; inset: 0; z-index: 9600; display: grid; justify-items: end; background: rgba(10,6,3,.55); }
.cb-drawer[hidden] { display: none !important; }
.cb-drawer .cb-card { width: min(440px, calc(100vw - 24px)); margin: calc(12px + env(safe-area-inset-top, 0px)) 12px calc(12px + env(safe-area-inset-bottom, 0px));
  max-height: calc(100% - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); overflow-y: auto; align-self: start; }
.cb-drawer-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.cb-drawer-head img { width: 56px; height: 56px; object-fit: contain; max-width: none; }
.cb-drawer-head h2 { font: 600 1.7rem/1 var(--cb-display); color: var(--cb-navy); margin: 0; flex: 1; }
.cb-x { appearance: none; border: 0; background: rgba(7,26,61,.08); color: var(--cb-navy); width: 44px; height: 44px; border-radius: 50%; cursor: pointer; font-size: 1.4rem; line-height: 1; }
.cb-x:focus-visible { outline: 3px solid var(--cb-teal); outline-offset: 2px; }
.cb-card h3 { font: 600 1.25rem/1.1 var(--cb-display); color: var(--cb-navy); margin: 18px 0 8px; }
.cb-card p { margin: 0 0 10px; }
.cb-help { font-size: .86rem; color: var(--cb-ink-soft); }
.cb-field { display: grid; gap: 6px; margin: 0 0 12px; }
.cb-field label { font-weight: 600; font-size: .9rem; color: var(--cb-navy); }
.cb-input, .cb-textarea { width: 100%; box-sizing: border-box; border: 2px solid rgba(7,26,61,.22); background: #fffdf7; color: var(--cb-ink); border-radius: 10px;
  padding: 12px 14px; font: 1.15rem/1.4 var(--cb-hand); }
.cb-textarea { min-height: 96px; resize: vertical; }
.cb-input:focus, .cb-textarea:focus { outline: none; border-color: var(--cb-teal); box-shadow: 0 0 0 3px rgba(32,184,208,.25); }
.cb-input.mono { font: 600 .82rem/1.4 ui-monospace, Menlo, Consolas, monospace; word-break: break-all; }
.cb-ideas { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.cb-ideas li { background: var(--cb-ivory); border-radius: 4px; padding: 10px 12px; box-shadow: 0 4px 10px -6px rgba(0,0,0,.35);
  display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; align-items: start; }
.cb-ideas .t { font: 1.15rem/1.3 var(--cb-hand); color: #2b3a67; overflow-wrap: anywhere; }
.cb-ideas .w { display: block; font: 600 .66rem/1.2 var(--cb-body); letter-spacing: .08em; text-transform: uppercase; color: var(--cb-ink-soft); margin-top: 4px; }
.cb-linkbtn { appearance: none; border: 0; background: none; color: var(--cb-ink-soft); text-decoration: underline; cursor: pointer; font: 500 .8rem var(--cb-body); padding: 4px; }
.cb-stamps { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 10px; }
.cb-stamp { aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; text-align: center; padding: 6px; font: 600 .6rem/1.1 var(--cb-body);
  border: 2px dashed rgba(106,88,66,.45); color: var(--cb-ink-soft); }
.cb-stamp.got { border: 3px double #8a5f0e; color: #6b4708; background: radial-gradient(circle, rgba(242,184,43,.35), rgba(242,184,43,.08)); transform: rotate(-8deg); }
.cb-pieces { display: grid; gap: 10px; }
.cb-toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 9900; background: var(--cb-navy); color: var(--cb-ivory);
  padding: 12px 18px; border-radius: 999px; font: 600 .9rem/1.2 var(--cb-body); box-shadow: var(--cb-shadow); max-width: calc(100vw - 32px); text-align: center; }
.cb-confirm { background: rgba(7,26,61,.06); border-radius: 10px; padding: 12px; margin-top: 8px; }

/* ---------- Phone layout ---------- */
@media (max-width: 820px) {
  .cb-book { grid-template-columns: minmax(0,1fr); grid-template-rows: auto minmax(0, 46vh) minmax(0,1fr) auto; }
  .cb-side { padding: 0 14px 90px; }
  .cb-side .cb-card { margin-top: 14px; }
  .cb-dock button { width: 52px; height: 52px; }
  .cb-book:not([hidden]) ~ .cb-dock { bottom: calc(52px + env(safe-area-inset-bottom, 0px)); }
  .cb-side { padding-bottom: 130px; }
}
@media (max-width: 820px) and (max-height: 560px) {
  .cb-book { grid-template-rows: auto minmax(0, 60vh) minmax(0,1fr) auto; }
}

@media (prefers-reduced-motion: reduce) {
  .cb-photo, .cb-btn, .cb-glow, .cb-glow.out { transition: none !important; animation: none !important; }
  .cb-piece.is-new { animation: none; box-shadow: 0 0 0 4px rgba(242,184,43,.55); }
}
