/* 배치: 낮은 해질녘 배너 위, 그 아래 게임 · 소개 · 점수 세 칸. 휴대폰에서는 한 줄로 쌓는다. */
:root {
  color-scheme: dark;
  /* 페이지: 보랏빛 해질녘 */
  --night: #1b1430;
  --panel: #251c3f;
  --line: #43356a;
  --dusk-top: #5d4b8c;
  --dusk-low: #c4a3c9;
  --ink: #f2edf9;
  --muted: #b6abcf;
  --title-ink: #1b1430;
  --glow: #f6cf5e;
  --glow-ink: #2a1d05;
  --error: #ff9b9b;
  /* 게임 화면: 하늘 → 남색 → 우주 */
  --sky: #a7dcf2;
  --navy: #26397a;
  --void: #04050c;
  --suit: #ffffff;
  --visor: #8fb4d9;

  /* 인터넷 글꼴 없이 컴퓨터에 있는 글꼴만 쓴다 */
  --font-body: "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  --font-display: var(--font-body);

  /* 배너 높이 (게임 자리 높이 계산에 쓴다) */
  --banner-h: 128px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--night);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.65;
}

/* 배너 */
.banner {
  position: relative;
  overflow: hidden;
  min-height: var(--banner-h);
  background: linear-gradient(180deg, var(--dusk-top) 0%, var(--dusk-low) 100%);
}
.banner-inner {
  position: relative;
  z-index: 2;
  max-width: 1180px;
  margin: 0 auto;
  padding-block: 18px 40px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.banner h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(28px, 4.5vw, 42px);
  line-height: 1.15;
  letter-spacing: 0.02em;
  color: var(--title-ink);
  text-wrap: balance;
}
.banner p {
  margin: 0;
  font-weight: 600;
  font-size: clamp(15px, 2.2vw, 18px);
  color: var(--title-ink);
}
.banner .moon {
  position: absolute;
  z-index: 1;
  right: 14%;
  top: 16px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--glow);
  box-shadow: 0 0 50px 14px color-mix(in srgb, var(--glow) 45%, transparent);
  opacity: 0.9;
}
.banner .dots { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.banner .dots i {
  position: absolute;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: var(--ink);
  opacity: 0.7;
}
.banner svg.ridges {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 56px;
  z-index: 1;
}

/* 세 칸 */
.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding-block: 20px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(0, 320px);
  gap: 24px;
  align-items: start;
}
.layout > * { min-width: 0; }

.label {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--muted);
}

/* 왼쪽: 게임 자리 */
.screen {
  position: relative;
  /* 컴퓨터 화면: 배너와 여백을 뺀 높이 안에 9:16 전체가 들어가게 한다 */
  height: min(568px, calc(100vh - var(--banner-h) - 92px));
  min-height: 320px;
  aspect-ratio: 9 / 16;
  max-width: 100%;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: linear-gradient(0deg, var(--sky) 0%, var(--navy) 55%, var(--void) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.screen .twinkle { position: absolute; inset: 0; pointer-events: none; }
.screen .twinkle i {
  position: absolute;
  width: 2px; height: 2px;
  border-radius: 50%;
  background: var(--ink);
}
.star {
  position: absolute;
  width: 13%;
  aspect-ratio: 46 / 44;
  background: var(--glow);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.astro {
  position: absolute;
  left: 50%;
  bottom: 30%;
  transform: translateX(-50%);
  width: 34px;
  height: 46px;
}
.astro .helmet {
  position: absolute; top: 0; left: 3px;
  width: 28px; height: 26px;
  border-radius: 50%;
  background: var(--suit);
}
.astro .helmet::after {
  content: "";
  position: absolute; top: 7px; left: 6px;
  width: 16px; height: 10px;
  border-radius: 6px;
  background: var(--visor);
}
.astro .suit {
  position: absolute; bottom: 0; left: 5px;
  width: 24px; height: 22px;
  border-radius: 8px 8px 6px 6px;
  background: var(--suit);
}
.placeholder {
  position: relative;
  z-index: 2;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px dashed color-mix(in srgb, var(--ink) 60%, transparent);
  background: color-mix(in srgb, var(--void) 55%, transparent);
  color: var(--ink);
  font-size: 14px;
}

/* 게임 canvas: 게임 자리를 꽉 채운다. 터치를 게임에만 넘기려고 canvas 에만 touch-action: none */
.game-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  background: var(--void);
  touch-action: none;
}
.game-canvas[hidden] { display: none; }
.game-canvas:focus { outline: none; }
/* 게임이 뜨면 장식 별과 우주인을 숨긴다 */
.screen.is-playing .twinkle,
.screen.is-playing .star,
.screen.is-playing .astro { display: none; }

/* 시작 단추와 불러오기 안내 */
.game-start {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
  text-align: center;
}
.game-start[hidden] { display: none; }
.game-status {
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--void) 55%, transparent);
  color: var(--ink);
  font-size: 14px;
  overflow-wrap: anywhere;
}
.game-status:empty { display: none; }

/* 버튼 */
.btn {
  font: inherit;
  font-weight: 600;
  font-size: 16px;
  padding: 12px 26px;
  border: 0;
  border-radius: 999px;
  background: var(--glow);
  color: var(--glow-ink);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px color-mix(in srgb, var(--glow) 40%, transparent); }
.btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

/* 가운데: 소개 */
.about h2, .board h2 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  line-height: 1.25;
  text-wrap: balance;
}
.about .lead { margin: 0 0 22px; max-width: 60ch; color: var(--ink); }
.section { padding-block: 18px; border-top: 1px solid var(--line); }
.keys { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0; }
kbd {
  display: inline-grid;
  place-items: center;
  min-width: 36px; height: 34px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  background: var(--panel);
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--ink);
}
.note { margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 18px;
  margin: 0;
}
.facts dt { color: var(--muted); font-size: 14px; }
.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* 오른쪽: 점수 */
.board {
  padding: 20px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.score-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 22px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; color: var(--muted); }
.field input {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--night);
  color: var(--ink);
}
.field input:focus-visible { outline: 2px solid var(--glow); outline-offset: 1px; }
.score-form .btn { align-self: stretch; }
/* 점수판은 한 쪽에 5줄. 줄 높이를 고정해서 쪽을 넘겨도 점수판 높이가 같다 */
.ranks {
  --rank-row: 46px;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: calc(var(--rank-row) * 5 + 8px); /* 8px: 1~3등 사이 간격 두 번 */
}
.ranks li {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  height: var(--rank-row);
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.ranks li.filler { border-top-color: transparent; }
.ranks .no { color: var(--glow); font-family: var(--font-display); font-weight: 700; font-size: 20px; line-height: 1; }
.ranks .who { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ranks .pts { font-weight: 600; }
.ranks .empty { display: flex; align-items: center; height: auto; min-height: var(--rank-row); padding-block: 10px; color: var(--muted); font-size: 14px; }
/* 점수판 쪽 넘기기: ‹ 1 / n › */
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 10px; }
.pager-btn {
  font: inherit;
  font-size: 20px;
  line-height: 1;
  width: 40px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--night);
  color: var(--ink);
  cursor: pointer;
}
.pager-btn:hover:not(:disabled) { border-color: var(--glow); color: var(--glow); }
.pager-btn:focus-visible { outline: 2px solid var(--glow); outline-offset: 1px; }
.pager-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.pager-page { min-width: 64px; text-align: center; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
/* 1~3등 강조 */
.ranks li.top {
  padding-inline: 8px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--glow) 10%, transparent);
}
.ranks li.top + li.top { margin-top: 4px; }
.ranks li.top .who, .ranks li.top .pts { font-weight: 700; }
.ranks li.top-1 .no { font-size: 26px; }
.ranks li.top-2 .no { font-size: 23px; }
.notice { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
/* 점수 올리기 안내 한 줄 (입력칸 대신) */
.score-guide { margin: 0 0 18px; font-size: 14px; color: var(--muted); }
/* 방금 올린 줄: 잠깐 빛나게 */
.ranks li.just-added {
  padding-inline: 8px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--glow) 28%, transparent);
  box-shadow: 0 0 0 2px var(--glow);
  animation: just-added 4s ease-out forwards;
}
@keyframes just-added {
  0%, 60% { background: color-mix(in srgb, var(--glow) 28%, transparent); box-shadow: 0 0 0 2px var(--glow); }
  100% { background: transparent; box-shadow: 0 0 0 2px transparent; }
}

/* 게임이 끝나면 뜨는 이니셜 창: 화면 가운데 */
.initials-dialog {
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  margin: auto;
  padding: 22px 20px 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--ink);
  text-align: center;
}
.initials-dialog::backdrop { background: color-mix(in srgb, var(--void) 70%, transparent); }
.initials-score {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--glow);
  font-variant-numeric: tabular-nums;
}
.initials-help { margin: 0 0 16px; font-size: 13px; color: var(--muted); }
.initials-slots { display: flex; justify-content: center; gap: 12px; margin-bottom: 14px; }
.initials-slot { display: flex; flex-direction: column; align-items: center; gap: 6px; }
/* 휴대폰에서 누르기 쉽게 가로세로 44px 이상 */
.initials-step {
  font: inherit;
  font-size: 18px;
  line-height: 1;
  min-width: 56px;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--night);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.initials-step:hover:not(:disabled) { border-color: var(--glow); color: var(--glow); }
.initials-step:focus-visible { outline: 2px solid var(--glow); outline-offset: 1px; }
.initials-step:disabled { opacity: 0.4; cursor: not-allowed; }
.initials-letter {
  display: grid;
  place-items: center;
  width: 56px;
  height: 64px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--night);
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
}
.initials-letter:focus { outline: none; border-color: var(--glow); color: var(--glow); }
.initials-dialog .message { margin-bottom: 12px; }
.initials-actions { display: flex; gap: 10px; }
.initials-actions .btn { flex: 1 1 0; min-height: 48px; touch-action: manipulation; }
.btn-quiet { background: var(--night); color: var(--ink); border: 1px solid var(--line); }
.btn-quiet:hover { box-shadow: none; border-color: var(--ink); }

/* 점수 올리기 안내 메시지 */
.message { margin: 0; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.message:empty { display: none; }
.message[data-kind="ok"] { color: var(--glow); font-weight: 600; }
.message[data-kind="error"] { color: var(--error); }

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* 맨 아래: 댓글 (세 칸과 같은 폭과 여백) */
.layout { padding-bottom: 24px; }
.comments-wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding-block: 0 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.comments {
  padding: 20px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.comments h2 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  line-height: 1.25;
}
.comment-form {
  display: grid;
  grid-template-columns: minmax(0, 200px) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin-bottom: 18px;
}
.comment-form .btn { margin-top: 23px; }
.comment-form .message { grid-column: 1 / -1; }
.field textarea {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--night);
  color: var(--ink);
  resize: vertical;
}
.field textarea:focus-visible { outline: 2px solid var(--glow); outline-offset: 1px; }
.count { align-self: flex-end; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.comment-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.comment-list li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-block: 12px;
  border-top: 1px solid var(--line);
  min-width: 0;
}
.comment-list .meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--muted); }
.comment-list .author { font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }
.comment-list .text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-list .pending .text { color: var(--muted); font-style: italic; }
.comment-list .empty { color: var(--muted); font-size: 14px; }

/* 관리자 페이지 */
.admin-header { background: linear-gradient(180deg, var(--dusk-top) 0%, var(--dusk-low) 100%); }
.admin-header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding-block: 18px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  align-items: baseline;
  justify-content: space-between;
}
.admin-header h1 { margin: 0; font-size: 28px; line-height: 1.2; color: var(--title-ink); }
.admin-header a { color: var(--title-ink); font-weight: 600; }
.admin-wrap { display: flex; flex-direction: column; gap: 20px; padding-top: 24px; }
.admin-login { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 12px; }
.admin-login .field { flex: 1 1 240px; min-width: 0; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.btn-small { font-size: 14px; padding: 6px 16px; }
.btn-danger { background: var(--error); color: var(--title-ink); }
.badge {
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line);
}
.badge-pending { color: var(--muted); }
.badge-visible { color: var(--glow); border-color: var(--glow); }

/* 관리자 페이지 두 칸: 좁은 화면에서는 댓글 아래 점수, 페이지 전체가 스크롤된다 */
.admin-columns { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.admin-panel { display: flex; flex-direction: column; min-width: 0; }

/* PC: 왼쪽부터 댓글, 점수, 활동 기록. 페이지는 움직이지 않고 목록 안에서만 스크롤한다 */
@media (min-width: 961px) {
  .admin-page { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
  .admin-page .admin-wrap { flex: 1 1 auto; min-height: 0; width: 100%; padding-bottom: 24px; }
  .admin-columns { flex: 1 1 auto; min-height: 0; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .admin-panel { min-height: 0; }
  .admin-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain; /* 목록 끝에 닿아도 페이지가 따라 움직이지 않게 */
    padding-right: 8px;
  }
}

@media (max-width: 960px) {
  .comment-form { grid-template-columns: minmax(0, 1fr); }
  .comment-form .btn { margin-top: 0; }
}

/* 휴대폰·좁은 화면: 배너, 게임, 소개, 점수 순서로 쌓기 */
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 32px; }
  .game { width: 100%; max-width: 360px; margin: 0 auto; }
  /* 휴대폰 세로 화면: 게임 높이가 화면 높이를 넘지 않게 폭을 줄인다 (9:16 유지) */
  .screen {
    width: min(100%, calc((100vh - 48px) * 9 / 16));
    width: min(100%, calc((100dvh - 48px) * 9 / 16));
    height: auto;
    min-height: 0;
    margin-inline: auto;
  }
  .banner .moon { width: 56px; height: 56px; right: 8%; }
}

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
  .btn:hover { transform: none; }
  .ranks li.just-added { animation: none; }
}
