:root {
  --sky: #e8f6ff;
  --sky-deep: #b8e4ff;
  --ink: #1e293b;
  --ink-muted: #64748b;
  --gold: #f59e0b;
  --gold-soft: #fef3c7;
  --cyan: #0ea5e9;
  --violet: #8b5cf6;
  --rose: #f43f5e;
  --green: #10b981;
  --card: #ffffff;
  --border: rgba(30, 41, 59, 0.08);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-hover: 0 4px 12px rgba(15, 23, 42, 0.1), 0 16px 40px rgba(15, 23, 42, 0.08);
  --radius: 16px;
  --radius-lg: 20px;
  --font: "Lexend", system-ui, sans-serif;
  --nav-h: 64px;
  --max: 1120px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(14, 165, 233, 0.18), transparent),
    radial-gradient(ellipse 60% 40% at 90% 0%, rgba(245, 158, 11, 0.12), transparent),
    linear-gradient(180deg, #f0f9ff 0%, #fffbeb 55%, #f8fafc 100%);
  background-attachment: fixed;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ===== Site header (web nav) ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.site-header-inner {
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  flex-shrink: 0;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--gold), #fbbf24);
  display: grid;
  place-items: center;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.35);
  font-size: 1.1rem;
}
.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  margin-left: 12px;
}
.nav-link {
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 650;
  font-size: 0.9rem;
  color: var(--ink-muted);
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: #f1f5f9; color: var(--ink); }
.nav-link.active {
  background: var(--gold-soft);
  color: #92400e;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.stat-pills {
  display: none;
  gap: 6px;
  align-items: center;
}
.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
  font-weight: 700;
  font-size: 0.78rem;
  white-space: nowrap;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--ink-muted);
  font-size: 1.1rem;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover {
  background: #fff;
  border-color: #cbd5e1;
  color: var(--ink);
}

.mobile-menu-btn { display: none; }

/* ===== Page shell ===== */
.page {
  flex: 1;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 28px 24px 48px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-head h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2.5vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}
.page-head .sub {
  margin: 6px 0 0;
  color: var(--ink-muted);
  font-size: 0.95rem;
  font-weight: 500;
}
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin-bottom: 12px;
  font-weight: 600;
}
.breadcrumb button {
  color: var(--cyan);
  font-weight: 700;
}
.breadcrumb button:hover { text-decoration: underline; }

/* ===== Home hero ===== */
.hero {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 20px;
  margin-bottom: 28px;
}
.hero-main {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  position: relative;
  overflow: hidden;
}
.hero-main::after {
  content: "";
  position: absolute;
  right: -40px;
  top: -40px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.2), transparent 70%);
  pointer-events: none;
}
.hero-main h1 {
  margin: 0;
  font-size: clamp(1.75rem, 3vw, 2.35rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.hero-main p {
  margin: 0;
  color: var(--ink-muted);
  font-size: 1.05rem;
  max-width: 36ch;
  line-height: 1.5;
}
.hero-cta { display: flex; gap: 10px; flex-wrap: wrap; }

.hero-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.panel strong { display: block; font-size: 0.95rem; }
.panel span { color: var(--ink-muted); font-size: 0.85rem; font-weight: 500; }
.panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.primary-btn {
  background: var(--gold);
  color: #1e293b;
  font-weight: 750;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 0.95rem;
  box-shadow: 0 1px 0 rgba(0,0,0,0.06);
  transition: filter 0.15s, transform 0.1s;
}
.primary-btn:hover { filter: brightness(1.05); }
.primary-btn:active { transform: translateY(1px); }
.ghost-btn {
  background: #fff;
  border: 1px solid var(--border);
  font-weight: 700;
  border-radius: 10px;
  padding: 11px 16px;
  color: var(--ink);
}
.ghost-btn:hover { background: #f8fafc; }

.bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  width: 100px;
  flex-shrink: 0;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--green);
  border-radius: inherit;
}

/* ===== Mode / category grids ===== */
.section-label {
  font-size: 0.8rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 12px;
}
.mode-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.mode-card {
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  text-align: left;
  box-shadow: var(--shadow);
  border: 1px solid transparent;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.mode-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
}
.mode-card .label {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
}
.mode-card h2 {
  margin: 6px 0 0;
  font-size: 1.45rem;
  font-weight: 800;
}
.mode-card p {
  margin: 4px 0 0;
  color: var(--ink-muted);
  font-weight: 500;
  font-size: 0.88rem;
}
.mode-card .glyph {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  background: rgba(255, 255, 255, 0.55);
  margin-top: 16px;
}
.mode-trace { background: linear-gradient(160deg, #fef08a, #fde047); }
.mode-swipe { background: linear-gradient(160deg, #bae6fd, #7dd3fc); }
.mode-scratch { background: linear-gradient(160deg, #fecdd3, #fda4af); }
.mode-games { background: linear-gradient(160deg, #ddd6fe, #c4b5fd); }

.cat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.cat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  box-shadow: var(--shadow);
  font-weight: 750;
  min-height: 130px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.cat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}
.cat-card .emoji { font-size: 2rem; }
.cat-card small { color: var(--ink-muted); font-weight: 600; }

/* ===== Item grid ===== */
.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 12px;
}
.item-bubble {
  aspect-ratio: 1;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 1.35rem;
  box-shadow: var(--shadow);
  position: relative;
  transition: transform 0.12s, filter 0.12s;
}
.item-bubble:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.03);
  filter: brightness(1.05);
}
.item-bubble.done::after {
  content: "✓";
  position: absolute;
  top: 5px;
  right: 6px;
  font-size: 0.7rem;
  background: rgba(255, 255, 255, 0.95);
  color: var(--green);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.item-bubble.locked { opacity: 0.4; filter: grayscale(0.5); }
.item-bubble.rtl { font-size: 1.5rem; }

/* ===== Activity (trace / scratch / swipe) ===== */
.activity-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 24px;
  align-items: start;
}
.activity-aside {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.big-label {
  font-size: 4rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.04em;
}
.accuracy {
  font-weight: 650;
  color: var(--ink-muted);
  font-size: 0.9rem;
}
.activity-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.canvas-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  height: min(62vh, 520px);
  touch-action: none;
}
.canvas-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.tool-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 700;
  box-shadow: var(--shadow);
  transition: background 0.15s;
}
.tool-btn:hover:not(:disabled) { background: #f8fafc; }
.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.tool-btn.danger { color: var(--rose); }
.item-nav {
  margin-top: 4px;
  align-items: center;
}
.item-pos {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--ink-muted);
  min-width: 3.5rem;
  text-align: center;
}

.scratch-stage {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  height: min(62vh, 520px);
}
.scratch-reveal {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  background: linear-gradient(180deg, #fff, #fffbeb);
}
.scratch-reveal img {
  width: min(50%, 220px);
  height: auto;
  object-fit: contain;
}
.scratch-reveal .word { font-size: 1.5rem; font-weight: 800; }
.scratch-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  touch-action: none;
}

.swipe-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 36px 28px;
  text-align: center;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  user-select: none;
}
.swipe-card img { width: 200px; height: 200px; object-fit: contain; }
.swipe-card .letter { font-size: 4.5rem; font-weight: 900; }
.swipe-hint { color: var(--ink-muted); font-weight: 600; margin: 0; }

/* ===== Games ===== */
.game-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.game-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 18px;
  box-shadow: var(--shadow);
  text-align: center;
  min-height: 150px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.game-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}
.game-card h3 { margin: 10px 0 6px; font-size: 1.05rem; }
.game-card p { margin: 0; color: var(--ink-muted); font-size: 0.85rem; }

.identify-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.option-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
  font-weight: 750;
  transition: outline 0.1s;
}
.option-card:hover { border-color: #94a3b8; }
.option-card img { width: 80px; height: 80px; margin: 0 auto 10px; object-fit: contain; }
.option-card.correct { outline: 3px solid var(--green); }
.option-card.wrong { outline: 3px solid var(--rose); opacity: 0.7; }

.prompt-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.prompt-box .prompt-letter { font-size: 3rem; font-weight: 900; }

.match-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-width: 640px;
  margin: 0 auto;
}
.match-col { display: flex; flex-direction: column; gap: 10px; }
.match-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
  text-align: center;
  font-weight: 750;
  min-height: 72px;
  display: grid;
  place-items: center;
}
.match-item.selected { outline: 3px solid var(--cyan); }
.match-item.matched { opacity: 0.35; pointer-events: none; }
.match-item img { width: 56px; height: 56px; object-fit: contain; }

.balloon-stage {
  position: relative;
  height: 440px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #7dd3fc, #e0f2fe);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.balloon {
  position: absolute;
  bottom: -80px;
  width: 68px;
  height: 84px;
  border-radius: 50% 50% 48% 48% / 58% 58% 42% 42%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 900;
  font-size: 1.35rem;
  animation: rise linear forwards;
  box-shadow: inset -8px -10px 0 rgba(0, 0, 0, 0.08);
  z-index: 2;
  transform-origin: center center;
}
.balloon-label {
  position: relative;
  z-index: 1;
  pointer-events: none;
}
.balloon-string {
  position: absolute;
  left: 50%;
  bottom: -22px;
  width: 2px;
  height: 22px;
  background: rgba(30, 41, 59, 0.35);
  transform: translateX(-50%);
  pointer-events: none;
}
.balloon.popping {
  animation: balloon-pop 0.45s ease-out forwards !important;
  pointer-events: none;
  z-index: 5;
}
.balloon.wrong-pop {
  filter: grayscale(0.35);
}
@keyframes rise {
  to { transform: translateY(-520px); }
}
@keyframes balloon-pop {
  0% { transform: scale(1); opacity: 1; }
  35% { transform: scale(1.35); opacity: 1; }
  100% { transform: scale(0); opacity: 0; }
}
.pop-bit {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  pointer-events: none;
  z-index: 6;
  animation: bit-fly 0.4s ease-out forwards;
}
@keyframes bit-fly {
  to {
    transform: translate(var(--dx), var(--dy)) scale(0.2);
    opacity: 0;
  }
}

/* ===== Progress ===== */
.progress-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.progress-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  font-weight: 650;
  font-size: 0.9rem;
}

/* ===== Settings modal ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.sheet {
  background: #fff;
  width: min(440px, 100%);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-hover);
  max-height: 85vh;
  overflow: auto;
}
.sheet h2 { margin: 0 0 8px; font-size: 1.35rem; }
.sheet-sub { margin: 0 0 20px; color: var(--ink-muted); font-size: 0.9rem; }
.setting-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 0;
  border-bottom: 1px solid #f1f5f9;
}
.setting-row:last-of-type { border-bottom: none; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  background: #f1f5f9;
  font-weight: 700;
  font-size: 0.85rem;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.chip:hover { border-color: #cbd5e1; }
.chip.on {
  background: var(--gold-soft);
  border-color: #fbbf24;
  color: #92400e;
}
.sheet-actions {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ===== Celebrate / walkthrough ===== */
.celebrate {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.4);
  padding: 20px;
}
.celebrate-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  text-align: center;
  width: min(360px, 100%);
  box-shadow: var(--shadow-hover);
  animation: pop 0.3s ease;
}
@keyframes pop {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.stars { font-size: 1.75rem; letter-spacing: 4px; color: var(--gold); }
.mascot { font-size: 3rem; margin: 4px 0; }

.walkthrough {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(15, 23, 42, 0.5);
  display: grid;
  place-items: center;
  padding: 20px;
}
.walk-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 28px;
  width: min(400px, 100%);
  text-align: center;
  box-shadow: var(--shadow-hover);
}
.walk-card .step { color: var(--ink-muted); font-weight: 700; font-size: 0.85rem; }

/* Mobile bottom nav — only on small screens */
.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  z-index: 40;
  backdrop-filter: blur(12px);
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 10px;
  color: var(--ink-muted);
  font-size: 0.68rem;
  font-weight: 700;
  flex: 1;
}
.nav-item .nav-ico { font-size: 1.2rem; }
.nav-item.active {
  color: var(--ink);
  background: var(--gold-soft);
}

.mobile-drawer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(15, 23, 42, 0.4);
}
.mobile-drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(300px, 86vw);
  height: 100%;
  background: #fff;
  padding: 20px;
  box-shadow: var(--shadow-hover);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mobile-drawer-panel .nav-link {
  display: block;
  padding: 12px 14px;
  border-radius: 10px;
}

/* ===== Responsive ===== */
@media (max-width: 960px) {
  .mode-grid,
  .game-grid,
  .cat-grid { grid-template-columns: repeat(2, 1fr); }
  .hero { grid-template-columns: 1fr; }
  .activity-layout { grid-template-columns: 1fr; }
  .activity-aside {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  .big-label { font-size: 2.75rem; }
  .identify-options { grid-template-columns: 1fr 1fr; }
  .progress-list { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .main-nav { display: none; }
  .stat-pills { display: none !important; }
  .mobile-menu-btn { display: grid; }
  .page { padding: 20px 16px 96px; }
  .bottom-nav { display: flex; }
  .mode-grid { grid-template-columns: 1fr; }
  .item-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 721px) {
  .stat-pills { display: flex; }
}
