:root {
  --ink: #17202a;
  --ink-soft: #3d4a57;
  --paper: #e8eef2;
  --panel: rgba(248, 251, 253, 0.92);
  --line: #b7c4ce;
  --accent: #0f5c66;
  --accent-deep: #0a3f46;
  --danger: #8b2e2e;
  --shadow: 0 18px 50px rgba(23, 32, 42, 0.18);
  --radius: 14px;
  --font-display: "Syne", sans-serif;
  --font-body: "Literata", "Times New Roman", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--ink);
  font-family: var(--font-body);
  background: var(--paper);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 0;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  position: relative;
  overflow: hidden;
}

.login-atmosphere {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 15% 20%, rgba(15, 92, 102, 0.28), transparent 55%),
    radial-gradient(ellipse 70% 50% at 85% 75%, rgba(23, 32, 42, 0.22), transparent 50%),
    linear-gradient(145deg, #d5e0e7 0%, #c5d3dc 45%, #aebfcb 100%);
  animation: drift 18s ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: scale(1) translate(0, 0); }
  to { transform: scale(1.05) translate(-1.5%, 1%); }
}

.login-panel {
  position: relative;
  width: min(420px, 100%);
  padding: 2.5rem 2.25rem;
  background: var(--panel);
  border: 1px solid rgba(183, 196, 206, 0.8);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: rise 0.7s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-panel .brand {
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.login-panel h1 {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 4vw, 2.3rem);
  font-weight: 700;
  margin: 0 0 0.5rem;
  line-height: 1.1;
}

.lede {
  margin: 0 0 1.75rem;
  color: var(--ink-soft);
  line-height: 1.5;
}

.login-form {
  display: grid;
  gap: 1rem;
}

.login-form label {
  display: grid;
  gap: 0.35rem;
}

.login-form label span,
.field span,
.ctrl span {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.login-form input,
.ctrl select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  background: #fff;
}

.login-form button,
.primary {
  border: 0;
  border-radius: 999px;
  padding: 0.8rem 1.2rem;
  background: var(--accent);
  color: #f4fafb;
  font-family: var(--font-display);
  font-weight: 600;
}

.login-form button:hover,
.primary:hover {
  background: var(--accent-deep);
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.95rem;
}

/* App shell */
.app-page {
  min-height: 100vh;
  height: 100vh;
  display: grid;
  grid-template-rows: 1fr;
  background:
    linear-gradient(180deg, rgba(15, 92, 102, 0.08), transparent 28%),
    linear-gradient(135deg, #d9e3ea, #eef3f6 55%, #d4dde4);
  overflow: hidden;
}

.ctrl {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.ctrl select {
  width: 100%;
  min-width: 0;
  padding: 0.45rem 0.6rem;
}

.ctrl-group {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.ghost {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
}

.ghost.tiny {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
}

.ghost:hover {
  border-color: var(--accent);
  color: var(--accent-deep);
}

.ghost[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent-deep);
  background: rgba(15, 92, 102, 0.1);
}

.pos {
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 4.5rem;
  text-align: center;
  color: var(--ink-soft);
}

.workspace {
  position: relative;
  display: grid;
  grid-template-columns: minmax(220px, 240px) minmax(280px, 1fr) minmax(280px, 1fr);
  grid-template-areas: "rail proof scan";
  gap: 0;
  min-height: 0;
  height: 100vh;
}

.workspace.no-scan {
  grid-template-columns: minmax(220px, 240px) minmax(280px, 1fr);
  grid-template-areas: "rail proof";
}

.workspace.rail-collapsed {
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  grid-template-areas: "proof scan";
}

.workspace.rail-collapsed.no-scan {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "proof";
}

.side-rail {
  grid-area: rail;
}

.proof-pane {
  grid-area: proof;
  min-width: 0;
}

.scan-pane {
  grid-area: scan;
  min-width: 0;
}

.side-rail,
.proof-pane,
.scan-pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  border-right: 1px solid rgba(183, 196, 206, 0.75);
  background: rgba(248, 251, 253, 0.55);
}

.side-rail {
  position: relative;
  z-index: 40;
  gap: 0.85rem;
  overflow: auto;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease;
}

.workspace.rail-collapsed .side-rail {
  /* Must not keep grid-area:rail (area missing when collapsed → blank main column) */
  grid-area: proof;
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: min(240px, 84vw);
  transform: translateX(-105%);
  opacity: 0;
  pointer-events: none;
  border-right: 1px solid rgba(183, 196, 206, 0.75);
  box-shadow: 12px 0 28px rgba(20, 28, 36, 0.18);
  background: rgba(248, 251, 253, 0.97);
}

.workspace.rail-collapsed.rail-hover .side-rail {
  transform: none;
  opacity: 1;
  pointer-events: auto;
}

.rail-peek {
  display: none;
  grid-area: proof;
  justify-self: start;
  align-self: center;
  position: absolute;
  left: 0;
  top: 50%;
  z-index: 45;
  transform: translateY(-50%);
  width: 1.35rem;
  height: 3.4rem;
  padding: 0;
  border: 1px solid rgba(183, 196, 206, 0.9);
  border-left: 0;
  border-radius: 0 10px 10px 0;
  background: rgba(248, 251, 253, 0.95);
  cursor: pointer;
  box-shadow: 4px 0 14px rgba(20, 28, 36, 0.12);
}

.workspace.rail-collapsed .rail-peek {
  display: grid;
  place-items: center;
}

.rail-peek-bars,
.rail-peek-bars::before,
.rail-peek-bars::after {
  display: block;
  width: 0.7rem;
  height: 2px;
  border-radius: 2px;
  background: #3d4a57;
}

.rail-peek-bars {
  position: relative;
}

.rail-peek-bars::before,
.rail-peek-bars::after {
  content: "";
  position: absolute;
  left: 0;
}

.rail-peek-bars::before { top: -5px; }
.rail-peek-bars::after { top: 5px; }

.rail-brand {
  display: grid;
  gap: 0.15rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid rgba(183, 196, 206, 0.65);
}

.rail-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-deep);
  line-height: 1.25;
}

.rail-user {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.rail-section {
  display: grid;
  gap: 0.55rem;
}

.rail-views,
.rail-tools {
  gap: 0.4rem;
}

.rail-btn {
  width: 100%;
  text-align: center;
  border-radius: 10px;
}

.rail-footer {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(183, 196, 206, 0.65);
}

.save-fab {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 60;
  min-width: 6.5rem;
  padding: 0.7rem 1.25rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent-deep, #0f5c66);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: 0 10px 28px rgba(15, 92, 102, 0.35);
  cursor: pointer;
}

.save-fab[hidden] {
  display: none !important;
}

.save-fab:hover {
  filter: brightness(1.08);
}

.workspace.no-scan .proof-pane {
  border-right: 0;
}

.scan-pane {
  border-right: 0;
}

.scan-pane[hidden] {
  display: none !important;
}

.pane-head-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  white-space: nowrap;
}

.badge-muted {
  color: var(--ink-soft);
  background: rgba(61, 74, 87, 0.08);
}

.pane-head,
.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.pane-head h2,
.rail-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
}

.meta,
.rail-meta,
.status {
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.date-pickers {
  display: grid;
  gap: 0.85rem;
}

.date-row {
  display: grid;
  gap: 0.3rem;
}

.date-row-label {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.date-stepper {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.35rem;
  align-items: center;
}

.date-stepper select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.55rem;
  background: #fff;
  min-width: 0;
}

.ghost.step {
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  font-size: 1.1rem;
  line-height: 1;
}

.rail-pos {
  margin: 1rem 0 0.35rem;
  text-align: left;
  min-width: 0;
}

.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.field-entry {
  flex: 1 1 auto;
  min-height: 0;
  margin-bottom: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-entry textarea {
  flex: 1 1 auto;
  min-height: 12rem;
  height: auto;
  resize: none;
  line-height: 1.55;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  background: #fff;
}

.page-sheet {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.page-sheet[hidden],
.workspace.book-mode .page-sheet {
  display: none !important;
}

.page-date {
  display: none;
  margin: 0;
}

.font-ctrl {
  min-width: 9rem;
}

.font-ctrl select {
  min-width: 9rem;
  padding: 0.45rem 0.6rem;
}

/* Diary page presentation */
.proof-pane.diary-view {
  background:
    radial-gradient(ellipse at 20% 0%, rgba(15, 92, 102, 0.06), transparent 50%),
    rgba(232, 238, 242, 0.9);
}

.proof-pane.diary-view .page-sheet {
  --page-rule: 1.75rem;
  margin: 0.25rem auto 0.75rem;
  width: min(100%, 42rem);
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--page-rule) 1.85rem calc(var(--page-rule) * 1.2);
  border-radius: 2px;
  background:
    linear-gradient(90deg, rgba(180, 80, 70, 0.18) 0 1px, transparent 1px),
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(var(--page-rule) - 1px),
      rgba(90, 130, 160, 0.22) calc(var(--page-rule) - 1px),
      rgba(90, 130, 160, 0.22) var(--page-rule)
    ),
    linear-gradient(165deg, #f7f1e4 0%, #efe6d4 55%, #e8dcc8 100%);
  background-attachment: local, local, scroll;
  /* Nudge rules so baselines sit on the ink lines for page fonts */
  background-position: 0 0, 0 0.55em, 0 0;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.65) inset,
    0 18px 40px rgba(23, 32, 42, 0.18),
    0 2px 6px rgba(23, 32, 42, 0.12);
  border: 1px solid rgba(150, 130, 100, 0.35);
  overflow: auto;
}

.proof-pane.diary-view .page-date {
  display: block;
  margin: 0 0 0 1.1rem;
  height: var(--page-rule);
  font-family: var(--page-font, "Caveat", cursive);
  font-size: calc(var(--page-rule) * 0.92);
  font-weight: 600;
  color: #2a3340;
  line-height: var(--page-rule);
}

.proof-pane.diary-view #entry-label {
  display: none;
}

.proof-pane.diary-view .field-entry {
  margin: 0;
  flex: 1 1 auto;
  min-height: 14rem;
}

.proof-pane.diary-view .field-entry textarea {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  padding: 0 0 0 1.1rem;
  min-height: 14rem;
  font-family: var(--page-font, "Caveat", cursive);
  font-size: calc(var(--page-rule) * 0.82);
  line-height: var(--page-rule);
  color: #1c2430;
  caret-color: #0f5c66;
}

.proof-pane.diary-view .field-entry textarea:focus {
  outline: none;
}

/* Book view */
.workspace.book-mode:not(.rail-collapsed) {
  grid-template-columns: minmax(220px, 240px) minmax(0, 1fr);
  grid-template-areas: "rail proof";
}

.workspace.book-mode.rail-collapsed,
.workspace.book-mode.rail-collapsed.no-scan {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "proof";
}

.workspace.book-mode .scan-pane {
  display: none !important;
}

.workspace.book-mode .side-rail {
  background: rgba(32, 38, 46, 0.96);
  border-right: 1px solid rgba(215, 221, 228, 0.12);
  color: #e8eef4;
}

.workspace.book-mode .rail-title {
  color: #e8eef4;
}

.workspace.book-mode .rail-user,
.workspace.book-mode .date-row-label,
.workspace.book-mode .rail-meta,
.workspace.book-mode .rail-pos,
.workspace.book-mode .rail-brand,
.workspace.book-mode .rail-footer,
.workspace.book-mode .rail-dates .rail-head h2 {
  color: rgba(232, 238, 244, 0.85);
  border-color: rgba(215, 221, 228, 0.18);
}

.workspace.book-mode .side-rail select,
.workspace.book-mode .side-rail .step,
.workspace.book-mode .side-rail .ghost {
  color: #e8eef4;
  background: rgba(248, 251, 253, 0.08);
  border-color: rgba(215, 221, 228, 0.25);
}

.workspace.book-mode .side-rail .ghost[aria-pressed="true"] {
  background: rgba(248, 251, 253, 0.18);
  border-color: rgba(215, 221, 228, 0.45);
}

.workspace.book-mode .proof-pane {
  border-right: 0;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(40, 28, 18, 0.35), transparent 55%),
    linear-gradient(160deg, #2a3038 0%, #1a1f26 55%, #12161c 100%);
}

.workspace.book-mode #proof-head .meta,
.workspace.book-mode #no-scan-badge {
  display: none;
}

.workspace.book-mode #proof-title {
  color: #d7dde4;
}

.workspace.book-mode .rail-peek {
  background: rgba(32, 38, 46, 0.95);
  border-color: rgba(215, 221, 228, 0.25);
}

.workspace.book-mode .rail-peek-bars,
.workspace.book-mode .rail-peek-bars::before,
.workspace.book-mode .rail-peek-bars::after {
  background: #d7dde4;
}

.book-stage {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 0.75rem 0.5rem;
  align-items: center;
  padding: 0.5rem 0 0;
}

.book-stage[hidden] {
  display: none !important;
}

.book-nav {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 999px;
  border: 1px solid rgba(215, 221, 228, 0.35);
  background: rgba(248, 251, 253, 0.12);
  color: #eef3f7;
  font-size: 1.4rem;
  font-family: var(--font-display);
  cursor: pointer;
  z-index: 5;
}

.book-nav:hover {
  background: rgba(248, 251, 253, 0.22);
}

.book-pos {
  grid-column: 1 / -1;
  margin: 0;
  text-align: center;
  color: rgba(215, 221, 228, 0.75);
  font-family: var(--font-display);
  font-size: 0.8rem;
}

.book-carousel {
  position: relative;
  width: 100%;
  min-width: 0;
  height: 100%;
  min-height: 0;
  align-self: stretch;
}

.book-carousel-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 220px;
  overflow: hidden;
  perspective: 1400px;
  touch-action: none;
  cursor: grab;
  user-select: none;
}

.book-carousel-viewport.is-grabbing {
  cursor: grabbing;
}

.book-carousel-track {
  position: absolute;
  inset: 0 auto 0 0;
  display: flex;
  align-items: center;
  height: 100%;
  will-change: transform;
  transform-style: preserve-3d;
  transition: transform 0.62s cubic-bezier(0.22, 1, 0.36, 1);
}

.book-carousel-track.is-dragging {
  transition: none;
}

.book-slot {
  position: relative;
  flex: 0 0 auto;
  width: min(72vw, 860px);
  max-width: 860px;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 0 0.35rem;
  box-sizing: border-box;
  transform-origin: center center;
  transition:
    transform 0.62s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.45s ease,
    filter 0.45s ease;
  transform-style: preserve-3d;
}

.book-carousel-track.is-dragging .book-slot {
  transition: none;
}

.book-slot.is-active {
  z-index: 4;
}

.book-slot:not(.is-active) {
  cursor: pointer;
}

.book-slot-cover {
  /* Closed book ≈ half an open spread */
  width: min(46%, 400px);
  aspect-ratio: 0.775 / 1;
  max-height: calc(100vh - 170px);
  border-radius: 2px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow:
    inset 8px 0 16px rgba(0, 0, 0, 0.25),
    inset -2px 0 0 rgba(255, 255, 255, 0.08),
    0 18px 40px rgba(0, 0, 0, 0.35);
  user-select: none;
  pointer-events: none;
}

.book-slot-cover-year {
  margin: 0;
  font-family: "Syne", sans-serif;
  font-weight: 700;
  font-size: clamp(1.8rem, 5vw, 3.4rem);
  letter-spacing: 0.08em;
  color: rgba(255, 248, 235, 0.92);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.book-slot.is-active .book-slot-cover {
  display: none;
}

.book-slot:not(.is-active) .book {
  display: none !important;
}

.book {
  --page-rule: 1.65rem;
  position: relative;
  width: 100%;
  margin: 0 auto;
  aspect-ratio: 1.55 / 1;
  max-height: calc(100vh - 170px);
  perspective: 1600px;
  transition:
    width 0.45s cubic-bezier(0.22, 1, 0.36, 1),
    max-width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Closed covers are a single leaf wide (half the open spread) */
.book.is-cover,
.book.is-rear {
  width: min(46%, 400px);
  max-width: 400px;
  aspect-ratio: 0.775 / 1;
}

.book-stack {
  position: absolute;
  top: 3%;
  bottom: 3%;
  width: 48%;
  border-radius: 2px;
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.book-stack.is-visible {
  opacity: 1;
}

.book-stack-left {
  left: 2%;
  transform-origin: right center;
  background: linear-gradient(90deg, #ebe2d2, #f4eee3);
}

.book-stack-right {
  right: 2%;
  transform-origin: left center;
  background: linear-gradient(270deg, #ebe2d2, #f4eee3);
}

.book.is-cover .book-stack,
.book.is-rear .book-stack {
  opacity: 0 !important;
  box-shadow: none !important;
  transform: none !important;
}

.book-cover {
  position: absolute;
  inset: 2.5% 3%;
  z-index: 3;
  display: grid;
  place-items: center;
  border-radius: 2px;
  background: var(--book-cover, #3d4a3a);
  box-shadow:
    inset 8px 0 16px rgba(0, 0, 0, 0.25),
    inset -2px 0 0 rgba(255, 255, 255, 0.08),
    0 18px 40px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(0, 0, 0, 0.35);
}

.book-cover-rear {
  place-items: end center;
  padding: 0 1rem 8%;
}

.book-cover[hidden] {
  display: none !important;
}

.book-cover-year {
  margin: 0;
  font-family: "Syne", sans-serif;
  font-weight: 700;
  font-size: clamp(2.2rem, 7vw, 3.8rem);
  letter-spacing: 0.08em;
  color: rgba(255, 248, 235, 0.92);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.book-cover-year-rear {
  font-size: clamp(0.9rem, 2vw, 1.15rem);
  font-weight: 600;
  letter-spacing: 0.14em;
  color: rgba(255, 248, 235, 0.78);
  text-shadow: none;
}

.book-spread {
  position: absolute;
  inset: 3% 2%;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr 14px 1fr;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.book-spread[hidden] {
  display: none !important;
}

.book-spread.front-only .book-leaf-left {
  background:
    linear-gradient(135deg, #d9d0c0, #cfc5b4);
}

.book-spread.front-only .book-leaf-left .book-leaf-date,
.book-spread.front-only .book-leaf-left .book-leaf-body {
  visibility: hidden;
}

.book-gutter {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0.05) 40%, rgba(0, 0, 0, 0.05) 60%, rgba(0, 0, 0, 0.18));
}

.book-leaf {
  --page-rule: 1.65rem;
  min-width: 0;
  padding: 0 1.15rem var(--page-rule);
  overflow: auto;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(var(--page-rule) - 1px),
      rgba(90, 130, 160, 0.2) calc(var(--page-rule) - 1px),
      rgba(90, 130, 160, 0.2) var(--page-rule)
    ),
    linear-gradient(165deg, #f8f2e6 0%, #efe6d4 100%);
  /* Align rule bottoms with text baselines (handwriting fonts) */
  background-position: 0 0.52em, 0 0;
  background-attachment: local, scroll;
}

.book-leaf-left {
  box-shadow: inset -10px 0 18px rgba(80, 60, 30, 0.08);
}

.book-leaf-right {
  box-shadow: inset 10px 0 18px rgba(80, 60, 30, 0.08);
}

.book-leaf-date {
  margin: 0;
  padding: 0;
  height: var(--page-rule);
  font-family: var(--page-font, Literata, serif);
  font-size: calc(var(--page-rule) * 0.88);
  font-weight: 600;
  line-height: var(--page-rule);
  color: #2a3340;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-leaf-body {
  margin: 0;
  padding: 0;
  white-space: pre-wrap;
  font-family: var(--page-font, Literata, serif);
  font-size: calc(var(--page-rule) * 0.78);
  line-height: var(--page-rule);
  color: #1c2430;
}

.proof-pane.diary-view .page-date,
.proof-pane.diary-view .field-entry textarea {
  font-family: var(--page-font, Caveat, cursive);
}

.scan-stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    repeating-linear-gradient(
      45deg,
      #ced8e0,
      #ced8e0 8px,
      #d7e0e7 8px,
      #d7e0e7 16px
    );
  display: grid;
  place-items: center;
}

.scan-stage img {
  max-width: 100%;
  transform-origin: top center;
  transition: transform 0.2s ease;
  box-shadow: 0 10px 30px rgba(23, 32, 42, 0.25);
}

.scan-empty {
  margin: 0;
  padding: 2rem;
  text-align: center;
  color: var(--ink-soft);
  max-width: 18rem;
}

.scan-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 0.75rem;
}

.scan-tools label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.status.dirty {
  color: #8a5a12;
}

.status.ok {
  color: var(--accent-deep);
}

.status.err {
  color: var(--danger);
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: minmax(200px, 220px) 1fr;
    grid-template-areas:
      "rail proof"
      "scan scan";
    grid-template-rows: 1fr 50vh;
    height: auto;
  }

  .workspace.no-scan {
    grid-template-columns: minmax(200px, 220px) 1fr;
    grid-template-areas: "rail proof";
    grid-template-rows: 1fr;
  }

  .workspace.rail-collapsed {
    grid-template-columns: 1fr;
    grid-template-areas:
      "proof"
      "scan";
  }

  .workspace.rail-collapsed.no-scan {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "proof";
    grid-template-rows: 1fr;
  }

  .scan-pane {
    min-height: 50vh;
  }
}

@media (max-width: 720px) {
  .workspace,
  .workspace.no-scan,
  .workspace.rail-collapsed,
  .workspace.rail-collapsed.no-scan {
    grid-template-columns: 1fr;
    grid-template-areas:
      "rail"
      "proof"
      "scan";
    height: auto;
  }

  .workspace.rail-collapsed .side-rail {
    position: relative;
    transform: none;
    opacity: 1;
    pointer-events: auto;
    width: auto;
    box-shadow: none;
    grid-area: rail;
  }

  .rail-peek {
    display: none !important;
  }

  .field-entry textarea {
    min-height: 16rem;
  }

  .save-fab {
    bottom: 0.85rem;
    right: 0.85rem;
  }
}

a.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: inherit;
}

a.ghost.rail-btn {
  width: 100%;
  box-sizing: border-box;
}
