/* 달까지 냥냥: 그림책 테마
   면지 무늬 위에 펼친 그림책 두 펼침을 놓는다.
   첫째 펼침은 그림(제목과 게임)과 이야기 글, 둘째 펼침은 점수판과 댓글이다. */

:root {
  --ink: #1c2560;
  --ink-soft: #4b4f80;
  --night: #172057;
  --moon: #ffcf3f;
  --moon-pale: #ffe7a1;
  --cat: #f58bb0;
  --cat-deep: #a8285a;
  --page-pink: #ffdfe9;
  --page-sky: #d5e9fc;
  --board: #7a2048;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .11 0 0 0 0 .14 0 0 0 0 .38 0 0 0 .08 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --spread-h: clamp(640px, calc(100svh - 64px), 820px);
  --display: "Gaegu", "Gowun Dodum", sans-serif;
  --body: "Gowun Dodum", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  scrollbar-color: var(--ink) #f4c02f;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f4c02f url("endpaper.svg") 0 0 / 180px 180px repeat;
  color: var(--ink);
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.7;
  word-break: keep-all;
  overflow-wrap: break-word;
  caret-color: var(--cat-deep);
}

::selection {
  background: var(--cat);
  color: var(--ink);
}

/* 개구체는 한글 자간이 넓어서 손글씨 제목과 단추는 조금 좁힌다 */
h1,
.how h2,
.page-head h2,
.folio,
.story strong,
.colophon dd,
.field label,
.comment-nickname,
.the-end,
#initials-title,
#game-start,
#comment-submit,
#initials-confirm,
#initials-cancel {
  letter-spacing: -0.035em;
}

h1,
h2,
p,
dl,
dd,
ol,
ul {
  margin: 0;
}

:focus-visible {
  outline: 3px solid var(--cat-deep);
  outline-offset: 3px;
}

button {
  font: inherit;
  cursor: pointer;
}

main {
  display: grid;
  justify-items: center;
  gap: 56px;
  padding: 32px 24px 40px;
}

/* ---------- 펼친 책 ---------- */

/* 책 표지 판이 쪽 둘레로 조금 드러나고, 가운데 접힌 자리에 그늘이 진다. */
.spread {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: min(1240px, 100%);
  padding: 12px;
  border-radius: 12px;
  background: var(--board);
  box-shadow:
    0 26px 50px -14px rgba(80, 40, 0, 0.5),
    0 4px 10px rgba(80, 40, 0, 0.22);
}

.spread::after {
  content: "";
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: 50%;
  width: 90px;
  transform: translateX(-50%);
  background: linear-gradient(
    to right,
    rgba(20, 10, 40, 0) 0%,
    rgba(20, 10, 40, 0.14) 40%,
    rgba(20, 10, 40, 0.32) 50%,
    rgba(20, 10, 40, 0.14) 60%,
    rgba(20, 10, 40, 0) 100%
  );
  pointer-events: none;
}

.page {
  position: relative;
  padding: 44px 56px 72px;
}

.page:first-child {
  border-radius: 6px 2px 2px 6px;
}

.page:last-child {
  border-radius: 2px 6px 6px 2px;
}

.page-pink {
  background: var(--grain), var(--page-pink);
}

.page-sky {
  background: var(--grain), var(--page-sky);
}

.page-night {
  background:
    var(--grain),
    url("stars.svg") 0 0 / 240px 240px repeat,
    linear-gradient(180deg, #121a4d 0%, #263380 100%);
  color: #eef0ff;
}

/* 쪽 번호 */
.folio {
  position: absolute;
  bottom: 22px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  line-height: 1;
}

.page:first-child .folio {
  left: 36px;
}

.page:last-child .folio {
  right: 36px;
}

/* ---------- 첫째 펼침 왼쪽: 제목과 게임 ---------- */

.spread-first .page {
  min-height: var(--spread-h);
}

.page-night {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding-top: 36px;
}

.title-block {
  text-align: center;
}

h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(52px, 5.4vw, 78px);
  line-height: 1;
}

.moon-word {
  color: var(--moon);
}

.cat-word {
  color: #ff9fc2;
}

.tagline {
  margin-top: 8px;
  font-size: 19px;
  color: #eef0ff;
}

#game-slot {
  position: relative;
  height: calc(var(--spread-h) - 250px);
  aspect-ratio: 9 / 16;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  overflow: hidden;
  background: #121a4d url("slot-cover.svg") center / cover no-repeat;
  box-shadow:
    0 0 0 4px var(--moon-pale),
    0 16px 30px rgba(5, 8, 30, 0.45);
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#game-start,
#game-status {
  position: relative;
}

#game-start {
  min-height: 58px;
  padding: 0 34px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--moon);
  color: var(--ink);
  font-family: var(--display);
  font-weight: 700;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(5, 8, 30, 0.45);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.2s;
}

#game-start:hover {
  background: #ffdc6b;
  transform: translateY(-2px);
}

#game-start:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 4px;
}

.slot-label {
  margin: 0 18px;
  padding: 12px 18px;
  border-radius: 14px;
  background: rgba(13, 19, 64, 0.88);
  color: #ffffff;
  font-size: 17px;
  text-align: center;
}

/* ---------- 첫째 펼침 오른쪽: 이야기 글 ---------- */

.spread-first .page-pink {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding-top: 40px;
}

.spot {
  width: 230px;
  height: auto;
  animation: hop 4.5s cubic-bezier(0.16, 1, 0.3, 1) 1s infinite;
  transform-origin: 30% 100%;
}

/* 고양이가 가끔 폴짝 뛴다 */
@keyframes hop {
  0%,
  72%,
  100% {
    transform: translateY(0);
  }
  80% {
    transform: translateY(-14px) rotate(-2deg);
  }
  88% {
    transform: translateY(0);
  }
}

.story {
  max-width: 30em;
}

.story p {
  font-size: 21px;
  line-height: 1.8;
}

.story p + p {
  margin-top: 12px;
}

.story strong {
  font-family: var(--display);
  font-weight: 700;
  font-size: 28px;
  line-height: 1;
  color: var(--cat-deep);
}

.how h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 28px;
  line-height: 1.2;
}

.controls {
  list-style: none;
  padding: 0;
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.controls li {
  display: flex;
  align-items: center;
  gap: 14px;
}

.keys {
  display: inline-flex;
  flex: none;
  justify-content: center;
  gap: 6px;
  min-width: 92px;
}

kbd {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 2.5px solid var(--ink);
  border-radius: 9px;
  background: #ffffff;
  box-shadow: 0 4px 8px -2px rgba(28, 37, 96, 0.35);
}

kbd svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.phone {
  width: 46px;
  height: 46px;
}

.phone rect {
  fill: #ffffff;
  stroke: var(--ink);
  stroke-width: 2.5;
}

.phone .tap {
  fill: var(--cat);
  stroke: var(--ink);
  stroke-width: 1.5;
}

/* 책 끝의 판권 자리처럼 게임 정보를 적는다 */
.colophon {
  margin-top: auto;
  padding-top: 18px;
  border-top: 2px dashed rgba(28, 37, 96, 0.4);
  display: grid;
  grid-template-columns: repeat(4, auto);
  justify-content: start;
  gap: 8px 36px;
}

.colophon dt {
  font-size: 15px;
  color: var(--ink-soft);
}

.colophon dd {
  font-family: var(--display);
  font-weight: 700;
  font-size: 24px;
  line-height: 1.2;
}

/* ---------- 둘째 펼침 ---------- */

.spread-second .page {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.page-head h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 46px;
  line-height: 1.1;
}

.unit {
  font-size: 15px;
  color: var(--ink-soft);
}

.note {
  font-size: 18px;
}

/* 점수판 */

.scores {
  list-style: none;
  padding: 0;
  margin-top: 10px;
}

.scores li {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 14px;
  min-height: 52px;
  padding: 4px 10px;
  border-bottom: 2px dotted rgba(28, 37, 96, 0.35);
}

.scores .rank {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 2.5px solid var(--ink);
  border-radius: 50%;
  background: #ffffff;
  font-family: var(--display);
  font-weight: 700;
  font-size: 21px;
  line-height: 1;
}

.scores .name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0.08em;
  line-height: 1.1;
}

.scores .points {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.scores li.first {
  min-height: 64px;
}

.scores li.first .rank {
  width: 46px;
  height: 46px;
  background: var(--moon);
  font-size: 25px;
}

.scores li.first .name {
  font-size: 32px;
}

.scores li.first .points {
  font-size: 23px;
}

.scores li.second .rank {
  background: var(--cat);
}

.scores li.third .rank {
  background: #9fcbf2;
}

/* 방금 올린 점수에는 형광펜을 긋는다 */
.scores li.just-added {
  background: linear-gradient(transparent 14%, #ffe17a 14%, #ffe17a 88%, transparent 88%) 0 0 / 100% 100% no-repeat;
  animation: marker 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes marker {
  from {
    background-size: 0% 100%;
  }
}

.scores li.soft,
.comments li.soft {
  display: block;
  margin-top: 6px;
  padding: 26px 16px;
  border: 2px dashed rgba(28, 37, 96, 0.4);
  border-radius: 14px;
  color: var(--ink-soft);
  text-align: center;
}

/* 점수판이 비면 아무도 밟지 않은 구름 계단을 그린다 */
.scores li.soft {
  padding-top: 176px;
  background: url("ladder.svg") center 26px / 220px auto no-repeat;
}

/* 댓글 */

.field {
  display: grid;
  gap: 2px;
}

.field label {
  font-family: var(--display);
  font-weight: 700;
  font-size: 23px;
  line-height: 1.3;
}

.field input,
.field textarea {
  width: 100%;
  border: 0;
  border-bottom: 2.5px solid var(--ink);
  border-radius: 0;
  background-color: transparent;
  color: var(--ink);
  font-family: var(--body);
  font-size: 18px;
}

.field input {
  min-height: 46px;
  padding: 6px 4px;
}

.field textarea {
  min-height: 112px;
  padding: 8px 4px;
  line-height: 1.7;
  resize: vertical;
}

.field input::placeholder,
.field textarea::placeholder {
  color: #6a5878;
}

.field input:focus-visible,
.field textarea:focus-visible {
  outline: 3px solid var(--cat-deep);
  outline-offset: 4px;
  border-radius: 4px;
}

#comment-submit,
#initials-confirm {
  min-height: 54px;
  padding: 0 30px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--moon-pale);
  font-family: var(--display);
  font-weight: 700;
  font-size: 25px;
  line-height: 1;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.2s;
}

#comment-submit {
  align-self: flex-start;
  margin-top: 6px;
}

#comment-submit:hover,
#initials-confirm:hover {
  background: #2a3684;
  transform: translateY(-2px);
}

#comment-submit:disabled,
#initials-confirm:disabled,
#initials-cancel:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.message {
  font-size: 17px;
  color: var(--cat-deep);
}

.comments {
  list-style: none;
  padding: 0;
  margin-top: 10px;
}

.comments li {
  padding: 14px 2px;
  border-top: 2px dotted rgba(28, 37, 96, 0.35);
}

.comments li.soft {
  border-top: 2px dashed rgba(28, 37, 96, 0.4);
}

.comment-nickname {
  font-family: var(--display);
  font-weight: 700;
  font-size: 23px;
  line-height: 1.3;
  color: var(--cat-deep);
}

.comment-text {
  margin-top: 2px;
  font-size: 18px;
  overflow-wrap: anywhere;
}

/* 끝맺음 */
.the-end {
  display: flex;
  align-items: center;
  gap: 18px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 44px;
  line-height: 1;
  color: var(--ink);
  padding: 10px 30px 14px;
  border-radius: 999px;
  background: var(--page-pink);
  box-shadow: 0 8px 18px -6px rgba(80, 40, 0, 0.4);
}

.the-end::before,
.the-end::after {
  content: "";
  width: 28px;
  height: 3px;
  border-radius: 2px;
  background: var(--ink);
}

/* ---------- 이니셜 창 ---------- */

#initials-dialog {
  width: min(420px, calc(100vw - 24px));
  padding: 30px 24px 24px;
  border: 0;
  border-radius: 18px;
  background: var(--grain), var(--page-pink);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 30px 60px -10px rgba(5, 8, 30, 0.6);
}

#initials-dialog[open] {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#initials-dialog::backdrop {
  background: rgba(13, 19, 64, 0.72);
}

#initials-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 36px;
  line-height: 1.15;
}

.dialog-help {
  font-size: 17px;
}

.initials-slots {
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* 칸마다 알파벳 나무 블록 하나. 지금 칠 칸은 점선 테두리로 두른다. */
.initial-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 3px dashed transparent;
  border-radius: 18px;
  cursor: pointer;
}

.initial-slot.active {
  border-color: var(--cat-deep);
}

.initial-letter {
  display: grid;
  place-items: center;
  width: 74px;
  height: 76px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #ffd85c;
  box-shadow: 0 6px 12px -3px rgba(28, 37, 96, 0.4);
  font-family: var(--display);
  font-weight: 700;
  font-size: 54px;
  line-height: 1;
}

.initial-slot:nth-child(2) .initial-letter {
  background: #ffb3cc;
}

.initial-slot:nth-child(3) .initial-letter {
  background: #a9d3f5;
}

.initial-step {
  display: grid;
  place-items: center;
  width: 58px;
  height: 48px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: #ffffff;
  color: var(--ink);
}

.initial-step svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.initial-step:hover {
  background: var(--moon-pale);
}

.initials-actions {
  display: flex;
  gap: 12px;
  width: 100%;
}

.initials-actions button {
  flex: 1;
}

#initials-cancel {
  min-height: 54px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-family: var(--display);
  font-weight: 700;
  font-size: 25px;
  line-height: 1;
}

#initials-cancel:hover {
  background: rgba(255, 255, 255, 0.7);
}

/* ---------- 좁은 화면: 쪽을 한 장씩 세로로 쌓는다 ---------- */

@media (max-width: 1100px) {
  .page {
    padding: 40px 36px 68px;
  }

  .colophon {
    grid-template-columns: repeat(2, auto);
  }
}

@media (max-width: 860px) {
  main {
    gap: 32px;
    padding: 12px 10px 28px;
  }

  .spread {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .spread::after {
    display: none;
  }

  .page:first-child {
    border-radius: 6px 6px 2px 2px;
  }

  .page:last-child {
    border-radius: 2px 2px 6px 6px;
  }

  .page + .page {
    border-top: 2px solid rgba(28, 37, 96, 0.12);
  }

  .spread-first .page {
    min-height: 0;
  }

  .page {
    padding: 28px 22px 60px;
  }

  .page:first-child .folio {
    left: 22px;
  }

  .page:last-child .folio {
    right: 22px;
  }

  .page-night {
    gap: 16px;
    padding: 18px 14px 52px;
  }

  h1 {
    font-size: 50px;
  }

  .tagline {
    margin-top: 4px;
    font-size: 17px;
  }

  /* 휴대폰 화면 높이 안에 게임 자리가 다 들어가게 한다 */
  #game-slot {
    height: min(calc(100svh - 160px), calc((100vw - 68px) * 16 / 9));
  }

  .spot {
    width: 180px;
  }

  .story p {
    font-size: 19px;
  }

  .page-head h2 {
    font-size: 40px;
  }

  .scores li {
    gap: 10px;
    padding: 4px 4px;
  }

  .scores .name {
    font-size: 24px;
  }

  .scores li.first .name {
    font-size: 28px;
  }

  .initial-letter {
    width: 66px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spot,
  .scores li.just-added {
    animation: none;
  }

  #game-start,
  #comment-submit,
  #initials-confirm {
    transition: none;
  }

  #game-start:hover,
  #comment-submit:hover,
  #initials-confirm:hover {
    transform: none;
  }
}
