/* Journal — glass chrome, serif pages.
   Closed books use the notes shelf. Open pages are worn paper. */

#journal-root {
  position: fixed;
  inset: 0 0 0 var(--nav);
  z-index: 30;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(1000px 560px at 18% 0%, rgba(255,255,255,.05), transparent 58%),
    rgba(8, 7, 10, .82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#journal-root[hidden] { display: none !important; }

.jn-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: none;
  margin: 14px 16px 0;
  padding: 12px 16px;
  background: var(--glass);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.jn-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
  cursor: pointer;
}
.jn-back svg { width: 14px; height: 14px; }
.jn-back:hover { color: var(--ink); }
.jn-back[hidden] { display: none; }
.jn-bar h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: 0;
  color: var(--ink);
}
.jn-bar h1 em { font-style: normal; }
.jn-bar h1 span,
.jn-kicker {
  display: block;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 3px;
}
.jn-range {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.jn-main {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  padding: 18px 28px 36px;
}
.jn-main.book-open {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 16px;
}
.jn-library { max-width: 1060px; margin: 0 auto; padding: 6px 0 40px; }
.jn-library[hidden],
.jn-stage[hidden] { display: none !important; }

.jn-stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.jn-tabs {
  flex: none;
  display: flex;
  gap: 4px;
  width: min(980px, 100%);
  max-width: 100%;
  overflow-x: auto;
  padding: 4px;
  background: var(--glass);
  border: 1px solid var(--hairline);
  border-radius: 28px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  scrollbar-width: none;
}
.jn-tabs::-webkit-scrollbar { display: none; }
.jn-tab {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.jn-tab:hover { color: var(--ink); }
.jn-tab.on {
  background: rgba(255,255,255,.92);
  color: #14121a;
}

.jn-scene {
  position: relative;
  flex: 1;
  min-height: 0;
  width: min(980px, 100%);
  display: flex;
  align-items: stretch;
  perspective: 1800px;
  perspective-origin: 50% 42%;
}
.jn-scene::before {
  content: '';
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 1%;
  height: 36px;
  background: radial-gradient(closest-side, rgba(0,0,0,.5), transparent);
  filter: blur(10px);
  pointer-events: none;
}

.jn-book {
  position: relative;
  flex: 1;
  min-height: 0;
  min-width: 0;
  width: 100%;
  max-height: 740px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  transform-style: preserve-3d;
  z-index: 1;
}
.jn-book::before {
  content: '';
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 28px;
  transform: translateX(-50%);
  pointer-events: none;
  background: linear-gradient(90deg,
    transparent,
    rgba(40, 24, 8, .22) 38%,
    rgba(255, 246, 230, .22) 50%,
    rgba(40, 24, 8, .28) 62%,
    transparent);
}

/* Worn leaf: tea, foxing, deckle. The plates on the board are gray-brown
   and stained, so the paper is dirtier than a fresh notebook. */
.jn-paper {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  color: #2a2118;
  font-family: var(--serif);
  background-color: #e7d3ae;
  background-image:
    radial-gradient(circle at 18% 86%, rgba(120, 72, 32, .28) 0 2px, rgba(120, 72, 32, .1) 4px, transparent 10px),
    radial-gradient(circle at 78% 14%, rgba(90, 60, 30, .22) 0 1.5px, rgba(90, 60, 30, .08) 3px, transparent 8px),
    radial-gradient(circle at 64% 68%, rgba(70, 48, 24, .16) 0 1px, transparent 6px),
    radial-gradient(46px 30px at 88% 78%, rgba(55, 38, 22, .16), transparent 72%),
    radial-gradient(70px 48px at 12% 22%, rgba(110, 80, 40, .12), transparent 70%),
    radial-gradient(130% 100% at 50% 50%, transparent 52%, rgba(110, 72, 32, .28) 100%),
    var(--grain),
    var(--stain),
    linear-gradient(165deg, #f0e2c6, #e4d0aa 42%, #d8c49a);
  background-size: auto, auto, auto, auto, auto, auto, 180px 180px, 520px 700px, auto;
  box-shadow: inset 0 0 30px rgba(110, 70, 28, .22), inset 0 0 6px rgba(80, 50, 18, .28);
}
.jn-paper::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(90px 54px at 8% 8%, rgba(70, 48, 24, .14), transparent 70%),
    radial-gradient(120px 70px at 96% 96%, rgba(50, 34, 18, .18), transparent 72%),
    linear-gradient(90deg, rgba(90, 60, 24, .05), transparent 18%, transparent 82%, rgba(70, 46, 20, .08));
}
.jn-paper.left {
  border-radius: 7px 1px 1px 9px;
  box-shadow: inset -18px 0 24px rgba(50, 28, 8, .16), inset 0 0 28px rgba(110, 70, 28, .18);
  -webkit-mask: var(--deckle-l) 0 0 / 100% 100% no-repeat;
  mask: var(--deckle-l) 0 0 / 100% 100% no-repeat;
  background-position: 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 40px 20px, -80px 40px, 0 0;
}
.jn-paper.right {
  border-radius: 1px 9px 11px 1px;
  box-shadow: inset 18px 0 24px rgba(50, 28, 8, .16), inset 0 0 28px rgba(110, 70, 28, .18);
  -webkit-mask: var(--deckle-r) 0 0 / 100% 100% no-repeat;
  mask: var(--deckle-r) 0 0 / 100% 100% no-repeat;
  background-position: 20px 30px, 0 0, 10px 8px, 0 0, 0 0, 0 0, 90px 140px, 180px -160px, 0 0;
}
.jn-page { z-index: 1; }
.jn-paper.left::before {
  background:
    radial-gradient(26px 18px at 10% 82%, rgba(60, 36, 16, .22), transparent 70%),
    radial-gradient(110px 60px at 24% 28%, rgba(100, 70, 36, .12), transparent 72%),
    radial-gradient(80% 100% at 0% 50%, rgba(80, 50, 20, .16), transparent 36%);
}
.jn-paper.right::before {
  background:
    radial-gradient(34px 22px at 84% 18%, rgba(50, 32, 16, .2), transparent 70%),
    radial-gradient(80px 50px at 70% 80%, rgba(90, 60, 30, .14), transparent 70%),
    radial-gradient(80% 100% at 100% 50%, rgba(80, 50, 20, .18), transparent 34%);
}
.jn-page.is-place,
.jn-page.is-place .jn-edit { cursor: crosshair; touch-action: none; }

.jn-body {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: auto;
  padding: 26px 28px 40px;
}
.jn-paper h2 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 22px;
  line-height: 1.25;
  letter-spacing: 0;
  color: #2a2118;
}
.jn-paper h3 {
  margin: 12px 0 6px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 16px;
  color: #2a2118;
}
.jn-paper .jn-kicker { color: rgba(42, 33, 24, .55); }
.jn-paper p,
.jn-paper li {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.45;
}
.jn-paper ul { margin: 0; padding: 0 0 0 1.05em; }
.jn-paper li { margin-bottom: 6px; }
.jn-paper li strong { font-weight: 600; }
.jn-flow { margin: 4px 0 0; padding: 0; list-style: none; }
.jn-flow li { margin: 0; }
.jn-flow li + li::before {
  content: '↓';
  display: block;
  margin: 2px 0 4px;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: .08em;
  color: rgba(42, 33, 24, .45);
}
.jn-edit {
  cursor: text;
  outline: none;
  border-radius: 2px;
  caret-color: #8a4e22;
}
.jn-edit:focus { background: rgba(255, 250, 240, .28); }
.jn-edit:empty::before {
  content: attr(data-placeholder);
  color: rgba(60, 42, 24, .38);
  font-style: italic;
  pointer-events: none;
}
.jn-plate { margin: 0; }
.jn-plate img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: 220px;
  object-fit: cover;
  border-radius: 1px;
  box-shadow: 0 8px 16px rgba(40, 24, 8, .22);
  filter: sepia(.18) contrast(1.04);
  transform: rotate(-0.6deg);
  cursor: pointer;
}
.jn-plate.is-on img {
  outline: 1px solid rgba(42, 33, 24, .55);
  outline-offset: 3px;
}
.jn-page.right .jn-plate img,
.jn-face.right .jn-plate img { transform: rotate(0.7deg); }
.jn-plate figcaption {
  margin-top: 10px;
  font-family: var(--serif);
  font-size: 14px;
  line-height: 1.4;
  color: rgba(42, 33, 24, .78);
}

.jn-folio {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  z-index: 2;
  text-align: center;
  font-family: var(--serif);
  font-size: 11px;
  font-style: italic;
  letter-spacing: .08em;
  color: rgba(90, 62, 32, .62);
  pointer-events: none;
}

/* Outer edges turn the leaf. The wash matches the notes book. */
.jn-edge {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 76px;
  z-index: 6;
  padding: 0;
  border: 0;
  background: transparent;
  color: rgba(70, 46, 22, .8);
  cursor: pointer;
  transition: background .25s var(--ease);
}
.jn-edge.left { left: 0; }
.jn-edge.right { right: 0; }
.jn-edge svg {
  position: absolute;
  top: 50%;
  width: 22px;
  height: 22px;
  opacity: 0;
  transform: translateY(-50%);
  transition: opacity .2s var(--ease);
  filter: drop-shadow(0 1px 0 rgba(255, 244, 220, .35));
}
.jn-edge.left svg { left: 12px; }
.jn-edge.right svg { right: 12px; }
.jn-edge.left:hover:not(:disabled) {
  background: linear-gradient(90deg, rgba(90, 60, 20, .16), transparent);
}
.jn-edge.right:hover:not(:disabled) {
  background: linear-gradient(270deg, rgba(90, 60, 20, .16), transparent);
}
.jn-edge:hover:not(:disabled) svg { opacity: 1; }
.jn-edge:disabled { cursor: default; }

/* A sheet hinged at the spine. It lifts, passes through edge-on, and lands. */
.jn-leaf {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 5;
  pointer-events: none;
  transform-style: preserve-3d;
  transform: translateZ(2px) rotateY(0deg);
}
.jn-leaf[hidden] { display: none !important; }
.jn-leaf.fwd { left: 50%; transform-origin: left center; }
.jn-leaf.rev { left: 0; transform-origin: right center; }
.jn-leaf.fwd.go { animation: jn-leaf-fwd 860ms cubic-bezier(.45, .05, .25, 1) forwards; }
.jn-leaf.rev.go { animation: jn-leaf-rev 860ms cubic-bezier(.45, .05, .25, 1) forwards; }
@keyframes jn-leaf-fwd {
  0% { transform: translateZ(2px) rotateY(0deg); }
  38% { transform: translateZ(34px) rotateY(-72deg); }
  100% { transform: translateZ(2px) rotateY(-180deg); }
}
@keyframes jn-leaf-rev {
  0% { transform: translateZ(2px) rotateY(0deg); }
  38% { transform: translateZ(34px) rotateY(72deg); }
  100% { transform: translateZ(2px) rotateY(180deg); }
}
.jn-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.jn-face.back { transform: rotateY(180deg); }
.jn-leaf.fwd .jn-face.front,
.jn-leaf.rev .jn-face.back { border-radius: 1px 8px 10px 1px; }
.jn-leaf.fwd .jn-face.back,
.jn-leaf.rev .jn-face.front { border-radius: 8px 1px 1px 10px; }
.jn-face::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(90deg, rgba(60, 36, 10, .32), rgba(255, 248, 230, .2) 42%, rgba(60, 36, 10, .16));
}
.jn-leaf.go .jn-face::after { animation: jn-shade 860ms ease-in-out; }
@keyframes jn-shade { 0%, 100% { opacity: 0; } 46% { opacity: 1; } }
.jn-book.is-turning .jn-edge { opacity: 0; pointer-events: none; }

.jn-scraps, .jn-live {
  position: absolute;
  inset: 0;
  overflow: visible;
}
.jn-scraps { pointer-events: none; z-index: 2; }
.jn-scrap { pointer-events: auto; }
.jn-live { pointer-events: none; z-index: 3; }
.jn-scrap {
  position: absolute;
  z-index: 2;
  cursor: grab;
  user-select: none;
}
.jn-scrap.is-on { z-index: 3; outline: 1px solid rgba(42, 33, 24, .4); outline-offset: 4px; }
.jn-scrap.kind-text {
  height: auto;
  padding: 2px 4px;
  background: rgba(247, 240, 224, .55);
}
.jn-ink {
  min-height: 1.2em;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.4;
  color: #2a2118;
  white-space: pre-wrap;
  word-break: break-word;
}
.jn-ink:empty::before {
  content: 'Write…';
  color: rgba(42, 33, 24, .35);
}
.jn-ink[contenteditable="true"] { user-select: text; cursor: text; outline: none; }
.jn-scrap.kind-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  box-shadow: 0 8px 16px rgba(40, 24, 8, .22);
  pointer-events: none;
}
.jn-scrap.kind-ink svg { display: block; width: 100%; height: 100%; overflow: visible; }
.jn-scrap.kind-ink path {
  fill: none;
  stroke: #241c14;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.jn-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(42, 33, 24, .45);
  background: #f3e6cc;
  color: #2a2118;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
}
.jn-scrap.is-on .jn-handle { opacity: 1; pointer-events: auto; }
.jn-rot { left: 50%; top: -20px; transform: translateX(-50%); cursor: grab; }
.jn-scale { right: -8px; bottom: -8px; cursor: nwse-resize; }
.jn-remove { left: -8px; top: -8px; }

.jn-dock {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: min(980px, 100%);
  padding: 8px;
  background: var(--glass);
  border: 1px solid var(--hairline);
  border-radius: 28px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.jn-tools { display: flex; gap: 6px; }
.jn-image-edit {
  flex: 1 1 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 14px;
}
.jn-image-edit[hidden] { display: none !important; }
.jn-slider {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.jn-slider input[type="range"] {
  width: 112px;
  accent-color: #f3ead8;
}
.jn-tool.on {
  color: #14121a;
  background: rgba(255,255,255,.92);
  border-color: transparent;
}
.jn-hint {
  margin: 0;
  flex: 1 1 180px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-3);
}
.jn-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.jn-reflect {
  position: absolute;
  right: 0;
  bottom: 64px;
  width: min(340px, calc(100% - 8px));
  padding: 16px;
  background: var(--glass);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow-tip);
  z-index: 6;
}
.jn-reflect[hidden] { display: none !important; }
.jn-reflect p { margin: 0 0 10px; font-family: var(--serif); font-size: 14.5px; line-height: 1.45; color: var(--ink-2); }
.jn-reflect .jn-kicker { color: var(--ink-3); }
.jn-reflect textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  margin-bottom: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--hairline);
  background: var(--glass-2);
  color: var(--ink);
  font: 15px/1.4 var(--serif);
  outline: none;
}
.jn-reflect-acts { display: flex; gap: 8px; justify-content: flex-end; }

@media (max-width: 900px) {
  #journal-root { inset: 0; }
  .jn-bar { margin: 10px 10px 0; }
  .jn-main { padding: 12px 12px 148px; }
  .jn-main.book-open { padding-bottom: 148px; }
  .jn-book { grid-template-columns: minmax(0, 1fr); width: 100%; }
  .jn-book::before,
  .jn-page.left { display: none; }
  .jn-page.right { border-radius: 10px; }
  .jn-leaf.fwd,
  .jn-leaf.rev { left: 0; width: 100%; }
  .jn-leaf.fwd { transform-origin: left center; }
  .jn-leaf.rev { transform-origin: right center; }
  .jn-plate img { max-height: 136px; }
  .jn-body { padding-bottom: 42px; }
  .jn-hint { flex: 1 1 100%; }
  .jn-reflect { right: 8px; left: 8px; width: auto; bottom: 168px; }
  .jn-edge { width: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  .jn-leaf.fwd.go,
  .jn-leaf.rev.go,
  .jn-leaf.go .jn-face::after { animation: none; }
}
