@import url("https://fonts.googleapis.com/css2?family=Gowun+Dodum&family=Poor+Story&display=swap");

:root {
  color-scheme: dark;
  --canvas: #000000;
  --text: #ffffff;
  --muted: #8f8f8f;
  --line: #ffffff;
  --paper: #e8e4d8;
  --paper-edge: #b5aa9a;
  --ink: #14313a;
  --accent: #236dff;
  --book-away: 0;
  --memory: 0;
  --dla: 0;
  --letter: 0;
  font-family: "Gowun Dodum", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--canvas);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  background: var(--canvas);
}

input,
button {
  font: inherit;
}

.site-shell {
  min-height: 100vh;
  position: relative;
}

.unlock-view,
.birthday-view {
  min-height: 100vh;
  position: absolute;
  inset: 0;
}

.unlock-view {
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

.unlock-content {
  width: min(360px, 100%);
  text-align: center;
}

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

h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.25;
  font-weight: 500;
  letter-spacing: 0;
}

.password-hint {
  margin: 14px 0 32px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.4;
}

.password-form {
  display: grid;
  gap: 20px;
  width: 100%;
}

input {
  width: 100%;
  height: 44px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  color: var(--text);
  background: transparent;
  text-align: center;
  font-size: 24px;
  letter-spacing: 0;
  outline: none;
}

input:focus {
  border-bottom-color: var(--text);
}

button {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--text);
  background: transparent;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0;
  cursor: pointer;
}

.password-feedback {
  min-height: 22px;
  margin: 18px 0 0;
  color: #ff3b30;
  font-size: 15px;
  line-height: 1.45;
}

.birthday-view {
  display: grid;
  place-items: center;
  padding: 0;
  overflow: hidden;
  background: var(--canvas);
  touch-action: none;
}

.book-stage {
  display: grid;
  place-items: center;
  width: min(94vw, 900px);
  min-height: 100vh;
  perspective: 2600px;
  opacity: calc(1 - var(--book-away));
  transform: translateY(calc(var(--book-away) * -34px)) scale(calc(1 - var(--book-away) * 0.06));
  transition: opacity 180ms linear;
}

.card {
  --open: 0;
  position: relative;
  width: clamp(300px, 30vw, 390px);
  aspect-ratio: 3 / 4.2;
  color: var(--ink);
  background: var(--paper);
  box-shadow:
    inset 18px 0 28px rgba(55, 40, 18, 0.18),
    20px 22px 70px rgba(0, 0, 0, 0.44);
  transform-style: preserve-3d;
  transform:
    translateX(calc(var(--open) * 76px))
    rotateZ(calc(var(--open) * 1.4deg))
    scale(calc(1 + var(--open) * 0.025));
  transition: box-shadow 240ms ease;
}

.card::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 0;
  width: 100%;
  height: 5px;
  background: var(--paper-edge);
  transform: skewX(-45deg);
  transform-origin: bottom;
}

.card::after {
  content: "";
  position: absolute;
  top: 0;
  right: -5px;
  width: 5px;
  height: 100%;
  background: #8f9a91;
  transform: skewY(-45deg);
  transform-origin: left;
}

.book-cover {
  position: absolute;
  inset: 0;
  z-index: 2;
  transform-origin: left;
  transform-style: preserve-3d;
  transform: rotateY(calc(var(--open) * -158deg));
  will-change: transform;
}

.cover-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--paper);
  backface-visibility: hidden;
}

.cover-front img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.cover-front::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.22), transparent 26%),
    linear-gradient(180deg, transparent 58%, rgba(0, 0, 0, 0.22));
  pointer-events: none;
}

.cover-back {
  transform: rotateY(180deg);
  background:
    linear-gradient(90deg, rgba(83, 61, 34, 0.28), transparent 20%),
    repeating-linear-gradient(0deg, rgba(120, 94, 58, 0.08) 0 1px, transparent 1px 18px),
    #efe8d9;
  box-shadow: inset 22px 0 34px rgba(63, 40, 18, 0.22);
}

.details {
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: clamp(28px, 3vw, 40px) clamp(22px, 2.4vw, 30px) 24px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(90, 62, 28, 0.19), transparent 13%),
    repeating-linear-gradient(0deg, transparent 0 23px, rgba(85, 64, 36, 0.08) 23px 24px),
    linear-gradient(135deg, #fff8ea, #eadfc9);
  font-family: "Poor Story", "Gowun Dodum", "Apple SD Gothic Neo", sans-serif;
}

.details::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 22px;
  width: 1px;
  background: rgba(154, 53, 40, 0.22);
}

.details h2 {
  position: relative;
  margin: 0 0 26px;
  color: var(--accent);
  text-align: left;
  font-family: "Poor Story", "Gowun Dodum", sans-serif;
  font-size: clamp(30px, 3.4vw, 42px);
  line-height: 1.08;
  font-weight: 400;
  letter-spacing: 0;
}

.details p {
  position: relative;
  margin: 0 0 11px;
  color: var(--ink);
  font-size: clamp(16px, 1.55vw, 19px);
  line-height: 1.32;
  font-weight: 400;
  letter-spacing: 0;
}

.details .text-right {
  margin-top: 20px;
  text-align: right;
}

.memory-stage {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(280px, 1fr);
  align-items: center;
  gap: clamp(28px, 6vw, 88px);
  width: min(1120px, calc(100vw - 64px));
  margin: auto;
  opacity: var(--memory);
  transform: translateY(calc((1 - var(--memory)) * 32px));
  pointer-events: none;
}

.birthday-view.is-memory-active .memory-stage {
  pointer-events: auto;
}

.memory-copy {
  justify-self: stretch;
  color: var(--text);
  font-family: "Poor Story", "Gowun Dodum", sans-serif;
  font-size: clamp(32px, 5vw, 72px);
  line-height: 1.1;
  text-align: center;
}

.memory-copy p {
  margin: 0 0 10px;
}

.division-photo {
  position: relative;
  width: min(62vw, 720px);
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: transparent;
  box-shadow: none;
  cursor: crosshair;
  touch-action: none;
}

.dla-stage {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(220px, 0.72fr) minmax(320px, 1fr);
  align-items: center;
  gap: clamp(28px, 6vw, 88px);
  width: min(1120px, calc(100vw - 64px));
  margin: auto;
  opacity: var(--dla);
  transform: translateY(calc((1 - var(--dla)) * 36px));
  pointer-events: none;
}

.birthday-view.is-dla-active .dla-stage {
  pointer-events: auto;
}

.letter-stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  width: min(100vw - 32px, 980px);
  margin: auto;
  opacity: var(--letter);
  transform: translateY(calc((1 - var(--letter)) * 36px)) scale(calc(0.985 + var(--letter) * 0.015));
  pointer-events: none;
}

.birthday-view.is-letter-ready .letter-stage {
  pointer-events: auto;
}

.birthday-view.is-letter-ready {
  touch-action: pan-y;
}

.letter-paper {
  width: min(100%, 860px);
  max-height: min(86vh, 900px);
  margin: 0;
  padding: clamp(26px, 4vw, 54px);
  overflow-y: auto;
  color: #162832;
  background:
    linear-gradient(90deg, rgba(122, 78, 35, 0.14), transparent 12%),
    repeating-linear-gradient(0deg, transparent 0 25px, rgba(71, 51, 31, 0.08) 25px 26px),
    linear-gradient(135deg, #fffaf0, #eadfc9);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.48);
  font-family: "Gowun Dodum", "Apple SD Gothic Neo", sans-serif;
  touch-action: pan-y;
}

.letter-paper p {
  margin: 0 0 clamp(6px, 1vh, 11px);
  font-size: clamp(13.5px, 1.55vw, 18px);
  line-height: 1.48;
  letter-spacing: 0;
  word-break: keep-all;
}

.letter-paper p:nth-of-type(4),
.letter-paper p:nth-of-type(6),
.letter-paper p:nth-of-type(8),
.letter-paper p:nth-of-type(12),
.letter-paper p:nth-of-type(15),
.letter-paper p:nth-of-type(17),
.letter-paper p:nth-of-type(19) {
  margin-bottom: clamp(16px, 2vh, 24px);
}

.dla-copy {
  justify-self: stretch;
  display: grid;
  justify-items: center;
  gap: 22px;
  color: var(--text);
  text-align: center;
}

.dla-copy p {
  margin: 0;
  font-family: "Poor Story", "Gowun Dodum", sans-serif;
  font-size: clamp(30px, 4.6vw, 62px);
  line-height: 1.05;
}

.dla-toggle {
  display: inline-grid;
  grid-template-columns: 18px auto;
  align-items: center;
  gap: 10px;
  width: auto;
  min-height: 42px;
  padding: 0 18px;
  border-color: rgba(255, 255, 255, 0.6);
  border-radius: 999px;
}

.dla-toggle-knob {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: #39ff88;
  box-shadow: 0 0 18px rgba(57, 255, 136, 0.78);
}

.dla-toggle[aria-pressed="false"] .dla-toggle-knob {
  background: #ff4a4a;
  box-shadow: 0 0 18px rgba(255, 74, 74, 0.7);
}

.dla-meter {
  width: min(220px, 70%);
  height: 2px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.18);
}

.dla-meter-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: #ffffff;
  transform: scaleX(0);
  transform-origin: left;
}

.dla-photo {
  position: relative;
  width: min(62vw, 720px);
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #050505;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.58);
}

#dla-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.division-photo::before {
  display: none;
}

.division-photo.is-drawing::before {
  opacity: 0;
}

#division-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

@media (max-width: 720px) {
  h1 {
    font-size: 26px;
  }

  .password-hint {
    margin-bottom: 28px;
    font-size: 16px;
  }

  .book-stage {
    width: 100vw;
    min-height: 100vh;
    overflow: hidden;
  }

  .card {
    width: min(64vw, 260px);
    transform:
      translateX(calc(var(--open) * 54px))
      rotateZ(calc(var(--open) * 0.7deg));
  }

  .details {
    padding: 24px 16px 18px 20px;
  }

  .details h2 {
    margin-bottom: 18px;
    font-size: 27px;
  }

  .details p {
    margin-bottom: 7px;
    font-size: 14.5px;
    line-height: 1.25;
  }

  .memory-stage {
    grid-template-columns: 1fr;
    gap: 24px;
    width: min(100vw - 32px, 480px);
  }

  .dla-stage {
    grid-template-columns: 1fr;
    gap: 24px;
    width: min(100vw - 32px, 480px);
  }

  .letter-stage {
    width: min(100vw - 24px, 480px);
  }

  .letter-paper {
    max-height: 84vh;
    padding: 24px 20px;
  }

  .letter-paper p {
    font-size: clamp(13px, 3.45vw, 15px);
    line-height: 1.45;
  }

  .memory-copy {
    justify-self: stretch;
    font-size: clamp(34px, 12vw, 54px);
  }

  .division-photo {
    width: min(88vw, 420px);
    justify-self: center;
  }

  .dla-photo {
    width: min(88vw, 420px);
    justify-self: center;
  }
}
