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

/* ─── Block Shadows ─────────────────────────────────────────────── */
main { gap: 10px; }

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

.sh-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: #c9ced8;
  font-variant-numeric: tabular-nums;
  min-height: 24px;
}
.sh-q { white-space: nowrap; }
.sh-legend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 700;
  color: #8f98aa;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sh-legend span { margin-right: 2px; }
.sh-legend i {
  font-style: normal;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  color: #10141d;
  font-size: 10px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sh-stage {
  padding: 3px 9px;
  border-radius: 999px;
  background: #1d2533;
  border: 1px solid #34405a;
  color: #e8eefc;
  font-size: 11.5px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.sh-stage[data-s="2"] { border-color: #3fb8a6; }
.sh-stage[data-s="3"] { border-color: #f2b33d; }
.sh-stage[data-s="4"] { border-color: #ee6a57; }
.sh-stage.pulse { animation: sh-pulse 0.9s ease-out 2; }
@keyframes sh-pulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 193, 69, 0.6); }
  40% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(255, 193, 69, 0); }
  100% { transform: scale(1); }
}

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

.sh-scene-area {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: radial-gradient(ellipse at 50% 40%, #151b28 0%, #0d1018 75%);
  overflow: hidden;
}
.sh-scene { display: block; }

.sh-timer {
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.sh-timer i {
  display: block;
  height: 100%;
  background: #5ee0c8;
  transform-origin: left center;
  border-radius: 3px;
}
.sh-timer i.mid { background: #ffc145; }
.sh-timer i.low { background: #ff6b5a; }

.sh-msg { position: relative; min-height: 34px; display: flex; align-items: center; justify-content: center; }
.sh-prompt {
  margin: 0;
  font-size: 13.5px;
  line-height: 17px;
  text-align: center;
  color: #dfe5f1;
  font-weight: 650;
}
.sh-prompt.first { color: #ffd27a; }
.sh-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;
  padding: 2px 12px;
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.85);
  white-space: nowrap;
}
.sh-float.go { animation: sh-float 0.9s ease-out forwards; }
.sh-float.ok { color: #3ddc97; }
.sh-float.bad { color: #ff6b78; }
.sh-float.late { color: #ffc145; }
.sh-float.bad.go, .sh-float.late.go { animation-duration: 1.9s; }
@keyframes sh-float {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.8); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  30% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

.sh-opts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.sh-opt {
  position: relative;
  font: inherit;
  padding: 4px;
  color: #f2f5fb;
  background: linear-gradient(#1c2434, #161d2a);
  border: 1.5px solid #34405a;
  border-radius: 14px;
  height: clamp(76px, 15.5dvh, 136px);
  min-width: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s, opacity 0.2s, transform 0.08s;
}
.sh-opt canvas { display: block; pointer-events: none; }
.sh-opt b {
  position: absolute;
  left: 6px;
  top: 5px;
  font-size: 10.5px;
  font-weight: 800;
  color: #7f8aa0;
  pointer-events: none;
}
.sh-opt:active:not(:disabled) { transform: scale(0.97); background: #232d40; }
.sh-opt:disabled { cursor: default; }
.sh-opt.ok { background: #173f31; border-color: #3ddc97; }
.sh-opt.right { background: #173f31; border-color: #3ddc97; animation: sh-blink 0.5s ease-in-out 3; }
.sh-opt.bad { background: #4c1b24; border-color: #ff5d6c; animation: sh-shake 0.32s ease-in-out; }
.sh-opt.dim { opacity: 0.35; }
@keyframes sh-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
@keyframes sh-blink { 50% { box-shadow: 0 0 0 4px rgba(61, 220, 151, 0.4); } }

/* start card */
.sh-start { gap: 12px; }
.sh-start-ico { line-height: 0; }
.sh-intro { margin: 0; font-size: 14.5px; line-height: 1.45; color: #e3e7ef; }
.sh-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;
}
.sh-plan li { display: flex; gap: 10px; align-items: center; }
.sh-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 */
.sh-sum { display: flex; gap: 10px; width: 100%; }
.sh-sum div, .sh-stagesum div {
  flex: 1;
  background: #1d2330;
  border-radius: 10px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.sh-sum span, .sh-stagesum span { font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #a9b0bf; text-transform: uppercase; letter-spacing: 0.04em; }
.sh-sum b { font-size: 17px; font-variant-numeric: tabular-nums; }
.sh-stagesum { display: flex; gap: 6px; width: 100%; }
.sh-stagesum b { font-size: 13px; font-variant-numeric: tabular-nums; }
.sh-chips { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.sh-chips i { width: 11px; height: 11px; border-radius: 3px; background: #333a48; }
.sh-chips i.ok { background: #3ddc97; }
.sh-chips i.bad { background: #ff5d6c; }
.sh-chips i.late { background: #a37b3c; }

@media (max-height: 620px) {
  main { gap: 8px; padding-top: max(56px, env(safe-area-inset-top)); padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  #game { gap: 5px; }
  .new-btn { min-height: 48px; }
  .score-box { padding: 5px 10px; }
  .score-val, .best-val { font-size: 19px; }
  .sh-start-ico svg { width: 70px; height: 56px; }
  .sh-intro { font-size: 13.5px; }
  .sh-plan { font-size: 12.5px; }
}
@media (max-width: 350px) {
  .sh-legend span { display: none; }
  .sh-stage { font-size: 11px; padding: 3px 7px; }
}
.sh-prompt { transition: opacity 0.15s; }
.sh-prompt.hide { opacity: 0; }
@media (max-height: 620px) {
  .overlay { padding-top: 64px; padding-bottom: 10px; }
  .overlay-card { padding: 14px 16px; gap: 8px; }
  .overlay-card h2 { font-size: 19px; }
  .overlay-score { font-size: 42px; }
  .overlay-card button { min-height: 40px; padding: 9px 16px; }
  .sh-chips i { width: 9px; height: 9px; }
}
