/* Vieraskirja: an open book of handwritten entries, and the form to write one (js/modules/guestbook.js) */
@font-face {
  font-family: "Caveat";
  font-display: swap;
  font-weight: 400 700;
  src: url(../fonts/Caveat-latin.woff2) format("woff2");
}

.guestbook {
  --paper: #FBF7EC;
  --paper-line: #DCE3EE;
  --pen: #1D3B8F;
  --pencil: #6B6F80;
  --ink-red: #B3261E;
  --page-h: 640px;
  display: grid;
  width: min(100% - (2 * var(--pad)), var(--wrap));
  margin: 0 auto 120px;
  gap: 72px;
}

/* The book: two pages on cloth covers, the spine shaded in the middle */
.gb-book {
  display: grid;
  gap: 20px;
}
.gb-spread {
  display: grid;
  position: relative;
  perspective: 2400px;
  grid-template-columns: 1fr 1fr;
  padding: 14px;
  border-radius: 10px;
  background: var(--deep);
  box-shadow: 0 24px 60px rgb(0 0 0 / .22);
}
.gb-page {
  position: relative;
  min-height: var(--page-h);
  padding: 44px 44px 48px;
  background: var(--paper) repeating-linear-gradient(transparent 0 35px, var(--paper-line) 35px 36px);
  line-height: 36px;
  color: var(--pen);
  font-family: "Caveat", cursive;
}
.gb-page:first-child {
  border-radius: 4px 0 0 4px;
  box-shadow: inset -26px 0 30px -24px rgb(0 0 0 / .35);
}
.gb-page:last-child {
  border-radius: 0 4px 4px 0;
  box-shadow: inset 26px 0 30px -24px rgb(0 0 0 / .35);
}
.gb-page:only-child { border-radius: 4px; }

/* The layout pass measures pages on an unseen one of the same size (js/modules/guestbook.js) */
.gb-probe {
  position: absolute;
  height: var(--page-h);
  min-height: 0;
  overflow: hidden;
  visibility: hidden;
}

/* Until the entries arrive, pencil lines where the writing will be */
.gb-skeleton {
  display: grid;
  align-content: start;
  gap: 22px;
}
.gb-skeleton i {
  width: 78%;
  height: 14px;
  border-radius: 7px;
  background: color-mix(in oklab, var(--pencil) 16%, transparent);
  animation: gb-wait 1.4s ease-in-out infinite alternate;
}
.gb-skeleton i:nth-child(3n + 2) { width: 56%; }
.gb-skeleton i:nth-child(3n) { width: 32%; margin-bottom: 30px; justify-self: end; }
@keyframes gb-wait {
  to { opacity: .45; }
}
/* Page numbers, and the folded outer corners that turn the page */
.gb-folio {
  position: absolute;
  bottom: 16px;
  color: var(--pencil);
  font-size: 19px;
  line-height: 1;
  pointer-events: none;
}

/* In the outer corners, as in a printed book: left on the left page, right on the right one */
.gb-page:first-child .gb-folio { left: 40px; }
.gb-page:last-child .gb-folio {
  right: 40px;
  left: auto;
}
.gb-corner {
  position: absolute;
  z-index: 6;
  width: 96px;
  height: 96px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: none;
}
.gb-corner:focus-visible {
  border-radius: 6px;
  outline: 2px dashed var(--pencil);
  outline-offset: -10px;
}

/* The curl (js/modules/page-curl.js): flap, shading and the page under it, drawn over the spread.
   Idle corners sit under the copies of a page being turned, the turning curl over them */
.gb-curl {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.gb-curl.is-turning { z-index: 4; }
.gb-turning, .gb-still {
  position: absolute;
  z-index: 3;
  margin: 0;
  pointer-events: none;
}

.gb-entry + .gb-entry { margin-top: 36px; }
.gb-date {
  margin: 0;
  color: var(--pencil);
  font-size: 19px;
}
.gb-message {
  margin: 0;
  font-size: 26px;
  overflow-wrap: anywhere;
}
.gb-picture {
  display: block;
  width: 100%;
  height: auto;
  margin: 6px 0;
  fill: none;
  stroke: var(--pen);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}
.gb-sign {
  display: block;
  width: auto;
  max-width: 100%;
  height: 108px;
  fill: none;
  stroke: var(--pen);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}
.gb-entry:not(:has(.gb-sign)) .gb-name { font-size: 34px; }
.gb-name {
  margin: 0;
  font-size: 27px;
}
.gb-empty {
  margin: 0;
  color: var(--pencil);
  font-size: 27px;
}


/* The blank page: write straight onto the paper, no boxes */
.gb-write {
  display: flex;
  flex-direction: column;
}

/* The signature has its own spot at the foot of the page, apart from the greeting */
[data-gb-part="signature"] {
  margin-top: auto;
  padding-top: 36px;
}
[data-gb-part="picture"] { margin-bottom: 36px; }
.gb-write[hidden] { display: none; }
.gb-ink {
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--pen);
  font: 400 26px / 36px "Caveat", cursive;
  resize: none;
}
.gb-ink::placeholder { color: var(--pencil); opacity: .7; }
.gb-ink:focus {
  border-radius: 4px;
  outline: 2px dashed var(--pencil);
  outline-offset: 6px;
}
textarea.gb-ink {
  min-height: 180px;
  field-sizing: content;
}
.gb-ink[aria-invalid="true"] { outline: 2px dashed var(--ink-red); outline-offset: 6px; }
.gb-part { display: grid; }
.gb-modes {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  margin: 0;
  gap: 4px 14px;
  color: var(--pencil);
  font: 21px / 36px "Caveat", cursive;
}
.gb-modes button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--pencil);
  font: inherit;
  cursor: pointer;
}
.gb-modes [aria-pressed="true"] { color: var(--pen); }
.gb-modes [aria-pressed="false"] { opacity: .45; }

/* Written already: after 30 days the page only thanks */
.gb-closed { display: none; margin: 0; font-size: 26px; }
[data-state="closed"] > :not(.gb-date, .gb-closed) { display: none; }
[data-state="closed"] .gb-closed { display: block; }

/* Drawn: a big pad with a dashed edge, darker while the pen is down; it holds still under the pen */
.gb-pad {
  display: block;
  width: 100%;
  height: auto;
  margin: 8px 0 12px;
  border: 2px dashed color-mix(in oklab, var(--pencil) 45%, transparent);
  border-radius: 6px;
  color: var(--pen);
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.gb-pad.is-drawing, .gb-pad:focus { border-color: var(--pen); outline: 0; }
[data-mode="type"] .gb-pad, [data-mode="type"] .gb-clear, [data-mode="draw"] textarea { display: none; }
.gb-modes .gb-clear { margin-left: auto; }

/* Typed: the name itself is the signature, large in the handwriting */
[data-mode="type"] .gb-signed, .gb-signed { justify-content: flex-start; }
[data-mode="type"] .gb-signed, [data-mode="type"] .gb-signed .gb-ink {
  font-size: 44px;
  line-height: 72px;
}
.gb-signed {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  margin: 0;
  gap: 6px;
  font-size: 27px;
}
.gb-signed .gb-ink {
  width: auto;
  min-width: 5ch;
  font-size: 27px;
  field-sizing: content;
}
.gb-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: flex-end;
  margin: 16px 0 0;
  gap: 12px;
}
.gb-submit {
  padding: 0;
  border: 0;
  background: none;
  font-family: "Caveat", cursive;
  cursor: pointer;
  color: var(--pen);
  font-size: 28px;
  font-weight: 700;
  text-decoration: underline wavy;
  text-decoration-thickness: 1px;
  text-underline-offset: 6px;
}
.gb-submit:disabled { opacity: .5; }
.gb-status {
  margin: 0;
  color: var(--ink-red);
  font-size: 24px;
  text-align: right;
}
.gb-status.is-done { color: var(--pen); }
.gb-status:empty { display: none; }

/* Hidden from people, filled in only by bots */
.gb-trap {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

@media (max-width: 760px) {
  .gb-spread {
    grid-template-columns: 1fr;
    padding: 8px;
  }
  .guestbook { --page-h: 520px; }
  .gb-page { padding: 30px 24px 34px; }
}
@media (prefers-reduced-motion: reduce) {
  .gb-skeleton i { animation: none; }
}

/* The intro is the page's own text, with links */
.page-hero .intro { max-width: 31em; }
.page-hero .intro p { margin: 0; }
.page-hero .intro a { color: var(--accent); }

/* The typing/drawing switch shows only over its part or while the part is in use; touch screens keep it */
@media (hover: hover) {
  .gb-modes {
    opacity: 0;
    transition: opacity .3s var(--ease);
  }
  .gb-part:is(:hover, :focus-within) .gb-modes,
  .gb-part[data-mode="draw"] .gb-modes { opacity: 1; }
}
@media (hover: hover) and (prefers-reduced-motion: reduce) {
  .gb-modes { transition: none; }
}
