:root {
  --topbar-h: 60px;
  --color-bg: #FFF8E7;
  --color-text: #2D2D2D;
  --color-primary: #FF6B9D;
  --color-blue: #4A90E2;
  --color-green: #5CC97A;
  --color-pink: #FF6B9D;
  --color-purple: #9B6BFF;
  --color-yellow: #FFD93D;
  --color-orange: #FF8A47;
  --color-teal: #5BD9D9;
  --color-brown: #A0784A;
  --color-mint: #7FE3B5;
  --color-correct: #5CC97A;
  --color-wrong: #FF6B6B;
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.10);
  --radius: 24px;
  --font-kid: 'Comic Sans MS', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font-kid);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 24px;
  background-image:
    radial-gradient(circle at 10% 20%, rgba(255, 217, 61, 0.25) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(155, 107, 255, 0.20) 0%, transparent 40%),
    radial-gradient(circle at 50% 50%, rgba(92, 201, 122, 0.15) 0%, transparent 50%);
}

/* ───────── 홈 ───────── */
.hero {
  text-align: center;
  padding: 40px 16px 32px;
}

.hero h1 {
  font-size: clamp(2.5rem, 6vw, 4rem);
  color: var(--color-primary);
  text-shadow: 3px 3px 0 rgba(255, 255, 255, 0.8);
  margin-bottom: 12px;
}

.subtitle {
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  color: #555;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 24px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
  align-content: center;
  padding: 24px 0;
}

.menu-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 36px 20px;
  background: white;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--color-text);
  box-shadow: var(--shadow-lg);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  text-align: center;
  border: 4px solid transparent;
}

.menu-card:hover,
.menu-card:focus-visible {
  transform: translateY(-6px) rotate(-1deg);
  outline: none;
}

.card-blue   { border-color: var(--color-blue); }
.card-green  { border-color: var(--color-green); }
.card-pink   { border-color: var(--color-pink); }
.card-purple { border-color: var(--color-purple); }
.card-orange { border-color: var(--color-orange); }
.card-teal   { border-color: var(--color-teal); }
.card-yellow { border-color: var(--color-yellow); }
.card-brown  { border-color: var(--color-brown); }
.card-mint   { border-color: var(--color-mint); }

.card-emoji {
  font-size: 4rem;
  margin-bottom: 12px;
  line-height: 1;
}

.card-title {
  font-size: 1.6rem;
  font-weight: bold;
  margin-bottom: 8px;
}

.card-desc {
  font-size: 1rem;
  color: #666;
}

.footer {
  text-align: center;
  padding: 24px;
  color: #888;
  font-size: 0.95rem;
}

/* ───────── 게임 공통 ───────── */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1100px;
  margin: 0 auto 24px;
  width: 100%;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: white;
  border: 3px solid var(--color-primary);
  border-radius: 999px;
  color: var(--color-primary);
  font-family: var(--font-kid);
  font-size: 1.1rem;
  font-weight: bold;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform 0.15s ease;
}

.back-btn:hover {
  transform: scale(1.05);
}

.game-title {
  font-size: clamp(1.3rem, 3vw, 2rem);
  color: var(--color-primary);
}

.score-board {
  display: flex;
  gap: 16px;
  font-size: 1.1rem;
  font-weight: bold;
}

.score-item {
  background: white;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
}

.score-item .label { color: #888; margin-right: 6px; }
.score-item .value { color: var(--color-primary); }

.game-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.prompt-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 48px 64px;
  text-align: center;
  min-width: 320px;
  position: relative;
}

.prompt-label {
  font-size: 1.2rem;
  color: #888;
  margin-bottom: 12px;
}

.prompt-target {
  font-size: clamp(5rem, 16vw, 11rem);
  font-weight: bold;
  color: var(--color-primary);
  line-height: 1.1;
  letter-spacing: 0.05em;
}

.prompt-target.small {
  font-size: clamp(3rem, 8vw, 5rem);
}

.input-area {
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.game-input {
  width: 100%;
  padding: 24px 28px;
  font-size: 2.5rem;
  font-family: var(--font-kid);
  text-align: center;
  border: 4px solid #ddd;
  border-radius: var(--radius);
  background: white;
  box-shadow: var(--shadow-md);
  outline: none;
  transition: border-color 0.18s ease, transform 0.18s ease;
}

.game-input:focus {
  border-color: var(--color-primary);
}

.game-input.correct {
  border-color: var(--color-correct);
  background: #E8F8EC;
  animation: pop 0.3s ease;
}

.game-input.wrong {
  border-color: var(--color-wrong);
  background: #FFEBEB;
  animation: shake 0.4s ease;
}

.hint {
  font-size: 1.1rem;
  color: #888;
}

.feedback {
  font-size: 3rem;
  min-height: 1.2em;
  font-weight: bold;
  animation: pop 0.4s ease;
}

.feedback.correct { color: var(--color-correct); }
.feedback.wrong   { color: var(--color-wrong); }

@keyframes pop {
  0%   { transform: scale(0.6); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-10px); }
  40%      { transform: translateX(10px); }
  60%      { transform: translateX(-8px); }
  80%      { transform: translateX(8px); }
}

/* ───────── 별 효과 ───────── */
.stars {
  display: flex;
  gap: 6px;
  font-size: 2rem;
  min-height: 2.5rem;
}

.star {
  opacity: 0.25;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.star.on {
  opacity: 1;
  transform: scale(1.15);
  filter: drop-shadow(0 0 8px var(--color-yellow));
}

/* ───────── 음악 페이지 ───────── */
.song-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  padding: 16px 0;
}

.song-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  border: 4px solid transparent;
  transition: transform 0.18s ease, border-color 0.18s ease;
  font-family: var(--font-kid);
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--color-text);
}

.song-card:hover {
  transform: translateY(-4px);
  border-color: var(--color-purple);
}

.song-card.active {
  border-color: var(--color-primary);
  background: #FFF0F5;
}

.song-emoji {
  font-size: 3rem;
  margin-bottom: 8px;
  line-height: 1;
}

.player-wrap {
  max-width: 900px;
  margin: 0 auto 24px;
  width: 100%;
  background: white;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-wrap iframe,
.player-placeholder {
  width: 100%;
  height: 100%;
  border: 0;
}

.player-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #aaa;
  font-size: 1.4rem;
  text-align: center;
  padding: 24px;
}

.player-placeholder .big-emoji {
  font-size: 5rem;
  margin-bottom: 12px;
}

.now-playing {
  text-align: center;
  margin: 12px 0 20px;
  font-size: 1.3rem;
  color: var(--color-primary);
  font-weight: bold;
  min-height: 1.5em;
}

/* ───────── 공통 상단 네비게이션 ───────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
}
.tb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--color-primary);
  font-weight: bold;
  font-family: var(--font-kid);
}
.tb-logo { font-size: 1.6rem; line-height: 1; }
.tb-name {
  font-size: 1.15rem;
  letter-spacing: 0.04em;
}
.tb-right { display: flex; align-items: center; gap: 12px; }
.tb-profile {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tb-who {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #f7f7f7;
  border-radius: 999px;
  font-family: var(--font-kid);
  font-weight: bold;
  color: var(--color-text);
  cursor: pointer;
}
.tb-avatar { font-size: 1.4rem; line-height: 1; }
.tb-profile .tb-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: white;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 8px;
  min-width: 180px;
  display: none;
  z-index: 110;
}
.tb-profile:hover .tb-menu, .tb-profile:focus-within .tb-menu {
  display: block;
}
.tb-profile .tb-menu a,
.tb-profile .tb-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border-radius: 10px;
  background: transparent;
  border: 0;
  color: var(--color-text);
  font-family: var(--font-kid);
  font-size: 0.95rem;
  font-weight: bold;
  cursor: pointer;
  text-decoration: none;
}
.tb-profile .tb-menu a:hover,
.tb-profile .tb-menu button:hover {
  background: #f5f5f5;
}
.tb-btn {
  display: inline-flex;
  align-items: center;
  padding: 9px 16px;
  border-radius: 999px;
  border: 2px solid #ddd;
  background: white;
  color: #555;
  font-family: var(--font-kid);
  font-weight: bold;
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
}
.tb-btn-primary {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

/* 햄버거 버튼 (모바일에서만) */
.tb-menu-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 0;
}
.tb-menu-btn span {
  display: block;
  width: 24px;
  height: 3px;
  background: var(--color-primary);
  border-radius: 2px;
}

/* 드로어 (모바일 메뉴) */
.tb-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  z-index: 200;
}
.tb-drawer-overlay.open { display: block; }
.tb-drawer {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: min(320px, 88vw);
  background: white;
  overflow-y: auto;
  animation: drawer-in 0.25s ease-out;
  display: flex;
  flex-direction: column;
}
@keyframes drawer-in {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}
.tb-drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 2px solid #f0f0f0;
  font-family: var(--font-kid);
  font-weight: bold;
  font-size: 1.1rem;
  color: var(--color-primary);
}
.tb-drawer-close {
  background: transparent;
  border: 0;
  font-size: 1.4rem;
  cursor: pointer;
  width: 36px; height: 36px;
  border-radius: 50%;
}
.tb-drawer-close:hover { background: #f5f5f5; }
.tb-drawer-profile {
  padding: 12px 20px;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tb-drawer-profile .tb-who { width: 100%; justify-content: flex-start; }
.tb-drawer-profile .tb-menu {
  position: static !important;
  display: flex !important;
  width: 100%;
  box-shadow: none;
  padding: 0;
  gap: 6px;
  flex-wrap: wrap;
}
.tb-drawer-profile .tb-menu a,
.tb-drawer-profile .tb-menu button {
  flex: 1;
  text-align: center;
  border: 2px solid #eee;
}
.tb-drawer-nav { padding: 12px 16px 24px; }
.tb-drawer-section { margin-top: 12px; }
.tb-drawer-section h4 {
  font-size: 0.85rem;
  color: #888;
  font-weight: bold;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  padding-left: 8px;
}
.tb-drawer-section ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.tb-drawer-section li a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--color-text);
  font-family: var(--font-kid);
  font-weight: bold;
}
.tb-drawer-section li a:hover,
.tb-drawer-section li a[aria-current="page"] {
  background: #FFF7E0;
}
.tb-drawer-section li a .emo {
  width: 32px;
  font-size: 1.4rem;
  text-align: center;
}

/* 데스크탑 vs 모바일 분기 */
@media (max-width: 700px) {
  :root { --topbar-h: 56px; }
  .topbar { padding: 0 14px; }
  .tb-name { font-size: 1rem; }
  .tb-profile { display: none; }
  .tb-menu-btn { display: flex; }
}

/* ───────── 반응형 ───────── */
@media (max-width: 700px) {
  body { padding: 12px; }
  .hero h1 { font-size: 2rem; }
  .hero { padding: 16px 8px 12px; }
  .prompt-card { padding: 24px 16px; min-width: 0; }
  .prompt-target { line-height: 1.05; }
  .game-input { font-size: 1.6rem; padding: 16px; }
  .game-header {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
  }
  .game-header .back-btn { padding: 10px 14px; font-size: 1rem; }
  .game-title { font-size: 1.1rem; flex: 1 1 100%; text-align: center; order: 2; }
  .score-board { gap: 8px; }
  .score-item { padding: 6px 12px; font-size: 0.9rem; }
  .menu-card { padding: 20px 14px; }
  .card-emoji { font-size: 2.6rem; margin-bottom: 6px; }
  .card-title { font-size: 1.15rem; }
  .card-desc { font-size: 0.85rem; }
  .feedback { font-size: 2.2rem; }
  /* 모달은 화면 가득 */
  .modal-backdrop .modal { max-width: 100% !important; padding: 20px; }
  /* 음악 노래 카드 사이즈 */
  .song-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .song-card { padding: 14px; font-size: 1rem; }
  .song-emoji { font-size: 2.4rem; }
  /* 노래 영상 비율 유지 */
  .player-wrap { aspect-ratio: 16 / 9; }
}

@media (max-width: 420px) {
  .game-title { font-size: 1rem; }
  .prompt-target { font-size: clamp(3.5rem, 18vw, 5.5rem); }
  .game-input { font-size: 1.4rem; padding: 14px; }
  .menu-card { padding: 14px 8px; }
  .card-emoji { font-size: 2.2rem; }
  .card-title { font-size: 1rem; }
  .card-desc { font-size: 0.78rem; }
  .song-grid { grid-template-columns: 1fr; }
  /* TTS 토글 작게 */
  #ttsToggle { width: 42px !important; height: 42px !important; font-size: 1.3rem !important; right: 10px !important; bottom: 10px !important; }
}
