/* Side quests journal (sidequests.html): an open, spiral-bound journal with
   a divider tab per hobby on its right edge, plus the stickers and drawings
   journal.js lays over its pages. Decorating itself only happens in the
   local site editor; the .jd-tray / .is-decorating rules below never show
   on the live site.

   Type follows jackiezhang.co.za: a handwriting face for labels and notes,
   a tall serif for titles, a pixel mono for descriptions. (Instrument Serif
   stands in for that site's Awesome Serif. Departure Mono is self-hosted;
   licence in assets/fonts/departure-mono/OFL.txt.) */
@font-face {
  font-family: "Departure Mono";
  src: url("assets/fonts/departure-mono/DepartureMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  --journal-paper: #fffdf7;
  --journal-dot: rgba(48, 30, 24, 0.12);
  --journal-edge: rgba(48, 30, 24, 0.12);
  --journal-gutter: rgba(48, 30, 24, 0.14);
  --journal-cover: #8c5a46;
  --journal-tab-3d: #f9e0d6;
  --journal-tab-print: #dbe6dc;
  --journal-tab-width: 44px;
  --journal-width: 1080px;
  --font-family-hand: "Gochi Hand", "Segoe Print", "Bradley Hand", cursive;
  --font-family-journal-title: "Instrument Serif", Georgia, serif;
  --font-family-journal-mono: "Departure Mono", var(--font-family-code);
  --journal-accent: #e05440;
}

/* Wider than the 700px case-study column, centred on it. */
.sq-journal {
  position: relative;
  width: min(var(--journal-width), calc(100vw - 48px));
  margin-left: calc(50% - min(var(--journal-width), calc(100vw - 48px)) / 2);
  padding-right: calc(var(--journal-tab-width) - 4px);
}

.sq-journal-book {
  position: relative;
  z-index: 1;
  padding: 12px;
  border-radius: 18px;
  background: var(--journal-cover);
  box-shadow: var(--shadow-md);
}

.sq-journal-spread {
  display: grid;
  grid-template-columns: 1fr 1fr;
  /* The stack of pages under the open ones. */
  border-radius: 8px;
  box-shadow:
    0 2px 0 -1px var(--journal-paper),
    0 3px 0 -1px var(--journal-edge),
    0 5px 0 -2px var(--journal-paper),
    0 6px 0 -2px var(--journal-edge);
}

.sq-journal-spread[hidden] { display: none; }

.sq-journal-sheet {
  position: relative;
  /* Room at the bottom for "next page" / "back". */
  padding: 40px 44px 64px;
  background-color: var(--journal-paper);
  /* Dot grid, like a bullet journal. */
  background-image: radial-gradient(var(--journal-dot) 1px, transparent 1.4px);
  background-size: 20px 20px;
  background-position: 10px 10px;
}

.sq-journal-left {
  border-radius: 8px 2px 2px 8px;
  padding-right: 52px;
  box-shadow: inset -26px 0 24px -24px var(--journal-gutter);
}

.sq-journal-right {
  border-radius: 2px 8px 8px 2px;
  padding-left: 52px;
  box-shadow: inset 26px 0 24px -24px var(--journal-gutter);
}

.sq-journal-sheet > :first-child { margin-top: 0; }

/* Spiral rings across the gutter: one wire loop per tile - a punched hole
   in each page, the wire arcing over the gutter between them (steel
   gradient, a highlight along its top, a soft shadow on the paper). */
.sq-journal-binding {
  position: absolute;
  /* Above the pages' photos and stickers - nothing slides over the wire. */
  z-index: 4;
  top: 30px;
  bottom: 30px;
  left: 50%;
  width: 60px;
  transform: translateX(-50%);
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 60 28%22 width=%2260%22 height=%2228%22%3E%3Cdefs%3E%3ClinearGradient id=%22w%22 x1=%220%22 y1=%220%22 x2=%220%22 y2=%221%22%3E%3Cstop offset=%220%22 stop-color=%22%234f4844%22/%3E%3Cstop offset=%22.3%22 stop-color=%22%23f1eeeb%22/%3E%3Cstop offset=%22.5%22 stop-color=%22%23bdb6b0%22/%3E%3Cstop offset=%22.8%22 stop-color=%22%236b635e%22/%3E%3Cstop offset=%221%22 stop-color=%22%233d3632%22/%3E%3C/linearGradient%3E%3ClinearGradient id=%22hole%22 x1=%220%22 y1=%220%22 x2=%220%22 y2=%221%22%3E%3Cstop offset=%220%22 stop-color=%22%231f1511%22/%3E%3Cstop offset=%221%22 stop-color=%22%234a362e%22/%3E%3C/linearGradient%3E%3Cfilter id=%22s%22 x=%22-20%25%22 y=%22-60%25%22 width=%22140%25%22 height=%22240%25%22%3E%3CfeGaussianBlur stdDeviation=%221.2%22/%3E%3C/filter%3E%3C/defs%3E%3Cellipse cx=%2211%22 cy=%2218%22 rx=%223.6%22 ry=%224.2%22 fill=%22url(%23hole)%22/%3E%3Cellipse cx=%2249%22 cy=%2216%22 rx=%223.6%22 ry=%224.2%22 fill=%22url(%23hole)%22/%3E%3Cpath d=%22M12 21 C15 7 45 5 48 19%22 fill=%22none%22 stroke=%22%232b1d18%22 stroke-opacity=%22.3%22 stroke-width=%224%22 stroke-linecap=%22round%22 filter=%22url(%23s)%22/%3E%3Cpath d=%22M11 18.5 C12.5 2 47.5 0 49 16.5%22 fill=%22none%22 stroke=%22url(%23w)%22 stroke-width=%224.4%22 stroke-linecap=%22round%22/%3E%3Cpath d=%22M13.2 10.5 C18 3.2 42 1.8 46.8 8.6%22 fill=%22none%22 stroke=%22%23fff%22 stroke-opacity=%22.8%22 stroke-width=%22.9%22 stroke-linecap=%22round%22/%3E%3Cpath d=%22M7.4 18.6 A3.6 4.2 0 0 0 14.6 18.6 A3.6 2.2 0 0 1 7.4 18.6 Z%22 fill=%22%232b1d18%22 fill-opacity=%22.85%22/%3E%3Cpath d=%22M45.4 16.6 A3.6 4.2 0 0 0 52.6 16.6 A3.6 2.2 0 0 1 45.4 16.6 Z%22 fill=%22%232b1d18%22 fill-opacity=%22.85%22/%3E%3C/svg%3E");
  background-size: 60px 28px;
  /* Whole rings only, spaced evenly down the spine - never a half one. */
  background-repeat: no-repeat space;
}

/* Turning the page: a handwritten "next page" in each bottom corner. */
.sq-journal-turn {
  position: absolute;
  z-index: 5;
  bottom: 22px;
  padding: 4px 8px;
  border: 0;
  background: none;
  font-family: var(--font-family-hand);
  font-size: var(--font-size-600);
  line-height: 1;
  color: var(--journal-accent);
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.sq-journal-turn[data-turn="-1"] { left: 30px; }
.sq-journal-turn[data-turn="1"] { right: 30px; }
.sq-journal-turn:hover { transform: translateX(var(--nudge, 3px)); }
.sq-journal-turn[data-turn="-1"]:hover { --nudge: -3px; }
.sq-journal-turn[hidden] { display: none; }

/* The page mid-turn (journal.js): the outgoing page and, on its back, the
   incoming one, rotating about the spine over a still copy of the page it
   uncovers last. */
.sq-flip-stage {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  perspective: 4200px;
}

.sq-flip-stage > * {
  position: absolute;
  top: 0;
  margin: 0;
}

.sq-flip-stage > :first-child { z-index: 0; }

.sq-flip-leaf {
  z-index: 1;
  transform-style: preserve-3d;
}

.sq-flip-leaf > * {
  position: absolute;
  inset: 0;
  margin: 0;
  backface-visibility: hidden;
}

.sq-flip-leaf > :last-child { transform: rotateY(180deg); }

.sq-journal-tabs {
  position: absolute;
  top: 64px;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sq-journal-tab {
  width: var(--journal-tab-width);
  padding: 18px 0 18px 6px;
  border: 1px solid var(--journal-edge);
  border-left: none;
  border-radius: 0 10px 10px 0;
  font-family: var(--font-family-hand);
  font-size: var(--font-size-600);
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--color-on-surface-muted);
  writing-mode: vertical-rl;
  cursor: pointer;
  /* Tucked behind the cover until picked. */
  transform: translateX(-8px);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), color 0.2s;
  box-shadow: var(--shadow-sm);
}

.sq-journal-tab[data-tab="3d"] { background: var(--journal-tab-3d); }
.sq-journal-tab[data-tab="print"] { background: var(--journal-tab-print); }
.sq-journal-tab:hover { transform: translateX(-4px); color: var(--color-on-surface); }
.sq-journal-tab[aria-selected="true"] { transform: translateX(0); color: var(--color-on-surface); }

.sq-journal-spread.is-turning .sq-journal-sheet { animation: sq-page-in 0.35s cubic-bezier(0.16, 1, 0.3, 1); }

@keyframes sq-page-in {
  from { opacity: 0; transform: translateX(10px); }
}

/* ---- What's on the pages ---- */
.sq-journal .cs-section h2,
.sq-journal h2 {
  position: relative;
  display: inline-block;
  margin: 0 0 6px;
  font-family: var(--font-family-hand);
  font-size: var(--font-size-1000);
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: none;
  color: var(--journal-accent);
}

/* Hand-drawn squiggle under the page label. */
.sq-journal h2::after {
  content: "";
  display: block;
  height: 8px;
  margin-top: 1px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 8'%3E%3Cpath d='M1 5 C6 1 10 1 15 4 S24 7 30 4 S40 1 45 4 S54 7 59 3' fill='none' stroke='%23e05440' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") left center / 60px 8px repeat-x;
}

.sq-journal h3.cs-h1-style {
  margin: 0 0 12px;
  font-family: var(--font-family-journal-title);
  font-size: 44px;
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -0.5px;
  color: var(--color-on-surface);
}

.sq-journal-sheet > p {
  max-width: 34em;
  font-family: var(--font-family-journal-mono);
  font-size: var(--font-size-100);
  line-height: 1.6;
  letter-spacing: 0.2px;
  color: var(--color-on-surface-muted);
}

.sq-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.sq-grid img {
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  display: block;
  background: var(--color-surface-container);
  cursor: zoom-in;
}

.sq-grid > img:nth-child(3n + 1),
.sq-grid > div:nth-child(3n + 1) img { transform: rotate(-1.6deg); }
.sq-grid > img:nth-child(3n + 2),
.sq-grid > div:nth-child(3n + 2) img { transform: rotate(1.2deg); }
.sq-grid > img:nth-child(3n),
.sq-grid > div:nth-child(3n) img { transform: rotate(-0.6deg); }
.sq-grid img { box-shadow: 0 4px 12px rgba(48, 30, 24, 0.12); }

.sq-grid .sq-wide { grid-column: 1 / -1; }
.sq-grid .sq-wide img { aspect-ratio: 16 / 9; }
.sq-grid .sq-big { grid-column: span 2; grid-row: span 2; }
.sq-grid-2 { grid-template-columns: repeat(2, 1fr); }
.sq-grid-2 img { aspect-ratio: 16 / 9; }
.sq-grid-1 { grid-template-columns: 1fr; }
.sq-grid-2.sq-grid-square img { aspect-ratio: 1 / 1; }
.sq-grid .sq-tall img { aspect-ratio: auto; height: auto; }

/* ---- Decorations ---- */
.jd-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  /* Decorations are sized in cqw - % of this layer's width, i.e. the whole
     page's - so they keep their place and size as the journal scales. */
  container-type: inline-size;
}

.jd-item {
  position: absolute;
  transform-origin: center;
  user-select: none;
}

.jd-item svg,
.jd-item img {
  display: block;
  width: 100%;
  height: auto;
}

/* A page photo lifted out of its grid. Still opens in the lightbox. */
.jd-photo { pointer-events: auto; }
.jd-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  background: var(--color-surface-container);
  box-shadow: 0 6px 16px rgba(48, 30, 24, 0.16);
  cursor: zoom-in;
}

.jd-sticker,
.jd-image { filter: drop-shadow(0 1px 1.5px rgba(48, 30, 24, 0.28)); }

.jd-text {
  font-family: var(--font-family-hand);
  font-weight: 400;
  line-height: 1.1;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

/* ---- Decorate mode (local site editor only) ---- */
.sq-journal.is-decorating .jd-layer { pointer-events: auto; cursor: default; }
.sq-journal.is-decorating[data-tool="pen"] .jd-layer,
.sq-journal.is-decorating[data-tool="marker"] .jd-layer { cursor: crosshair; }
.sq-journal.is-decorating[data-tool="text"] .jd-layer { cursor: text; }
.sq-journal.is-decorating[data-tool="place"] .jd-layer { cursor: copy; }
.sq-journal.is-decorating[data-tool="eraser"] .jd-layer { cursor: not-allowed; }
.sq-journal.is-decorating[data-tool="select"] .jd-item,
.sq-journal.is-decorating[data-tool="select"] .jd-photo img { cursor: move; }
.sq-journal.is-decorating .jd-layer { outline: 2px dashed rgba(232, 80, 91, 0.35); outline-offset: -6px; }

.jd-item.is-selected { outline: 1.5px solid #e8505b; outline-offset: 3px; }
.jd-text[contenteditable] { outline: 1.5px dashed #e8505b; cursor: text; user-select: text; min-width: 1em; }

.jd-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #e8505b;
  box-sizing: border-box;
}

.jd-handle[data-handle="resize"] { right: -10px; bottom: -10px; cursor: nwse-resize; }
.jd-handle[data-handle="rotate"] { left: 50%; top: -30px; margin-left: -7px; cursor: grab; }
.jd-handle[data-handle="rotate"]::after { content: ""; position: absolute; left: 4px; top: 12px; width: 2px; height: 14px; background: #e8505b; }
.jd-handle[data-handle="delete"] {
  right: -12px; top: -12px; width: 20px; height: 20px;
  background: #e8505b; color: #fff; border: 0;
  font: 700 14px/20px system-ui, sans-serif; text-align: center; cursor: pointer;
}

.jd-tray {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 1900;
  width: 248px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 10px;
  border-radius: 16px;
  background: #1d120e;
  color: #fdfbf8;
  font: 500 13px/1.3 Roboto, system-ui, sans-serif;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.jd-tray[data-open="false"] { width: auto; padding: 4px; border-radius: 100px; }
.jd-tray[data-open="false"] > :not(.jd-tray-toggle) { display: none; }

.jd-tray button {
  border: 0;
  border-radius: 8px;
  padding: 7px 9px;
  background: rgba(253, 251, 248, 0.08);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.jd-tray button:hover { background: rgba(253, 251, 248, 0.16); }
.jd-tray button[aria-pressed="true"] { background: #fdfbf8; color: #2e1b15; }
.jd-tray button:disabled { opacity: 0.4; cursor: default; }
.jd-tray .jd-primary { background: #e8505b; color: #fff; }
.jd-tray .jd-tray-toggle { width: 100%; border-radius: 100px; padding: 9px 14px; background: transparent; }
.jd-tray[data-open="true"] .jd-tray-toggle { background: rgba(253, 251, 248, 0.08); }

.jd-tray h3 {
  margin: 12px 2px 6px;
  font: 600 11px/1.2 Roboto, system-ui, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(253, 251, 248, 0.6);
}

.jd-row { display: flex; flex-wrap: wrap; gap: 4px; }

.jd-input {
  flex: 1 1 120px;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid rgba(253, 251, 248, 0.2);
  border-radius: 8px;
  background: rgba(253, 251, 248, 0.06);
  color: inherit;
  font: inherit;
}

.jd-input::placeholder { color: rgba(253, 251, 248, 0.45); }
select.jd-input option { color: #1d120e; }
.jd-row > button { flex: 1 1 auto; }

.jd-swatch { width: 26px; height: 26px; flex: 0 0 auto !important; padding: 0 !important; border-radius: 50% !important; box-shadow: inset 0 0 0 2px rgba(253, 251, 248, 0.25); }
.jd-swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px #1d120e, 0 0 0 4px #fdfbf8; }

.jd-stickers { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.jd-stickers button { padding: 5px; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; }
.jd-stickers svg { width: 100%; height: 100%; }
.jd-stickers button[aria-pressed="true"] { background: #fdfbf8; }

.jd-hint { margin: 10px 2px 2px; font-size: 12px; color: rgba(253, 251, 248, 0.6); }

@media (max-width: 760px) {
  .sq-journal { padding-right: calc(var(--journal-tab-width) - 6px); }
  .sq-journal-book { padding: 8px; border-radius: 14px; }
  .sq-journal-spread { grid-template-columns: 1fr; }
  .sq-journal-sheet { padding: 28px 22px 32px; }
  .sq-journal-right { padding-bottom: 60px; }
  .sq-journal-left { border-radius: 8px 8px 0 0; box-shadow: none; padding-right: 22px; }
  .sq-journal-right { border-radius: 0 0 8px 8px; box-shadow: none; padding-left: 22px; border-top: 1px dashed var(--journal-edge); }
  .sq-journal-binding { display: none; }
  /* Placed photos and decorations are laid out against the wide pages,
     where the text sits differently, so phones get the tidy grid. */
  .jd-layer { display: none; }
  .sq-journal h3.cs-h1-style { font-size: 36px; }
  :root { --journal-tab-width: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  .sq-journal-tab,
  .sq-journal-turn { transition: none; }
  .sq-journal-spread.is-turning .sq-journal-sheet { animation: none; }
}
