: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;
}

/* ─── Clock Reader ─────────────────────────────────────────────── */
main { gap: 12px; }

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

.ck-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  color: #c9ced8;
  font-variant-numeric: tabular-nums;
  min-height: 24px;
}

.ck-stage {
  padding: 3px 10px;
  border-radius: 999px;
  background: #1d2533;
  border: 1px solid #34405a;
  color: #e8eefc;
  font-size: 12px;
  letter-spacing: 0.04em;
}
.ck-stage[data-s="2"] { border-color: #5ee0c8; }
.ck-stage[data-s="3"] { border-color: #ffc145; }
.ck-stage[data-s="4"] { border-color: #ff7a5c; }
.ck-stage.pulse { animation: ck-pulse 0.9s ease-out 2; }
@keyframes ck-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); }
}

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

.ck-stage-area {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ck-canvas { display: block; }

.ck-msg { position: relative; min-height: 26px; display: flex; align-items: center; justify-content: center; }
.ck-float {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 24px;
  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.6);
  white-space: nowrap;
}
.ck-float.go { animation: ck-float 0.65s ease-out forwards; }
.ck-float.ok { color: #3ddc97; }
.ck-float.bad { color: #ff6b78; }
.ck-float.late { color: #ffc145; }
.ck-float.bad.go, .ck-float.late.go { animation-duration: 1.4s; }
@keyframes ck-float {
  0% { opacity: 0; transform: translate(-50%, -30%) 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%, -60%) scale(1); }
}

.ck-hint {
  margin: 0;
  min-height: 18px;
  font-size: 13px;
  line-height: 18px;
  text-align: center;
  color: #ffd27a;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.25s;
}
.ck-hint.show { opacity: 1; }

.ck-opts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.ck-opt {
  font: inherit;
  font-size: clamp(22px, 6.5vw, 30px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  color: #f2f5fb;
  background: linear-gradient(#1f2838, #18202d);
  border: 1px solid #34405a;
  border-radius: 14px;
  min-height: clamp(52px, 8.6vh, 66px);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s, opacity 0.2s, transform 0.08s;
}
.ck-opt:active:not(:disabled) { transform: scale(0.97); background: #273247; }
.ck-opt:disabled { cursor: default; }
.ck-opt.ok { background: #1c4d3a; border-color: #3ddc97; color: #eafff5; }
.ck-opt.right { background: #1c4d3a; border-color: #3ddc97; color: #eafff5; animation: ck-blink 0.5s ease-in-out 2; }
.ck-opt.bad { background: #5a1f28; border-color: #ff5d6c; color: #ffe8ea; animation: ck-shake 0.32s ease-in-out; }
.ck-opt.dim { opacity: 0.4; }
@keyframes ck-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
@keyframes ck-blink { 50% { box-shadow: 0 0 0 4px rgba(61, 220, 151, 0.35); } }

/* start card */
.ck-start { gap: 14px; }
.ck-start-ico { line-height: 0; }
.ck-intro { margin: 0; font-size: 15px; line-height: 1.45; color: #e3e7ef; }
.ck-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;
}
.ck-plan li { display: flex; gap: 10px; align-items: center; }
.ck-plan b {
  flex: 0 0 22px;
  height: 22px;
  border-radius: 50%;
  background: #2b3549;
  color: #ffd27a;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.overlay-card .start-btn { background: #2566c4; border-color: #2566c4; font-weight: 800; }

/* result card */
.ck-sum { display: flex; gap: 10px; width: 100%; }
.ck-sum div, .ck-stagesum div {
  flex: 1;
  background: #1d2330;
  border-radius: 10px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ck-sum span, .ck-stagesum span { font-size: 10.5px; white-space: nowrap; color: #a9b0bf; text-transform: uppercase; letter-spacing: 0.05em; }
.ck-sum b { font-size: 17px; font-variant-numeric: tabular-nums; }
.ck-stagesum { display: flex; gap: 6px; width: 100%; }
.ck-stagesum b { font-size: 14px; font-variant-numeric: tabular-nums; }
.ck-chips { display: grid; grid-template-columns: repeat(20, 1fr); gap: 2px; width: 100%; }
.ck-chips i { height: 8px; border-radius: 2px; background: #2a2f3a; }
.ck-chips i.ok { background: #3ddc97; }
.ck-chips i.bad { background: #ff5d6c; }
.ck-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; }
  .ck-start-ico svg { width: 54px; height: 54px; }
}
