@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@500;700;800&family=Fredoka:wght@500;600;700&display=swap');

/* ==========================================================================
   TOKENS
   ========================================================================== */
:root {
  --font-focus: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-game: 'Fredoka', 'Manrope', sans-serif;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 26px;
  --radius-pill: 999px;

  --shadow-soft: 0 6px 20px rgba(30, 41, 59, 0.06);
  --shadow-card: 0 12px 40px rgba(30, 41, 59, 0.08);

  --transition-fast: 150ms ease;
  --transition-med: 280ms cubic-bezier(.4,0,.2,1);
}

/* Mode Fokus / Serius (default) — palet tenang, minim distraksi */
:root,
[data-theme="focus"] {
  --bg-base: #FAFAFA;
  --bg-gradient: none;
  --surface: #FFFFFF;
  --surface-alt: #F1F3F5;
  --border: #E4E7EB;
  --text-primary: #1F2933;
  --text-muted: #687076;
  --accent: #3B5FD9;
  --accent-contrast: #FFFFFF;
  --success: #2F9E63;
  --success-bg: #E6F6ED;
  --error: #C75C4F;
  --error-bg: #FBEAE7;
  --comet-glow: rgba(59, 95, 217, 0.25);
  --font-display: var(--font-focus);
  --font-body: var(--font-focus);
}

/* Mode Gamifikasi / Warna-warni — pastel lembut, playful */
[data-theme="game"] {
  --bg-base: #F2EBFF;
  --bg-gradient: radial-gradient(circle at 12% 8%, #FFE9D6 0%, transparent 45%),
                 radial-gradient(circle at 88% 18%, #D6F5E3 0%, transparent 50%),
                 linear-gradient(160deg, #F3EAFF 0%, #E8F6FF 100%);
  --surface: rgba(255, 255, 255, 0.88);
  --surface-alt: rgba(255, 255, 255, 0.6);
  --border: #E3D9FB;
  --text-primary: #3A3550;
  --text-muted: #756E92;
  --accent: #FF8B6B;
  --accent-contrast: #FFFFFF;
  --success: #29A87C;
  --success-bg: #DFFBEF;
  --error: #E2685A;
  --error-bg: #FFE9E4;
  --comet-glow: rgba(255, 139, 107, 0.35);
  --font-display: var(--font-game);
  --font-body: var(--font-game);
}

/* ==========================================================================
   RESET
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg-gradient) , var(--bg-base);
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-weight: 500;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: background-color var(--transition-med), color var(--transition-med);
  overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

.app-screen { display: none; }
.app-screen.active { display: block; animation: screenIn var(--transition-med); }

@keyframes screenIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   TOP BAR — theme toggle, ruang kosong (white space) untuk kurangi cemas
   ========================================================================== */
.top-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 18px 20px 0;
  min-height: 56px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 6px;
  box-shadow: var(--shadow-soft);
}

.theme-toggle button {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.theme-toggle button.is-active {
  background: var(--accent);
  color: var(--accent-contrast);
}

/* Ruang kosong wajib minimal 100px sebelum konten utama */
.whitespace-buffer {
  height: 110px;
  width: 100%;
}

.app-shell {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 20px 60px;
}

/* ==========================================================================
   TYPOGRAPHY
   ========================================================================== */
.app-title {
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 5vw, 2.3rem);
  font-weight: 800;
  text-align: center;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

.app-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.98rem;
  margin: 0 0 36px;
  font-weight: 500;
}

/* ==========================================================================
   SETUP SCREEN
   ========================================================================== */
.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow-card);
}

.field-group { margin-bottom: 28px; }

.field-label {
  display: block;
  font-weight: 700;
  font-size: 0.92rem;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.count-options {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.count-chip {
  border: 2px solid var(--border);
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-weight: 800;
  font-size: 1rem;
  color: var(--text-primary);
  min-width: 56px;
  text-align: center;
  transition: all var(--transition-fast);
}

.count-chip.is-selected {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

.table-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.table-check {
  position: relative;
}

.table-check input {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.table-check label {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  user-select: none;
}

.table-check input:checked + label {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
  transform: scale(1.03);
}

.table-check input:focus-visible + label {
  outline: 3px solid var(--comet-glow);
  outline-offset: 2px;
}

.field-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 10px;
}

.btn-primary {
  width: 100%;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 800;
  font-size: 1.05rem;
  padding: 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-card); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
  width: 100%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 14px;
  border-radius: var(--radius-md);
  margin-top: 12px;
}

/* ==========================================================================
   READY / TRANSITION SCREEN — layar "anak", tombol besar START TIMER
   ========================================================================== */
.ready-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: 20px;
}

.ready-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 36px;
  width: 100%;
  box-shadow: var(--shadow-soft);
}

.ready-summary-row {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  padding: 6px 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.ready-summary-row span:last-child { color: var(--text-primary); }

.start-timer-btn {
  width: 220px;
  height: 220px;
  max-width: 60vw;
  max-height: 60vw;
  border-radius: 50%;
  border: none;
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 75%, black));
  color: var(--accent-contrast);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.4rem;
  box-shadow: 0 16px 40px var(--comet-glow);
  animation: pulseReady 2.2s ease-in-out infinite;
  transition: transform var(--transition-fast);
}

.start-timer-btn:hover { transform: scale(1.04); }
.start-timer-btn:active { transform: scale(0.97); }

@keyframes pulseReady {
  0%, 100% { box-shadow: 0 16px 40px var(--comet-glow); }
  50% { box-shadow: 0 16px 56px var(--comet-glow), 0 0 0 14px var(--comet-glow); }
}

.ready-hint {
  margin-top: 24px;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.ready-hint kbd {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  font-family: inherit;
  font-weight: 800;
}

/* ==========================================================================
   QUIZ SCREEN
   ========================================================================== */
.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 12px;
}

.progress-track {
  flex: 1;
  height: 10px;
  background: var(--surface-alt);
  border-radius: var(--radius-pill);
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-pill);
  transition: width var(--transition-med);
}

.timer-display {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  min-width: 76px;
  text-align: center;
  white-space: nowrap;
  box-shadow: var(--shadow-soft);
}

.timer-display.is-low { color: var(--error); border-color: var(--error); }

/* Streak — "comet trail" indikator */
.streak-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 14px;
  min-height: 28px;
}

.streak-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  transition: all var(--transition-med);
}

.streak-dot.is-lit {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--comet-glow);
  transform: scale(1.15);
}

.streak-label {
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--accent);
  margin-left: 6px;
}

.quiz-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 24px 28px;
  text-align: center;
  box-shadow: var(--shadow-card);
  position: relative;
  transition: background-color var(--transition-fast);
}

.quiz-card.flash-correct { animation: flashGreen 0.45s ease; }
.quiz-card.flash-wrong { animation: flashRed 0.6s ease; }

@keyframes flashGreen {
  0% { background-color: var(--success-bg); }
  100% { background-color: var(--surface); }
}
@keyframes flashRed {
  0%, 30% { background-color: var(--error-bg); }
  100% { background-color: var(--surface); }
}

.question-text {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.8rem, 12vw, 4rem);
  letter-spacing: -0.02em;
  margin: 0 0 24px;
  font-variant-numeric: tabular-nums;
}

.answer-input {
  width: 100%;
  max-width: 260px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2.2rem;
  text-align: center;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 3px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition-fast);
  font-variant-numeric: tabular-nums;
}

.answer-input:focus { border-color: var(--accent); }

.hint-box {
  margin-top: 18px;
  min-height: 24px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--error);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.hint-box.is-visible { opacity: 1; }

/* On-screen numpad — besar & empuk untuk sentuhan tablet */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 26px;
}

.numpad-key {
  border: none;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  padding: 18px 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-soft);
  transition: transform var(--transition-fast), background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.numpad-key:active { transform: scale(0.94); background: var(--accent); color: var(--accent-contrast); }

.numpad-key.numpad-clear {
  background: var(--error-bg);
  color: var(--error);
  font-size: 1.05rem;
}

.numpad-key.numpad-zero { grid-column: span 1; }

/* ==========================================================================
   SUMMARY SCREEN
   ========================================================================== */
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow-card);
}

.summary-emoji { font-size: 3.4rem; margin-bottom: 6px; }

.summary-message {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.3rem;
  margin: 0 0 28px;
  line-height: 1.35;
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.stat-box {
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  padding: 16px 10px;
}

.stat-value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.6rem;
  display: block;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-box.is-correct .stat-value { color: var(--success); }
.stat-box.is-wrong .stat-value { color: var(--error); }

.personal-best-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--success-bg);
  color: var(--success);
  font-weight: 800;
  font-size: 0.92rem;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  margin-bottom: 24px;
}

.summary-actions { display: flex; flex-direction: column; gap: 12px; }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 420px) {
  .table-grid { grid-template-columns: repeat(5, 1fr); gap: 8px; }
  .numpad { gap: 9px; }
  .numpad-key { padding: 16px 0; font-size: 1.3rem; }
  .quiz-card { padding: 28px 16px 22px; }
  .whitespace-buffer { height: 90px; }
}

@media (min-width: 700px) {
  .answer-input { font-size: 2.6rem; }
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
