/* ════════════════════════════════════════════
   CSS Variables & Reset
════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:        #C62828;
  --primary-dark:   #8E0000;
  --primary-light:  #FFEBEE;
  --accent:         #FFD700;
  --bg:             #FDF8F0;
  --card:           #FFFFFF;
  --text:           #1A1A1A;
  --text-muted:     #757575;
  --success:        #2E7D32;
  --success-bg:     #E8F5E9;
  --danger:         #C62828;
  --danger-bg:      #FFEBEE;
  --warn-bg:        #FFF8E1;
  --warn:           #F57F17;
  --border:         #E8DDD0;
  --shadow:         0 2px 16px rgba(0,0,0,.09);
  --radius:         14px;
  --radius-sm:      8px;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Poppins', 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ════════════════════════════════════════════
   Screen switching
════════════════════════════════════════════ */
.screen            { display: none; min-height: 100vh; }
.screen.active     { display: block; animation: fadeUp .3s ease; }

#loading-screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ════════════════════════════════════════════
   Layout helpers
════════════════════════════════════════════ */
.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px;
}
.quiz-container { padding-top: 14px; }

/* ════════════════════════════════════════════
   Card
════════════════════════════════════════════ */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

/* ════════════════════════════════════════════
   HOME – header
════════════════════════════════════════════ */
.home-header {
  text-align: center;
  padding: 36px 0 24px;
}
.logo {
  font-family: 'Noto Sans SC', serif;
  font-size: 3.2rem;
  color: var(--primary);
  letter-spacing: 6px;
  text-shadow: 2px 3px 6px rgba(198,40,40,.25);
  margin-bottom: 8px;
  line-height: 1;
}
.home-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.home-header p { color: var(--text-muted); font-size: .9rem; }

/* ════════════════════════════════════════════
   Form elements
════════════════════════════════════════════ */
.form-group { margin-bottom: 18px; }

.form-group label {
  display: block;
  font-size: .83rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group select {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: #FAFAF8;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.form-group input[type="text"]:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(198,40,40,.12);
  background: #fff;
}
.form-group input.input-error { border-color: var(--danger) !important; }

/* Toggle row */
.toggle-row { margin-bottom: 20px; }
.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

/* Checkbox styled as pill toggle */
.toggle-label input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: #bbb;
  border: none;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .25s;
  outline: none;
}
.toggle-label input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .25s;
}
.toggle-label input[type="checkbox"]:checked {
  background: var(--primary);
}
.toggle-label input[type="checkbox"]:checked::after {
  transform: translateX(18px);
}

/* ════════════════════════════════════════════
   Buttons
════════════════════════════════════════════ */
.btn {
  display: inline-block;
  padding: 13px 22px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-family: inherit;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all .18s;
  line-height: 1.3;
}
.btn-full { width: 100%; margin-bottom: 10px; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(198,40,40,.35);
}
.btn-primary:active { transform: translateY(0); box-shadow: none; }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}
.btn-outline:hover {
  background: var(--primary-light);
  transform: translateY(-1px);
}

/* ════════════════════════════════════════════
   Error banner
════════════════════════════════════════════ */
.error-banner {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #FFCDD2;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: .85rem;
  font-weight: 500;
}

/* ════════════════════════════════════════════
   Loading
════════════════════════════════════════════ */
.center-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.spinner {
  width: 52px;
  height: 52px;
  border: 5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
.loading-text { color: var(--text-muted); font-weight: 500; }

/* ════════════════════════════════════════════
   Quiz – sticky header
════════════════════════════════════════════ */
.quiz-header {
  background: var(--primary);
  color: #fff;
  padding: 10px 16px 8px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.quiz-meta {
  display: flex;
  justify-content: space-between;
  font-size: .82rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.timer-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.timer-track {
  flex: 1;
  height: 7px;
  background: rgba(255,255,255,.28);
  border-radius: 4px;
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 1s linear, background .35s;
}
.timer-fill.warn  { background: #FFA726; }
.timer-fill.danger { background: #EF5350; }

.timer-num {
  font-size: .8rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 22px;
  text-align: right;
  transition: color .35s;
}
.timer-num.warn   { color: #FFA726; }
.timer-num.danger { color: #EF5350; }

/* Overall progress */
.overall-track {
  height: 4px;
  background: #E0E0E0;
  overflow: hidden;
}
.overall-fill {
  height: 100%;
  background: var(--primary);
  transition: width .4s ease;
  width: 0%;
}

/* ════════════════════════════════════════════
   Question card
════════════════════════════════════════════ */
.question-card { padding: 20px 18px; }

.badges-row { display: flex; gap: 8px; margin-bottom: 16px; }
.badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: capitalize;
}
.badge-cat  { background: var(--primary-light); color: var(--primary); }
.badge-diff { background: var(--warn-bg);       color: var(--warn); }

/* Chinese character */
.chinese-block {
  text-align: center;
  padding: 18px 0 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.chinese-char {
  font-family: 'Noto Sans SC', serif;
  font-size: 5.5rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.1;
  text-shadow: 2px 3px 0 rgba(198,40,40,.12);
  user-select: none;
}
.pinyin-text {
  font-size: 1.15rem;
  color: var(--text-muted);
  margin-top: 6px;
  font-style: italic;
}

/* Tombol reveal pinyin — muncul saat toggle "Tampilkan Pinyin" OFF */
.pinyin-hint {
  margin-top: 8px;
  padding: 4px 14px;
  border: 1.5px dashed var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: .8rem;
  cursor: pointer;
  transition: all .2s;
  display: inline-block;
}
.pinyin-hint:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-light);
}

.pick-label {
  font-size: .8rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 14px;
}

/* ════════════════════════════════════════════
   Choices
════════════════════════════════════════════ */
.choices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.choice-btn {
  padding: 14px 10px;
  min-height: 64px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: #fff;
  color: var(--text);
  font-family: inherit;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .18s;
  text-align: center;
  word-break: break-word;
}
.choice-btn:not(:disabled):hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(198,40,40,.18);
}
.choice-btn.correct {
  background: var(--success-bg);
  border-color: var(--success);
  color: var(--success);
  animation: bounceIn .3s ease;
}
.choice-btn.wrong {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
  animation: shake .35s ease;
}
.choice-btn:disabled { cursor: not-allowed; opacity: .75; }

/* ════════════════════════════════════════════
   Results – hero
════════════════════════════════════════════ */
.results-hero { text-align: center; }
.results-hero h2 { font-size: 1.4rem; margin-bottom: 6px; }
.result-player {
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 20px;
}

/* SVG ring */
.score-ring {
  position: relative;
  width: 148px;
  height: 148px;
  margin: 0 auto 16px;
}
.ring-svg {
  width: 148px;
  height: 148px;
  transform: rotate(-90deg);
}
.ring-bg {
  fill: none;
  stroke: #F0E6DD;
  stroke-width: 10;
}
.ring-arc {
  fill: none;
  stroke: var(--primary);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 314.16;
  stroke-dashoffset: 314.16;
  transition: stroke-dashoffset 1s ease;
}
.ring-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-pct {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}
.ring-frac {
  font-size: .9rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.stars-row { font-size: 1.8rem; letter-spacing: 4px; margin-bottom: 8px; }
.result-msg { font-size: 1.1rem; font-weight: 600; color: var(--text); }

/* Results action buttons */
.results-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.results-actions .btn {
  flex: 1;
  min-width: 120px;
}

/* ════════════════════════════════════════════
   Answer review
════════════════════════════════════════════ */
.review-title { font-size: 1rem; font-weight: 700; margin-bottom: 14px; }
.answer-review { display: flex; flex-direction: column; gap: 8px; }

.review-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border-left: 4px solid;
  animation: fadeUp .2s ease;
}
.review-item.r-ok      { background: var(--success-bg); border-color: var(--success); }
.review-item.r-wrong   { background: var(--danger-bg);  border-color: var(--danger); }
.review-item.r-timeout { background: var(--warn-bg);    border-color: var(--warn); }

.review-num {
  font-size: .78rem;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 22px;
  padding-top: 2px;
}
.review-content { flex: 1; }
.review-zh {
  font-family: 'Noto Sans SC', serif;
  font-size: 1rem;
  font-weight: 700;
}
.review-py { font-size: .78rem; color: var(--text-muted); font-style: italic; font-weight: 400; }
.review-ans { font-size: .83rem; margin-top: 3px; }

/* ════════════════════════════════════════════
   Leaderboard
════════════════════════════════════════════ */
.lb-header { text-align: center; padding: 28px 0 16px; }
.lb-header h2 { font-size: 1.5rem; margin-bottom: 4px; }
.lb-header p  { color: var(--text-muted); font-size: .9rem; }

.lb-table { width: 100%; border-collapse: collapse; }
.lb-table th {
  background: var(--primary);
  color: #fff;
  padding: 10px 10px;
  text-align: left;
  font-size: .78rem;
  font-weight: 600;
}
.lb-table th:first-child { border-radius: var(--radius-sm) 0 0 0; }
.lb-table th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }
.lb-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
}
.lb-table tr:last-child td { border-bottom: none; }
.lb-table tbody tr:hover td { background: var(--primary-light); transition: background .15s; }

.lb-loading { text-align: center; color: var(--text-muted); padding: 28px; }
.lb-empty   { text-align: center; color: var(--text-muted); padding: 32px; font-size: .9rem; }

/* ════════════════════════════════════════════
   Animations
════════════════════════════════════════════ */
@keyframes spin      { to { transform: rotate(360deg); } }
@keyframes fadeUp    { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounceIn  { 0%{transform:scale(.94)} 55%{transform:scale(1.06)} 100%{transform:scale(1)} }
@keyframes shake     { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-7px)} 75%{transform:translateX(7px)} }

/* ════════════════════════════════════════════
   Responsive
════════════════════════════════════════════ */
@media (max-width: 380px) {
  .chinese-char { font-size: 4.2rem; }
  .choices-grid { grid-template-columns: 1fr; }
  .results-actions { flex-direction: column; }
  .logo { font-size: 2.4rem; }
}
