/* 냥냥일보 호외: 「달까지 냥냥」 을 1면 특종으로 다룬 신문 지면
   신문 용지 바탕, 먹색 글자, 호외용 붉은 별색 하나. 게임 자리는 1면 보도사진이다. */

:root {
  --paper: #e3e3df;        /* 신문 용지: 누런 크림색이 아닌 회색빛 갱지 */
  --paper-deep: #d4d4ce;   /* 상자 바탕 */
  --paper-light: #f1f1ee;  /* 입력칸 */
  --ink: #16161a;          /* 먹 */
  --ink-soft: #3b3a40;     /* 덜 중요한 글자 */
  --red: #b0141f;          /* 호외 별색 */
  --red-deep: #8d0f18;
  --red-wash: #f0d3cf;     /* 방금 올린 기록 */
  --night: #15173d;        /* 보도사진 밤하늘 */
  --pink: #ff8fc4;

  --serif: 'Nanum Myeongjo', serif;
  --head: 'Hahmlet', 'Nanum Myeongjo', serif;
  --gothic: 'Gothic A1', sans-serif;

  --page-width: 1360px;
  --gutter: 32px;

  /* 컴퓨터에서 첫 화면 안에 보도사진이 다 들어오도록 창 높이에 맞춘다 */
  --slot-height: clamp(460px, calc(100vh - 250px), 700px);
}

* {
  box-sizing: border-box;
}

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

html {
  background: var(--paper);
  scrollbar-color: var(--ink-soft) var(--paper-deep);
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.7;
  word-break: keep-all;      /* 한글이 낱자 중간에서 끊기지 않게 한다 */
  overflow-wrap: anywhere;   /* 아주 긴 글자는 칸 안에서 줄을 바꾼다 */
  /* 신문 용지의 거친 결 */
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.1 0 0 0 0 0.1 0 0 0 0 0.08 0 0 0 0.07 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E"),
    var(--paper);
}

::selection {
  background: var(--red);
  color: #fff;
}

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

/* ---------- 제호 ---------- */

.masthead {
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 18px var(--gutter) 0;
}

.masthead-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding-bottom: 12px;
}

.ear {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 170px;
  padding: 8px 12px;
  border: 1px solid var(--ink);
  font-family: var(--gothic);
  font-size: 13px;
  line-height: 1.45;
}

.ear strong {
  font-weight: 900;
}

.ear-right {
  justify-self: end;
  text-align: right;
}

.nameplate {
  display: flex;
  align-items: center;
  gap: 18px;
}

.nameplate h1 {
  position: relative;
  font-family: var(--head);
  font-weight: 900;
  font-size: 84px;
  line-height: 1;
  letter-spacing: -0.03em;
}

/* 제호 오른쪽 위의 작은 초승달 */
.nameplate-moon {
  position: absolute;
  top: -6px;
  right: -26px;
  width: 26px;
  height: 26px;
  fill: var(--red);
}

/* 호외 도장: 붉은 네모 안에 두 글자를 세로로 찍는다 */
.extra-stamp {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 68px;
  height: 84px;
  background: var(--red);
  color: #fff;
  font-family: var(--gothic);
  font-weight: 900;
  font-size: 30px;
  line-height: 1.05;
  box-shadow: inset 0 0 0 3px var(--red), inset 0 0 0 5px #fff;
  transform: rotate(-4deg);
  animation: stamp 0.55s cubic-bezier(0.16, 1, 0.3, 1) 0.15s both;
}

@keyframes stamp {
  from {
    transform: rotate(-12deg) scale(1.45);
    filter: blur(1px);
  }
  to {
    transform: rotate(-4deg) scale(1);
    filter: blur(0);
  }
}

/* 제호 아래 두 줄 괘선 사이의 발행 줄 */
.dateline {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 24px;
  padding: 6px 0;
  border-top: 4px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  box-shadow: 0 -7px 0 -6px var(--ink);
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 13px;
}

/* ---------- 1면 배치 ---------- */

.front {
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 22px var(--gutter) 36px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 0 28px;
  align-items: start;
}

.lead-story {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 0 24px;
  align-items: start;
}

/* 세로쓰기 머리기사 제목: 옛 신문처럼 위에서 아래로 읽는다 */
.vertical-head {
  writing-mode: vertical-rl;
  font-family: var(--head);
  font-weight: 900;
  font-size: clamp(48px, 7.4vh, 68px);
  line-height: 1.12;
  letter-spacing: 0.02em;
}

.vertical-head span {
  display: block;
}

.head-red {
  color: var(--red);
}

/* ---------- 보도사진: 게임 자리 ---------- */

.lead-photo {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#game-slot {
  position: relative;
  width: calc(var(--slot-height) * 9 / 16);
  aspect-ratio: 9 / 16;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: hidden;
  background: var(--night) url("photo.svg") center / cover no-repeat;
  border: 1px solid var(--ink);
  outline: 1px solid var(--ink);
  outline-offset: 3px;
}

/* 게임 화면은 게임 자리를 꽉 채운다.
   손가락 동작은 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 {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 0 26px 0 20px;
  border: 0;
  background: var(--red);
  color: #fff;
  font-family: var(--gothic);
  font-weight: 900;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 0 0 3px var(--paper), 0 10px 24px rgba(5, 6, 25, 0.55);
  transition: background-color 0.2s ease-out;
}

/* 게임이 켜지면 app.js 가 hidden 을 붙인다. 위의 display 가 hidden 을 덮지 않게 한다. */
#game-start[hidden] {
  display: none;
}

#game-start svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

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

#game-start:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 5px;
}

.slot-label {
  padding: 10px 16px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  border: 1px solid var(--ink);
}

.lead-photo figcaption {
  max-width: calc(var(--slot-height) * 9 / 16);
  font-family: var(--gothic);
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
}

/* ---------- 본문 ---------- */

.story-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-left: 24px;
  border-left: 1px solid var(--ink);
  max-width: 62ch;
}

.deck {
  font-family: var(--head);
  font-weight: 800;
  font-size: 26px;
  line-height: 1.35;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--ink);
}

.byline {
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 13px;
}

.lede {
  font-weight: 800;
}

/* 첫 글자를 크게: 머리기사 본문의 시작 */
.lede::first-letter {
  float: left;
  margin: 6px 8px 0 0;
  font-family: var(--head);
  font-weight: 900;
  font-size: 54px;
  line-height: 0.9;
  color: var(--red);
}

.howto,
.facts {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px 16px;
  background: var(--paper-deep);
  border-top: 3px solid var(--ink);
}

.howto h3,
.facts h3 {
  font-family: var(--gothic);
  font-weight: 900;
  font-size: 16px;
}

.controls {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.controls li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.keys {
  display: inline-flex;
  gap: 6px;
}

kbd {
  min-width: 36px;
  padding: 2px 9px;
  border: 1px solid var(--ink);
  border-bottom-width: 3px;
  background: var(--paper-light);
  color: var(--ink);
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 15px;
  text-align: center;
}

.facts dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 20px;
}

.facts dl div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 4px;
  border-bottom: 1px dotted var(--ink);
}

.facts dt {
  font-family: var(--gothic);
  font-size: 14px;
  color: var(--ink-soft);
}

.facts dd {
  font-weight: 800;
}

/* ---------- 오른쪽 단: 기록 소식 ---------- */

.records {
  padding-left: 24px;
  border-left: 3px double var(--ink);
}

#scoreboard {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.records-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  background: var(--ink);
  color: var(--paper);
}

.records-head h2 {
  font-family: var(--head);
  font-weight: 900;
  font-size: 24px;
  line-height: 1.3;
}

.records-head span {
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 13px;
}

.records-note {
  font-size: 15px;
  line-height: 1.6;
}

.scores {
  list-style: none;
  padding: 0;
  font-family: var(--gothic);
  font-variant-numeric: tabular-nums;
}

.scores li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--ink);
}

.scores li:last-child {
  border-bottom: 0;
}

.rank {
  flex: none;
  width: 22px;
  font-weight: 900;
  text-align: right;
}

/* 이니셜과 점수 사이를 점선으로 잇는다 (시세표처럼) */
.name {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.name::after {
  content: "";
  flex: 1;
  border-bottom: 2px dotted var(--ink-soft);
}

.points {
  font-weight: 700;
}

/* 1위: 붉은 별색으로 크게 */
.scores .first {
  padding: 10px 4px 12px;
  border-bottom: 3px solid var(--ink);
}

.first .rank,
.first .name,
.first .points {
  font-size: 22px;
  font-weight: 900;
}

.first .rank,
.first .points {
  color: var(--red);
}

.second .rank,
.third .rank {
  color: var(--red);
}

/* 빈 상태와 오류 안내 줄 */
.scores li.soft,
.comments li.soft {
  display: block;
  padding: 14px 4px;
  font-family: var(--serif);
  font-style: normal;
  color: var(--ink-soft);
  border-bottom: 0;
}

/* 방금 올린 기록: 붉은 바탕을 깔았다가 걷어 낸다 */
.scores li.just-added {
  background: var(--red-wash);
  outline: 2px solid var(--red);
  outline-offset: 0;
  animation: just-added-ink 1.2s cubic-bezier(0.16, 1, 0.3, 1) 2;
}

@keyframes just-added-ink {
  from {
    background: var(--red);
    color: #fff;
  }
  to {
    background: var(--red-wash);
  }
}

/* ---------- 독자 투고 ---------- */

.letters {
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 0 var(--gutter) 40px;
}

.letters > h2 {
  padding: 10px 0 8px;
  border-top: 4px solid var(--ink);
  box-shadow: 0 -7px 0 -6px var(--ink);
  font-family: var(--head);
  font-weight: 900;
  font-size: 34px;
  line-height: 1.2;
}

.letters-grid {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 0 28px;
  padding-top: 14px;
  border-top: 1px solid var(--ink);
}

.letter-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.field label {
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 14px;
}

.field input,
.field textarea {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper-light);
  color: var(--ink);
  caret-color: var(--red);
  font-family: var(--serif);
  font-size: 17px;
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--ink-soft);
  opacity: 1;
}

/* 투고 내용 칸은 원고지처럼 붉은 칸을 깐다. 글이 길어지면 칸도 함께 올라간다. */
.field textarea {
  padding: 0 0 0 4px;
  line-height: 32px;
  resize: vertical;
  background:
    linear-gradient(to right, rgba(176, 20, 31, 0.22) 1px, transparent 1px) 4px 0 / 32px 32px local,
    linear-gradient(to bottom, rgba(176, 20, 31, 0.32) 1px, transparent 1px) 0 0 / 100% 32px local,
    var(--paper-light);
}

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

#comment-submit,
#initials-confirm {
  min-height: 48px;
  padding: 0 24px;
  border: 0;
  background: var(--red);
  color: #fff;
  font-family: var(--gothic);
  font-weight: 900;
  font-size: 18px;
  cursor: pointer;
  transition: background-color 0.2s ease-out;
}

#comment-submit {
  align-self: flex-start;
}

#comment-submit:hover,
#initials-confirm:hover {
  background: var(--red-deep);
}

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

#comment-message,
#initials-message {
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 15px;
  color: var(--red);
}

/* 실린 투고: 본문을 먼저, 필명을 끝에 서명처럼 둔다 */
.comments {
  list-style: none;
  padding: 0;
  columns: 2 260px;
  column-gap: 28px;
  column-rule: 1px solid var(--ink);
}

.comments li {
  break-inside: avoid;
  display: flex;
  flex-direction: column-reverse;
  gap: 4px;
  padding: 0 0 14px;
  margin-bottom: 14px;
  border-bottom: 1px dotted var(--ink);
}

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

.comment-nickname {
  align-self: flex-end;
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 14px;
}

.comment-nickname::before {
  content: "— ";
}

/* 필명 없이 안내 문구만 있는 줄 */
.comments li:not(:has(.comment-nickname)):not(.soft) .comment-text {
  color: var(--ink-soft);
}

.colophon {
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 10px var(--gutter) 28px;
}

.colophon p {
  padding-top: 8px;
  border-top: 1px solid var(--ink);
  font-family: var(--gothic);
  font-size: 13px;
  text-align: center;
}

/* ---------- 이니셜 창: 기록 접수 ---------- */

#initials-dialog {
  width: min(380px, calc(100vw - 32px));
  padding: 22px 22px 20px;
  border: 1px solid var(--ink);
  outline: 1px solid var(--ink);
  outline-offset: -6px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(10, 10, 20, 0.45);
  text-align: center;
}

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

#initials-dialog::backdrop {
  background: rgba(22, 22, 26, 0.62);
}

#initials-dialog h2 {
  padding-bottom: 10px;
  border-bottom: 3px double var(--ink);
  font-family: var(--head);
  font-weight: 900;
  font-size: 30px;
  line-height: 1.25;
}

.dialog-help {
  font-size: 15px;
  line-height: 1.6;
}

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

/* 이니셜 한 칸은 납 활자 한 벌처럼 보인다 */
.initial-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 2px solid transparent;
  cursor: pointer;
}

/* 키보드로 친 글자가 들어갈 칸 */
.initial-slot.active {
  border-color: var(--red);
}

.initial-letter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 72px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--head);
  font-weight: 900;
  font-size: 44px;
  line-height: 1;
}

.initial-slot.active .initial-letter {
  background: var(--red);
  color: #fff;
}

/* 휴대폰에서 누르기 쉽게 가로세로 44px 이상으로 만든다 */
.initial-step {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  min-height: 44px;
  border: 1px solid var(--ink);
  background: var(--paper-light);
  color: var(--ink);
  cursor: pointer;
}

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

.initial-step:hover {
  background: var(--paper-deep);
}

.initials-actions {
  display: flex;
  gap: 10px;
}

.initials-actions button {
  flex: 1;
  min-width: 44px;
}

.secondary-button {
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 17px;
  cursor: pointer;
}

.secondary-button:hover:not(:disabled) {
  background: var(--paper-deep);
}

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

/* ---------- 작은 컴퓨터, 태블릿: 기록 소식을 아래로 내린다 ---------- */

@media (max-width: 1180px) {
  .front {
    grid-template-columns: minmax(0, 1fr);
    gap: 28px;
  }

  .records {
    padding: 0;
    border-left: 0;
  }

  .scores {
    columns: 2 240px;
    column-gap: 28px;
    column-rule: 1px solid var(--ink);
  }

  .scores li {
    break-inside: avoid;
  }
}

@media (max-width: 960px) {
  .lead-story {
    grid-template-columns: auto auto;
  }

  .story-body {
    grid-column: 1 / -1;
    margin-top: 24px;
    padding: 18px 0 0;
    border-left: 0;
    border-top: 1px solid var(--ink);
    max-width: none;
  }

  .letters-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
  }
}

/* ---------- 휴대폰: 제호, 세로 제목과 사진, 본문, 기록, 투고 순서 ---------- */

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

  body {
    font-size: 16px;
  }

  .masthead {
    padding-top: 12px;
  }

  .masthead-row {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    gap: 0;
    padding-bottom: 8px;
  }

  .ear {
    display: none;
  }

  .nameplate {
    gap: 12px;
  }

  .nameplate h1 {
    font-size: 50px;
  }

  .nameplate-moon {
    width: 18px;
    height: 18px;
    right: -18px;
    top: -4px;
  }

  .extra-stamp {
    width: 44px;
    height: 54px;
    font-size: 19px;
    box-shadow: inset 0 0 0 2px var(--red), inset 0 0 0 3px #fff;
  }

  .dateline {
    justify-content: center;
    font-size: 12px;
    gap: 0 14px;
  }

  .dateline span:last-child {
    display: none;
  }

  .front {
    padding-top: 14px;
  }

  .lead-story {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0 12px;
  }

  .vertical-head {
    font-size: 30px;
  }

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

  .lead-photo figcaption {
    max-width: none;
  }

  .deck {
    font-size: 21px;
  }

  .facts dl {
    grid-template-columns: minmax(0, 1fr);
  }

  .scores {
    columns: auto;
  }

  .letters > h2 {
    font-size: 28px;
  }

  #comment-submit {
    align-self: stretch;
  }

  .comments {
    columns: auto;
  }

  .initial-letter {
    width: 60px;
  }

  .initial-step {
    width: 60px;
  }
}

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

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