/* =============================================
   AI GIỎI HƠN — Giao diện sáng, vui, animation
   ============================================= */

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

:root {
  --purple:     #7c3aed;
  --purple-l:   #a78bfa;
  --purple-d:   #5b21b6;
  --pink:       #ec4899;
  --cyan:       #06b6d4;
  --yellow:     #f59e0b;
  --green:      #10b981;
  --red:        #ef4444;
  --bg-from:    #ddd6fe;
  --bg-to:      #bfdbfe;
  --surface:    #ffffff;
  --surface2:   #f3f4f6;
  --text:       #1e1b4b;
  --text-muted: #6b7280;
  --radius:     24px;
  --radius-sm:  16px;
  --shadow:     0 8px 32px rgba(124,58,237,.18);
  --shadow-lg:  0 20px 60px rgba(124,58,237,.22);
}

/* ---- Base ---- */
html, body {
  height: 100%;
  font-family: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  background: linear-gradient(135deg, var(--bg-from) 0%, var(--bg-to) 100%);
  min-height: 100dvh;
}

/* Hình nền động */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(167,139,250,.35) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(6,182,212,.25) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(236,72,153,.15) 0%, transparent 60%);
  z-index: 0;
  animation: bgPulse 8s ease-in-out infinite alternate;
}
@keyframes bgPulse {
  from { opacity: .7; }
  to   { opacity: 1; }
}

/* ---- Màn hình ---- */
.screen {
  display: none;
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  padding: 28px 16px 40px;
  justify-content: center;
  align-items: flex-start;
}
.screen.active { display: flex; }

/* ---- Card ---- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: var(--shadow-lg);
  animation: slideUp .4s cubic-bezier(.34,1.56,.64,1) both;
}
.card.center {
  align-items: center;
  text-align: center;
  padding-top: 56px;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(40px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- Logo ---- */
.logo {
  font-size: 30px;
  font-weight: 900;
  text-align: center;
  background: linear-gradient(135deg, var(--purple), var(--pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -.5px;
  animation: logoBounce 1.2s cubic-bezier(.34,1.56,.64,1) both;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.logo-img {
  width: 72px;
  height: 72px;
  animation: logoBounce 1.2s cubic-bezier(.34,1.56,.64,1) both, floatBob 3s ease-in-out infinite 1.2s;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 12px rgba(124,58,237,.3));
}
@keyframes floatBob {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-6px); }
}
@keyframes logoBounce {
  from { opacity: 0; transform: scale(.6) rotate(-6deg); }
  to   { opacity: 1; transform: scale(1) rotate(0); }
}

.subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 16px;
  margin-top: -8px;
}

/* ---- Input ---- */
input[type="text"] {
  width: 100%;
  background: var(--surface2);
  border: 2.5px solid #e5e7eb;
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  font-size: 18px;
  color: var(--text);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
input[type="text"]:focus {
  border-color: var(--purple-l);
  box-shadow: 0 0 0 4px rgba(124,58,237,.12);
}
input[type="text"]::placeholder { color: #c4b5fd; }

/* ---- Buttons ---- */
.btn {
  width: 100%;
  padding: 17px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  min-height: 56px;
  transition: transform .15s, box-shadow .15s, filter .15s;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: .2px;
}
.btn:active  { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none !important; }

.btn-primary {
  background: linear-gradient(135deg, var(--purple), var(--pink));
  color: #fff;
  box-shadow: 0 6px 20px rgba(124,58,237,.35);
}
.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
  box-shadow: 0 8px 28px rgba(124,58,237,.45);
  transform: translateY(-2px);
}

.btn-secondary {
  background: linear-gradient(135deg, var(--cyan), #3b82f6);
  color: #fff;
  box-shadow: 0 6px 20px rgba(6,182,212,.3);
}
.btn-secondary:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-2px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 16px;
  min-height: 48px;
}
.btn-ghost:hover { color: var(--purple); }

.btn-share {
  background: linear-gradient(135deg, #10b981, #06b6d4);
  color: #fff;
  box-shadow: 0 6px 20px rgba(16,185,129,.3);
  font-size: 17px;
}
.btn-share:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(16,185,129,.4);
}
.btn-share.copied {
  background: linear-gradient(135deg, #7c3aed, #ec4899);
  box-shadow: 0 6px 20px rgba(124,58,237,.35);
}

.btn-group { display: flex; flex-direction: column; gap: 12px; }

/* ---- Chọn mức ---- */
.level-group { display: flex; flex-direction: column; gap: 14px; }

.level-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: var(--surface2);
  border: 3px solid transparent;
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  cursor: pointer;
  transition: border-color .2s, background .2s, transform .15s, box-shadow .2s;
}
.level-card input[type="radio"] { display: none; }
.level-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.08); }
.level-card.selected {
  border-color: var(--purple);
  background: #f5f3ff;
  box-shadow: 0 0 0 4px rgba(124,58,237,.1);
}

.level-name { font-size: 20px; font-weight: 800; }
.level-desc { font-size: 15px; color: var(--text-muted); }

/* ---- Phòng chờ ---- */
.room-code {
  font-size: 58px;
  font-weight: 900;
  letter-spacing: 10px;
  text-align: center;
  background: linear-gradient(135deg, var(--purple), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-variant-numeric: tabular-nums;
  animation: roomCodePop .5s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes roomCodePop {
  from { transform: scale(.7); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}

.hint { font-size: 14px; color: var(--text-muted); text-align: center; }

.players-list { display: flex; flex-direction: column; gap: 10px; }
.player-item {
  background: linear-gradient(135deg, #f5f3ff, #ede9fe);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 17px;
  font-weight: 700;
  animation: slideUp .3s both;
  border: 2px solid #ddd6fe;
}
.player-item .avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), var(--pink));
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.host-badge {
  margin-left: auto;
  background: linear-gradient(135deg, var(--yellow), #f97316);
  color: #fff;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 99px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.level-badge {
  background: linear-gradient(135deg, #f5f3ff, #ede9fe);
  border: 2px solid #ddd6fe;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
  color: var(--purple);
}

/* ---- Cảnh báo Khó ---- */
.warning-icon {
  font-size: 64px;
  text-align: center;
  animation: wiggle 1s ease-in-out infinite;
}
@keyframes wiggle {
  0%,100% { transform: rotate(-5deg); }
  50%      { transform: rotate(5deg); }
}
.warning-text {
  text-align: center;
  line-height: 1.8;
  font-size: 17px;
}

/* ---- Đếm ngược ---- */
.countdown-label {
  font-size: 20px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
}
.countdown-number {
  font-size: 112px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--purple), var(--pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: countBounce .7s cubic-bezier(.34,1.56,.64,1) both;
  line-height: 1;
}
@keyframes countBounce {
  from { transform: scale(.3) rotate(-20deg); opacity: 0; }
  to   { transform: scale(1)  rotate(0deg);   opacity: 1; }
}

/* ---- Header câu hỏi ---- */
#screen-question {
  padding: 0;
  flex-direction: column;
  align-items: stretch;
}
.question-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  background: var(--surface);
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
  position: sticky;
  top: 0;
  z-index: 10;
}
#q-progress {
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
  color: var(--purple);
}
#timer-text {
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
  min-width: 30px;
  text-align: right;
  color: var(--purple);
}

#timer-bar-wrap {
  flex: 1;
  height: 10px;
  background: #e5e7eb;
  border-radius: 99px;
  overflow: hidden;
}
#timer-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--purple), var(--pink));
  border-radius: 99px;
  transition: width .1s linear, background .3s;
  width: 100%;
}
#timer-bar.warning { background: linear-gradient(90deg, #f59e0b, #f97316); }
#timer-bar.danger  { background: linear-gradient(90deg, #ef4444, #dc2626); }

/* ---- Nội dung câu hỏi ---- */
.question-body {
  padding: 24px 18px 40px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
}
.question-text {
  font-size: 21px;
  font-weight: 700;
  line-height: 1.6;
  margin-bottom: 24px;
  color: var(--text);
  animation: slideUp .35s both;
}

.options-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 18px;
}
.option-btn {
  width: 100%;
  background: var(--surface);
  border: 2.5px solid #e5e7eb;
  border-radius: var(--radius-sm);
  padding: 17px 18px;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  min-height: 58px;
  transition: border-color .15s, background .15s, transform .12s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  animation: optionIn .3s both;
}
.option-btn:nth-child(1) { animation-delay: .05s; }
.option-btn:nth-child(2) { animation-delay: .10s; }
.option-btn:nth-child(3) { animation-delay: .15s; }
.option-btn:nth-child(4) { animation-delay: .20s; }

@keyframes optionIn {
  from { opacity: 0; transform: translateX(-20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.option-btn:hover:not(:disabled) {
  border-color: var(--purple-l);
  background: #f5f3ff;
  transform: translateX(4px);
  box-shadow: 0 4px 16px rgba(124,58,237,.15);
}
.option-btn:active { transform: scale(.97); }
.option-btn:disabled { cursor: default; }

.opt-letter {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple-l), var(--purple));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  flex-shrink: 0;
}

.skip-btn {
  min-height: 48px;
  font-size: 16px;
  color: #9ca3af;
}

/* ---- Chờ đối thủ ---- */
.spinner {
  width: 56px; height: 56px;
  border: 5px solid #e5e7eb;
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Kết quả ---- */
#screen-result {
  align-items: flex-start;
  padding: 24px 16px 48px;
}
.result-wrap {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.result-banner {
  text-align: center;
  font-size: 32px;
  font-weight: 900;
  padding: 20px 24px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: logoBounce .6s cubic-bezier(.34,1.56,.64,1) both;
}

.result-scores { display: flex; flex-direction: column; gap: 12px; }
.score-item {
  background: var(--surface);
  border: 2.5px solid #e5e7eb;
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  animation: slideUp .4s both;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.score-item:nth-child(2) { animation-delay: .1s; }
.score-item.winner {
  border-color: var(--green);
  background: #ecfdf5;
  box-shadow: 0 4px 16px rgba(16,185,129,.2);
}
.score-name { font-weight: 800; font-size: 18px; }
.score-val  { font-size: 26px; font-weight: 900; color: var(--purple); }

/* ---- Phân tích từng câu ---- */
.section-title {
  font-size: 18px;
  font-weight: 900;
  color: var(--purple-d);
  padding: 4px 0;
}

.result-breakdown { display: flex; flex-direction: column; gap: 12px; }

.breakdown-item {
  background: var(--surface);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.07);
  animation: slideUp .35s both;
  border: 2px solid #e5e7eb;
}
.breakdown-item.correct  { border-color: var(--green); }
.breakdown-item.wrong    { border-color: var(--red); }
.breakdown-item.skipped  { border-color: #d1d5db; }

.breakdown-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
}
.breakdown-num {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; flex-shrink: 0;
  color: #fff;
}
.correct  .breakdown-num { background: var(--green); }
.wrong    .breakdown-num { background: var(--red); }
.skipped  .breakdown-num { background: #9ca3af; }

.breakdown-result-icon {
  font-size: 20px; flex-shrink: 0;
}
.breakdown-score {
  margin-left: auto;
  font-size: 15px;
  font-weight: 800;
  color: var(--purple);
  white-space: nowrap;
}
.breakdown-q {
  font-size: 15px;
  font-weight: 700;
  flex: 1;
  line-height: 1.4;
}

.breakdown-answers {
  padding: 0 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.answer-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 14px;
  line-height: 1.4;
}
.answer-label {
  font-weight: 800;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 80px;
  color: var(--text-muted);
}
.answer-val { flex: 1; }
.answer-val.highlight-correct { color: var(--green); font-weight: 800; }
.answer-val.highlight-wrong   { color: var(--red);   font-weight: 700; text-decoration: line-through; }

/* ---- Confetti canvas ---- */
#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9998;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--purple-d);
  color: #fff;
  padding: 14px 24px;
  border-radius: 99px;
  font-size: 16px;
  font-weight: 700;
  z-index: 9999;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 8px 28px rgba(0,0,0,.25);
  transition: opacity .3s;
  animation: toastIn .3s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes toastIn {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0);    opacity: 1; }
}
.toast.hidden { opacity: 0; pointer-events: none; }

h2 {
  font-size: 24px;
  font-weight: 900;
  text-align: center;
  color: var(--purple-d);
}

/* My score display */
#my-score-display {
  font-size: 40px;
  font-weight: 900;
  color: var(--purple);
  display: block;
  margin: 4px 0 4px;
}
#screen-waiting h2 { font-size: 22px; }
