/* 달까지 냥냥: 타이포그래피 포스터 테마
   파란 잉크 한 면 위에 흰 글자와 분홍 글자를 12칸 격자로 앉힌다.
   첫 장(파랑)은 게임과 점수판, 둘째 장(분홍)은 댓글이다. */

:root {
  --blue: #1a2bc8;        /* 바탕 잉크 */
  --navy: #0b1250;        /* 게임 자리, 분홍 위 글자 */
  --pink: #ff6fb5;        /* 둘째 잉크. 파랑 위에서는 큰 글자에만 쓴다 */
  --pink-light: #ffd6ea;  /* 분홍 면 위 입력칸 */
  --paper: #ffffff;
  --pale: #c9d0ff;        /* 파랑 위 덜 중요한 글자 */
  --plum: #3a1340;        /* 분홍 위 덜 중요한 글자 */
  --rule: rgba(255, 255, 255, 0.32);
  --guide: rgba(255, 255, 255, 0.1);

  --margin: 40px;
  --gutter: 24px;

  --display: 'Hahmlet', serif;
  --text: 'Gothic A1', sans-serif;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  color-scheme: dark;
  scrollbar-color: var(--pink) var(--navy);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--blue);
  color: var(--paper);
  font-family: var(--text);
  font-size: 16px;
  line-height: 1.6;
  word-break: keep-all;      /* 한글이 낱자 중간에서 끊기지 않게 한다 */
  overflow-wrap: anywhere;   /* 아주 긴 글자는 칸 안에서 줄을 바꾼다 */
  caret-color: var(--pink);
}

::selection {
  background: var(--pink);
  color: var(--navy);
}

button {
  font: inherit;
  color: inherit;
}

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

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

/* ---------- 첫 장: 포스터 격자 ---------- */

.poster {
  position: relative;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: auto auto 1fr;
  column-gap: var(--gutter);
  row-gap: 20px;
  min-height: 100vh;
  min-height: 100svh;
  padding: 24px var(--margin) 32px;
}

.poster > * {
  position: relative;
  z-index: 1;
  min-width: 0;
}

/* 칸 경계 안내선: 본문과 같은 12칸 격자를 바탕에 깐다 */
.poster > .guides {
  position: absolute;
  inset: 0 var(--margin);
  z-index: 0;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gutter);
  pointer-events: none;
}

.guides span {
  border-left: 1px solid var(--guide);
  border-right: 1px solid var(--guide);
}

/* 위 띠: 제작자, 장르, 플랫폼, 제작 도구를 세 칸씩 나눠 앉힌다 */
.credits {
  grid-column: 1 / -1;
  grid-row: 1;
  display: grid;
  grid-template-columns: subgrid;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}

.credits div {
  grid-column: span 3;
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.credits dt {
  font-size: 13px;
  font-weight: 700;
  color: var(--pale);
}

.credits dd {
  font-size: 16px;
  font-weight: 800;
}

/* 제목: 포스터의 주인공 */
.title {
  grid-column: 1 / 10;
  grid-row: 2;
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(56px, min(12.4vw, 21vh), 196px);
  line-height: 0.94;
  letter-spacing: -0.045em;
  white-space: nowrap;
}

.title-word {
  display: inline-block;
  animation: rise 0.9s var(--ease-out) both;
}

.title-pink {
  color: var(--pink);
  animation-delay: 0.12s;
}

@keyframes rise {
  from {
    transform: translateY(0.22em);
  }
  to {
    transform: none;
  }
}

.tagline {
  grid-column: 10 / 13;
  grid-row: 2;
  align-self: end;
  padding-bottom: 0.4em;
  font-family: var(--display);
  font-weight: 700;
  font-size: 24px;
  line-height: 1.3;
}

/* ---------- 게임 자리 ---------- */

.stage {
  grid-column: 5 / 9;
  grid-row: 3;
  display: flex;
  justify-content: center;
  gap: 10px;
  min-height: 0;
}

/* 세로 눈금자: 아래에서 위로 읽는 글자와 눈금 */
.ruler {
  flex: none;
  writing-mode: vertical-rl;
  text-orientation: sideways;
  transform: rotate(180deg);
  padding-right: 18px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--pale);
  position: relative;
}

/* 눈금: 16px 마다 짧은 눈금, 80px 마다 긴 눈금 (ruler.svg 한 장을 세로로 되풀이) */
.ruler::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 12px;
  background: url("ruler.svg") right top / 12px 80px repeat-y;
}

/* 게임 자리 둘레의 재단선: 네 모서리에 인쇄물 재단 표시를 놓는다 */
.slot-frame {
  height: 100%;
  padding: 14px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M0 13.5h12M13.5 0v12' stroke='white' fill='none'/%3E%3C/svg%3E") left top / 14px 14px no-repeat,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M2 13.5h12M0.5 0v12' stroke='white' fill='none'/%3E%3C/svg%3E") right top / 14px 14px no-repeat,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M0 0.5h12M13.5 2v12' stroke='white' fill='none'/%3E%3C/svg%3E") left bottom / 14px 14px no-repeat,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M2 0.5h12M0.5 2v12' stroke='white' fill='none'/%3E%3C/svg%3E") right bottom / 14px 14px no-repeat;
}

#game-slot {
  position: relative;
  height: 100%;
  aspect-ratio: 9 / 16;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
  background: var(--navy);
}

/* 게임 화면은 게임 자리를 꽉 채운다.
   손가락 동작은 canvas 안에서만 게임이 받고, 페이지의 스크롤과 확대는 그대로 둔다. */
#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* 시작 단추와 안내 문구를 canvas 위에 놓는다 */
#game-start,
#game-status {
  position: relative;
}

#game-start {
  min-height: 60px;
  padding: 0 34px;
  border: 0;
  background: var(--pink);
  color: var(--navy);
  font-family: var(--display);
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -0.02em;
  cursor: pointer;
  transition: background-color 0.2s var(--ease-out);
}

#game-start:hover {
  background: var(--paper);
}

#game-start:focus-visible {
  outline-color: var(--paper);
  outline-offset: 5px;
}

.slot-label {
  padding: 12px 18px;
  border: 1px solid var(--paper);
  background: var(--navy);
  font-size: 15px;
  font-weight: 700;
  text-align: center;
}

/* ---------- 소개와 조작 ---------- */

.intro {
  grid-column: 1 / 5;
  grid-row: 3;
  display: flex;
  flex-direction: column;
}

.lead {
  max-width: 24em;
  font-family: var(--display);
  font-weight: 500;
  font-size: 20px;
  line-height: 1.6;
}

.small-head {
  margin-top: 32px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
  font-size: 13px;
  font-weight: 800;
  color: var(--pale);
}

.controls {
  list-style: none;
  padding: 0;
}

.controls li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 15px;
}

.keys {
  flex: none;
  display: inline-flex;
  gap: 6px;
  min-width: 94px;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
  border: 2px solid var(--paper);
  font-family: var(--text);
  font-size: 14px;
  font-weight: 800;
}

kbd svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: square;
}

.key-word {
  padding: 0 12px;
}

/* ---------- 점수판 ---------- */

#scoreboard {
  grid-column: 9 / 13;
  grid-row: 3;
  display: flex;
  flex-direction: column;
}

.board-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 6px;
  border-bottom: 3px solid var(--paper);
}

.board-head h2 {
  font-family: var(--display);
  font-weight: 900;
  font-size: 44px;
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.board-limit {
  font-size: 13px;
  font-weight: 700;
  color: var(--pale);
}

.scores {
  list-style: none;
  padding: 0;
}

.scores li {
  display: grid;
  grid-template-columns: 2.4rem minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--rule);
  font-variant-numeric: tabular-nums;
}

.rank {
  font-family: var(--display);
  font-weight: 900;
  font-size: 20px;
  color: var(--pale);
}

.name {
  font-family: var(--display);
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.14em;
}

.points {
  font-weight: 800;
  font-size: 17px;
}

/* 1~3등: 순위 숫자를 분홍으로. 1등은 줄 전체를 크게 쓴다. */
.scores .first .rank,
.scores .second .rank,
.scores .third .rank {
  color: var(--pink);
}

.scores .first {
  padding: 4px 0 8px;
}

.scores .first .rank,
.scores .first .name {
  font-size: 34px;
  line-height: 1.15;
}

.scores .first .name {
  color: var(--pink);
}

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

.scores li.soft {
  display: block;
  padding: 16px 0;
  font-size: 15px;
  color: var(--pale);
}

/* 방금 올린 줄: 분홍으로 칠하고 세 번 깜빡인다 */
.scores li.just-added {
  background: var(--pink);
  box-shadow: -8px 0 0 var(--pink), 8px 0 0 var(--pink);
  animation: just-added 0.7s ease-out 3;
}

.scores li.just-added span {
  color: var(--navy);
}

@keyframes just-added {
  from {
    background: var(--paper);
    box-shadow: -8px 0 0 var(--paper), 8px 0 0 var(--paper);
  }
}

.board-note {
  margin-top: 12px;
  font-size: 14px;
  color: var(--pale);
}

/* ---------- 둘째 장: 댓글 ---------- */

.sheet-pink {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gutter);
  row-gap: 32px;
  padding: 72px var(--margin) 88px;
  background: var(--pink);
  color: var(--navy);
  caret-color: var(--navy);
}

.sheet-pink ::selection {
  background: var(--navy);
  color: var(--pink);
}

.sheet-pink :focus-visible {
  outline-color: var(--navy);
}

.sheet-title {
  grid-column: 1 / 5;
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(80px, 11vw, 168px);
  line-height: 0.9;
  letter-spacing: -0.05em;
}

.comment-body {
  grid-column: 5 / 13;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 40px var(--gutter);
  align-items: start;
}

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 14px;
  font-weight: 800;
}

.field input,
.field textarea {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 2px solid var(--navy);
  border-radius: 0;
  background: var(--pink-light);
  color: var(--navy);
  font-family: var(--text);
  font-size: 16px;
}

.field textarea {
  padding: 10px 14px;
  resize: vertical;
}

.field input::placeholder,
.field textarea::placeholder {
  color: #6b2a5e;
  opacity: 1;
}

.field input:focus-visible,
.field textarea:focus-visible {
  outline: 3px solid var(--navy);
  outline-offset: 2px;
}

.form-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 20px;
}

#comment-submit {
  min-height: 52px;
  padding: 0 28px;
  border: 0;
  background: var(--navy);
  color: var(--paper);
  font-family: var(--display);
  font-weight: 800;
  font-size: 19px;
  cursor: pointer;
  transition: background-color 0.2s var(--ease-out);
}

#comment-submit:hover {
  background: var(--blue);
}

#comment-submit:disabled {
  opacity: 0.6;
  cursor: default;
}

#comment-message {
  padding-top: 10px;
  border-top: 2px solid var(--navy);
  font-size: 15px;
  font-weight: 700;
}

.comments {
  list-style: none;
  padding: 0;
  border-bottom: 2px solid var(--navy);
}

.comments li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 0 16px;
  border-top: 2px solid var(--navy);
}

.comment-nickname {
  font-family: var(--display);
  font-weight: 800;
  font-size: 20px;
}

.comment-text {
  font-size: 16px;
  white-space: pre-wrap;   /* 입력한 줄바꿈을 그대로 보여 준다 */
}

/* 닉네임 없이 글 한 줄만 있는 줄(빈 상태, 오류 문구)은 한 단계 낮춘다 */
.comments li:not(:has(.comment-nickname)) {
  border-top-style: dashed;
  color: var(--plum);
}

/* ---------- 맨 아래 ---------- */

.colophon {
  overflow: hidden;
  padding: 28px var(--margin) 0;
  background: var(--blue);
}

.colophon p {
  font-size: 14px;
  font-weight: 700;
  color: var(--pale);
}

/* 아래 가장자리에서 잘린 큰 글자 */
.colophon .colophon-giant {
  margin: 8px 0 -0.14em;
  font-family: var(--display);
  font-weight: 900;
  font-size: 22vw;
  line-height: 1;
  letter-spacing: -0.06em;
  white-space: nowrap;
  color: var(--pink);
}

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

#initials-dialog {
  width: min(400px, calc(100vw - 32px));
  padding: 28px 24px 24px;
  border: 0;
  border-top: 10px solid var(--pink);
  border-radius: 0;
  background: var(--blue);
  color: var(--paper);
  box-shadow: 0 24px 60px rgba(5, 9, 40, 0.55);
}

#initials-dialog[open] {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

#initials-dialog::backdrop {
  background: rgba(11, 18, 80, 0.82);
}

#initials-dialog h2 {
  font-family: var(--display);
  font-weight: 900;
  font-size: 34px;
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.dialog-help {
  font-size: 15px;
  color: var(--pale);
}

.initials-slots {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 6px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.initial-slot {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 8px 0;
  cursor: pointer;
}

.initial-letter {
  position: relative;
  padding-bottom: 6px;
  font-family: var(--display);
  font-weight: 900;
  font-size: 68px;
  line-height: 1.05;
  text-align: center;
}

/* 키보드로 친 글자가 들어갈 칸: 글자를 분홍으로, 밑에 분홍 줄을 긋는다 */
.initial-slot.active .initial-letter {
  color: var(--pink);
}

.initial-slot.active .initial-letter::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: 0;
  height: 5px;
  background: var(--pink);
}

/* 휴대폰에서 누르기 쉽게 높이 48px, 너비는 칸을 꽉 채운다 */
.initial-step {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  min-width: 48px;
  border: 2px solid var(--rule);
  background: transparent;
  cursor: pointer;
  transition: border-color 0.15s var(--ease-out), background-color 0.15s var(--ease-out);
}

.initial-step svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: var(--paper);
  stroke-width: 2.6;
  stroke-linecap: square;
}

.initial-step:hover {
  border-color: var(--paper);
  background: rgba(255, 255, 255, 0.08);
}

#initials-message {
  font-size: 15px;
  font-weight: 700;
}

.initials-actions {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 10px;
}

.initials-actions button {
  min-height: 54px;
  border: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: 19px;
  cursor: pointer;
}

#initials-cancel {
  border: 2px solid var(--paper);
  background: transparent;
  color: var(--paper);
}

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

#initials-confirm {
  background: var(--pink);
  color: var(--navy);
}

#initials-confirm:hover {
  background: var(--paper);
}

.initials-actions button:disabled {
  opacity: 0.55;
  cursor: default;
}

/* ---------- 태블릿과 작은 컴퓨터 ---------- */

@media (max-width: 1080px) {
  :root {
    --margin: 28px;
    --gutter: 20px;
  }

  .poster {
    grid-template-rows: auto auto auto auto;
    row-gap: 24px;
  }

  .title {
    grid-column: 1 / -1;
    font-size: clamp(56px, 13vw, 140px);
  }

  .tagline {
    grid-column: 1 / -1;
    grid-row: 3;
    align-self: start;
    padding-bottom: 0;
  }

  .stage {
    grid-column: 1 / 7;
    grid-row: 4 / span 2;
    align-self: start;
  }

  .slot-frame {
    height: auto;
    width: min(100%, calc((100svh - 32px) * 9 / 16 + 28px));
  }

  #game-slot {
    width: 100%;
    height: auto;
  }

  .intro {
    grid-column: 7 / 13;
    grid-row: 4;
  }

  #scoreboard {
    grid-column: 7 / 13;
    grid-row: 5;
  }

  .sheet-title {
    grid-column: 1 / -1;
  }

  .comment-body {
    grid-column: 1 / -1;
  }
}

/* ---------- 휴대폰: 제목, 게임, 소개, 점수판, 정보 순서로 쌓는다 ---------- */

@media (max-width: 720px) {
  :root {
    --margin: 16px;
    --gutter: 12px;
  }

  .poster,
  .poster > .guides,
  .sheet-pink {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .guides span:nth-child(n + 5) {
    display: none;
  }

  .poster {
    grid-template-rows: none;
    row-gap: 14px;
    padding-top: 14px;
  }

  .poster > * {
    grid-column: 1 / -1;
    grid-row: auto;
  }

  .title {
    order: 1;
    font-size: min(16vw, 72px);
  }

  .tagline {
    order: 2;
    font-size: 17px;
  }

  .tagline br {
    display: none;
  }

  .stage {
    order: 3;
    grid-row: auto;
    justify-content: center;
  }

  /* 휴대폰 세로 화면에서 게임 자리가 화면 높이를 넘지 않게 한다 */
  .slot-frame {
    width: min(100%, calc((100svh - 40px) * 9 / 16 + 28px));
  }

  .ruler {
    display: none;
  }

  .intro {
    order: 4;
    margin-top: 16px;
  }

  #scoreboard {
    order: 5;
    grid-column: 1 / -1;
    margin-top: 28px;
  }

  .credits {
    order: 6;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px var(--gutter);
    margin-top: 28px;
    padding-top: 14px;
    padding-bottom: 0;
    border-top: 1px solid var(--rule);
    border-bottom: 0;
  }

  .credits div {
    grid-column: auto;
    flex-direction: column;
    gap: 0;
  }

  .lead {
    font-size: 18px;
  }

  .sheet-pink {
    padding: 48px var(--margin) 64px;
    row-gap: 24px;
  }

  .comment-body {
    grid-template-columns: minmax(0, 1fr);
    gap: 32px;
  }

  .colophon .colophon-giant {
    font-size: 40vw;
  }

  .initial-letter {
    font-size: 60px;
  }
}

/* 움직임을 줄이도록 설정한 사람에게는 등장과 깜빡임을 끈다 */
@media (prefers-reduced-motion: reduce) {
  .title-word,
  .scores li.just-added {
    animation: none;
  }

  #game-start,
  #comment-submit,
  .initial-step {
    transition: none;
  }
}
