/* Anvi's Diary — a book you can turn the pages of.
   Everything here is self-contained: no web fonts, no CDN, nothing to expire. */

:root {
  --ink:        #3a332b;
  --ink-soft:   #8b8073;
  --accent:     #8a6a4b;
  --paper:      #f7f0e2;
  --paper-edge: #ece1cd;
  --desk:       #2e2823;
  --rule:       2.1rem;

  --font-body: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-hand: "Snell Roundhand", "Segoe Script", "Bradley Hand", "Brush Script MT", cursive;

  /* A whisper of paper grain, inline so it never 404s. */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='.035'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(ellipse at 50% 0%, #443b33 0%, var(--desk) 70%);
}

/* ---------- password gate ---------- */

body.gate { display: grid; place-items: center; }

.lock {
  width: min(23rem, 88vw);
  padding: 2.5rem 2rem;
  text-align: center;
  background: var(--paper);
  border-radius: 4px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
.lock h1 { margin: 0; font-family: var(--font-hand); font-size: 2.1rem; font-weight: 400; }
.lock .sub { margin: .25rem 0 1.75rem; color: var(--ink-soft); font-size: .9rem; font-style: italic; }
.lock input {
  width: 100%;
  padding: .7rem;
  margin-bottom: .9rem;
  text-align: center;
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--paper-edge);
}
.lock input:focus { outline: none; border-bottom-color: var(--accent); }
.lock button {
  width: 100%;
  padding: .7rem;
  font: inherit;
  color: var(--paper);
  background: var(--accent);
  border: none;
  border-radius: 3px;
  cursor: pointer;
}
.lock button:hover { background: #74583d; }
.msg { color: #a5382c; font-size: .85rem; margin: 0 0 1rem; }

/* ---------- chrome ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1.25rem 1.75rem .5rem;
}
.topbar h1 {
  margin: 0;
  font-family: var(--font-hand);
  font-size: 1.7rem;
  font-weight: 400;
  color: #e8dcc6;
}
.controls { display: flex; align-items: center; gap: 1rem; }
.controls a {
  color: #b6a68d;
  text-decoration: none;
  font-size: .85rem;
  letter-spacing: .04em;
}
.controls a:hover { color: #e8dcc6; }
#jump {
  font-family: inherit;
  font-size: .85rem;
  padding: .3rem .5rem;
  color: #e8dcc6;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 3px;
  max-width: 15rem;
}
#jump option { color: var(--ink); background: var(--paper); }

.empty {
  color: var(--ink-soft);
  text-align: center;
  margin-top: 25vh;
  font-style: italic;
}

.counter {
  text-align: center;
  color: #7d7062;
  font-size: .8rem;
  letter-spacing: .12em;
  margin: 1rem 0 2.5rem;
}

/* ---------- the book ---------- */

.stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  /* Room above and below for the turning leaf, which perspective makes taller
     than the book while it is upright. */
  padding: 2rem 1rem 2.5rem;
}

.turn {
  flex: none;
  width: 3rem;
  height: 3rem;
  font-size: 2rem;
  line-height: 1;
  color: #9a8b76;
  background: none;
  border: none;
  cursor: pointer;
  transition: color .2s, transform .2s;
}
.turn:hover:not([disabled]) { color: #efe4cd; transform: scale(1.15); }
.turn[disabled] { opacity: .2; cursor: default; }

.book {
  position: relative;
  display: flex;
  width: min(64rem, 92vw);
  height: min(38rem, 72vh);
  perspective: 3000px;
  border-radius: 3px;
  box-shadow:
    0 2px 4px rgba(0, 0, 0, .3),
    0 30px 70px rgba(0, 0, 0, .55);
}

.page {
  position: relative;
  width: 50%;
  height: 100%;
  padding: 2.75rem 2.5rem;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: var(--paper);
  background-image: var(--grain);
  scrollbar-width: thin;
  scrollbar-color: var(--paper-edge) transparent;
}
.page::-webkit-scrollbar { width: 6px; }
.page::-webkit-scrollbar-thumb { background: var(--paper-edge); border-radius: 3px; }

/* The gutter: pages curve into the middle. */
.page.left  { border-radius: 3px 0 0 3px; box-shadow: inset -18px 0 26px -22px rgba(60, 40, 15, .75); }
.page.right { border-radius: 0 3px 3px 0; box-shadow: inset  18px 0 26px -22px rgba(60, 40, 15, .75); }

.spine {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  transform: translateX(-1px);
  background: linear-gradient(to right, rgba(90, 65, 30, .28), rgba(120, 95, 55, .05), rgba(90, 65, 30, .28));
  z-index: 3;
  pointer-events: none;
}

/* ---------- page contents ---------- */

.date-head {
  margin: 0 0 .25rem;
  font-family: var(--font-hand);
  font-size: clamp(1.5rem, 3.2vw, 2.15rem);
  font-weight: 400;
  line-height: 1.25;
  color: var(--accent);
}
.age-line {
  margin: 0 0 1.75rem;
  font-size: .85rem;
  font-style: italic;
  color: var(--ink-soft);
}
.date-head + .age-line { margin-top: .35rem; }

.rule {
  width: 3.5rem;
  height: 1px;
  margin: 0 0 1.75rem;
  background: var(--paper-edge);
  border: none;
}

/* Photos, pinned to the page like prints in an album. Each card shrinks to
   its own photo, so portraits and landscapes both keep their shape. */
.photos {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 1.5rem 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.photos li {
  max-width: calc(50% - .625rem);
  padding: .55rem .55rem 1.4rem;
  background: #fffdf7;
  box-shadow: 0 2px 8px rgba(60, 45, 20, .3);
  transition: transform .25s ease, box-shadow .25s ease;
  cursor: zoom-in;
}
.photos li:only-child { max-width: 100%; }
.photos li:nth-child(3n+1) { transform: rotate(-1.6deg); }
.photos li:nth-child(3n+2) { transform: rotate(1.1deg); }
.photos li:nth-child(3n)   { transform: rotate(-.5deg); }
.photos li:hover { transform: rotate(0) scale(1.03); box-shadow: 0 8px 20px rgba(60, 45, 20, .4); z-index: 2; }

.photos img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 14rem;
  background: var(--paper-edge);
}
.photos li:only-child img { max-height: 19rem; }
.photos figcaption {
  margin-top: .6rem;
  font-family: var(--font-hand);
  font-size: .95rem;
  text-align: center;
  color: var(--ink-soft);
}

.no-photos {
  margin-top: 30%;
  text-align: center;
  font-style: italic;
  color: #c3b7a3;
  font-size: .9rem;
}

/* The written page, on ruled paper. */
.entry-text {
  font-size: 1.05rem;
  line-height: var(--rule);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  background-image: linear-gradient(to bottom, transparent calc(var(--rule) - 1px), #ded1b8 calc(var(--rule) - 1px));
  background-size: 100% var(--rule);
}

/* ---------- the turning leaf ---------- */

.leaf {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  z-index: 4;
  transform-style: preserve-3d;
  transition: transform .68s cubic-bezier(.4, .06, .3, 1);
}
.leaf.forward  { left: 50%; transform-origin: left center;  transform: rotateY(0); }
.leaf.backward { left: 0;   transform-origin: right center; transform: rotateY(0); }
.leaf.forward.go  { transform: rotateY(-180deg); }
.leaf.backward.go { transform: rotateY(180deg); }

.leaf-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  padding: 2.75rem 2.5rem;
  background-color: var(--paper);
  backface-visibility: hidden;
  box-shadow: 0 0 24px rgba(0, 0, 0, .25);
}
.leaf-face.back { transform: rotateY(180deg); }

/* ---------- lightbox ---------- */

.lightbox[hidden] { display: none; }   /* our display rule would otherwise win over [hidden] */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 3vmin;
  background: rgba(20, 16, 12, .93);
  cursor: zoom-out;
}
.lightbox img {
  /* Viewport units, not 100%: the grid track is auto-sized, so a percentage
     max-height has nothing definite to resolve against and is ignored. */
  max-width: 94vw;
  max-height: 94vh;
  padding: .7rem;
  background: #fffdf7;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}

/* ---------- one page at a time on a phone ----------
   The spread folds into a single scrolling page: date and photos first,
   then the day's writing. No leaf to turn, so the flip is skipped. */

@media (max-width: 52rem) {
  .stage { padding: .5rem; }
  .book {
    flex-direction: column;
    width: 100%;
    height: auto;
    min-height: 60vh;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
    /* The sheet is one continuous page here, so the paper lives on the book
       and the halves stay transparent — otherwise the grain tile restarts
       between them and leaves a visible seam. */
    background-color: var(--paper);
    background-image: var(--grain);
  }
  .page {
    width: 100%;
    height: auto;
    overflow: visible;
    border-radius: 0;
    box-shadow: none;
    background: none;
    padding: 1.9rem 1.4rem;
  }
  .page.left { padding-bottom: 0; }
  .page.left:empty { display: none; }
  .page.right { padding-bottom: 5.5rem; }   /* clear of the floating turn buttons */
  .spine, .leaf, .no-photos { display: none; }

  /* Turning controls move out of the way, within thumb reach. */
  .turn {
    position: fixed;
    bottom: 1.1rem;
    z-index: 5;
    width: 2.9rem;
    height: 2.9rem;
    border-radius: 50%;
    color: #e8dcc6;
    background: rgba(46, 40, 35, .88);
    box-shadow: 0 3px 12px rgba(0, 0, 0, .5);
  }
  .turn.prev { left: 1.1rem; }
  .turn.next { right: 1.1rem; }
  .counter { margin-bottom: 5.5rem; }
  .photos img { max-height: 11rem; }
  .photos li:only-child img { max-height: 15rem; }
}

@media (prefers-reduced-motion: reduce) {
  .leaf { display: none; }
  .photos li, .turn { transition: none; }
}
