*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: linear-gradient(135deg, #ffeaa7, #fab1a0, #a29bfe, #74b9ff);
  background-size: 400% 400%;
  animation: bgshift 20s ease infinite;
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

@keyframes bgshift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.game {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 24px 16px 40px;
  gap: 16px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 12px;
  flex-wrap: wrap;
}

.games {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.game-btn {
  padding: 6px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.65);
  border: 3px solid transparent;
  font-weight: 800;
  font-size: 22px;
  color: #576574;
  cursor: pointer;
  line-height: 1.1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transition: transform 0.1s;
  text-align: center;
}

.game-btn small {
  display: block;
  font-size: 11px;
  font-weight: 600;
  opacity: 0.75;
}

.game-btn.active {
  background: #fdcb6e;
  border-color: #e17055;
  color: #2d3436;
  transform: scale(1.05);
}

.score-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.7);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.score-label { color: #2d3436; }
.score { color: #d63031; font-size: 28px; }

.stage {
  position: relative;
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.number {
  font-size: min(60vh, 70vw);
  font-weight: 900;
  line-height: 1;
  color: #fff;
  text-shadow:
    0 0 30px rgba(255, 255, 255, 0.6),
    6px 6px 0 rgba(0, 0, 0, 0.15);
  animation: pop 0.5s ease-out;
  white-space: nowrap;
}

.number.equation {
  font-size: min(28vh, 22vw);
  letter-spacing: 0.05em;
}

.number.picture {
  text-shadow: none;
  color: initial !important;
  font-size: min(55vh, 60vw);
  animation: pop 0.5s ease-out;
}

.hint {
  font-size: 20px;
  font-weight: 700;
  color: rgba(45, 52, 54, 0.7);
  text-align: center;
  margin: 8px 0 0;
  min-height: 28px;
}

.live-caption {
  margin: 0;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: rgba(45, 52, 54, 0.85);
  background: rgba(255, 255, 255, 0.55);
  padding: 6px 16px;
  border-radius: 999px;
  min-height: 30px;
  min-width: 120px;
  align-self: center;
  transition: opacity 0.15s;
}

.live-caption:empty { visibility: hidden; }
.live-caption:before { content: "🎤 "; opacity: 0.7; }
.live-caption.interim { opacity: 0.55; font-style: italic; }
.live-caption.final { opacity: 1; }

@keyframes pop {
  0% { transform: scale(0.3) rotate(-20deg); opacity: 0; }
  60% { transform: scale(1.15) rotate(5deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.number.wrong {
  animation: shake 0.5s;
  color: #fff;
}

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

.status {
  font-size: 22px;
  font-weight: 700;
  color: #2d3436;
  background: rgba(255, 255, 255, 0.7);
  padding: 12px 24px;
  border-radius: 999px;
  margin: 0;
  text-align: center;
  min-height: 52px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.mic {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 40px;
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  background: #e17055;
  border: none;
  border-radius: 999px;
  box-shadow: 0 8px 0 #b74a30, 0 12px 24px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.mic:active {
  transform: translateY(4px);
  box-shadow: 0 4px 0 #b74a30, 0 8px 16px rgba(0, 0, 0, 0.2);
}

.mic.listening {
  background: #d63031;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 8px 0 #b02020, 0 12px 24px rgba(214, 48, 49, 0.6); }
  50% { box-shadow: 0 8px 0 #b02020, 0 12px 40px rgba(214, 48, 49, 1); }
}

.mic-icon { font-size: 34px; }

.skip {
  padding: 10px 22px;
  font-size: 18px;
  font-weight: 700;
  color: #2d3436;
  background: rgba(255, 255, 255, 0.8);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
}

.skip:active { transform: translateY(2px); }

.bottom-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.test-open {
  padding: 10px 22px;
  font-size: 16px;
  font-weight: 700;
  color: #2d3436;
  background: rgba(255, 255, 255, 0.8);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
}

.test-open:active { transform: translateY(2px); }

.test-panel {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.test-panel.hidden { display: none; }

.test-panel-inner {
  background: #fff;
  border-radius: 24px;
  padding: 24px 20px;
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  color: #2d3436;
}

.test-panel-inner h2 {
  margin: 0 0 16px;
  font-size: 22px;
}

.test-panel-inner h3 {
  margin: 20px 0 8px;
  font-size: 16px;
}

.test-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: #f1f2f6;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}

.diag-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #f1f2f6;
  font-size: 15px;
}

.diag-label {
  flex: 0 0 auto;
  font-weight: 600;
  color: #576574;
  min-width: 120px;
}

.diag-value {
  flex: 1;
  font-weight: 700;
}

.diag-value.ok { color: #10ac84; }
.diag-value.bad { color: #ee5253; }
.diag-value.pending { color: #576574; }

.meter {
  flex: 1;
  height: 16px;
  background: #f1f2f6;
  border-radius: 999px;
  overflow: hidden;
}

.meter-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #48dbfb, #1dd1a1, #feca57, #ff6b6b);
  transition: width 0.05s linear;
}

.diag-hint {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: #fff9c4;
  border-radius: 12px;
  font-size: 13px;
  color: #5f4b00;
  line-height: 1.5;
}

.diag-hint.bad {
  background: #ffebee;
  color: #b71c1c;
}

.diag-log {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 12px;
  min-height: 100px;
  max-height: 200px;
  overflow-y: auto;
  font-size: 15px;
  line-height: 1.6;
}

.diag-log .entry {
  padding: 4px 0;
  border-bottom: 1px dashed #e0e0e0;
}

.diag-log .entry:last-child { border-bottom: none; }

.diag-log .entry.interim { color: #999; font-style: italic; }
.diag-log .entry.final { color: #2d3436; font-weight: 700; }

.diag-log .muted { color: #999; font-style: italic; margin: 0; }

.party {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.party .emoji {
  position: absolute;
  font-size: 60px;
  animation: fly 1.2s ease-out forwards;
}

@keyframes fly {
  0% { transform: translate(0, 0) scale(0.3) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.4) rotate(var(--rot)); opacity: 0; }
}
