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

/* ─── Parade Tally ───────────────────────────────────────────── */
#game {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  min-height: 0;
}
.tl-info {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; font-weight: 700; color: #b8c0d0;
  min-height: 22px; flex: 0 0 auto;
}
.tl-round { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tl-dots { margin-left: auto; display: flex; gap: 4px; min-width: 0; justify-content: flex-end; }
.tl-dots i { flex: 0 1 8px; min-width: 4px; height: 8px; border-radius: 50%; background: #2a3040; }
.tl-dots i.now { background: #e8eefc; box-shadow: 0 0 0 2px rgba(232, 238, 252, 0.25); }
.tl-dots i.hi { background: #38d9c9; }
.tl-dots i.mid { background: #ffb340; }
.tl-dots i.lo { background: #ff6b6b; }

.tl-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 150px;
  max-height: calc(min(100vw - 32px, 448px) * 1.1);
  border-radius: 18px;
  background: #0f1626;
  border: 1px solid #222a3a;
  overflow: hidden;
}
.tl-cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.tl-cap {
  position: absolute; left: 0; right: 0; top: 8px;
  margin: 0; padding: 0 12px;
  text-align: center;
  font-size: 15px; font-weight: 800; color: #e8eefc;
  line-height: 1.25;
  pointer-events: none;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}
.tl-sub {
  position: absolute; left: 0; right: 0; top: 29px;
  margin: 0; padding: 0 12px;
  text-align: center;
  font-size: 12px; font-weight: 700; color: #9aa6bd;
  pointer-events: none;
}
.tl-sub.warn { color: #ffd43b; }
.tl-sub.good { color: #38d9c9; font-size: 14px; }
.tl-sub.bad { color: #ffb340; font-size: 14px; }
.tl-bar {
  position: absolute; left: 12px; right: 12px; bottom: 8px;
  height: 4px; border-radius: 2px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden; pointer-events: none;
}
.tl-bar i {
  display: block; height: 100%;
  background: linear-gradient(90deg, #4dabf7, #9775fa);
  transform-origin: left center;
  transform: scaleX(1);
}
.tl-stage.asking .tl-bar i { background: linear-gradient(90deg, #ffd43b, #38d9c9); }
.tl-feedback {
  position: absolute; left: 50%; bottom: 18px;
  transform: translate(-50%, 6px);
  margin: 0; padding: 6px 14px;
  border-radius: 999px;
  background: rgba(8, 11, 18, 0.9);
  border: 1px solid #2a3346;
  font-size: 13px; font-weight: 600; color: #d6dcea;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  opacity: 0; pointer-events: none;
}
.tl-feedback.show { opacity: 1; transform: translate(-50%, 0); transition: opacity 0.2s ease, transform 0.25s ease; }
.tl-feedback b { font-size: 15px; }
.tl-feedback.hi b { color: #38d9c9; }
.tl-feedback.mid b { color: #ffb340; }
.tl-feedback.lo b { color: #ff8a8a; }

/* entry row + keypad */
.tl-entry, .tl-pad { flex: 0 0 auto; display: grid; gap: 8px; }
.tl-entry { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 2fr); }
.tl-pad { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.tl-key, .tl-display {
  font: inherit;
  height: clamp(42px, 7.4dvh, 64px);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.tl-key {
  border: 1px solid #2f3a50;
  background: #1a2132;
  color: #e8eefc;
  font-size: clamp(20px, 3.2dvh, 26px); font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.12s ease, opacity 0.2s ease, transform 0.08s ease;
}
.tl-key:active:not(:disabled) { background: #26304a; transform: scale(0.96); }
.tl-key:disabled { opacity: 0.35; cursor: default; }
.tl-ok { background: #38d9c9; border-color: #38d9c9; color: #06231d; font-size: 17px; }
.tl-ok:active:not(:disabled) { background: #2bbfb0; }
.tl-ok.next { background: #e8eefc; border-color: #e8eefc; color: #0d1320; opacity: 1; }
.tl-ok:disabled { background: #1a2132; border-color: #2f3a50; color: #e8eefc; }
.tl-del { font-size: 20px; }
.tl-display {
  background: #0a0f1a;
  border: 1px solid #2f3a50;
  color: #fff;
  font-size: clamp(24px, 4dvh, 32px); font-weight: 800;
  letter-spacing: 0.04em;
}
.tl-display.muted { color: #6f7b93; font-size: 14px; font-weight: 700; letter-spacing: 0; }
#game.typing .tl-display { border-color: #38d9c9; box-shadow: 0 0 0 2px rgba(56, 217, 201, 0.25); }
#game.typing .tl-display.muted { font-size: clamp(24px, 4dvh, 32px); animation: tl-blink 1s steps(2) infinite; }
@keyframes tl-blink { 50% { opacity: 0.3; } }
/* 좌상단 ← 홈, 우상단 🏆 명예의 전당 — 모든 게임 공통 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;
}

/* start + result cards */
.tl-start { gap: 14px; }
.tl-start-ico { display: flex; gap: 6px; justify-content: center; line-height: 0; }
.tl-intro { margin: 0; font-size: 14px; line-height: 1.5; color: #cfd6e4; }
.tl-plan { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 7px; text-align: left; }
.tl-plan li { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #d6dcea; line-height: 1.3; }
.tl-plan .k {
  flex: 0 0 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; color: #0d1320; background: #4dabf7;
}
.tl-plan .k.warn { background: #ffd43b; }
.tl-plan .k.good { background: #38d9c9; }
.overlay-card .start-btn { background: #38d9c9; border-color: #38d9c9; color: #06231d; font-weight: 800; }
.overlay-card { background: #141a26; border-color: #252e40; }
.tl-sum { display: flex; gap: 6px; width: 100%; }
.tl-sum div {
  flex: 1; min-width: 0;
  background: #0f141f; border: 1px solid #242c3c; border-radius: 10px;
  padding: 6px 4px; display: flex; flex-direction: column; gap: 2px;
}
.tl-sum span { font-size: 11px; color: #9aa6bd; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.tl-sum b { font-size: 16px; font-variant-numeric: tabular-nums; }
.tl-chips { display: flex; align-items: flex-end; gap: 3px; height: 34px; width: 100%; }
.tl-chips i { flex: 1; height: var(--h); border-radius: 3px 3px 1px 1px; background: #ff6b6b; }
.tl-chips i.hi { background: #38d9c9; }
.tl-chips i.mid { background: #ffb340; }

@media (max-height: 640px) {
  main { gap: 8px; }
  .overlay-card { padding: 16px 18px; gap: 9px; }
  .overlay-score { font-size: 44px; }
  .overlay-card button { min-height: 40px; padding: 9px 18px; }
  .tl-chips { height: 26px; }
  #game { gap: 7px; }
  .tl-entry, .tl-pad { gap: 6px; }
  .tl-cap { font-size: 14px; }
}
