/* The desk, the book, and the ink.
   The page is a stack: parchment colour, a noise layer for grain, and a shadow
   near the spine so the paper looks like it is bending into the binding. */

:root {
  --ink: #1b2440;
  --ink-soft: rgba(27, 36, 64, 0.62);
  --ink-faint: rgba(27, 36, 64, 0.3);
  --ink-voice: #14100c;
  --parchment: #e7dcc0;
  --parchment-deep: #cdbc95;
  --leather: #2a1a12;
  --dark: #120d0a;
  --gold: #c9a227;
  --page-w: min(44vw, 540px);
  --page-h: min(76vh, 740px);
  --hand: "Caveat", "Segoe Script", cursive;
  --hand-voice: "Petit Formal Script", "Snell Roundhand", cursive;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(120% 90% at 50% 6%, #33231a 0%, var(--dark) 52%, #050303 100%);
  color: var(--parchment);
  font-family: "Cormorant Garamond", Georgia, serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  padding: 1.5rem 1rem;
  overflow: hidden;
}

/* Candlelight. A soft warm pool that breathes, plus a vignette over everything. */
.candle {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  background:
    radial-gradient(60% 45% at 50% 34%, rgba(255, 196, 110, 0.16) 0%, rgba(255, 170, 80, 0.05) 45%, rgba(0,0,0,0) 70%),
    radial-gradient(110% 100% at 50% 50%, rgba(0,0,0,0) 45%, rgba(0,0,0,0.55) 100%);
  animation: flicker 5.5s ease-in-out infinite;
  mix-blend-mode: screen;
}

@keyframes flicker {
  0%, 100% { opacity: 0.85; }
  22%      { opacity: 1; }
  38%      { opacity: 0.72; }
  57%      { opacity: 0.96; }
  74%      { opacity: 0.8; }
}

.desk { display: flex; flex-direction: column; align-items: center; gap: 1.1rem; }

/* The book itself. It sits shut until the page is opened, and the cover lifts away. */
.diary {
  position: relative;
  display: flex;
  border-radius: 8px;
  background:
    linear-gradient(180deg, #3a2418 0%, #24150e 60%, #1a0f0a 100%);
  padding: 16px;
  box-shadow:
    0 45px 110px rgba(0, 0, 0, 0.8),
    inset 0 0 0 1px rgba(201, 162, 39, 0.12);
  transform-origin: center;
  transition: transform 900ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.diary.is-shut { transform: scale(0.96) rotateX(6deg); }

.spine {
  position: absolute;
  left: 50%;
  top: 10px;
  bottom: 10px;
  width: 34px;
  transform: translateX(-50%);
  background:
    linear-gradient(90deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.5) 42%, rgba(0,0,0,0.62) 50%, rgba(0,0,0,0.5) 58%, rgba(0,0,0,0) 100%);
  pointer-events: none;
  z-index: 4;
}

.page {
  position: relative;
  width: var(--page-w);
  height: var(--page-h);
  padding: 2rem 2.1rem 1.6rem;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(120, 92, 48, 0.16) 0%, rgba(120, 92, 48, 0) 12%),
    linear-gradient(0deg,  rgba(120, 92, 48, 0.16) 0%, rgba(120, 92, 48, 0) 12%),
    var(--parchment);
  isolation: isolate;
}

/* Paper grain, drawn with an SVG turbulence filter so there are no image files. */
.page::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.5;
  mix-blend-mode: multiply;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)' opacity='0.34'/%3E%3C/svg%3E");
}

.page > * { position: relative; z-index: 1; }

.page--left {
  border-radius: 5px 0 0 5px;
  box-shadow: inset -26px 0 34px -22px rgba(60, 40, 20, 0.75);
}

.page--right {
  border-radius: 0 5px 5px 0;
  box-shadow: inset 26px 0 34px -22px rgba(60, 40, 20, 0.75);
}

/* Left page furniture */
.plate { text-align: center; }

.title {
  font-size: clamp(1.6rem, 2.4vw, 2.4rem);
  font-weight: 600;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  margin: 0;
  text-indent: 0.34em;
  color: var(--ink-voice);
}

.subtitle {
  margin: 0.35rem 0 0;
  font-style: italic;
  font-size: 0.95rem;
  opacity: 0.62;
}

.plate::after {
  content: "";
  display: block;
  width: 46%;
  height: 1px;
  margin: 0.9rem auto 0;
  background: linear-gradient(90deg, transparent, var(--ink-faint), transparent);
}

.plate--foot::after { display: none; }

.memories {
  flex: 1;
  overflow-y: auto;
  margin: 1.2rem -0.4rem 1rem;
  padding: 0 0.4rem;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-faint) transparent;
}

.memories__empty { font-style: italic; opacity: 0.45; }

.memory {
  margin: 0 0 0.85rem;
  line-height: 1.45;
  animation: bleed 1.4s ease both;
}

.memory--you {
  font-family: var(--hand);
  font-size: 1.18rem;
  color: var(--ink-soft);
}

.memory--voice {
  font-family: var(--hand-voice);
  font-size: 1.02rem;
  color: rgba(20, 16, 12, 0.55);
  padding-left: 1.1rem;
}

@keyframes bleed {
  from { opacity: 0; filter: blur(2px); }
  to   { opacity: 1; filter: blur(0); }
}

/* The state lamp */
.lamp {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  opacity: 0.66;
}

.lamp__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-faint);
  box-shadow: 0 0 0 0 rgba(27, 36, 64, 0.4);
}

.lamp[data-state="stirring"] .lamp__dot,
.lamp[data-state="thinking"] .lamp__dot {
  background: var(--gold);
  animation: pulse 1.4s ease-in-out infinite;
}

.lamp[data-state="awake"] .lamp__dot { background: #6b2f2f; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(201, 162, 39, 0.5); }
  50%      { box-shadow: 0 0 0 7px rgba(201, 162, 39, 0); }
}

/* Right page: the living surface */
.surface {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0 1.2rem;
}

.surface__scroll {
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  scrollbar-width: none;
}

.surface__scroll::-webkit-scrollbar { display: none; }

.line {
  margin: 0 0 1.1rem;
  line-height: 1.5;
  word-break: break-word;
}

.line--you {
  font-family: var(--hand);
  font-size: 1.55rem;
  color: var(--ink);
  text-align: right;
}

.line--voice {
  font-family: var(--hand-voice);
  font-size: 1.25rem;
  color: var(--ink-voice);
  line-height: 1.85;
}

.line--note {
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: 1rem;
  opacity: 0.55;
  text-align: center;
}

/* Ink soaking into the paper. Each letter is its own span so the fade can travel. */
.glyph {
  opacity: 0;
  animation: dry 420ms ease forwards;
}

@keyframes dry {
  from { opacity: 0; filter: blur(3px); transform: translateY(1px); }
  to   { opacity: 1; filter: blur(0); transform: none; }
}

.line.is-sinking {
  animation: sink 2.6s ease forwards;
}

@keyframes sink {
  0%   { opacity: 1; filter: blur(0); }
  60%  { opacity: 0.35; filter: blur(1.2px); }
  100% { opacity: 0; filter: blur(3px); transform: translateY(-4px); }
}

/* The nib, a small blot of wet ink that follows the last written letter */
.nib {
  display: inline-block;
  width: 0.42em;
  height: 0.42em;
  margin-left: 0.08em;
  border-radius: 60% 40% 55% 45%;
  background: var(--ink-voice);
  animation: wet 900ms ease-in-out infinite;
  vertical-align: baseline;
}

@keyframes wet {
  0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.85; }
  50%      { transform: scale(1.25) rotate(12deg); opacity: 0.5; }
}

/* Writing line at the foot of the page */
.quill {
  display: flex;
  gap: 0.8rem;
  align-items: flex-end;
  border-top: 1px solid var(--ink-faint);
  padding-top: 0.9rem;
}

.quill__pen {
  flex: 1;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  caret-color: var(--ink);
  font-family: var(--hand);
  font-size: 1.5rem;
  line-height: 1.35;
  padding: 0.1rem 0;
  outline: none;
  max-height: 6.5rem;
  overflow-y: auto;
}

.quill__pen::placeholder { color: var(--ink-faint); }

.quill__ink {
  position: relative;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border: 1px solid var(--ink-faint);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transition: background 300ms ease, transform 200ms ease;
}

.quill__ink:hover:not(:disabled) { background: rgba(27, 36, 64, 0.08); transform: translateY(-1px); }
.quill__ink:disabled { opacity: 0.35; cursor: default; }

.quill__blot {
  position: absolute;
  inset: 12px;
  border-radius: 62% 38% 55% 45% / 45% 55% 42% 58%;
  background: var(--ink);
}

/* Controls under the book */
.rail { display: flex; gap: 0.7rem; align-items: center; flex-wrap: wrap; justify-content: center; }

.rail__btn {
  font-family: inherit;
  font-size: 0.92rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--parchment);
  background: rgba(231, 220, 192, 0.04);
  border: 1px solid rgba(231, 220, 192, 0.24);
  border-radius: 2px;
  padding: 0.55rem 1.15rem;
  cursor: pointer;
  transition: border-color 250ms ease, color 250ms ease, background 250ms ease;
}

.rail__btn:hover { border-color: var(--gold); color: var(--gold); }

/* Keyboard users need to see where they are. The ring uses the candle colour so that it
   belongs to the page, and it only shows for keyboard focus. */
.rail__btn:focus-visible,
.quill__ink:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.quill__pen:focus-visible {
  outline: none;
  box-shadow: 0 2px 0 -1px var(--ink);
}
.rail__btn:disabled { opacity: 0.4; cursor: default; }
.rail__btn--ghost { opacity: 0.62; font-size: 0.8rem; padding: 0.45rem 0.9rem; }

.rail__meter {
  position: relative;
  width: min(320px, 70vw);
  height: 22px;
  border: 1px solid rgba(231, 220, 192, 0.22);
  border-radius: 2px;
  overflow: hidden;
}

.rail__fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(90deg, rgba(201, 162, 39, 0.5), rgba(201, 162, 39, 0.18));
  transition: width 400ms ease;
}

.rail__label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.85;
}

.colophon {
  max-width: 64ch;
  text-align: center;
  font-size: 0.82rem;
  line-height: 1.5;
  opacity: 0.42;
  margin: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Small screens get one page at a time, and the left page becomes a short header. */
@media (max-width: 900px) {
  body { overflow-y: auto; justify-content: flex-start; }
  .diary { flex-direction: column; padding: 10px; }
  .spine { display: none; }
  .page {
    width: min(92vw, 560px);
    border-radius: 4px;
    box-shadow: none;
  }
  .page--left { height: auto; padding-bottom: 1.1rem; }
  .page--right { height: min(70vh, 620px); border-top: 1px solid rgba(120, 92, 48, 0.3); }
  .memories { max-height: 22vh; }
  .title { font-size: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  .candle { animation: none; }
  .glyph, .memory, .line.is-sinking, .nib { animation: none !important; opacity: 1; filter: none; }
}
