/* cooctal Arcade 공통 틀 (MGW-DEV-007, 요구사항 v03)
   화면 3개: 시작 페이지(home.css) / 게임 화면(이 파일 .game-page) / 결과 화면(이 파일 .rs, common/ranking.js)
   - 스크롤 없는 풀사이즈: 세로·가로 어느 방향이든 한 화면(100dvh) 안
   - 게임 화면: 게임 요소(판·점수) + 아주 작은 co 로고 + 뒤로가기 아이콘 + 플레이 수만 (광고 없음)
     세로 화면: 위 줄(뒤로·점수·버튼) / 판 / 아래 작은 줄(플레이 수·로고)
     가로 화면: 왼쪽 띠(뒤로·로고) / 판 / 오른쪽 띠(점수·버튼·플레이 수)
   - 판 크기 --size: 남는 공간에서 판 비율(--aspect = 높이/폭)을 지키는 최대 크기
   - 광고: 결과 화면 맨 아래 작은 띠 하나만 (MGW-DEV-008, .rs-ad, common/ads.js). 시작·게임 화면에는 없다
   외부 폰트·이미지 없음. */
:root {
  --cf-ink: #1d2540;
  --cf-muted: #5f6987;
  --cf-accent: #3f6fe0;
  --cf-accent-ink: #2a52c0;  /* 밝은 바탕 위 파란 글자 (4.5:1 이상) */
  --cf-line: #d9deea;
  --cf-bg: #f3f5fa;
  --cf-font: system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;

  --cf-safe-y: calc(env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px));
  --cf-safe-x: calc(env(safe-area-inset-left, 0px) + env(safe-area-inset-right, 0px));
  /* 세로 화면 판 밖 높이: 위 줄 44 + 아래 줄 20 + 판 위아래 간격 8+8 */
  --bar-h: 44px;
  --foot-h: 20px;
  --rail-w: 76px;
  --extra-h: 0px;        /* 판 아래 게임 고유 줄(행성 순서 막대 등) */
  --aspect: 1;           /* 판 높이 / 폭 */
  --main-w: calc(100vw - 16px - var(--cf-safe-x));
  --main-h: calc(100vh - var(--bar-h) - var(--foot-h) - 16px - var(--cf-safe-y));
  --main-h: calc(100dvh - var(--bar-h) - var(--foot-h) - 16px - var(--cf-safe-y));
}
@media (orientation: landscape) {
  :root {
    --main-w: calc(100vw - 2 * var(--rail-w) - 16px - var(--cf-safe-x));
    --main-h: calc(100vh - 16px - var(--cf-safe-y));
    --main-h: calc(100dvh - 16px - var(--cf-safe-y));
  }
}

/* ---------- 게임 화면 ---------- */
.game-page {
  --size: min(var(--main-w), (var(--main-h) - var(--extra-h)) / var(--aspect));
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: var(--bar-h) minmax(0, 1fr) var(--foot-h);
  grid-template-areas: "bar" "main" "foot";
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  box-sizing: border-box;
  background: var(--cf-bg);
  color: var(--cf-ink);
  font-family: var(--cf-font);
}
.bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 6px;
  width: var(--size);
  min-width: min(100%, 300px);
  max-width: 100%;
  margin: 0 auto;
}
.hud { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 10px; }
.play-area {
  grid-area: main;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 0;
  padding: 8px 0;
}
.foot {
  grid-area: foot;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: var(--size);
  min-width: min(100%, 300px);
  max-width: 100%;
  margin: 0 auto;
  height: var(--foot-h);
}

/* 아이콘 버튼 (누르는 범위 44×44) */
.ibtn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--cf-ink);
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.ibtn:hover { background: rgba(29, 37, 64, 0.07); }
.ibtn:focus-visible { outline: 3px solid var(--cf-accent); outline-offset: -3px; }
.ibtn:disabled { opacity: 0.4; cursor: default; }
.ibtn[hidden] { display: none; }
.back { margin-left: -8px; }
.act { margin-left: auto; margin-right: -8px; }

/* 점수: 숫자만 크게, 최고점은 작은 트로피 + 숫자 */
.score { margin: 0; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.3px; line-height: 1; }
.best { display: inline-flex; align-items: center; gap: 3px; margin: 0; font-size: 13px; font-weight: 700; color: var(--cf-muted); font-variant-numeric: tabular-nums; line-height: 1; }
.best svg { width: 14px; height: 14px; }
.plays { display: inline-flex; align-items: center; gap: 3px; margin: 0; font-size: 11px; font-weight: 700; color: var(--cf-muted); font-variant-numeric: tabular-nums; line-height: 1; }
.plays[hidden] { display: none; }
.co { display: block; width: auto; height: 11px; opacity: 0.55; }
.foot .co { margin-left: auto; }

/* 가로 화면: 왼쪽 띠(뒤로·로고) / 판 / 오른쪽 띠(점수·버튼·플레이 수) */
@media (orientation: landscape) {
  .game-page {
    grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--rail-w);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "back main hud" ". main ." "co main plays";
  }
  .bar, .foot { display: contents; }
  .back { grid-area: back; margin: 6px 0 0; justify-self: center; }
  .hud { grid-area: hud; flex-direction: column; align-items: center; gap: 10px; padding-top: 10px; }
  .act { order: -1; margin: 0; }
  .plays { grid-area: plays; justify-self: center; margin-bottom: 10px; }
  .foot .co { grid-area: co; justify-self: center; margin: 0 0 12px; }
  .score { font-size: 22px; }
}

/* 판 위 아이콘 (시작·계속·새 판) */
.board-cover {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 18px;
  border-radius: inherit;
  background: rgba(20, 26, 44, 0.55);
}
.board-cover.show { display: flex; }
.board-cover.ready { background: rgba(20, 26, 44, 0.25); }
.cover-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #ffd56b;
  color: var(--cf-ink);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}
.cover-btn.sub { width: 56px; height: 56px; background: #fff; }
.cover-btn svg { width: 34px; height: 34px; }
.cover-btn.sub svg { width: 26px; height: 26px; }
.cover-btn:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.cover-btn[hidden] { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 결과 화면 / 랭킹 보기 (common/ranking.js) ---------- */
html.rs-open, html.rs-open body { overflow: hidden; }
.rs {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  background: var(--cf-bg);
  color: var(--cf-ink);
  font-family: var(--cf-font);
  animation: rs-in 200ms ease-out;
}
.rs > * { width: min(100% - 16px, 460px); }
.rs-head { flex: none; display: flex; align-items: center; gap: 10px; height: 52px; }
.rs-game { font-size: 13px; font-weight: 700; color: var(--cf-muted); }
.rs-score { flex: 1 1 auto; text-align: center; font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.rs-score[hidden] { display: block; visibility: hidden; }
.rs-logo { width: auto; height: 11px; opacity: 0.55; }
.rs-list { flex: 1 1 auto; min-height: 0; margin: 0; padding: 0; list-style: none; overflow: hidden; }
.rs-row {
  display: grid;
  grid-template-columns: 3.2em minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.rs-row:nth-child(odd) { background: #e9edf6; }
.rs-rank { text-align: center; font-weight: 800; color: var(--cf-muted); }
.rs-row:nth-child(-n+3) .rs-rank { color: var(--cf-accent-ink); }
.rs-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.rs-val { text-align: right; font-weight: 800; }
.rs-sep { height: 22px; text-align: center; line-height: 22px; color: var(--cf-muted); }
.rs-me, .rs-row.rs-hi, .rs-row.rs-mine { background: #fff1c7 !important; box-shadow: inset 0 0 0 2px #f5b041; }
.rs-me { height: 48px; }
.rs-me .rs-rank { color: var(--cf-ink) !important; }
.rs-form { display: flex; align-items: center; gap: 4px; min-width: 0; }
.rs-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 38px;
  padding: 0 8px;
  border: 0;
  border-bottom: 2px solid #f5b041;
  border-radius: 6px 6px 0 0;
  background: #fff;
  color: var(--cf-ink);
  font: inherit;
  font-size: 16px;     /* 16px 미만이면 iOS가 화면을 확대한다 */
  font-weight: 700;
  caret-color: var(--cf-accent);
  user-select: text;
  -webkit-user-select: text;
}
.rs-input:focus { outline: none; border-bottom-color: var(--cf-accent); }
.rs-ok {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--cf-accent);
  color: #fff;
  cursor: pointer;
}
.rs-ok:disabled { opacity: 0.5; cursor: default; }
.rs-ok:focus-visible { outline: 3px solid var(--cf-ink); outline-offset: 2px; }
.rs-shake { animation: rs-shake 360ms ease-in-out; }
.rs-turnstile { flex: none; }
.rs-turnstile[hidden] { display: none; }
.rs-foot { flex: none; display: flex; align-items: center; justify-content: center; gap: 28px; height: 72px; }
.rs-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--cf-ink);
  box-shadow: 0 4px 14px rgba(29, 37, 64, 0.14);
  cursor: pointer;
  text-decoration: none;
}
.rs-again { background: var(--cf-accent); color: #fff; }
.rs-btn svg { width: 26px; height: 26px; }
.rs-btn:focus-visible { outline: 3px solid var(--cf-ink); outline-offset: 3px; }

/* 광고 띠 (결과 화면에만, common/ads.js): 맨 아래 50px 줄. 화면 위에 떠서 덮지 않는다(레이아웃 안의 줄).
   실수 클릭 방지: 처음으로·다시 하기 버튼 아래 끝과 띠 사이 40px 이상(아래 줄 안 여백 8 + 위 여백 32),
   이름 입력 칸·확인 버튼은 그 위 표 안이라 더 멀다. */
.rs > .rs-ad {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 50px;
  margin-top: 32px;
  overflow: hidden;
}
.rs-house { display: block; height: 50px; border-radius: 6px; overflow: hidden; }
.rs-house img { display: block; width: auto; height: 50px; }
.rs-house:focus-visible { outline: 3px solid var(--cf-accent); outline-offset: -3px; }

/* 낮은 가로 화면: 위 줄·아래 줄을 줄인다 */
@media (max-height: 420px) {
  .rs-head { height: 40px; }
  .rs-score { font-size: 22px; }
  .rs-foot { height: 56px; }
  .rs-btn { width: 48px; height: 48px; }
  .rs > .rs-ad { margin-top: 36px; }   /* 버튼 아래 여백이 4px로 줄어 40px를 맞춘다 */
}

@keyframes rs-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rs-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@media (prefers-reduced-motion: reduce) { .rs, .rs-shake { animation: none; } }
