:root {
  --bg: #FFFDF7;
  --bg-warm: #FDF4E1;
  --surface: #FFFFFF;
  --ink: #2B2118;
  --ink-soft: #5D4E42;
  --border: #EFE5D5;
  --amber: #F59E0B;
  --amber-dark: #D97706;
  --sky: #0EA5E9;
  --mint: #10B981;
  --sun: #EAB308;
  --lavender: #8B5CF6;
  --shadow: 0 12px 32px rgba(43, 33, 24, 0.08);
}

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

body {
  margin: 0;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 10%, rgba(254, 243, 199, 0.9) 0%, transparent 40%),
    radial-gradient(circle at 88% 85%, rgba(224, 242, 254, 0.85) 0%, transparent 45%),
    var(--bg);
  min-height: 100vh;
}

h1, h2, h3, button { font-family: 'Fredoka', 'Nunito', sans-serif; }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 253, 247, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1060px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; font-size: 1.25rem; font-weight: 700; }
.brand img { width: 42px; height: 42px; border-radius: 50%; background: #FEF3C7; padding: 3px; }

.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.score-pill {
  background: #FEF3C7; border: 2px solid #FDE68A; color: #92400E;
  padding: 7px 14px; border-radius: 999px; font-weight: 700; font-size: 0.95rem;
}

.btn-status {
  background: #FFFFFF; border: 2px solid var(--amber); color: #B45309;
  padding: 7px 14px; border-radius: 999px; font-weight: 600; font-size: 0.88rem; cursor: pointer;
}
.btn-status.unlocked { background: #DCFCE7; border-color: #86EFAC; color: #166534; }

.btn-mute {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--border);
  background: #fff; font-size: 1.1rem; cursor: pointer;
}

/* Main */
.app-main { max-width: 1060px; margin: 0 auto; padding: 24px 20px 64px; }

.hero-card {
  background: linear-gradient(135deg, #FFFBEB 0%, #FFFFFF 55%, #F0FDF4 100%);
  border: 2px solid #FDE68A; border-radius: 28px; padding: 26px 28px;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 22px;
  box-shadow: var(--shadow); margin-bottom: 28px;
}

.hero-duo { width: 104px; height: 104px; object-fit: contain; }
.hero-tag {
  display: inline-block; background: #FEF3C7; color: #B45309;
  font-size: 0.76rem; font-weight: 800; padding: 4px 12px; border-radius: 999px; margin-bottom: 8px;
}
.hero-card h1 { margin: 0 0 6px; font-size: clamp(1.4rem, 2.6vw, 2rem); }
.hero-card p { margin: 0; color: var(--ink-soft); font-size: 0.98rem; }

/* Worlds Grid */
.worlds-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }

.world-card {
  background: #fff; border: 3px solid var(--border); border-radius: 24px;
  padding: 22px; display: flex; align-items: center; gap: 18px; text-align: left;
  cursor: pointer; box-shadow: var(--shadow); transition: transform 0.18s ease, box-shadow 0.18s ease;
  color: var(--ink);
}
.world-card:hover { transform: translateY(-4px); box-shadow: 0 18px 36px rgba(43,33,24,0.12); }

.world-card.theme-sky { border-color: #BAE6FD; background: linear-gradient(135deg, #F0F9FF, #FFFFFF); }
.world-card.theme-mint { border-color: #A7F3D0; background: linear-gradient(135deg, #ECFDF5, #FFFFFF); }
.world-card.theme-sun { border-color: #FDE68A; background: linear-gradient(135deg, #FFFBEB, #FFFFFF); }
.world-card.theme-lavender { border-color: #DDD6FE; background: linear-gradient(135deg, #F5F3FF, #FFFFFF); }

.world-img-wrap img { width: 86px; height: 86px; object-fit: contain; }
.world-info { flex: 1; }
.world-info h2 { margin: 0 0 4px; font-size: 1.32rem; }
.world-info p { margin: 0 0 10px; font-size: 0.9rem; color: var(--ink-soft); font-family: 'Nunito', sans-serif; font-weight: 700; }

.world-progress { display: flex; align-items: center; gap: 10px; font-size: 0.8rem; font-weight: 800; color: var(--ink-soft); }
.mini-bar { flex: 1; height: 9px; background: #EFE5D5; border-radius: 999px; overflow: hidden; }
.mini-bar span { display: block; height: 100%; background: linear-gradient(90deg, #F59E0B, #10B981); border-radius: 999px; transition: width 0.3s ease; }
.play-arrow {
  width: 44px; height: 44px; border-radius: 50%; background: rgba(43,33,24,0.06);
  display: inline-flex; align-items: center; justify-content: center; font-size: 1.1rem; flex-shrink: 0;
}

/* Game Stage */
.game-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.btn-back {
  background: #fff; border: 2px solid var(--border); padding: 9px 18px;
  border-radius: 999px; font-weight: 600; font-size: 0.95rem; cursor: pointer;
}
.mode-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab-btn {
  background: #fff; border: 2px solid var(--border); padding: 9px 16px;
  border-radius: 999px; font-weight: 600; cursor: pointer;
}
.tab-btn.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.world-pill { padding: 7px 16px; border-radius: 999px; font-weight: 700; font-size: 0.88rem; color: #fff; }
.world-pill.sky { background: #0284C7; }
.world-pill.mint { background: #059669; }
.world-pill.sun { background: #D97706; }
.world-pill.lavender { background: #7C3AED; }
.world-pill.amber { background: #EA580C; }

.stage-card {
  background: #fff; border: 2px solid var(--border); border-radius: 28px;
  padding: 28px; box-shadow: var(--shadow); margin-bottom: 24px;
}

.prompt-row { display: flex; align-items: center; gap: 18px; margin-bottom: 24px; }
.prompt-row.compact { justify-content: space-between; }
.helper-char { width: 82px; height: 82px; object-fit: contain; flex-shrink: 0; }
.prompt-eyebrow { font-size: 0.85rem; font-weight: 800; color: var(--amber-dark); text-transform: uppercase; letter-spacing: 0.04em; }
.prompt-title { margin: 2px 0 4px; font-size: clamp(1.35rem, 2.5vw, 1.9rem); }
.prompt-sub { margin: 0; color: var(--ink-soft); font-size: 1rem; }
.accent-sky { color: #0284C7; }
.accent-lav { color: #7C3AED; }

.btn-speak {
  margin-left: auto; width: 56px; height: 56px; border-radius: 50%;
  background: #FEF3C7; border: 2px solid #FDE68A; font-size: 1.5rem; cursor: pointer; flex-shrink: 0;
}
.btn-speak:hover { transform: scale(1.06); }

/* Options */
.options-grid { display: grid; gap: 16px; }
.options-grid.four { grid-template-columns: repeat(4, 1fr); }
.options-grid.three { grid-template-columns: repeat(3, 1fr); }

.option-tile {
  background: #FFFDF7; border: 3px solid var(--border); border-radius: 22px;
  padding: 20px 14px; cursor: pointer; transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 112px; color: var(--ink);
}
.option-tile:hover { transform: translateY(-3px); border-color: var(--amber); }
.option-tile.correct { background: #DCFCE7 !important; border-color: #10B981 !important; transform: scale(1.03); }
.option-tile.wrong { background: #FEE2E2 !important; border-color: #EF4444 !important; animation: shake 0.3s; }

.ar-big { font-size: 3.4rem; line-height: 1.1; }
.ar-med { font-size: 2.6rem; min-height: 84px; min-width: 84px; padding: 12px 22px; }
.ar-giant { font-size: 6rem; line-height: 1.1; display: block; }
.ar-num { font-size: 2.8rem; line-height: 1; }
.num-tr { font-size: 0.88rem; font-weight: 800; color: var(--ink-soft); font-family: 'Nunito', sans-serif; }

.harakat-legend { display: flex; gap: 8px; flex-wrap: wrap; }
.h-tag { padding: 6px 12px; border-radius: 999px; font-weight: 800; font-size: 0.85rem; }

.harakat-showcase {
  text-align: center; border: 3px solid; border-radius: 26px; padding: 24px;
  max-width: 340px; margin: 0 auto 24px;
}
.harakat-hint { font-size: 0.95rem; font-weight: 800; color: var(--ink-soft); }
.sound-big { font-size: 2.1rem; font-weight: 700; }
.sound-label { font-size: 0.86rem; font-weight: 800; font-family: 'Nunito', sans-serif; }

/* Trace Canvas */
.trace-wrap {
  background: #F8FAFC; border: 3px dashed #BAE6FD; border-radius: 22px;
  display: flex; justify-content: center; padding: 10px; touch-action: none;
}
#traceCanvas { max-width: 100%; height: auto; cursor: crosshair; }

.trace-controls { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 18px; }
.color-dots { display: flex; gap: 10px; }
.color-dot { width: 36px; height: 36px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px #CBD5E1; cursor: pointer; }
.color-dot.active { box-shadow: 0 0 0 3px var(--ink); transform: scale(1.1); }
.trace-btns { display: flex; gap: 10px; flex-wrap: wrap; }

/* Numbers & Math */
.dates-box {
  background: #FFFBEB; border: 2px solid #FDE68A; border-radius: 22px; padding: 22px;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-bottom: 22px;
}
.date-item { font-size: 2.5rem; }
.math-showcase {
  display: flex; justify-content: center; align-items: center; gap: 18px;
  font-size: 4rem; font-weight: 700; color: #D97706; margin-bottom: 4px;
}
.math-op { color: var(--ink-soft); font-size: 2.6rem; }
.math-q { background: #FEF3C7; padding: 4px 24px; border-radius: 18px; border: 3px dashed #F59E0B; }
.math-sub { text-align: center; color: var(--ink-soft); font-weight: 700; margin-bottom: 22px; }

/* Word Builder */
.shy-banner { background: #F5F3FF; border: 1px solid #DDD6FE; color: #5B21B6; padding: 7px 14px; border-radius: 999px; font-size: 0.88rem; }
.word-target-preview {
  background: #FAF5FF; border: 3px solid #DDD6FE; border-radius: 22px;
  padding: 24px; display: flex; justify-content: center; align-items: center; gap: 16px; margin-bottom: 22px; min-height: 112px;
}
.word-slot {
  width: 72px; height: 72px; border-radius: 16px; border: 3px dashed #C4B5FD;
  background: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 2.5rem; color: #A78BFA;
}
.word-slot.filled { border-style: solid; border-color: #7C3AED; color: var(--ink); background: #EDE9FE; }
.word-complete { font-size: 4rem; color: #059669; font-weight: 700; }
.builder-tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }

/* Feedback & Buttons */
.feedback-bar { margin-top: 18px; padding: 14px 18px; border-radius: 16px; font-weight: 700; text-align: center; min-height: 24px; }
.feedback-bar.ok { background: #DCFCE7; color: #166534; }
.feedback-bar.try { background: #FEF3C7; color: #92400E; }

.btn-action {
  border: none; padding: 13px 24px; border-radius: 999px; font-size: 1rem; font-weight: 600;
  color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
.btn-action.amber { background: linear-gradient(135deg, #F59E0B, #EA580C); box-shadow: 0 8px 20px rgba(234,88,12,0.28); }
.btn-action.sky { background: linear-gradient(135deg, #0EA5E9, #0284C7); }
.btn-soft {
  background: #FFFDF7; border: 2px solid var(--border); color: var(--ink);
  padding: 11px 20px; border-radius: 999px; font-weight: 600; font-size: 0.95rem; cursor: pointer; text-decoration: none;
}

/* Badges & Certificate */
.badges-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.badge-card {
  border: 2px solid var(--border); border-radius: 20px; padding: 18px; text-align: center; background: #FAF7F2; opacity: 0.78;
}
.badge-card.earned { background: #FFFBEB; border-color: #F59E0B; opacity: 1; }
.badge-emoji { font-size: 2.5rem; margin-bottom: 6px; }
.badge-card h3 { margin: 0 0 4px; font-size: 1.05rem; }
.badge-card p { margin: 0 0 10px; font-size: 0.82rem; color: var(--ink-soft); }

.cert-controls { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.cert-controls input {
  flex: 1; min-width: 220px; padding: 12px 16px; border-radius: 14px; border: 2px solid var(--border); font-size: 1rem; font-family: inherit;
}
.certificate-box {
  border: 6px double #F59E0B; border-radius: 24px; padding: 34px 28px; text-align: center;
  background: linear-gradient(180deg, #FFFDF7, #FEF3C7);
}
.cert-logo { width: 96px; margin: 0 auto 10px; }
.cert-kicker { font-weight: 800; letter-spacing: 0.14em; color: #B45309; font-size: 0.85rem; }
.cert-name { font-size: 2.4rem; margin: 10px 0; color: #EA580C; }
.cert-text { max-width: 560px; margin: 0 auto 20px; font-size: 1.05rem; color: var(--ink-soft); }
.cert-stamps { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-bottom: 20px; }
.cert-stamp { background: #fff; border: 2px solid #E5E7EB; padding: 6px 12px; border-radius: 999px; font-size: 0.85rem; opacity: 0.45; }
.cert-stamp.on { border-color: #10B981; background: #DCFCE7; opacity: 1; font-weight: 700; }
.cert-sign { font-family: 'Fredoka', sans-serif; font-weight: 700; color: #92400E; }

/* Modal & Demo End */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(43,33,24,0.55); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  background: #fff; border-radius: 28px; padding: 30px; max-width: 460px; width: 100%;
  text-align: center; position: relative; box-shadow: 0 24px 60px rgba(0,0,0,0.22);
}
.modal-close {
  position: absolute; top: 16px; right: 16px; width: 36px; height: 36px; border-radius: 50%;
  border: none; background: #F3F4F6; cursor: pointer; font-size: 1rem;
}
.modal-desc { color: var(--ink-soft); font-size: 0.96rem; margin-bottom: 18px; }
.unlock-form { display: flex; gap: 10px; flex-direction: column; }
.unlock-form input { padding: 13px 16px; border-radius: 14px; border: 2px solid var(--border); font-size: 1rem; text-align: center; font-weight: 700; text-transform: uppercase; }
.code-msg { margin-top: 10px; font-weight: 700; font-size: 0.9rem; min-height: 22px; }
.code-msg.ok { color: #059669; }
.code-msg.err { color: #DC2626; }
.modal-shop-hint { margin-top: 16px; font-size: 0.88rem; color: var(--ink-soft); }
.modal-shop-hint a { color: #EA580C; font-weight: 800; }

.demo-end-box { text-align: center; padding: 24px 12px; }
.demo-end-box p { color: var(--ink-soft); max-width: 520px; margin: 8px auto 22px; font-size: 1.05rem; }
.demo-end-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }

/* Confetti */
.confetti-piece {
  position: fixed; top: -12px; width: 12px; height: 12px; border-radius: 3px; z-index: 300;
  animation: fall 1.2s ease-out forwards; pointer-events: none;
}
@keyframes fall {
  to { transform: translateY(100vh) rotate(540deg); opacity: 0; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

@media (max-width: 820px) {
  .hero-card { grid-template-columns: 1fr; text-align: center; }
  .hero-duo { margin: 0 auto; }
  .worlds-grid, .badges-grid { grid-template-columns: 1fr; }
  .options-grid.four { grid-template-columns: repeat(2, 1fr); }
}

@media print {
  .topbar, .game-top, .cert-controls, .stage-card:not(.cert-section), .cert-section > h2, .cert-section > p { display: none !important; }
  .stage-card.cert-section { border: none; box-shadow: none; padding: 0; }
}
