:root {
  --parchment-light: #efdcb0;
  --parchment-mid: #e3cb95;
  --parchment-dark: #c9a86a;
  --ink-presence: rgba(24, 16, 10, 0.88);
  --ink-user: rgba(28, 24, 66, 0.82);
  --ink-flash: rgba(24, 16, 10, 0.28);
  --rule-line: rgba(120, 92, 52, 0.22);
  --line-height: 2.6rem;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "EB Garamond", Georgia, serif;
  background: #7a5a33;
  min-height: 100vh;
  /* Stop iOS from bouncing the whole document while writing. */
  overscroll-behavior: none;
}

.book {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 0;
}

/* The page itself: full-bleed parchment with faint ruled lines, no visible
   input chrome anywhere. Everything written lands directly on it. */
.page {
  position: relative;
  width: 100%;
  max-width: 820px;
  min-height: 100vh;
  padding: 7vh 8vw calc(7vh + env(safe-area-inset-bottom)) 8vw;
  background-color: var(--parchment-mid);
  background-image:
    /* ruled lines */
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(var(--line-height) - 1px),
      var(--rule-line) calc(var(--line-height) - 1px),
      var(--rule-line) var(--line-height)
    ),
    /* aged blotching */
    radial-gradient(ellipse at 22% 18%, rgba(255, 246, 214, 0.55), transparent 55%),
    radial-gradient(ellipse at 78% 72%, rgba(150, 112, 60, 0.28), transparent 60%),
    linear-gradient(160deg, var(--parchment-light), var(--parchment-dark));
  background-attachment: local, scroll, scroll, scroll;
  box-shadow:
    inset 0 0 160px rgba(90, 62, 26, 0.35),
    0 0 60px rgba(0, 0, 0, 0.45);
  cursor: text;
}

.transcript {
  display: block;
}

/* Every written line, yours and its, sits in the same column and on the same
   ruled baseline, so the exchange reads as one continuous handwritten page. */
.line {
  /* Caveat comes from Google Fonts; if that request fails, fall back to a
     real handwriting face rather than a serif. Snell Roundhand and Bradley
     Hand ship with iPadOS/macOS, Segoe Script with Windows. */
  font-family: "Caveat", "Snell Roundhand", "Bradley Hand", "Segoe Script", cursive;
  font-size: 1.85rem;
  line-height: var(--line-height);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.line.presence {
  color: var(--ink-presence);
}

.line.user {
  color: var(--ink-user);
}

/* A failed request, not a reply from the presence - must never be
   mistakable for one. Same treatment as .system (serif, small, italic)
   plus a rust warning tone, so a glance is enough to tell them apart. */
.line.flash {
  color: var(--ink-error, #8a3324);
  font-family: "EB Garamond", Georgia, serif;
  font-size: 1rem;
  font-style: italic;
}

.line.system {
  color: rgba(90, 62, 26, 0.65);
  font-family: "EB Garamond", Georgia, serif;
  font-size: 1rem;
  font-style: italic;
}

/* Marks where one visit ends and the next begins: a torn edge across the
   page, not just a ruled line, so returning after time away reads as a new
   page, not a continued one. */
.session-break {
  height: 22px;
  margin: calc(var(--line-height) / 2) 0;
  background-image:
    linear-gradient(135deg, var(--ink-presence) 25%, transparent 25%),
    linear-gradient(225deg, var(--ink-presence) 25%, transparent 25%);
  background-position: 0 0, 9px 0;
  background-size: 18px 22px;
  background-repeat: repeat-x;
  opacity: 0.85;
}

/* The live writing line. No border, no background, no box: just a caret
   sitting on the page where you left off. Apple Pencil writes straight into
   this via Scribble on iPad. */
.entry {
  outline: none;
  border: none;
  background: none;
  min-height: var(--line-height);
  caret-color: var(--ink-user);
  -webkit-user-modify: read-write-plaintext-only;
}

.entry.thinking {
  opacity: 0.45;
}

.hint {
  font-family: "EB Garamond", Georgia, serif;
  font-size: 0.85rem;
  color: rgba(90, 62, 26, 0.5);
  margin: var(--line-height) 0 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

.hint.gone {
  opacity: 0;
}


.data-display {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-family: "EB Garamond", Georgia, serif;
  font-size: 0.9rem;
  color: rgba(90, 62, 26, 0.5);
  text-align: center;
  user-select: none;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
}

dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  max-width: 440px;
  width: 90%;
  color: #2a1d10;
  background: var(--parchment-light);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

#intro-form {
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-family: "EB Garamond", Georgia, serif;
}

#intro-form h2 {
  margin: 0;
  font-weight: normal;
}

#intro-form p {
  margin: 0;
  line-height: 1.5;
}

/* The one thing every visitor needs before writing: what this is, plainly,
   without the legal/safety register competing for the same attention. */
.intro-lede {
  font-size: 1.05rem;
}

/* Privacy detail and the account code are real but secondary on a first
   visit - collapsed so the picker and the "open" button are what a new
   visitor actually has to look at. */
.intro-fineprint {
  font-size: 0.88rem;
  color: rgba(42, 29, 16, 0.75);
}

.intro-fineprint summary {
  cursor: pointer;
  padding: 2px 0;
}

.intro-fineprint p {
  margin: 8px 0 0;
  line-height: 1.45;
}

.intro-fineprint .engine-picker {
  margin-top: 10px;
}

/* Present but quiet: a safety net, not the dominant note in the room. */
.intro-safety {
  font-size: 0.85rem;
  color: rgba(42, 29, 16, 0.65);
  line-height: 1.45;
}

.engine-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.95rem;
}

.engine-picker[hidden] {
  display: none;
}

.engine-picker select,
.engine-picker input {
  font-family: "EB Garamond", Georgia, serif;
  font-size: 1rem;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(90, 62, 26, 0.35);
  background: var(--parchment-mid);
  color: #2a1d10;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
}

#intro-accept {
  font-family: "EB Garamond", Georgia, serif;
  font-size: 1rem;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  background: #2a1d10;
  color: var(--parchment-light);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

#intro-accept:hover {
  background: #3a2a18;
}

#intro-accept:active {
  transform: scale(0.97);
}

@media (max-width: 600px) {
  :root {
    --line-height: 2.3rem;
  }
  .line {
    font-size: 1.6rem;
  }
  .page {
    padding: 5vh 7vw calc(5vh + env(safe-area-inset-bottom)) 7vw;
  }
}

.account-btn {
  margin-left: 10px;
  font-family: "EB Garamond", Georgia, serif;
  font-size: 0.85rem;
  min-height: 32px;
  background: none;
  border: 1px solid rgba(90, 62, 26, 0.3);
  color: rgba(90, 62, 26, 0.7);
  padding: 2px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.account-btn:hover {
  background: rgba(90, 62, 26, 0.12);
}

.account-form {
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-family: "EB Garamond", Georgia, serif;
}

.account-form h2 {
  margin: 0;
  font-weight: normal;
}

.account-note {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.45;
  color: rgba(42, 29, 16, 0.8);
}

.account-note[hidden] {
  display: none;
}

.account-status {
  font-size: 0.95rem;
  line-height: 1.6;
}

.account-status:empty {
  display: none;
}

.account-section {
  border-top: 1px solid rgba(90, 62, 26, 0.2);
  padding-top: 12px;
}

.account-section h3 {
  margin: 0 0 8px;
  font-weight: normal;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(90, 62, 26, 0.65);
}

.account-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.account-actions .wide {
  grid-column: 1 / -1;
}

.account-actions button,
.dialog-close {
  font-family: "EB Garamond", Georgia, serif;
  font-size: 0.95rem;
  min-height: 44px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid rgba(90, 62, 26, 0.35);
  background: var(--parchment-mid);
  color: #2a1d10;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.account-actions button:hover,
.dialog-close:hover {
  background: var(--parchment-dark);
}

.account-actions button:active,
.dialog-close:active {
  transform: scale(0.97);
}

.account-actions button:focus-visible,
.dialog-close:focus-visible,
#intro-accept:focus-visible {
  outline: 2px solid #2a1d10;
  outline-offset: 2px;
}

.account-actions button.primary {
  background: #2a1d10;
  color: var(--parchment-light);
  border-color: #2a1d10;
  font-weight: 600;
}

/* A button that costs money says so, before the click, not after. */
.account-actions button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.2;
}

.btn-price {
  font-size: 0.78rem;
  opacity: 0.7;
}

.account-actions button.primary:hover {
  background: #3a2a18;
}

.account-actions button:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.dialog-close {
  background: #2a1d10;
  color: var(--parchment-light);
  border: none;
}
