:root {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  touch-action: manipulation;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  overflow: hidden;
  background: #0a0a0a;
  color: #f5f5f5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

main {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding:
    max(60px, env(safe-area-inset-top))
    16px
    max(20px, env(safe-area-inset-bottom));
  gap: 16px;
}

/* 점수바: SCORE | BEST | New 버튼 */
.score-bar {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.score-box {
  flex: 1;
  background: #161616;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 8px 12px;
  text-align: center;
  min-width: 0;
}

.score-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a0a0a0;
}

.score-val,
.best-val {
  display: block;
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: #f5f5f5;
  margin-top: 2px;
  line-height: 1.1;
}

.new-btn {
  flex: 0 0 auto;
  font: inherit;
  color: #fff;
  background: #4f9eff;
  border: none;
  border-radius: 12px;
  padding: 0 18px;
  min-height: 56px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}

.new-btn:active { background: #3d8ae8; }

/* 게임 영역 — 보드/캠버스/그리드 등을 여기에 */
#game {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;   /* 작은 폰에서 아래 조작 요소가 화면 밖으로 밀리지 않게 */
}

/* 좌상단 ← 홈, 우상단 🏆 명예의 전당 — 모든 게임 공통 chrome */
.home-link,
.hof-link {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  z-index: 10;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  text-decoration: none;
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.15s ease;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.home-link { left:  max(12px, env(safe-area-inset-left)); }
.hof-link  { right: max(12px, env(safe-area-inset-right)); }

@media (hover: hover) {
  .home-link:hover,
  .hof-link:hover {
    background: rgba(0, 0, 0, 0.55);
  }
}

/* 오버레이 (게임 종료 / 완료 시 점수 + 저장 버튼) */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.overlay[hidden] { display: none; }

.overlay-card {
  background: #161616;
  border: 1px solid #2a2a2a;
  border-radius: 18px;
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  text-align: center;
  min-width: 240px;
  max-width: 320px;
  width: 100%;
}

.overlay-card h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.overlay-score {
  margin: 0;
  font-size: 56px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1;
}

.overlay-card button {
  font: inherit;
  color: #fff;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 12px 20px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

.overlay-card button:active {
  background: rgba(255, 255, 255, 0.18);
}

.overlay-card .save-btn {
  background: #4f9eff;
  border-color: #4f9eff;
}

.overlay-card .save-btn:active {
  background: #3d8ae8;
}

/* ─── Map Bearings ─────────────────────────────────────────────── */
main { gap: 10px; }

#game {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 7px;
}

.cp-dots {
  display: grid;
  grid-template-columns: repeat(20, 1fr);
  gap: 3px;
  flex: 0 0 auto;
}
.cp-dots i { height: 5px; border-radius: 3px; background: #262c38; }
.cp-dots i:nth-child(5n + 1) { margin-left: 2px; }
.cp-dots i.now { background: #8fa2c8; }
.cp-dots i.ok { background: #3ddc97; }
.cp-dots i.bad { background: #ff5d6c; }
.cp-dots i.late { background: #a37b3c; }

/* question card: heading cue + what to find */
.cp-q {
  flex: 0 0 auto;
  background: #141b24;
  border: 1px solid #2a3646;
  border-radius: 12px;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 58px;
  justify-content: center;
}
.cp-q p {
  margin: 0;
  text-align: center;
  line-height: 24px;
  overflow-wrap: anywhere;
}
.cp-cue { font-size: 13.5px; color: #b9c6d6; }
.cp-ask { font-size: 16px; font-weight: 700; color: #f5f7fb; }
.cp-dir { color: #ffd27a; text-transform: uppercase; letter-spacing: 0.04em; }
.cp-lm { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; vertical-align: top; }
.cp-lm b { color: #ffe9a8; }
.cp-cue .cp-lm b { color: #ffd27a; }
.cp-ico {
  display: inline-block;
  width: 22px;
  height: 22px;
  background: radial-gradient(circle at 40% 35%, #4e7d45, #2f5230);
  border-radius: 50%;
}

.cp-map-area {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cp-canvas { display: block; }
.cp-count, .cp-stage {
  position: absolute;
  top: 0;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.cp-count { left: 0; color: #c9ced8; }
.cp-stage {
  right: 0;
  padding: 2px 9px;
  border-radius: 999px;
  background: #1d2533;
  border: 1px solid #34405a;
  color: #e8eefc;
  letter-spacing: 0.04em;
}
.cp-stage[data-s="2"] { border-color: #5ee0c8; }
.cp-stage[data-s="3"] { border-color: #ffc145; }
.cp-stage[data-s="4"] { border-color: #ff7a5c; }
.cp-stage.pulse { animation: cp-pulse 0.9s ease-out 2; }
@keyframes cp-pulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 193, 69, 0.6); }
  40% { transform: scale(1.12); box-shadow: 0 0 0 6px rgba(255, 193, 69, 0); }
  100% { transform: scale(1); }
}

.cp-float {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px;
  line-height: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  opacity: 0;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.75);
  white-space: nowrap;
}
.cp-float.go { animation: cp-float 0.65s ease-out forwards; }
.cp-float.ok { color: #3ddc97; }
.cp-float.bad { color: #ff6b78; }
.cp-float.late { color: #ffc145; }
.cp-float.bad.go, .cp-float.late.go { animation-duration: 1.5s; }
@keyframes cp-float {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(0.8); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  35% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}

.cp-msg { flex: 0 0 auto; position: relative; min-height: 22px; display: flex; align-items: center; justify-content: center; }
.cp-hint {
  margin: 0;
  min-height: 17px;
  font-size: 12.5px;
  line-height: 17px;
  text-align: center;
  color: #ffd27a;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.25s;
}
.cp-hint.show { opacity: 1; }

/* the dial: you in the middle, top = straight ahead */
.cp-dial-wrap {
  flex: 0 0 auto;
  height: clamp(132px, 27vh, 240px);
  display: flex;
  justify-content: center;
}
.cp-dial {
  height: 100%;
  aspect-ratio: 1;
  display: block;
  touch-action: none;
  cursor: pointer;
  overflow: visible;
}
.cp-w path {
  fill: #1c2635;
  stroke: #3a4a62;
  stroke-width: 1.2;
  transition: fill 0.12s, stroke 0.12s, opacity 0.2s;
}
.cp-w text { pointer-events: none; text-anchor: middle; dominant-baseline: central; }
.cp-ar { font-size: 25px; font-weight: 800; fill: #e9eef8; }
.cp-wl { font-size: 13px; font-weight: 700; fill: #aab6c8; }
.cp-w:focus { outline: none; }
.cp-w:focus-visible path { stroke: #ffd27a; stroke-width: 2.5; }
@media (hover: hover) {
  .cp-dial:not(.off) .cp-w:hover path { fill: #253349; }
}
.cp-w:first-child .cp-ar { fill: #8fd3ff; }
.cp-dial.off { cursor: default; }
.cp-dial.off .cp-w path { fill: #18202c; }
.cp-w.ok path, .cp-w.right path { fill: #1c4d3a; stroke: #3ddc97; stroke-width: 2.5; }
.cp-w.right path { animation: cp-blink 0.5s ease-in-out 3; }
.cp-w.bad path { fill: #5a1f28; stroke: #ff5d6c; stroke-width: 2.5; }
.cp-w.dim { opacity: 0.45; }
@keyframes cp-blink { 50% { fill: #2b7a5a; } }
.cp-me-bg { fill: #0f151d; stroke: #2a3646; stroke-width: 1.5; }
.cp-me-nose { fill: #8fd3ff; }
.cp-me-sh { fill: #2f7cf6; }
.cp-me-head { fill: #f1d2b0; stroke: #3b2a1c; stroke-width: 1; }

/* start card */
.cp-start { gap: 14px; }
.cp-start-ico { line-height: 0; }
.cp-intro { margin: 0; font-size: 15px; line-height: 1.45; color: #e3e7ef; }
.cp-plan {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  width: 100%;
  font-size: 13px;
  color: #c9ced8;
  line-height: 1.35;
}
.cp-plan li { display: flex; gap: 10px; align-items: center; }
.cp-plan b {
  flex: 0 0 22px;
  height: 22px;
  border-radius: 50%;
  background: #2c4352;
  color: #ffd27a;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* result card */
.cp-sum { display: flex; gap: 10px; width: 100%; }
.cp-sum div, .cp-stagesum div {
  flex: 1;
  background: #1d2330;
  border-radius: 10px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.cp-sum span, .cp-stagesum span { font-size: 10.5px; white-space: nowrap; color: #a9b0bf; text-transform: uppercase; letter-spacing: 0.05em; overflow: hidden; text-overflow: ellipsis; }
.cp-sum b { font-size: 17px; font-variant-numeric: tabular-nums; }
.cp-stagesum { display: flex; gap: 6px; width: 100%; }
.cp-stagesum b { font-size: 14px; font-variant-numeric: tabular-nums; }
.cp-chips { display: grid; grid-template-columns: repeat(20, 1fr); gap: 2px; width: 100%; }
.cp-chips i { height: 8px; border-radius: 2px; background: #2a2f3a; }
.cp-chips i.ok { background: #3ddc97; }
.cp-chips i.bad { background: #ff5d6c; }
.cp-chips i.late { background: #a37b3c; }

@media (max-height: 640px) {
  .overlay-card { padding: 18px 18px; gap: 9px; }
  .overlay-card .overlay-score { font-size: 46px; }
  .overlay-card button { min-height: 40px; padding: 9px 18px; }
  .cp-start-ico svg { width: 54px; height: 54px; }
  .cp-q { min-height: 52px; padding: 4px 8px; }
  .cp-ask { font-size: 15px; }
  .cp-dial-wrap { height: 128px; }
}
