:root {
  --bg: #0f172a;
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --secondary: #64748b;
  --text: #1e293b;
  --text-light: #64748b;
  --card-bg: #ffffff;
  --radius: 16px;
  --font-heading: 'Inter', sans-serif;
  --font-body: 'Inter', sans-serif;
}

/* SD theme: cerah, playful, besar */
body[data-level="sd"] {
  --primary: #ff6b6b;
  --primary-dark: #e64545;
  --secondary: #4ecdc4;
  --radius: 28px;
  --font-heading: 'Fredoka', sans-serif;
  --font-body: 'Fredoka', sans-serif;
}

/* SMP theme: cerah tapi rapi */
body[data-level="smp"] {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --secondary: #f59e0b;
  --radius: 18px;
  --font-heading: 'Inter', sans-serif;
  --font-body: 'Inter', sans-serif;
}

/* SMA theme: clean, minimalis, netral */
body[data-level="sma"] {
  --primary: #334155;
  --primary-dark: #1e293b;
  --secondary: #0ea5e9;
  --radius: 10px;
  --font-heading: 'Inter', sans-serif;
  --font-body: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  color: var(--text);
  background: #0b1020;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #eef2ff, #e0e7ff);
}

.screen.active { display: flex; }

body[data-level="sd"] .screen { background: linear-gradient(160deg, #fff1e6, #ffe3e3); }
body[data-level="sma"] .screen { background: #f1f5f9; }

/* ---------- Screen 1: Grade select ---------- */
.grade-wrap {
  text-align: center;
  padding: 24px;
  max-width: 480px;
}
.logo { width: 72px; margin-bottom: 8px; }
.grade-wrap h1 {
  font-family: var(--font-heading);
  font-size: 2rem;
  margin: 8px 0 4px;
  color: var(--text);
}
.subtitle { color: var(--text-light); margin: 0 0 24px; font-size: 0.95rem; }
.ask { font-weight: 600; margin-bottom: 12px; }
.grade-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.grade-btn {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 1.05rem;
  box-shadow: 0 6px 18px rgba(0,0,0,0.08);
  min-width: 96px;
  transition: transform 0.15s ease;
  color: var(--text);
}
.grade-btn:active { transform: scale(0.95); }
.grade-btn .emoji { font-size: 2rem; }

/* ---------- Screen 2: Mode select ---------- */
.mode-wrap {
  text-align: center;
  padding: 24px;
  width: 100%;
  max-width: 360px;
}
.mode-wrap h2 { font-family: var(--font-heading); margin-bottom: 20px; }
.mode-btn {
  display: block;
  width: 100%;
  padding: 16px 20px;
  border-radius: var(--radius);
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 14px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.08);
}
.mode-btn.primary { background: var(--primary); color: #fff; }
.mode-btn.secondary { background: #fff; color: var(--text); border: 2px solid var(--primary); }
.mode-btn.small { padding: 10px 16px; font-size: 0.95rem; margin-bottom: 0; width: auto; flex: 1; }
.link-btn { background: none; color: var(--text-light); margin-top: 8px; font-size: 0.9rem; text-decoration: underline; }

/* ---------- Screen 3: AR ---------- */
#screen-ar { background: #000; }
#ar-container { position: absolute; inset: 0; }
#ar-container video, #ar-container canvas { width: 100% !important; height: 100% !important; object-fit: cover; }

.overlay-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(11,16,32,0.92);
  color: #fff;
  text-align: center;
  padding: 32px;
  z-index: 5;
}
.overlay-msg.hidden { display: none; }
.spinner {
  width: 42px; height: 42px;
  border: 4px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.ar-hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 4;
  text-align: center;
  max-width: 90%;
}

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.back-btn { position: absolute; top: 16px; right: 16px; z-index: 6; }

/* ---------- Screen 5: Demo preview ---------- */
#screen-preview { background: radial-gradient(circle at center, #1e293b, #0b1020); }
#demo-preview-container { position: absolute; inset: 0; }
#demo-preview-container canvas { width: 100% !important; height: 100% !important; display: block; }
#screen-preview .ar-hint { color: #fff; }

/* ---------- Screen 4: Demo mode ---------- */
#screen-demo { background: #f8fafc; align-items: stretch; }
.demo-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
}
.demo-header .icon-btn { background: #e2e8f0; color: var(--text); position: static; }
.demo-header h2 { font-family: var(--font-heading); margin: 0; }
.demo-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  padding: 0 16px 24px;
  align-content: start;
}
.demo-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.demo-card img { width: 48px; height: 32px; object-fit: cover; border-radius: 4px; margin-bottom: 8px; }
.demo-card .name { font-weight: 700; font-size: 0.9rem; }
.demo-card .player { font-size: 0.78rem; color: var(--text-light); }

/* ---------- Info panel (shared) ---------- */
.info-panel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  transition: transform 0.25s ease;
}
.info-panel.hidden { transform: translateY(110%); pointer-events: none; }
.info-panel-inner {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 480px;
  padding: 20px 20px 28px;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.15);
  max-height: 70vh;
  overflow-y: auto;
}
.close-btn { position: absolute; top: 10px; right: 10px; background: #e2e8f0; color: var(--text); }
.info-flag { width: 40px; height: 28px; object-fit: cover; border-radius: 3px; margin-bottom: 8px; }
.info-panel-inner h3 { margin: 0 0 2px; font-family: var(--font-heading); font-size: 1.3rem; }
#info-country-line { margin: 0 0 10px; color: var(--text-light); font-size: 0.85rem; }
#info-text { margin: 0 0 10px; line-height: 1.5; }
.info-fact { background: #fffbeb; border-radius: 10px; padding: 8px 12px; font-size: 0.9rem; }
.info-fact:empty { display: none; }
.info-actions { display: flex; gap: 10px; margin-top: 14px; }
.info-actions.hidden { display: none; }

body[data-level="sd"] .info-panel-inner h3 { font-size: 1.6rem; }
body[data-level="sd"] #info-text { font-size: 1.1rem; }

.quiz-box { margin-top: 16px; border-top: 1px solid #e2e8f0; padding-top: 14px; }
.quiz-box.hidden { display: none; }
.quiz-options { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.quiz-option {
  background: #f1f5f9;
  border-radius: 10px;
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 0.95rem;
}
.quiz-option.correct { background: #dcfce7; color: #166534; }
.quiz-option.wrong { background: #fee2e2; color: #991b1b; }
.quiz-result { margin-top: 10px; font-weight: 700; }

@media (min-width: 600px) {
  .demo-grid { grid-template-columns: repeat(3, 1fr); }
}
