* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  background: linear-gradient(180deg, #eaf6ff 0%, #dff0e0 100%);
  color: #2b2b2b;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 48px;
}

.screen {
  display: none;
  width: 100%;
  max-width: 900px;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: fade-in 0.25s ease;
}

.screen.active {
  display: flex;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.title {
  font-size: clamp(28px, 6vw, 44px);
  margin: 8px 0 4px;
}

.subtitle {
  font-size: clamp(18px, 3vw, 22px);
  color: #555;
  margin-bottom: 20px;
}

.loading-bar-track {
  width: 100%;
  max-width: 360px;
  height: 22px;
  background: white;
  border-radius: 12px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.1);
  overflow: hidden;
  margin-bottom: 10px;
}

.loading-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4d96ff, #2ecc71);
  border-radius: 12px;
  transition: width 0.2s ease;
}

.screen-title {
  font-size: clamp(26px, 5vw, 36px);
  margin: 8px 0 20px;
}

/* Buttons */
.primary-btn {
  font-size: clamp(20px, 3.5vw, 26px);
  font-weight: bold;
  padding: 18px 48px;
  margin-top: 28px;
  border: none;
  border-radius: 20px;
  background: #ff9f43;
  color: white;
  box-shadow: 0 6px 0 #d97e1a;
  cursor: pointer;
  transition: transform 0.05s ease;
}

.primary-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #d97e1a;
}

.primary-btn:disabled {
  background: #cfcfcf;
  box-shadow: 0 6px 0 #a8a8a8;
  cursor: not-allowed;
}

.primary-btn.hidden {
  display: none;
}

/* Login numpad */
.seat-display {
  font-size: clamp(36px, 8vw, 56px);
  letter-spacing: 8px;
  font-weight: bold;
  background: white;
  border-radius: 16px;
  padding: 12px 32px;
  margin-bottom: 24px;
  min-width: 200px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.1);
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 340px;
}

.num-btn {
  font-size: clamp(24px, 5vw, 32px);
  font-weight: bold;
  padding: 22px 0;
  border: none;
  border-radius: 16px;
  background: white;
  box-shadow: 0 5px 0 #c9c9c9;
  cursor: pointer;
}

.num-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #c9c9c9;
}

.num-btn.wide {
  grid-column: span 2;
  font-size: clamp(16px, 3vw, 20px);
  background: #ffe0e0;
}

/* Rules */
.rules-list {
  list-style: none;
  padding: 0;
  font-size: clamp(18px, 3.5vw, 24px);
  text-align: left;
  max-width: 480px;
}

.rules-list li {
  background: white;
  border-radius: 14px;
  padding: 16px 20px;
  margin-bottom: 14px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.08);
}

/* Quiz screens */
.quiz-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: clamp(16px, 3vw, 22px);
  font-weight: bold;
  margin-bottom: 8px;
}

.timer {
  background: #ff6b6b;
  color: white;
  padding: 8px 18px;
  border-radius: 12px;
  font-variant-numeric: tabular-nums;
}

.question-counter {
  font-size: clamp(16px, 3vw, 20px);
  color: #666;
  margin: 4px 0 16px;
}

.audio-prompt {
  margin-bottom: 20px;
}

.play-btn {
  font-size: clamp(20px, 4vw, 28px);
  font-weight: bold;
  padding: 24px 40px;
  border: none;
  border-radius: 50px;
  background: #4d96ff;
  color: white;
  box-shadow: 0 6px 0 #2f6fd1;
  cursor: pointer;
}

.play-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #2f6fd1;
}

.play-btn:disabled {
  background: #b8c9de;
  box-shadow: 0 6px 0 #8fa0b5;
  cursor: not-allowed;
}

.hint {
  color: #777;
  font-size: 15px;
  margin-top: 8px;
}

.prompt-image-wrap {
  margin-bottom: 20px;
}

.prompt-image {
  width: min(60vw, 320px);
  border-radius: 20px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.15);
}

.choices-grid {
  display: grid;
  gap: 16px;
  width: 100%;
}

.grid-4 {
  grid-template-columns: repeat(2, 1fr);
  max-width: 560px;
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
  max-width: 500px;
}

.choice-btn {
  border: 5px solid transparent;
  border-radius: 18px;
  background: white;
  padding: 8px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.choice-btn img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 12px;
}

.choice-btn .choice-label {
  font-size: clamp(16px, 3vw, 20px);
  font-weight: bold;
}

.choice-btn.audio-choice {
  flex-direction: row;
  justify-content: center;
  padding: 28px 12px;
  font-size: clamp(18px, 3.5vw, 24px);
  font-weight: bold;
  gap: 12px;
}

.choice-btn.audio-choice .choice-label::before {
  content: "🎧 ";
}

.choice-btn.audio-choice.previewing {
  border-color: #4d96ff;
  background: #eaf3ff;
}

.choice-btn.audio-choice.previewing .choice-label::before {
  content: "🔊 ";
}

.choice-btn.audio-choice.playing .choice-label::before {
  content: "";
}

.eq-bars {
  display: none;
  align-items: flex-end;
  height: 22px;
  gap: 3px;
}

.choice-btn.audio-choice.playing .eq-bars {
  display: flex;
}

.eq-bars span {
  width: 5px;
  background: #4d96ff;
  border-radius: 2px;
  animation: eq-bounce 0.7s ease-in-out infinite;
}

.eq-bars span:nth-child(1) {
  animation-delay: 0s;
}

.eq-bars span:nth-child(2) {
  animation-delay: 0.2s;
}

.eq-bars span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes eq-bounce {
  0%, 100% { height: 6px; }
  50% { height: 22px; }
}

.choice-btn.correct {
  border-color: #2ecc71;
  background: #eafff0;
}

.choice-btn.wrong {
  border-color: #ff6b6b;
  background: #fff0f0;
}

.choice-btn:disabled {
  cursor: default;
  opacity: 0.9;
}

/* Results */
.score-summary {
  font-size: clamp(18px, 3.5vw, 22px);
  background: white;
  border-radius: 18px;
  padding: 20px 32px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}

.score-summary p {
  margin: 6px 0;
}

.total-score {
  font-size: clamp(24px, 4.5vw, 30px);
  font-weight: bold;
  color: #ff9f43;
}

.leaderboard-title {
  margin-top: 28px;
}

.leaderboard-list {
  width: 100%;
  max-width: 420px;
  text-align: left;
  padding: 0 0 0 28px;
  font-size: clamp(16px, 3vw, 20px);
}

.leaderboard-list li {
  background: white;
  border-radius: 10px;
  padding: 8px 14px;
  margin-bottom: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

/* Matching game */
.matching-board {
  position: relative;
  display: flex;
  gap: 130px;
  width: 100%;
  max-width: 820px;
  justify-content: center;
}

.matching-lines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.matching-lines path {
  fill: none;
  stroke: #2ecc71;
  stroke-width: 4;
  stroke-linecap: round;
}

.matching-column {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  position: relative;
  z-index: 1;
}

.match-item {
  border: 4px solid transparent;
  border-radius: 16px;
  background: white;
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: clamp(16px, 2.8vw, 19px);
  font-weight: bold;
  box-shadow: 0 3px 8px rgba(0,0,0,0.08);
}

.match-item img {
  width: 76px;
  height: 76px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
}

.match-item.selected {
  border-color: #4d96ff;
  box-shadow: 0 0 0 4px rgba(77, 150, 255, 0.25);
}

.match-item.paired {
  border-color: #2ecc71;
  background: #eafff0;
  opacity: 0.85;
  cursor: default;
}

.match-item.wrong-flash {
  border-color: #ff6b6b;
  background: #fff0f0;
}

.match-dot {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #2ecc71;
  transform: translate(-50%, -50%);
  z-index: 2;
}
