/* =========================================================
   Elimu Live — Shared Design System
   Educational science games: Biology · Physics · Chemistry · CS
   ========================================================= */

:root {
  /* Brand */
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --brand-glow: rgba(99, 102, 241, 0.45);

  /* Subject accents */
  --biology: #10b981;
  --physics: #f59e0b;
  --chemistry: #ef4444;
  --cs: #3b82f6;

  /* Surfaces (dark theme) */
  --bg: #0b1020;
  --bg-2: #111a33;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-2: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.22);

  /* Text */
  --text: #eef2ff;
  --text-dim: #9aa6c8;
  --text-faint: #6b7799;

  /* Status */
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;

  /* Geometry */
  --r-sm: 10px;
  --r: 16px;
  --r-lg: 24px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 6px 20px rgba(0, 0, 0, 0.28);

  --nav-h: 66px;
  --max: 1240px;

  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Code", "Consolas", ui-monospace, monospace;
}

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

html, body { min-height: 100%; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 12% -8%, rgba(124, 58, 237, 0.28), transparent 60%),
    radial-gradient(900px 550px at 92% 0%, rgba(59, 130, 246, 0.22), transparent 58%),
    radial-gradient(800px 700px at 50% 110%, rgba(16, 185, 129, 0.16), transparent 60%),
    linear-gradient(180deg, var(--bg), #070a16 70%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
  overflow-x: hidden;
}

img, canvas, svg { max-width: 100%; display: block; }

a { color: inherit; text-decoration: none; }

h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .4em; letter-spacing: -0.02em; }

button, input, select { font: inherit; color: inherit; }

/* ---------- Layout ---------- */
.wrap { width: min(100% - 2.5rem, var(--max)); margin-inline: auto; }
@media (max-width: 640px) { .wrap { width: min(100% - 1.4rem, var(--max)); } }

.section { padding: 3.2rem 0; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.section-head p { margin: 0; color: var(--text-dim); }

/* ---------- Navbar ---------- */
.nav {
  position: sticky; top: 0; z-index: 60;
  height: var(--nav-h);
  display: flex; align-items: center;
  backdrop-filter: blur(14px);
  background: rgba(8, 12, 26, 0.72);
  border-bottom: 1px solid var(--border);
}
.nav-inner { display: flex; align-items: center; gap: 1rem; width: min(100% - 2.5rem, var(--max)); margin-inline: auto; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.15rem; }
.brand .logo {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  display: grid; place-items: center; font-size: 1.1rem;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 6px 18px var(--brand-glow);
}
.brand span.accent { background: linear-gradient(90deg, #a78bfa, #60a5fa); -webkit-background-clip: text; background-clip: text; color: transparent; }

.nav-links { display: flex; align-items: center; gap: .25rem; margin-left: auto; }
.nav-links a {
  padding: .5rem .8rem; border-radius: 999px; font-size: .93rem; font-weight: 600;
  color: var(--text-dim); transition: .18s;
}
.nav-links a:hover, .nav-links a.active { color: var(--text); background: var(--surface-2); }
.nav-toggle { display: none; margin-left: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .5rem .7rem; cursor: pointer; }

@media (max-width: 760px) {
  .nav-toggle { display: block; }
  .nav-links {
    position: absolute; top: var(--nav-h); left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: .2rem;
    background: rgba(9, 13, 28, 0.98); border-bottom: 1px solid var(--border);
    padding: 0 .6rem; margin: 0; visibility: hidden;
    max-height: 0; overflow: hidden; transition: max-height .3s ease, visibility .3s;
  }
  .nav-links.open { max-height: 420px; padding: .6rem; visibility: visible; }
  .nav-links a { padding: .7rem 1rem; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .78rem 1.35rem; border-radius: 999px; border: 1px solid transparent;
  font-weight: 700; font-size: .95rem; cursor: pointer; transition: .2s;
  background: var(--surface-2); color: var(--text);
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 10px 28px var(--brand-glow); }
.btn-primary:hover { box-shadow: 0 14px 34px var(--brand-glow); }
.btn-ghost { background: transparent; border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-lg { padding: .95rem 1.8rem; font-size: 1.02rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 1.5rem;
  box-shadow: var(--shadow-sm); backdrop-filter: blur(10px);
}

/* ---------- Hero ---------- */
.hero { padding: 3.4rem 0 1.5rem; display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 2rem; align-items: center; }
.hero h1 { font-size: clamp(2.1rem, 5.2vw, 3.6rem); margin-bottom: .5rem; }
.hero h1 .grad { background: linear-gradient(90deg, #a78bfa, #60a5fa 55%, #34d399); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p.lead { font-size: clamp(1rem, 2.2vw, 1.15rem); color: var(--text-dim); max-width: 56ch; }
.hero-actions { display: flex; gap: .8rem; flex-wrap: wrap; margin-top: 1.5rem; }
@media (max-width: 900px) { .hero { grid-template-columns: 1fr; padding-top: 2.4rem; } }

.hero-visual { position: relative; display: grid; place-items: center; min-height: 260px; }
.orb {
  position: absolute; border-radius: 50%; filter: blur(2px);
  animation: float 7s ease-in-out infinite;
}
.orb.a { width: 150px; height: 150px; background: radial-gradient(circle at 30% 30%, #a78bfa, #4f46e5); top: 5%; left: 8%; box-shadow: 0 0 60px rgba(124, 58, 237, .6); }
.orb.b { width: 100px; height: 100px; background: radial-gradient(circle at 30% 30%, #fca5a5, #ef4444); bottom: 12%; right: 12%; animation-delay: -2s; box-shadow: 0 0 50px rgba(239, 68, 68, .5); }
.orb.c { width: 76px; height: 76px; background: radial-gradient(circle at 30% 30%, #6ee7b7, #10b981); top: 48%; right: 4%; animation-delay: -4s; box-shadow: 0 0 45px rgba(16, 185, 129, .5); }
.orb.d { width: 64px; height: 64px; background: radial-gradient(circle at 30% 30%, #93c5fd, #3b82f6); bottom: 4%; left: 24%; animation-delay: -1s; box-shadow: 0 0 40px rgba(59, 130, 246, .5); }
@keyframes float { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-16px) } }

/* ---------- Stats strip ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-top: 1.2rem; }
.stat { text-align: center; padding: 1rem; border-radius: var(--r); background: var(--surface); border: 1px solid var(--border); }
.stat b { display: block; font-size: 1.5rem; }
.stat small { color: var(--text-dim); }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Subject/game grid ---------- */
.grid { display: grid; gap: 1.2rem; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }

.subject-card { position: relative; overflow: hidden; }
.subject-card::after {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: var(--accent, var(--brand));
}
.subject-card .icon {
  width: 52px; height: 52px; border-radius: 15px; display: grid; place-items: center;
  font-size: 1.5rem; margin-bottom: .9rem;
  background: color-mix(in srgb, var(--accent, var(--brand)) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent, var(--brand)) 45%, transparent);
}
.subject-card h3 { margin-bottom: .2rem; }
.subject-card .tag { font-size: .78rem; text-transform: uppercase; letter-spacing: .12em; color: var(--accent, var(--brand)); font-weight: 800; }
.subject-card p { color: var(--text-dim); font-size: .93rem; margin: .6rem 0 1rem; }

.game-card { display: flex; flex-direction: column; transition: .22s; }
.game-card:hover { transform: translateY(-4px); border-color: var(--border-strong); box-shadow: var(--shadow); }
.game-card .badge {
  align-self: flex-start; font-size: .72rem; font-weight: 800; letter-spacing: .1em;
  text-transform: uppercase; padding: .28rem .6rem; border-radius: 999px;
  background: color-mix(in srgb, var(--accent, var(--brand)) 20%, transparent);
  color: color-mix(in srgb, var(--accent, var(--brand)) 85%, white);
  border: 1px solid color-mix(in srgb, var(--accent, var(--brand)) 42%, transparent);
}
.game-card h3 { margin: .75rem 0 .3rem; font-size: 1.12rem; }
.game-card p { color: var(--text-dim); font-size: .92rem; flex: 1; }
.game-card .meta { display: flex; gap: .9rem; flex-wrap: wrap; font-size: .82rem; color: var(--text-faint); margin: .8rem 0 1rem; }

/* ---------- Game shell ---------- */
.game-shell { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 1.2rem; align-items: start; padding: 1.6rem 0 3rem; flex: 1; }
@media (max-width: 980px) {
  .game-shell { display: flex; flex-direction: column; gap: .75rem; padding: .8rem 0 1.5rem; }
  .game-shell .hud { display: contents; }
  .game-shell .hud .card:nth-child(2) { order: -2; }
  .game-shell .board-wrap { order: -1; }
  .game-shell .board-wrap, .game-shell .hud .card { width: 100%; min-width: 0; }
  .game-shell .hud .card:first-child { order: 0; }
  .game-shell .hud .card:nth-child(n+3) { order: 1; }
}

.hud { display: grid; gap: .7rem; }
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.hud .label { font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; color: var(--text-faint); font-weight: 700; }
.hud .value { font-weight: 800; font-variant-numeric: tabular-nums; }

.pill { display: inline-flex; align-items: center; gap: .45rem; padding: .45rem .8rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 700; font-size: .88rem; }

.progress { height: 9px; border-radius: 999px; background: rgba(255,255,255,.09); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0%; border-radius: inherit; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .35s ease; }

.hearts { letter-spacing: .15em; font-size: 1.05rem; }
.hearts .off { opacity: .22; }

/* Board area */
.board { background: linear-gradient(180deg, rgba(255,255,255,.055), rgba(255,255,255,.02)); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 1.3rem; box-shadow: var(--shadow-sm); }
.board-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }

.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  background: rgba(6, 9, 20, 0.82); backdrop-filter: blur(8px); border-radius: var(--r-lg); z-index: 20; padding: 1.5rem;
}
.board-wrap { position: relative; }
.hidden { display: none !important; }

/* Inputs */
.input, .select {
  width: 100%; padding: .7rem .9rem; border-radius: var(--r-sm);
  background: rgba(255,255,255,.06); border: 1px solid var(--border); outline: none;
  transition: .18s;
}
.input:focus, .select:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(99,102,241,.18); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 140%);
  background: rgba(12, 17, 34, .96); border: 1px solid var(--border-strong);
  padding: .8rem 1.2rem; border-radius: 999px; font-weight: 700; z-index: 200;
  box-shadow: var(--shadow); transition: transform .3s ease; max-width: 92vw; text-align: center;
}
.toast.show { transform: translate(-50%, 0); }
.toast.ok { border-color: var(--ok); }
.toast.bad { border-color: var(--bad); }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--border); padding: 2rem 0; color: var(--text-faint); font-size: .88rem; margin-top: 2rem; }
.footer-inner { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: center; }

/* ---------- Utilities ---------- */
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.center { display: grid; place-items: center; text-align: center; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--mono); }
.mt-1 { margin-top: .5rem } .mt-2 { margin-top: 1rem } .mt-3 { margin-top: 1.6rem }
.mb-2 { margin-bottom: 1rem }

/* ---------- Animations ---------- */
.pop { animation: pop .35s ease; }
@keyframes pop { 0% { transform: scale(.9); opacity: .4 } 100% { transform: scale(1); opacity: 1 } }
.shake { animation: shake .4s ease; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-8px)} 40%{transform:translateX(8px)} 60%{transform:translateX(-5px)} 80%{transform:translateX(5px)} }
.fade-in { animation: fadeIn .4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: none } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}