.cover-copy {
  z-index: 2;
}

.journal-visual {
  position: absolute;
  z-index: 1;
  inset-block-start: 50%;
  inset-inline-end: clamp(45px, 8.9vw, 118px);
  width: clamp(176px, 24vw, 300px);
  aspect-ratio: 0.74;
  pointer-events: none;
  perspective: 1280px;
  perspective-origin: 56% 45%;
  transform: translateY(-50%);
}

.journal-book {
  position: absolute;
  inset: 0;
  transform: rotate(-7deg) rotateY(-9deg);
  transform-style: preserve-3d;
}

.journal-back,
.journal-stack,
.journal-lid,
.journal-lid-front {
  position: absolute;
  inset: 0;
  border-radius: 2px 8px 8px 2px;
}

.journal-back {
  border: 1px solid #53606c;
  background: linear-gradient(105deg, #141d28, #263844 65%, #182630);
  box-shadow: 0 29px 49px #080d17b3, 4px 4px 13px #0b132096;
  transform: translateZ(-3px);
}

.journal-stack {
  inset: 7px 5px 7px 6px;
  border-radius: 1px 6px 6px 1px;
  background: repeating-linear-gradient(0deg, #bfa98a 0 1px, #ddd0b4 1px 3px);
  box-shadow: 2px 2px 2px #0308137d;
  transform: translateZ(0);
}

.journal-stack::after {
  position: absolute;
  right: 23%;
  bottom: -16px;
  width: 12px;
  height: 19px;
  background: #9b594d;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 77%, 0 100%);
  content: "";
}

.journal-page-heading {
  position: absolute;
  inset: 7% 11% auto 15%;
  z-index: 2;
  color: #5d4837;
  font: 400 clamp(.58rem, 2.5vmin, 1.2rem)/1.18 "Gaegu Diary", var(--heading);
  word-break: keep-all;
  backface-visibility: hidden;
}

.journal-page-heading p {
  margin: 0;
}

.journal-page-edition {
  color: #392b20;
  font-size: 1.31em;
  font-weight: 700;
}

.journal-page-date {
  padding-block-start: .14em;
  color: #6b5644;
  font-size: .88em;
}

.journal-page-write,
.journal-page-note {
  padding-block-start: .5em;
}

:is(.journal-page-write, .journal-page-note) > span {
  display: block;
  inline-size: max-content;
  max-inline-size: 100%;
}

.album-spread-start .journal-page-heading,
.journal-print-main {
  visibility: hidden;
}

.album-spread.is-writing-opening .album-spread-start .journal-page-heading,
.album-spread.is-stamping-opening .journal-print-main {
  visibility: visible;
}

@media (prefers-reduced-motion: no-preference) {
  .album-spread.is-writing-opening .album-spread-start :is(.journal-page-edition, .journal-page-date),
  .album-spread.is-writing-opening .journal-page-write > span {
    animation: journal-write-first-entry 380ms steps(12, end) backwards;
  }

  .album-spread.is-writing-opening .album-spread-start .journal-page-date {
    animation-delay: 320ms;
  }

  .album-spread.is-writing-opening .journal-page-write > span {
    animation-delay: 640ms;
    animation-duration: 470ms;
  }

  .album-spread.is-writing-opening .journal-page-write > span + span {
    animation-delay: 1070ms;
    animation-duration: 350ms;
  }

  .album-spread.is-stamping-opening .journal-print-main {
    animation: journal-opening-stamp 570ms cubic-bezier(.22, .74, .28, 1) backwards;
  }
}

@keyframes journal-write-first-entry {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0); }
}

@keyframes journal-opening-stamp {
  from { opacity: 0; transform: translate(4%, -4%) scale(1.09) rotate(4deg); }
  57% { opacity: 1; transform: translate(0, 1.5%) scale(.976) rotate(-2.6deg); }
  to { opacity: 1; transform: rotate(-2deg); }
}

.journal-print {
  position: absolute;
  margin: 0;
  padding: 2.35% 2.35% 6%;
  border: 1px solid #d4c3a3;
  border-radius: 1px;
  background: #fff9eb;
  box-shadow: 1px 3px 6px #50351f60;
  backface-visibility: hidden;
}

.journal-print > img {
  display: block;
  width: 100%;
  height: 100%;
  border: 1px solid #907a628c;
  object-fit: cover;
}

.journal-print-main {
  inset: 43% 12% 9% 16%;
  z-index: 1;
  transform: rotate(-2deg);
}

.journal-print-main::after,
.journal-print-history::after {
  position: absolute;
  z-index: 1;
  inset: -4% 36% auto;
  height: 13%;
  clip-path: polygon(2% 2%, 99% 0, 96% 100%, 0 94%);
  background: #d9b77688;
  box-shadow: inset 0 0 2px #d7bb84;
  transform: rotate(5deg);
  pointer-events: none;
  content: "";
}

.journal-print-history > img {
  height: auto;
  aspect-ratio: 16 / 9;
}

.journal-print-history::after {
  height: 19%;
}

.journal-lid {
  transform: translateZ(8px);
  transform-origin: left center;
  transform-style: preserve-3d;
}

.journal-lid-front {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  padding: 22px 18px 22px 30px;
  border: 1px solid #77838a;
  overflow: hidden;
  color: #dec7a4;
  background:
    linear-gradient(90deg, #111b27 0 6%, #71849165 6% 6.5%, #192330 6.5% 10%, transparent 10%),
    repeating-linear-gradient(90deg, #d7e3e812 0 1px, transparent 1px 4px),
    repeating-linear-gradient(0deg, #10172023 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at 65% 38%, #394b5b, #202e3c 78%);
  box-shadow: inset 0 0 28px #101922a8;
  text-align: center;
}

.journal-lid-front::before {
  position: absolute;
  inset: 15px 15px 15px calc(10% + 9px);
  border: 1px solid #dcc29479;
  border-radius: 1px 4px 4px 1px;
  content: "";
}

.journal-lid-front strong {
  font-family: var(--heading);
  font-size: clamp(0.82rem, 1.5vw, 1.15rem);
  font-weight: 700;
  letter-spacing: 0.13em;
}

.journal-lid-front span:last-child {
  color: #cfbea4;
  font-size: clamp(0.64rem, 1vw, 0.79rem);
  letter-spacing: 0.085em;
}

.journal-lid-mark {
  color: #e2c99f;
  font-family: var(--heading);
  font-size: clamp(1.2rem, 2.5vw, 1.85rem);
  line-height: 1;
}

.experience-tools {
  display: flex;
  align-items: center;
  justify-content: end;
  flex: 1 1 auto;
  gap: 0.55rem 1rem;
  flex-wrap: wrap;
}

.journal-entry {
  isolation: isolate;
  position: relative;
  display: grid;
  min-height: clamp(365px, 49vw, 500px);
  padding: clamp(18px, 4vw, 48px);
  align-content: center;
  overflow: hidden;
  color: #38302e;
  background: radial-gradient(ellipse at 50% 52%, #83674a2d 0, transparent 69%);
}

.journal-entry-paper {
  position: relative;
  width: min(100%, 775px);
  min-height: 322px;
  margin: 0 auto;
  padding: clamp(25px, 4.6vw, 49px) clamp(28px, 6.8vw, 76px);
  border: 1px solid #d2c3a7;
  border-radius: 2px 5px 6px 2px;
  background:
    linear-gradient(90deg, #876a4420, transparent 10%),
    repeating-linear-gradient(0deg, #8e745008 0 1px, transparent 1px 3px),
    #f1e8d5;
  box-shadow: 0 18px 44px #070b12a1, 2px 3px 0 #cbbc9c, 3px 6px 0 #a99b80;
}

.journal-entry-paper::before {
  position: absolute;
  inset: 0 auto 0 clamp(13px, 3.3vw, 35px);
  width: 1px;
  background: #ac776336;
  pointer-events: none;
  content: "";
}

.journal-entry-paper::after {
  position: absolute;
  inset: auto 0 0 auto;
  width: 15px;
  aspect-ratio: 1;
  border-radius: 2px 0 5px 0;
  background: linear-gradient(135deg, #fcf5e4 0 49%, #d4c6a7 50%, #b8a889 100%);
  content: "";
  pointer-events: none;
}

.journal-entry.is-writing .journal-entry-paper {
  animation: settle-paper 360ms ease-out both;
}

@keyframes settle-paper {
  from { opacity: 0.42; transform: rotate(-1deg) translateY(6px); }
  to { opacity: 1; transform: rotate(0) translateY(0); }
}

.journal-entry-date {
  color: #775c47;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.journal-entry h2 {
  margin-block: 8px 15px;
  font-family: var(--heading);
  font-size: clamp(1.57rem, 3.5vw, 2.49rem);
  line-height: 1.32;
  letter-spacing: -0.055em;
}

.book-sheet .journal-entry-paper {
  display: flex;
  max-block-size: clamp(235px, calc(100dvh - 170px), 630px);
  flex-direction: column;
  padding-block: clamp(19px, 3.5dvh, 42px);
}

.journal-entry-heading {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: start;
  column-gap: 10px;
}

@font-face {
  font-family: "Gaegu Diary";
  src: url("fonts/Gaegu-Regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

.journal-entry-body {
  position: relative;
  min-block-size: 0;
  padding-inline-end: 8px;
  overflow-y: auto;
  overflow-anchor: none;
  overscroll-behavior: contain;
  scrollbar-color: #9b8267 #e9ddc6;
}

.journal-entry-body:focus-visible {
  outline: 2px solid #765332;
  outline-offset: -2px;
}

.diary-quotation:not([hidden]) {
  grid-column: 1 / -1;
  grid-row: -1 / span 1;
  flex: none;
  margin: auto 0 12px;
  padding-block-start: clamp(5px, 1.4dvh, 12px);
  text-align: center;
  font-family: var(--heading);
  word-break: keep-all;
  text-wrap: balance;
}

.diary-quotation blockquote {
  margin: 0;
  font-size: clamp(15px, 2.3vw, 23px);
  line-height: 1.4;
}

.diary-quotation cite {
  font: normal 0.78rem/1.4 var(--heading);
}

.ink-line {
  --ink-line-height: 2.38rem;
  min-height: calc(2 * var(--ink-line-height));
  margin-block: 0 14px;
  color: #3e2e27;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 calc(var(--ink-line-height) - 1px),
    #8f795a58 calc(var(--ink-line-height) - 1px) var(--ink-line-height)
  );
  font: 700 clamp(1.17rem, 2.9vw, 1.57rem)/var(--ink-line-height) var(--heading);
  white-space: pre-wrap;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.journal-entry.has-diary-text .ink-line {
  font-family: "Gaegu Diary", var(--heading);
  font-size: clamp(1.36rem, 3vw, 1.8rem);
  font-weight: 400;
}

@media (orientation: landscape) and (max-height: 550px) and (pointer: coarse) {
  .journal-entry.has-diary-text .ink-line {
    font-size: 1.30rem;
  }
}

.ink-word {
  display: inline-block;
  max-inline-size: 100%;
  vertical-align: top;
}

.ink-drawing {
  display: block;
  inline-size: auto;
  block-size: auto;
  max-inline-size: min(100%, 26rem);
  max-block-size: min(28dvh, 9rem);
  object-fit: contain;
  object-position: left center;
  margin-block: .2em .35em;
  opacity: 0;
}

.ink-drawing-inline {
  display: inline-block;
  vertical-align: -.2em;
  block-size: 1.2em;
  margin: 0 .12em;
}

.ink-drawing.is-written { opacity: 1; }

@media (prefers-reduced-motion: no-preference) {
  .is-writing .ink-drawing { transition: opacity 220ms ease-out; }
}

.ink-glyph {
  position: relative;
  display: inline-block;
  block-size: var(--ink-line-height);
  vertical-align: top;
  opacity: 0;
  clip-path: inset(0 100% 0 0);
  white-space: pre;
}

.ink-glyph.is-written {
  opacity: 1;
  clip-path: inset(0);
  transition: clip-path 135ms ease-out, opacity 60ms linear;
  transition-delay: var(--ink-stroke-delay, 0ms);
}

.journal-entry:not(.is-writing) .ink-glyph {
  transition: none;
}

.ink-glyph.ink-active::after {
  position: absolute;
  inset: auto -2px 0.29em auto;
  width: 0.17em;
  height: 0.54em;
  border-radius: 40% 50% 70% 15%;
  background: #8b573e;
  box-shadow: 0 0 1px #533728;
  content: "";
  transform: rotate(28deg);
}

.journal-entry-source {
  color: #735e4c;
  font-size: 0.75rem;
}

.journal-entry-source:empty {
  display: none;
}

.screen-reader-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (orientation: landscape) and (max-height: 550px) and (pointer: coarse) {
  .book-sheet .journal-entry .ink-line {
    font-size: clamp(1.25rem, 2.6vw, 1.5rem);
  }
}

@media (max-width: 780px) {
  .journal-visual {
    inset-inline-end: 4.5%;
    width: clamp(148px, 25vw, 212px);
  }

  .experience-tools {
    gap: 0.3rem 0.55rem;
  }
}

@media (max-width: 560px) {
  .header-inner {
    min-height: 64px;
    flex-wrap: wrap;
    row-gap: 8px;
    padding-block: 9px;
  }

  .header-actions {
    margin-inline-start: auto;
  }

  .cover {
    align-content: end;
    grid-template-rows: auto auto;
    block-size: 530px;
  }

  .cover-copy {
    grid-row: 2;
  }

  .journal-visual {
    position: relative;
    inset: auto;
    grid-row: 1;
    justify-self: center;
    width: clamp(112px, 35vw, 158px);
    margin: 26px 0 0;
    transform: none;
  }

  .journal-lid-front {
    gap: 7px;
    padding: 12px 10px 12px 17px;
  }

  .journal-lid-front::before {
    inset: 8px 7px 8px calc(10% + 5px);
  }

  .experience-head {
    align-items: center;
  }

  .experience-tools {
    justify-content: flex-end;
  }

  .journal-entry-paper {
    min-height: 290px;
  }

  .ink-line {
    --ink-line-height: 2.15rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ink-glyph.ink-active::after {
    display: none;
  }
}
