* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bzzt-abyss, #0b1020);
  color: var(--text, #fff);
  /* 본문은 Pretendard(shared/bzzt-tokens.css 에서 자체 호스팅), 타이틀/라틴은 CDN 폰트 */
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

canvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

.layer {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}

#score {
  font-size: clamp(44px, 10vmin, 88px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  text-shadow: 0 4px 28px rgba(0, 0, 0, .6);
  transition: transform .09s ease-out;
}

#combo {
  font-size: clamp(12px, 1.8vmin, 16px);
  font-weight: 600;
  letter-spacing: .18em;
  opacity: 0;
  transition: opacity .2s;
}

#menu-btn {
  position: fixed;
  top: calc(6px + env(safe-area-inset-top));
  left: 6px;
  z-index: 10;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 30px;
  line-height: 44px;
  cursor: pointer;
  opacity: .8;
}

/* =====================================================================
 * 허브 메뉴 — BZZT! 디자인 시스템 (shared/bzzt-tokens.css 의 토큰 사용).
 * microgames/ 와 같은 색·간격·라운드·리프트를 쓰므로 두 페이지가 한 제품처럼 보인다.
 * ===================================================================== */
#overlay {
  position: fixed;
  inset: 0;
  /* games/racing.js 는 셸의 HUD 캔버스 밑에 별도 WebGL 캔버스를 z-index:0 으로
     붙인다. #overlay 는 z-index 가 없어서(auto) 그 z-index:0 캔버스와 같은
     스태킹 버킷에 들어갔는데, 캔버스가 DOM 상 더 나중에 붙어서(body 에 append)
     같은 버킷 안에서 나중 순서가 이겨 불투명한 3D 씬이 메뉴 패널을 통째로
     덮어버렸다(실측 확인 — 유저 스크린샷으로 텍스트가 아예 안 보임을 확인).
     오버레이는 어떤 게임이 떠 있든 항상 최상단이어야 하는 모달이라, 명시적으로
     z-index 를 준다. */
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background:
    radial-gradient(ellipse 46% 34% at 20% 22%, rgba(168, 85, 247, .20), transparent 70%),
    radial-gradient(ellipse 40% 30% at 80% 40%, rgba(6, 182, 212, .16), transparent 70%),
    radial-gradient(ellipse 46% 36% at 50% 86%, rgba(236, 72, 153, .14), transparent 70%),
    rgba(5, 8, 18, .82);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  /* 카테고리가 늘어나면 메뉴가 화면보다 길어질 수 있다 — 그때만 스크롤 */
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

#overlay.hidden {
  display: none !important;
}

#menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3, 12px);
  width: 100%;
  max-width: 940px;
  margin: auto;
  padding-block: 8px;
}

/* ── 헤더 (로고 + 연결 상태) ── */
.hub-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3, 12px);
  width: 100%;
  margin-bottom: var(--s-4, 16px);
}

/* 로고는 밝은 배경용 원본(노란 다이아 + 검은 워드마크)이라 어두운 배경에서 글자가 묻힌다.
   브랜드 색을 임의로 바꾸지 않고, 밝은 칩을 깔아서 원본 그대로 읽히게 한다. */
.hub-logo {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: var(--r-sm, 8px);
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
}
.hub-logo img { height: 18px; width: auto; display: block; }

.hub-header-right { display: inline-flex; align-items: center; gap: var(--s-2, 8px); }

.hub-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 2px solid var(--line-strong, rgba(255, 255, 255, .16));
  border-radius: var(--r-sm, 8px);
  background: rgba(15, 23, 42, .55);
  color: var(--text-mid, rgba(255, 255, 255, .68));
  cursor: pointer;
  transition: transform var(--t-press, .08s), border-color var(--t-hover, .15s), color var(--t-hover, .15s);
}
.hub-icon-btn:hover { border-color: var(--neon-cyan, #06b6d4); color: var(--neon-cyan-lit, #67e8f9); }
.hub-icon-btn:active { transform: var(--press-sink, translateY(2px)); }
.hub-icon-btn.off { color: var(--text-faint, rgba(255, 255, 255, .4)); }

.hub-lang {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: rgba(15, 23, 42, .6);
  border: 1px solid var(--line-strong, rgba(255, 255, 255, .16));
  border-radius: var(--r-pill, 999px);
}

.hub-lang button {
  font-family: var(--font-arcade, inherit);
  font-size: 11px;
  letter-spacing: var(--ls-arcade, .08em);
  padding: 6px 12px;
  border: none;
  border-radius: var(--r-pill, 999px);
  background: transparent;
  color: var(--text-faint, rgba(255, 255, 255, .45));
  cursor: pointer;
}

.hub-lang button.active { background: var(--grad-cool, #06b6d4); color: #fff; }

.hub-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  border-radius: var(--r-pill, 999px);
  border: 1px solid rgba(248, 113, 113, .45);
  background: rgba(127, 29, 29, .35);
  color: #fecaca;
  font-family: var(--font-ui, inherit);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.hub-status.connected {
  border-color: rgba(16, 185, 129, .5);
  background: rgba(6, 78, 59, .38);
  color: #a7f3d0;
}

.hub-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f87171;
  box-shadow: 0 0 8px currentColor;
  flex-shrink: 0;
}

.hub-status.connected .hub-status-dot { background: #34d399; }

/* ── 히어로 ── */
.hub-hero { margin-bottom: var(--s-5, 20px); }

#menu-title {
  font-family: var(--font-display, inherit);
  font-size: clamp(34px, 7vmin, 62px);
  line-height: 1.05;
  color: var(--text-hi, #fff);
  text-shadow: var(--text-glow-violet, none);
}

#menu-sub {
  margin-top: 8px;
  font-size: clamp(13px, 2vmin, 16px);
  color: var(--text-mid, rgba(255, 255, 255, .68));
}

/* ── 카테고리 섹션 ── */
#menu-cards {
  display: flex;
  flex-direction: column;
  gap: var(--s-8, 32px);
  width: 100%;
}

.menu-section { width: 100%; text-align: left; }

.menu-section-head {
  display: flex;
  align-items: baseline;
  gap: var(--s-3, 12px);
}

.menu-section-title {
  font-family: var(--font-display, inherit);
  font-size: 22px;
  color: var(--text-hi, #fff);
}

.menu-section-en {
  font-family: var(--font-arcade, monospace);
  font-size: 12px;
  letter-spacing: var(--ls-arcade, .08em);
  color: var(--neon-cyan-lit, #67e8f9);
}

.menu-section-count {
  margin-left: auto;
  font-family: var(--font-arcade, monospace);
  font-size: 12px;
  color: var(--text-faint, rgba(255, 255, 255, .4));
}

.menu-section-desc {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--text-faint, rgba(255, 255, 255, .45));
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(268px, 1fr));
  gap: var(--s-4, 16px);
  margin-top: var(--s-4, 16px);
}

/* ── 게임 카드 ── */
.game-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--s-3, 12px);
  padding: var(--s-5, 20px);
  border: 2px solid var(--line, rgba(255, 255, 255, .1));
  border-radius: var(--r-lg, 16px);
  background: rgba(15, 23, 42, .62);
  box-shadow: var(--lift-neutral, none);
  color: var(--text, #fff);
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: transform var(--t-press, .08s) var(--ease-out, ease-out),
              border-color var(--t-hover, .15s), box-shadow var(--t-hover, .15s);
}

.game-card:hover { transform: var(--hover-rise, translateY(-2px)); }
.game-card:active { transform: var(--press-sink, translateY(4px)); box-shadow: var(--lift-pressed, none); }

.game-card.tone-violet:hover { border-color: rgba(196, 181, 253, .7); box-shadow: var(--glow-violet, none); }
.game-card.tone-cyan:hover   { border-color: rgba(103, 232, 249, .7); box-shadow: var(--glow-cyan, none); }
.game-card.tone-gold:hover   { border-color: rgba(253, 224, 71, .7);  box-shadow: var(--glow-gold, none); }

.game-card-icon { flex-shrink: 0; line-height: 1; filter: drop-shadow(0 0 12px currentColor); }
.game-card.tone-violet .game-card-icon { color: var(--neon-violet-lit, #c4b5fd); }
.game-card.tone-cyan   .game-card-icon { color: var(--neon-cyan-lit, #67e8f9); }
.game-card.tone-gold   .game-card-icon { color: var(--gold-lit, #fde047); }

.game-card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.game-card-title {
  font-family: var(--font-ui, inherit);
  font-weight: var(--fw-black, 900);
  font-size: 18px;
  line-height: 1.25;
  color: var(--text-hi, #fff);
  word-break: keep-all;
}

.game-card-titleen {
  margin-top: 2px;
  font-family: var(--font-arcade, monospace);
  font-style: normal;
  font-size: 10.5px;
  letter-spacing: var(--ls-arcade, .08em);
  color: var(--text-faint, rgba(255, 255, 255, .4));
}

.game-card-tagline {
  margin-top: 8px;
  font-size: 13px;
  line-height: var(--lh-body, 1.55);
  color: var(--text-mid, rgba(255, 255, 255, .64));
  word-break: keep-all;
}

.game-card-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.game-card .card-best {
  font-family: var(--font-arcade, monospace);
  font-style: normal;
  font-size: 12px;
  color: var(--gold, #facc15);
  white-space: nowrap;
}

.game-card .card-ext { color: var(--text-faint, rgba(255, 255, 255, .4)); line-height: 1; }

/* 지연 로딩 상태 — 카드를 누르고 스크립트를 받는 동안 */
.game-card.loading { cursor: progress; opacity: .7; }
.game-card.loading::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  border-radius: 0 0 var(--r-lg, 16px) var(--r-lg, 16px);
  background: var(--grad-cool, linear-gradient(90deg, #06b6d4, #8b5cf6));
  animation: hub-loading 1s ease-in-out infinite;
}

@keyframes hub-loading {
  0%   { clip-path: inset(0 100% 0 0); }
  50%  { clip-path: inset(0 0 0 0); }
  100% { clip-path: inset(0 0 0 100%); }
}

.game-card.load-failed { border-color: var(--fail-lit, #f87171); }
.game-card.load-failed::after {
  content: '불러오지 못했습니다 — 다시 누르면 재시도';
  position: absolute;
  left: var(--s-5, 20px); right: var(--s-5, 20px); bottom: 6px;
  font-size: 11px;
  color: var(--fail-lit, #f87171);
}

#panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

#panel-title {
  font-size: clamp(32px, 6.6vmin, 60px);
  font-weight: 700;
  letter-spacing: -0.02em;
}

#panel-subtitle {
  font-size: clamp(14px, 2.1vmin, 19px);
  opacity: .74;
  line-height: 1.65;
}

#panel-hint {
  font-size: clamp(11px, 1.5vmin, 13px);
  opacity: .38;
  letter-spacing: .1em;
  text-transform: uppercase;
}

#panel-best {
  font-size: clamp(12px, 1.6vmin, 14px);
  opacity: .5;
  margin-top: 4px;
}

#touch-hint {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(60px + env(safe-area-inset-top)) 0 calc(96px + env(safe-area-inset-bottom));
  font-size: 12px;
  letter-spacing: .08em;
  opacity: 0;
  color: #7d8ba3;
  pointer-events: none;
  transition: opacity .3s;
}

#touch-hint.visible {
  opacity: 1;
}

/* 허브 메뉴에서는 진단 HUD 를 숨긴다 — 헤더의 상태 배지가 같은 정보를 주고,
   HUD 가 카드 위로 떠서 마지막 카드를 가렸다. 게임 중에만 표시. */
body.menu-open #hud { display: none; }

#hud {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.6;
  color: #8fa3b8;
  background: rgba(0, 0, 0, .45);
}

.hud-line {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.hud-label {
  opacity: .6;
}

#hud b {
  color: #e6edf3;
  font-weight: 600;
}

#hud b.warn {
  color: #ffb347;
}

#hud b.err {
  color: #ff6b6b;
}

.hud-devices {
  flex-basis: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 900px) {
  #hud {
    left: 20px;
    right: auto;
    bottom: 20px;
    flex-direction: column;
    gap: 2px;
    padding: 14px 18px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 12px;
    background: rgba(8, 10, 20, .78);
    font-size: 12px;
  }

  .hud-devices {
    flex-basis: auto;
    max-width: 340px;
  }

  #touch-hint {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  #score {
    font-size: clamp(30px, 8vmin, 50px);
  }
}

/* 모바일 허브 — 헤더는 한 줄 유지하고 상태 배지는 점만 남긴다 (microgames 헤더와 같은 규칙) */
@media (max-width: 720px) {
  #overlay { padding: 16px 14px 28px; }

  .hub-header { gap: 8px; margin-bottom: var(--s-3, 12px); }
  .hub-logo { padding: 4px 7px; }
  .hub-logo img { height: 15px; }
  .hub-lang button { padding: 5px 9px; font-size: 10px; }
  .hub-icon-btn { width: 34px; height: 34px; }

  .hub-status { padding: 7px; gap: 0; }
  .hub-status #hub-status-text { display: none; }

  .menu-grid { grid-template-columns: 1fr; gap: var(--s-3, 12px); margin-top: var(--s-3, 12px); }
  #menu-cards { gap: var(--s-6, 24px); }
  .game-card { padding: var(--s-4, 16px); }
}
