@font-face {
  font-family: 'Patrick Hand';
  src: url('/fonts/patrickhand-latin.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Caveat';
  src: url('/fonts/caveat-latin.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f6f5f1;
  --ink: #1b1b1b;
  --ink-soft: #55534f;
  --ink-faint: #a8a59e;
  --sai-t: env(safe-area-inset-top, 0px);
  --sai-r: env(safe-area-inset-right, 0px);
  --sai-b: env(safe-area-inset-bottom, 0px);
  --sai-l: env(safe-area-inset-left, 0px);
  color-scheme: light only;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  font-family: 'Patrick Hand', 'Segoe Print', 'Comic Sans MS', cursive;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}

.hand {
  font-family: 'Patrick Hand', 'Segoe Print', cursive;
}

/* ---------- corner sound toggle ---------- */
.corner {
  position: fixed;
  top: calc(10px + var(--sai-t));
  right: calc(14px + var(--sai-r));
  z-index: 20;
  background: transparent;
  border: 0;
  padding: 6px 8px;
  font-size: 17px;
  color: var(--ink-faint);
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: color 0.3s, opacity 0.6s;
  opacity: 0;
}
.corner.shown { opacity: 1; }
.corner:hover, .corner:focus-visible { color: var(--ink-soft); outline: none; }
.corner[aria-pressed="true"] { color: var(--ink); }
.corner::after {
  content: '';
  display: block;
  height: 1px;
  margin-top: 1px;
  background: currentColor;
  opacity: 0.35;
  transform: rotate(-0.6deg);
}

/* ---------- touch controls ---------- */
#touch {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 15;
  pointer-events: none;
  display: none;
  padding: 0 calc(16px + var(--sai-r)) calc(16px + var(--sai-b)) calc(16px + var(--sai-l));
  opacity: 0;
  transition: opacity 0.8s ease;
}
#touch.enabled { display: block; }
#touch.shown { opacity: 1; }
#touch .pad {
  display: flex;
  gap: 14px;
  align-items: flex-end;
}
.tbtn {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  width: 66px;
  height: 66px;
  border-radius: 40% 60% 55% 45% / 55% 45% 55% 45%;
  border: 2px solid rgba(27, 27, 27, 0.55);
  background: rgba(246, 245, 241, 0.55);
  color: var(--ink);
  font-family: 'Patrick Hand', cursive;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.4s ease;
  -webkit-backdrop-filter: blur(1px);
  backdrop-filter: blur(1px);
}
.tbtn:nth-child(2) { border-radius: 60% 40% 45% 55% / 45% 55% 45% 55%; }
.tbtn.down { transform: scale(0.94); background: rgba(27, 27, 27, 0.85); color: var(--paper); }
.tbtn.look {
  position: absolute;
  right: calc(18px + var(--sai-r));
  bottom: calc(18px + var(--sai-b));
  width: 78px;
  height: 62px;
  font-size: 22px;
  border-radius: 55% 45% 50% 50% / 45% 55% 50% 50%;
  opacity: 0;
  pointer-events: none;
}
.tbtn.look.avail { opacity: 1; pointer-events: auto; }

/* ---------- notebook page ---------- */
#page {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(12px + var(--sai-t)) calc(12px + var(--sai-r)) calc(12px + var(--sai-b)) calc(12px + var(--sai-l));
  background: rgba(246, 245, 241, 0.72);
  opacity: 1;
  transition: opacity 0.25s ease;
}
#page.hidden { opacity: 0; pointer-events: none; }
.sheet {
  position: relative;
  width: min(560px, 100%);
  max-height: 100%;
  overflow: hidden;
  background: #fbfaf7;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  box-shadow: 3px 4px 0 rgba(27, 27, 27, 0.08);
  transform: rotate(-0.4deg) translateY(0);
  transition: transform 0.3s cubic-bezier(.2,.9,.3,1.2);
}
#page.hidden .sheet { transform: rotate(-0.4deg) translateY(10px) scale(0.98); }
.sheet-inner {
  max-height: calc(100vh - 32px - var(--sai-t) - var(--sai-b));
  max-height: calc(100dvh - 32px - var(--sai-t) - var(--sai-b));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 26px 30px 28px 30px;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0 27px,
    rgba(27, 27, 27, 0.07) 27px 28px
  );
  background-position: 0 14px;
}
.sheet .close {
  position: absolute;
  top: 6px;
  right: 12px;
  z-index: 2;
  background: transparent;
  border: 0;
  font-size: 30px;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 6px 10px;
}
.sheet .close:hover, .sheet .close:focus-visible { color: var(--ink); outline: none; }

.sheet h2 {
  font-family: 'Caveat', 'Patrick Hand', cursive;
  font-weight: 600;
  font-size: 38px;
  line-height: 1;
  margin: 0 0 10px;
  letter-spacing: 0.01em;
}
.sheet .kicker {
  font-size: 15px;
  color: var(--ink-faint);
  margin: 0 0 4px;
  letter-spacing: 0.06em;
}
.sheet p {
  font-size: 19px;
  line-height: 28px;
  margin: 0 0 14px;
}
.sheet p.small { font-size: 16px; color: var(--ink-soft); }
.sheet .tech {
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 17px;
  color: var(--ink-soft);
}
.sheet .tech li { position: relative; }
.sheet .tech li::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 2px;
  height: 1px;
  background: currentColor;
  opacity: 0.45;
  transform: rotate(-1deg);
}
.sheet .shot {
  display: block;
  width: 100%;
  margin: 4px 0 16px;
  border: 2px solid var(--ink);
  border-radius: 8px 120px 6px 100px / 60px 6px 90px 8px;
  padding: 6px;
  background: #fff;
}
.sheet .shot canvas.ph {
  display: block;
  width: 100%;
  height: auto;
}
.sheet .shot img {
  display: block;
  width: 100%;
  height: auto;
  filter: grayscale(1) contrast(1.05);
  transition: filter 0.6s ease;
}
.sheet .shot img:hover { filter: grayscale(0.2); }
.sheet .shot.empty {
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-faint);
  font-size: 17px;
  background:
    repeating-linear-gradient(45deg, transparent 0 9px, rgba(27,27,27,0.05) 9px 10px);
}
.sheet .links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  font-size: 20px;
  margin-top: 6px;
}
.sheet .links a {
  color: var(--ink);
  text-decoration: none;
  position: relative;
}
.sheet .links a::after {
  content: '';
  position: absolute;
  left: -2px; right: -2px; bottom: 0;
  height: 2px;
  background: var(--ink);
  transform: rotate(-0.8deg);
  opacity: 0.8;
}
.sheet .links a:hover::after, .sheet .links a:focus-visible::after { height: 3px; opacity: 1; }
.sheet .links a:focus-visible { outline: none; }
.sheet .links a.dead { color: var(--ink-faint); pointer-events: none; }
.sheet .links a.dead-link { color: var(--ink-soft); }
.sheet .links a.dead-link::after { opacity: 0.25; }
.sheet .links a.dead-link s { text-decoration-thickness: 2px; }
.sheet .links a.dead-link .tag { font-size: 15px; color: var(--ink-faint); letter-spacing: 0.05em; }
.sheet .links a.dead::after { opacity: 0.3; }

.sheet ul.plain {
  margin: 0 0 14px;
  padding-left: 22px;
  font-size: 19px;
  line-height: 28px;
}
.sheet ul.plain li.struck { text-decoration: line-through; color: var(--ink-faint); }
.sheet ul.plain li.faint { color: var(--ink-faint); }

.sheet .foot {
  font-size: 15px;
  color: var(--ink-faint);
  margin-top: 6px;
}

.noscript {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  font-size: 20px;
}

@media (max-width: 480px) {
  .sheet h2 { font-size: 32px; }
  .sheet-inner { padding: 22px 22px 24px; }
  .sheet p { font-size: 18px; line-height: 28px; }
  .tbtn { width: 60px; height: 60px; font-size: 28px; }
}

@media (max-height: 430px) {
  .tbtn { width: 52px; height: 52px; font-size: 24px; }
  .tbtn.look { width: 68px; height: 50px; font-size: 19px; }
  .sheet-inner { padding: 16px 22px 18px; }
  .sheet h2 { font-size: 30px; margin-bottom: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet, #page, #touch, .tbtn, .corner { transition: none; }
}
.sheet .abandoned-title {
  position: relative;
  display: inline-block;
  color: var(--ink-soft);
}
.sheet .abandoned-title::before,
.sheet .abandoned-title::after {
  content: '';
  position: absolute;
  left: -5px;
  right: -9px;
  top: 48%;
  height: 3px;
  background: var(--ink);
  transform: rotate(-2deg);
  opacity: 0.8;
}
.sheet .abandoned-title::after { top: 58%; transform: rotate(1.5deg); height: 2px; }
.sheet .abandoned-note {
  margin: -5px 0 10px 14px;
  color: var(--ink-soft);
  font-family: 'Caveat', 'Patrick Hand', cursive;
  font-size: 22px;
  transform: rotate(-1deg);
}
