/* =============================================
   질문 배틀 - 전체 스타일
   ============================================= */

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

:root {
  --team-a: #3b82f6;
  --team-a-light: #dbeafe;
  --team-b: #eab308;
  --team-b-light: #fef9c3;
  --team-c: #22c55e;
  --team-c-light: #dcfce7;
  --bg-dark: #0f172a;
  --bg-mid: #1e293b;
  --bg-card: #1e293b;
  --text-main: #f1f5f9;
  --text-sub: #94a3b8;
  --accent: #f59e0b;
  --radius: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
  font-family: 'Noto Sans KR', sans-serif;
  background: var(--bg-dark);
  color: var(--text-main);
  overflow-x: hidden;
}

/* ── 화면 전환 ── */
.screen { display: none; width: 100%; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* =============================================
   화면 1: 타이틀
   ============================================= */
.title-bg {
  flex: 1;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
}
.title-bg::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 30% 40%, rgba(99,102,241,0.15) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 60%, rgba(245,158,11,0.1) 0%, transparent 60%);
}
.title-content {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; gap: 32px;
  padding: 40px 20px;
}
.game-title {
  font-size: clamp(2.8rem, 6vw, 5rem);
  font-weight: 900;
  background: linear-gradient(90deg, #f59e0b, #ef4444, #a855f7, #3b82f6);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  text-align: center;
  text-shadow: none;
  animation: titlePulse 3s ease-in-out infinite;
}
@keyframes titlePulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.2); }
}
.game-subtitle {
  font-size: 1.1rem; color: var(--text-sub);
  text-align: center; letter-spacing: 0.05em;
}
.team-cards {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: center;
}
.team-card {
  background: rgba(255,255,255,0.05);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 24px 32px;
  text-align: center;
  backdrop-filter: blur(10px);
  transition: transform 0.3s, box-shadow 0.3s;
  cursor: default;
}
.team-card:hover { transform: translateY(-6px); }
.team-card.team-a { border-color: var(--team-a); box-shadow: 0 0 20px rgba(59,130,246,0.3); }
.team-card.team-b { border-color: var(--team-b); box-shadow: 0 0 20px rgba(234,179,8,0.3); }
.team-card.team-c { border-color: var(--team-c); box-shadow: 0 0 20px rgba(34,197,94,0.3); }
.team-icon { font-size: 2.4rem; margin-bottom: 8px; }
.team-name { font-size: 1.2rem; font-weight: 700; }
.team-label { font-size: 0.85rem; color: var(--text-sub); margin-top: 4px; }
.vs-badge {
  font-size: 1.4rem; font-weight: 900; color: var(--accent);
  background: rgba(245,158,11,0.15);
  border-radius: 50%; width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
}
.title-buttons { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.btn-main {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff; border: none; border-radius: 50px;
  padding: 14px 36px; font-size: 1.1rem; font-weight: 700;
  cursor: pointer; transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 20px rgba(239,68,68,0.4);
  font-family: inherit;
}
.btn-main:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(239,68,68,0.5); }
.btn-sub {
  background: rgba(255,255,255,0.08);
  color: var(--text-main); border: 2px solid rgba(255,255,255,0.15);
  border-radius: 50px;
  padding: 14px 36px; font-size: 1.1rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
  font-family: inherit;
}
.btn-sub:hover { background: rgba(255,255,255,0.15); }

/* =============================================
   화면 2: 규칙
   ============================================= */
#screen-rules {
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
  align-items: center; justify-content: center; padding: 40px 20px;
}
.rules-container {
  max-width: 860px; width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 24px;
}
.rules-title { font-size: 2rem; font-weight: 900; }
.rules-desc { color: var(--text-sub); font-size: 1rem; }
.rules-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; width: 100%; }
.rule-card {
  background: rgba(255,255,255,0.05);
  border-radius: var(--radius); padding: 28px 20px; text-align: center;
  border: 2px solid rgba(255,255,255,0.08);
  position: relative; overflow: hidden;
}
.rule-card.attack { border-color: rgba(239,68,68,0.4); }
.rule-card.defend { border-color: rgba(59,130,246,0.4); }
.rule-card.steal  { border-color: rgba(245,158,11,0.4); }
.rule-num {
  position: absolute; top: 12px; left: 16px;
  font-size: 2rem; font-weight: 900; opacity: 0.12;
}
.rule-icon { font-size: 2.4rem; margin-bottom: 12px; }
.rule-card h3 { font-size: 1.2rem; font-weight: 700; margin-bottom: 10px; }
.rule-card p { font-size: 0.9rem; color: var(--text-sub); line-height: 1.6; margin-bottom: 14px; }
.rule-time { font-size: 0.85rem; color: var(--accent); }
.golden-key {
  background: rgba(245,158,11,0.1); border: 1px solid rgba(245,158,11,0.3);
  border-radius: 10px; padding: 12px 24px;
  font-size: 0.95rem; color: var(--accent); text-align: center;
}
.score-rules { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.sr {
  padding: 8px 20px; border-radius: 50px; font-weight: 700; font-size: 0.95rem;
}
.sr.correct { background: rgba(34,197,94,0.15); color: #4ade80; }
.sr.steal   { background: rgba(245,158,11,0.15); color: #fbbf24; }
.sr.wrong   { background: rgba(239,68,68,0.15); color: #f87171; }

/* =============================================
   화면 3: 게임
   ============================================= */
#screen-game {
  background: var(--bg-dark);
  min-height: 100vh; flex-direction: column;
}
.game-layout { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* 헤더 */
.game-header {
  background: var(--bg-mid);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0; gap: 12px; flex-wrap: wrap;
}
.round-info { display: flex; flex-direction: column; align-items: flex-start; }
.round-label { font-size: 0.7rem; color: var(--text-sub); text-transform: uppercase; letter-spacing: 0.1em; }
.round-num { font-size: 1.3rem; font-weight: 900; color: var(--accent); }
.game-logo { font-size: 1.4rem; font-weight: 900; }
.turn-info { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.turn-badge {
  padding: 6px 14px; border-radius: 50px;
  font-size: 0.85rem; font-weight: 700;
}
.attack-badge { background: rgba(239,68,68,0.2); color: #f87171; border: 1px solid rgba(239,68,68,0.3); }
.defend-badge { background: rgba(59,130,246,0.2); color: #93c5fd; border: 1px solid rgba(59,130,246,0.3); }

/* 메인 영역 */
.game-main {
  flex: 1; display: flex; flex-direction: column; gap: 16px;
  padding: 16px; overflow-y: auto;
}

/* ── 점수판 ── */
.scoreboard {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
}
.team-score-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 2px solid rgba(255,255,255,0.08);
  padding: 20px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  transition: box-shadow 0.3s, transform 0.2s;
  position: relative; overflow: hidden;
}
.team-score-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
}
.team-score-card.team-a { border-color: rgba(59,130,246,0.4); }
.team-score-card.team-a::before { background: var(--team-a); }
.team-score-card.team-b { border-color: rgba(234,179,8,0.4); }
.team-score-card.team-b::before { background: var(--team-b); }
.team-score-card.team-c { border-color: rgba(34,197,94,0.4); }
.team-score-card.team-c::before { background: var(--team-c); }

.team-score-card.score-up   { animation: scoreUp 0.5s ease; }
.team-score-card.score-down { animation: scoreDown 0.5s ease; }
@keyframes scoreUp {
  0% { transform: scale(1); }
  40% { transform: scale(1.06); box-shadow: 0 0 30px rgba(34,197,94,0.5); }
  100% { transform: scale(1); }
}
@keyframes scoreDown {
  0% { transform: scale(1); }
  40% { transform: scale(0.96); box-shadow: 0 0 30px rgba(239,68,68,0.5); }
  100% { transform: scale(1); }
}

.ts-header { display: flex; align-items: center; gap: 8px; }
.ts-icon { font-size: 1.4rem; }
.ts-name { font-size: 1rem; font-weight: 700; }
.ts-label { font-size: 0.75rem; color: var(--text-sub); }

.ts-score {
  font-size: clamp(2.8rem, 5vw, 4.5rem);
  font-weight: 900; line-height: 1;
  transition: all 0.3s;
}
.team-a .ts-score { color: #60a5fa; }
.team-b .ts-score { color: #fbbf24; }
.team-c .ts-score { color: #4ade80; }

.ts-stats { display: flex; gap: 16px; font-size: 0.8rem; color: var(--text-sub); }
.ts-stats b { color: var(--text-main); }

.ts-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; width: 100%; }
.score-btn {
  border: none; border-radius: 10px;
  padding: 8px 4px; font-size: 0.85rem; font-weight: 700;
  cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.correct-btn { background: rgba(34,197,94,0.2); color: #4ade80; border: 1px solid rgba(34,197,94,0.3); }
.correct-btn:hover { background: rgba(34,197,94,0.4); transform: scale(1.05); }
.steal-btn   { background: rgba(245,158,11,0.2); color: #fbbf24; border: 1px solid rgba(245,158,11,0.3); }
.steal-btn:hover { background: rgba(245,158,11,0.4); transform: scale(1.05); }
.wrong-btn   { background: rgba(239,68,68,0.2); color: #f87171; border: 1px solid rgba(239,68,68,0.3); }
.wrong-btn:hover { background: rgba(239,68,68,0.4); transform: scale(1.05); }
.reset-btn   { background: rgba(255,255,255,0.06); color: var(--text-sub); border: 1px solid rgba(255,255,255,0.1); grid-column: span 2; }
.reset-btn:hover { background: rgba(255,255,255,0.12); }

/* ── 컨트롤 패널 ── */
.control-panel {
  display: flex; flex-direction: column; gap: 16px;
}
.timers-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.timer-box {
  background: var(--bg-card);
  border-radius: var(--radius); padding: 20px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  border: 2px solid rgba(255,255,255,0.08);
}
.prep-timer { border-color: rgba(168,85,247,0.4); }
.ans-timer  { border-color: rgba(245,158,11,0.4); }
.timer-label { font-size: 0.9rem; font-weight: 700; letter-spacing: 0.03em; }
.prep-timer .timer-label { color: #c084fc; }
.ans-timer  .timer-label { color: #fbbf24; }

.timer-circle {
  position: relative; width: 100px; height: 100px;
}
.timer-circle svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.bg-circle { fill: none; stroke: rgba(255,255,255,0.08); stroke-width: 8; }
.prog-circle {
  fill: none; stroke-width: 8; stroke-linecap: round;
  transition: stroke-dashoffset 1s linear;
}
.prep-timer .prog-circle { stroke: #a855f7; }
.ans-timer  .prog-circle { stroke: #f59e0b; }
.timer-num {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.8rem; font-weight: 900;
}
.prep-timer .timer-num { color: #c084fc; }
.ans-timer  .timer-num  { color: #fbbf24; }

.timer-circle.danger .prog-circle { stroke: #ef4444; animation: timerDanger 0.5s ease-in-out infinite alternate; }
.timer-circle.danger .timer-num { color: #ef4444; animation: timerDanger 0.5s ease-in-out infinite alternate; }
@keyframes timerDanger { from { opacity: 1; } to { opacity: 0.5; } }

.timer-controls { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.tc-btn {
  border: none; border-radius: 8px;
  padding: 7px 12px; font-size: 0.78rem; font-weight: 700;
  cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.tc-btn.start { background: rgba(34,197,94,0.2); color: #4ade80; border: 1px solid rgba(34,197,94,0.3); }
.tc-btn.start:hover:not(:disabled) { background: rgba(34,197,94,0.4); }
.tc-btn.pause { background: rgba(245,158,11,0.2); color: #fbbf24; border: 1px solid rgba(245,158,11,0.3); }
.tc-btn.pause:hover:not(:disabled) { background: rgba(245,158,11,0.4); }
.tc-btn.reset { background: rgba(255,255,255,0.06); color: var(--text-sub); border: 1px solid rgba(255,255,255,0.1); }
.tc-btn.reset:hover { background: rgba(255,255,255,0.15); }
.tc-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* 라운드 컨트롤 */
.round-control {
  background: var(--bg-card);
  border-radius: var(--radius); padding: 20px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  border: 2px solid rgba(255,255,255,0.08);
}
.turn-selector { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.turn-selector label { font-size: 0.85rem; color: var(--text-sub); font-weight: 600; }
.turn-selector select {
  background: rgba(255,255,255,0.08); color: var(--text-main);
  border: 1px solid rgba(255,255,255,0.15); border-radius: 8px;
  padding: 7px 12px; font-size: 0.9rem; font-family: inherit;
  cursor: pointer; outline: none;
}
.turn-selector select:focus { border-color: var(--accent); }
.btn-next-round {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff; border: none; border-radius: 50px;
  padding: 10px 28px; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: all 0.2s; font-family: inherit;
  box-shadow: 0 4px 16px rgba(99,102,241,0.4);
}
.btn-next-round:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(99,102,241,0.5); }
.btn-end-game {
  background: rgba(239,68,68,0.15); color: #f87171;
  border: 1px solid rgba(239,68,68,0.3); border-radius: 50px;
  padding: 10px 22px; font-size: 0.9rem; font-weight: 700;
  cursor: pointer; transition: all 0.2s; font-family: inherit;
}
.btn-end-game:hover { background: rgba(239,68,68,0.3); }

/* =============================================
   화면 4: 결과
   ============================================= */
#screen-result {
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
  align-items: center; justify-content: center; padding: 40px 20px;
  position: relative; overflow: hidden;
}
.result-container {
  display: flex; flex-direction: column; align-items: center; gap: 28px;
  position: relative; z-index: 1; max-width: 700px; width: 100%;
}
.result-title {
  font-size: 2.4rem; font-weight: 900;
  background: linear-gradient(90deg, #f59e0b, #ef4444);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.result-podium {
  display: flex; align-items: flex-end; justify-content: center; gap: 12px; width: 100%;
}
.podium-item {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  flex: 1; max-width: 200px;
}
.podium-rank { font-size: 2.4rem; }
.podium-emoji { font-size: 2rem; }
.podium-name { font-size: 1.1rem; font-weight: 700; }
.podium-score { font-size: 2rem; font-weight: 900; }
.podium-bar {
  width: 100%; border-radius: 12px 12px 0 0;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 8px; min-height: 60px;
}
.podium-bar.rank-1 { height: 120px; background: linear-gradient(180deg, rgba(245,158,11,0.4), rgba(245,158,11,0.1)); border: 2px solid rgba(245,158,11,0.5); }
.podium-bar.rank-2 { height: 90px; background: linear-gradient(180deg, rgba(148,163,184,0.3), rgba(148,163,184,0.1)); border: 2px solid rgba(148,163,184,0.4); }
.podium-bar.rank-3 { height: 70px; background: linear-gradient(180deg, rgba(180,83,9,0.3), rgba(180,83,9,0.1)); border: 2px solid rgba(180,83,9,0.4); }

.result-detail { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.result-row {
  background: rgba(255,255,255,0.05); border-radius: 12px;
  padding: 14px 20px; display: flex; align-items: center; justify-content: space-between;
  border: 1px solid rgba(255,255,255,0.08);
}
.rr-team { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1rem; }
.rr-stats { display: flex; gap: 20px; font-size: 0.9rem; color: var(--text-sub); }
.rr-score { font-size: 1.4rem; font-weight: 900; }

.result-buttons { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* =============================================
   공통 UI
   ============================================= */

/* 점수 토스트 */
.score-toast {
  position: fixed; top: 80px; left: 50%; transform: translateX(-50%);
  background: rgba(30,41,59,0.95); border: 2px solid rgba(255,255,255,0.15);
  border-radius: 50px; padding: 12px 28px;
  font-size: 1.1rem; font-weight: 700;
  z-index: 9999; pointer-events: none;
  opacity: 0; transition: opacity 0.3s;
  backdrop-filter: blur(10px);
  white-space: nowrap;
}
.score-toast.show { opacity: 1; }
.score-toast.toast-up   { color: #4ade80; border-color: rgba(34,197,94,0.4); }
.score-toast.toast-down { color: #f87171; border-color: rgba(239,68,68,0.4); }

/* 타이머 알림 모달 */
.timer-alert {
  position: fixed; inset: 0; z-index: 9998;
  background: rgba(0,0,0,0.75); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.timer-alert.hidden { display: none; }
.alert-content {
  background: var(--bg-mid); border-radius: var(--radius);
  padding: 40px; text-align: center; border: 2px solid rgba(239,68,68,0.4);
  box-shadow: 0 0 40px rgba(239,68,68,0.3);
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.alert-icon { font-size: 3rem; animation: alertPop 0.5s ease; }
@keyframes alertPop { 0% { transform: scale(0); } 80% { transform: scale(1.2); } 100% { transform: scale(1); } }
.alert-msg { font-size: 1.6rem; font-weight: 900; }
.alert-content button {
  background: var(--accent); color: #000; border: none; border-radius: 50px;
  padding: 10px 32px; font-size: 1rem; font-weight: 700; cursor: pointer;
  font-family: inherit; transition: all 0.2s;
}
.alert-content button:hover { transform: scale(1.05); }

/* 폭죽 파티클 */
.firework {
  position: absolute; width: 8px; height: 8px; border-radius: 50%;
  animation: firework 2s ease-out forwards;
  opacity: 0;
}
@keyframes firework {
  0%   { transform: translate(0,0) scale(1); opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

/* ── 반응형 ── */
@media (max-width: 768px) {
  .scoreboard { grid-template-columns: 1fr; }
  .timers-row { grid-template-columns: 1fr; }
  .round-control { flex-direction: column; align-items: stretch; }
  .turn-selector { flex-direction: column; }
  .game-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .ts-buttons { grid-template-columns: 1fr 1fr; }
  .result-podium { flex-direction: column; align-items: center; }
  .podium-bar { height: 60px !important; }
}
