/* Journaling Bible — calm paper look.
   IMPORTANT: the page geometry and typography below are part of the drawing
   coordinate system. Changing them moves text under existing drawings. */

:root {
  --desk: #d8cfbf;
  --paper: #fbf8f1;
  --ink: #2a251f;
  --muted: #8a8174;
  --rule: #e4dccb;
  --bar: #f3eee3;
  --accent: #7a5c3a;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font-family: -apple-system, system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

/* ---------- toolbar ---------- */
#toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 14px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: var(--bar);
  border-bottom: 1px solid #ddd4c2;
  box-shadow: 0 1px 6px rgba(60, 45, 20, 0.06);
}
.group { display: flex; align-items: center; gap: 4px; }

button, select, .menu-btn {
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  min-height: 40px;
  touch-action: manipulation;
}
button { padding: 0 8px; cursor: pointer; }
button.icon { min-width: 40px; font-size: 24px; line-height: 1; }
button.text { padding: 0 12px; }
button:active { background: rgba(122, 92, 58, 0.12); }
button:disabled { opacity: 0.3; }
select {
  -webkit-appearance: none;
  appearance: none;
  padding: 0 12px;
  background: var(--paper);
  border-color: #ddd4c2;
  font-family: Georgia, serif;
}
#book { width: 170px; }
#chapter { width: 64px; text-align: center; }

button svg {
  width: 24px; height: 24px; display: block;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.tool { width: 44px; }
.tool.on { background: #fff; border-color: #d3c7b0; box-shadow: 0 1px 2px rgba(0,0,0,0.06); }
.tool[data-tool="hl"] .hl-line { stroke: #f2c94c; stroke-width: 3; }
.tool[data-tool="wc"] .wc-dab { stroke: #5b9bd5; stroke-width: 3; }

.swatch {
  width: 34px; min-width: 34px; height: 34px; min-height: 34px;
  border-radius: 50%; padding: 0;
  display: grid; place-items: center;
}
.swatch span { width: 22px; height: 22px; border-radius: 50%; display: block; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12); }
.swatch.on { border-color: var(--accent); }

.size { width: 38px; min-width: 38px; display: grid; place-items: center; padding: 0; }
.size span { display: block; border-radius: 50%; background: var(--ink); }
.size.on { background: #fff; border-color: #d3c7b0; }

/* ---------- menu ---------- */
#menu {
  position: fixed; z-index: 20; right: 12px;
  top: calc(env(safe-area-inset-top) + 62px);
  width: 300px; padding: 10px;
  background: var(--paper); border: 1px solid #ddd4c2; border-radius: 14px;
  box-shadow: 0 8px 30px rgba(60, 45, 20, 0.18);
  display: flex; flex-direction: column; gap: 6px;
}
#menu[hidden] { display: none; }
#menu button, .menu-btn { text-align: left; padding: 8px 12px; display: flex; align-items: center; background: #fff; border-color: #e6dfd0; }
#menu .small { font-size: 13px; color: var(--muted); margin: 4px 4px 0; line-height: 1.4; }

/* ---------- page ---------- */
#viewport { padding: 34px 0 calc(env(safe-area-inset-bottom) + 30px); }
#sheet-wrap { position: relative; margin: 0 auto; isolation: isolate; }

/* soft leather cover, wrapped round behind the folded-back pages */
#cover {
  position: absolute; z-index: -1;
  top: -15px; bottom: -17px; left: -40px; right: -16px;
  border-radius: 30px 20px 20px 30px;
  background:
    /* the cover rolling round the fold on the left */
    linear-gradient(to right, rgba(0,0,0,0.45) 0, rgba(255,235,200,0.10) 9px, rgba(0,0,0,0.08) 18px, rgba(0,0,0,0) 28px),
    /* soft sheen */
    radial-gradient(ellipse 70% 45% at 35% 18%, rgba(255,235,205,0.16), rgba(255,235,205,0) 70%),
    radial-gradient(ellipse 60% 40% at 70% 85%, rgba(0,0,0,0.18), rgba(0,0,0,0) 70%),
    /* pebbled grain */
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='g'><feTurbulence type='turbulence' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.28 0'/></filter><rect width='100%' height='100%' filter='url(%23g)'/></svg>"),
    linear-gradient(165deg, #7a5233, #5e3d24 50%, #4d311c);
  box-shadow:
    inset 0 1px 1px rgba(255,230,200,0.18), inset 0 -2px 3px rgba(0,0,0,0.25),
    0 2px 4px rgba(40,25,10,0.30), 0 20px 44px rgba(40,25,10,0.30);
}
/* stitching round the edge of the cover */
#cover::after {
  content: ""; position: absolute; inset: 7px;
  border-radius: 24px 14px 14px 24px;
  border: 1.5px dashed rgba(232, 205, 160, 0.42);
}
/* the pages already read, folded round behind: a rounded bundle of page edges */
#fold {
  position: absolute; z-index: 0; top: 3px; bottom: 3px; left: -22px; width: 22px;
  border-radius: 14px 0 0 14px;
  background:
    linear-gradient(to right, rgba(55,38,18,0.50) 0, rgba(55,38,18,0.16) 30%, rgba(255,250,235,0.10) 55%, rgba(55,38,18,0.05) 75%, rgba(55,38,18,0.22) 100%),
    repeating-linear-gradient(to right, #f1e8d4 0 1.6px, #d6c8aa 1.6px 2.4px),
    #efe6d1;
  box-shadow: -1px 0 2px rgba(40,25,10,0.25);
  pointer-events: none;
}

/* red ribbon bookmark hanging out of the bottom */
#sheet-wrap::after {
  content: ""; position: absolute; z-index: 2;
  right: 18%; bottom: -46px; width: 16px; height: 64px;
  background: linear-gradient(to right, #7d1f1f, #a83232 45%, #8a2424);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%);
  box-shadow: 0 2px 3px rgba(0,0,0,0.25);
  pointer-events: none;
}
#sheet-wrap.turn-next { animation: turn-next 0.32s ease-out; }
#sheet-wrap.turn-prev { animation: turn-prev 0.32s ease-out; }
@keyframes turn-next { from { opacity: 0.35; transform: translateX(26px); } to { opacity: 1; transform: none; } }
@keyframes turn-prev { from { opacity: 0.35; transform: translateX(-26px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #sheet-wrap.turn-next, #sheet-wrap.turn-prev { animation: none; } }

#page {
  position: absolute; left: 0; top: 0;
  width: 840px;                 /* fixed page width — see app.js PAGE_W */
  transform-origin: 0 0;
  border-radius: 0 4px 4px 0;
  /* paper: binding shadow on the spine side, soft aged edges, fine grain, gentle mottling */
  background:
    linear-gradient(to right, rgba(70,50,25,0.22) 0, rgba(95,70,35,0.09) 10px, rgba(95,70,35,0.03) 28px, rgba(95,70,35,0) 50px),
    linear-gradient(to left, rgba(120,90,45,0.07) 0, rgba(120,90,45,0) 22px),
    linear-gradient(to bottom, rgba(120,90,45,0.05) 0, rgba(120,90,45,0) 30px),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='260' height='260'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.42  0 0 0 0 0.33  0 0 0 0 0.2  0 0 0 0.10 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='900' height='900'><filter id='m'><feTurbulence type='fractalNoise' baseFrequency='0.006' numOctaves='3' seed='4' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.62  0 0 0 0 0.5  0 0 0 0 0.3  0 0 0 0.16 -0.04'/></filter><rect width='100%' height='100%' filter='url(%23m)'/></svg>"),
    #fbf7ec;
  /* stacked page edges (the thickness of the book) with a hint of gilt */
  box-shadow:
    1px 1px 0 #f4eddc, 2px 2px 0 #ddd2bb,
    3px 3px 0 #f2eada, 4px 4px 0 #d8ccb3,
    5px 5px 0 #efe6d3, 6px 6px 0 #cdbf9f,
    7px 7px 0 #e9dfc8, 8px 8px 0 #c4ad7a,
    0 1px 3px rgba(40,25,10,0.25);
  touch-action: pan-y;          /* fingers scroll; pencil is handled in JS */
}

/* Bible text column: x 52 … 480 */
#text {
  position: relative;
  z-index: 2;
  width: 428px;
  margin-left: 52px;
  padding: 56px 0 80px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 30px;
  font-kerning: normal;
  font-variant-ligatures: none;
  letter-spacing: 0;
  word-spacing: 0;
  text-align: left;
  hyphens: none;
  -webkit-hyphens: none;
  overflow-wrap: break-word;
  color: var(--ink);
  pointer-events: none;
}
#text h1 {
  font-weight: normal;
  font-size: 32px;
  line-height: 40px;
  margin: 0 0 4px;
  letter-spacing: 0.5px;
}
#text h1 .num { color: var(--accent); }
#text .sub {
  font-size: 13px; line-height: 20px; letter-spacing: 2px;
  text-transform: uppercase; color: var(--muted);
  margin: 0 0 26px;
}
#text p { margin: 0; }
#text .vn {
  font-size: 11px;
  line-height: 0;
  vertical-align: 0.6em;
  color: var(--accent);
  margin-right: 3px;
  font-family: Georgia, serif;
}
#text .verse { }
#text.poetry .verse { display: block; padding-left: 18px; text-indent: -18px; }

/* running header + page number, like a printed Bible (outside the text flow) */
#runhead {
  position: absolute; z-index: 2; top: 22px; left: 52px; right: 28px;
  display: flex; justify-content: space-between;
  font-family: Georgia, serif; font-size: 11px; line-height: 14px;
  letter-spacing: 2.5px; text-transform: uppercase; color: var(--muted);
  padding-bottom: 6px; border-bottom: 1px solid var(--rule);
  pointer-events: none;
}
#runhead .rh-right { padding-right: 4px; font-style: italic; letter-spacing: 1.5px; text-transform: none; font-size: 12px; }
#folio {
  position: absolute; z-index: 2; bottom: 22px; left: 0; width: 504px;
  text-align: center; font-family: Georgia, serif; font-size: 12px; color: var(--muted);
  letter-spacing: 1px; pointer-events: none;
}
#folio::before, #folio::after { content: "~"; margin: 0 10px; color: #c9bba0; }

/* journaling lines in the margin, aligned with the Bible text baselines (top set in app.js) */
#margin-lines {
  position: absolute; z-index: 1; left: 526px; right: 30px; bottom: 60px;
  background: repeating-linear-gradient(to bottom, transparent 0 28.4px, rgba(176,160,130,0.26) 28.4px 30px);
  pointer-events: none;
}

/* margin column: x 504 … 840 (40%) */
#margin-rule {
  position: absolute; z-index: 1;
  left: 504px; top: 56px; bottom: 48px;
  border-left: 1px solid #e2d6bf;
  pointer-events: none;
}

.layer {
  position: absolute; left: 0; top: 0;
  width: 840px; height: 100%;
  overflow: visible;
  pointer-events: none;
}
#hl-layer { z-index: 1; mix-blend-mode: multiply; }   /* highlighter + watercolour, behind the text */
#ink-layer { z-index: 3; }                           /* over the text */

#bottom-nav {
  display: flex; justify-content: space-between;
  max-width: 840px; margin: 64px auto 0; padding: 0 12px;
}
#bottom-nav button { font-family: Georgia, serif; color: var(--accent); padding: 0 14px; }
#credit { text-align: center; font-size: 12px; color: var(--muted); margin: 10px 0 0; }

#loading {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--desk); color: var(--muted); font-family: Georgia, serif; font-size: 20px; z-index: 50;
}
#loading[hidden] { display: none; }

#menu .sync { margin: 0 4px 6px; color: var(--ink); }
#more { position: relative; }
#more.unsynced::after {   /* small amber dot when drawings haven't reached the Mac mini */
  content: ""; position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; border-radius: 50%; background: #e3a63b;
}
