/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #6c5ce7;
  --primary-dark: #5a4bd1;
  --accent: #fdcb6e;
  --accent-dark: #f0b429;
  --bg: #0f0f1a;
  --bg-card: rgba(26, 26, 46, 0.65);
  --bg-card-hover: rgba(34, 34, 58, 0.7);
  --glass-blur: 16px;
  --glass-border: rgba(255, 255, 255, 0.08);
  --text: #e0e0e0;
  --text-muted: #8888aa;
  --success: #00b894;
  --danger: #e17055;
  --gap-color: #3d3d5c;
  --radius: 16px;
  --radius-sm: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(108, 92, 231, 0.15) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(253, 203, 110, 0.1) 0%, transparent 50%);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.screen {
  display: none;
  min-height: 100vh;
}
.screen.active {
  display: flex;
}

button {
  cursor: pointer;
  border: none;
  font-size: 1rem;
  font-family: inherit;
  transition: all 0.2s;
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input, select {
  font-family: inherit;
  font-size: 1rem;
}

/* ===== 大廳 ===== */
.lobby-container {
  margin: auto;
  padding: 2rem 1rem;
  text-align: center;
  width: 100%;
  max-width: 420px;
}

.game-title {
  font-size: 2.5rem;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.25rem;
}
.subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

.lobby-card {
  background: var(--bg-card);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: left;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.lobby-card label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 1rem;
}
.lobby-card label:first-child {
  margin-top: 0;
}
.lobby-card input,
.lobby-card select {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid #333;
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.lobby-card input:focus,
.lobby-card select:focus {
  border-color: var(--primary);
}

.lobby-actions {
  margin-top: 1.5rem;
}
.lobby-actions button {
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 1.05rem;
}
.lobby-actions button:hover:not(:disabled) {
  background: var(--primary-dark);
}

.divider-text {
  text-align: center;
  color: var(--text-muted);
  margin: 0.8rem 0;
  font-size: 0.85rem;
}

.join-row {
  display: flex;
  gap: 0.5rem;
}
.join-row input {
  flex: 1;
}
.join-row button {
  width: auto;
  padding: 0.7rem 1.2rem;
  white-space: nowrap;
}

.game-rules-brief {
  margin-bottom: 1.5rem;
  text-align: left;
}
.game-rules-brief details {
  background: var(--bg-card);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
}
.game-rules-brief summary {
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--accent);
  font-weight: 600;
}
.game-rules-brief ul {
  margin-top: 0.6rem;
  padding-left: 1.2rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.7;
}
.game-rules-brief li strong {
  color: var(--success);
}

.section-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

.loading-status {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--accent);
}
.loading-status.loaded {
  color: var(--success);
}
.loading-status.error {
  color: var(--danger);
}

/* ===== 等待室 ===== */
.waiting-container {
  margin: auto;
  padding: 2rem 1rem;
  text-align: center;
  width: 100%;
  max-width: 500px;
}
.waiting-container h2 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}
.waiting-container h2 span {
  color: var(--accent);
  font-family: monospace;
  letter-spacing: 2px;
}

.player-list {
  background: var(--bg-card);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.5rem;
  min-height: 60px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.player-list .player-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.3rem;
  border-bottom: 1px solid #2a2a40;
}
.player-list .player-item:last-child {
  border-bottom: none;
}
.player-item .host-badge {
  background: var(--accent);
  color: #000;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

.btn-primary {
  padding: 0.75rem 2rem;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 1.05rem;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 1rem;
}

/* ===== 遊戲主畫面 ===== */
.game-layout {
  display: flex;
  flex-direction: row;
  min-height: 100vh;
  width: 100%;
}

.timeline-panel {
  flex: 1;
  padding: 1.25rem;
  overflow-y: auto;
  max-height: 100vh;
  border-right: 1px solid var(--glass-border);
  background: rgba(15, 15, 26, 0.4);
}
.control-panel {
  width: 380px;
  min-width: 320px;
  padding: 1.25rem;
  overflow-y: auto;
  max-height: 100vh;
  background: rgba(15, 15, 26, 0.4);
}

/* Game info bar */
.game-info-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}
#current-turn-label {
  color: var(--accent);
  font-weight: 600;
}
.win-score-label {
  color: var(--success);
  font-weight: 600;
  font-size: 0.85rem;
}

/* Scoreboard */
.scoreboard {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.score-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-card);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  padding: 0.3rem 0.7rem;
  border-radius: 20px;
  font-size: 0.8rem;
}
.score-chip.active-player {
  border: 1px solid var(--accent);
}
.score-chip .chip-pts {
  color: var(--success);
  font-weight: 600;
}
.score-chip .chip-tokens {
  color: var(--accent);
}

/* Timeline */
.timeline-title {
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

.timeline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: stretch;
  min-height: 80px;
  padding: 0.5rem;
  background: var(--bg-card);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.timeline-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(108, 92, 231, 0.8), rgba(90, 75, 209, 0.9));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  min-width: 78px;
  max-width: 110px;
  text-align: center;
  line-height: 1.3;
  box-shadow: 0 4px 16px rgba(108, 92, 231, 0.25);
  transition: transform 0.2s, box-shadow 0.2s;
}
.timeline-card .card-year {
  font-weight: 700;
  font-size: 0.9rem;
}
.timeline-card .card-title {
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0.95;
  margin-top: 1px;
}
.timeline-card .card-artist {
  font-size: 0.6rem;
  opacity: 0.7;
}
.timeline-card.just-placed {
  border: 2px solid var(--accent);
  animation: pulse 0.6s ease;
}

.timeline-gap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  min-height: 60px;
  border: 2px dashed var(--gap-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--gap-color);
  font-size: 1.4rem;
  transition: all 0.2s;
  flex-shrink: 0;
}
.timeline-gap:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(253, 203, 110, 0.08);
}
.timeline-gap.selected {
  border-color: var(--accent);
  background: rgba(253, 203, 110, 0.15);
  color: var(--accent);
}
.timeline-gap.bet-selected {
  border-color: var(--success);
  background: rgba(0, 184, 148, 0.15);
  color: var(--success);
}

/* Music section */
.music-section {
  margin-bottom: 1rem;
}
.player-wrapper {
  position: relative;
  width: 100%;
  margin-bottom: 0.5rem;
}
#yt-player-container {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 56.25%;
  overflow: hidden;
  border-radius: var(--radius-sm);
}
#yt-player-container iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
}
.yt-mask {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(26, 26, 46, 0.85), rgba(45, 45, 68, 0.85));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: var(--radius-sm);
}
.mask-icon {
  font-size: 3rem;
  animation: bounce 1.5s infinite;
}

.playback-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.btn-play {
  padding: 0.6rem 1.5rem;
  background: var(--success);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.btn-play:hover:not(:disabled) {
  background: #00a884;
}
.btn-replay {
  padding: 0.6rem 1rem;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
}
.btn-replay:hover:not(:disabled) {
  background: var(--primary-dark);
}
.timer-display {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: monospace;
  color: var(--accent);
  min-width: 50px;
  text-align: center;
}
.btn-swap {
  padding: 0.5rem 0.8rem;
  background: var(--danger);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.btn-swap:hover:not(:disabled) {
  opacity: 0.85;
}
.btn-direct {
  padding: 0.5rem 0.8rem;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  color: #000;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
}
.btn-direct:hover:not(:disabled) {
  opacity: 0.85;
}

.winner-announcement {
  text-align: center;
  margin-top: 1.25rem;
  padding: 1rem;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(253, 203, 110, 0.12);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}

/* Guess section */
.guess-section {
  background: var(--bg-card);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.guess-section h3 {
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
}
.guess-section input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid #333;
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  margin-bottom: 0.5rem;
}
.guess-section input:focus {
  border-color: var(--primary);
  outline: none;
}
.guess-section .btn-primary {
  width: 100%;
  margin-top: 0.3rem;
}

/* Betting section */
.betting-section {
  background: var(--bg-card);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.betting-section h3 {
  font-size: 0.95rem;
  margin-bottom: 0.3rem;
}
.bet-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.betting-timeline {
  margin-bottom: 0.75rem;
}
.bet-guess-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.bet-guess-row input {
  flex: 1;
  padding: 0.6rem 0.8rem;
  border: 1px solid #333;
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
}
.bet-guess-row input:focus {
  border-color: var(--primary);
  outline: none;
}
.betting-section .btn-primary {
  width: 100%;
}

/* Reveal section */
.reveal-section {
  background: var(--bg-card);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.reveal-section h3 {
  margin-bottom: 0.75rem;
}
.reveal-answer {
  text-align: center;
  margin-bottom: 1rem;
}
.reveal-answer .answer-song {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
}
.reveal-answer .answer-detail {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}
.reveal-result-list {
  list-style: none;
  padding: 0;
}
.reveal-result-list li {
  padding: 0.4rem 0;
  border-bottom: 1px solid #2a2a40;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
}
.reveal-result-list li:last-child {
  border-bottom: none;
}
.result-correct {
  color: var(--success);
}
.result-wrong {
  color: var(--danger);
}
.reveal-section .btn-primary {
  width: 100%;
  margin-top: 1rem;
}

/* ===== Animations ===== */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* ===== RWD: Mobile ===== */
@media (max-width: 768px) {
  .game-layout {
    flex-direction: column;
  }
  .timeline-panel {
    border-right: none;
    border-bottom: 1px solid #2a2a40;
    max-height: none;
    overflow-y: visible;
  }
  .control-panel {
    width: 100%;
    min-width: auto;
    max-height: none;
    overflow-y: visible;
  }
  .game-title {
    font-size: 2rem;
  }
  .timeline {
    flex-wrap: wrap;
  }
}
