/* ============================================================
   Crispin's World — common.css
   Palette, typography, layout primitives, top bar, layout shell
   ============================================================ */

:root {
  /* Core palette — tween friendly */
  --purple: #6B21A8;
  --purple-dark: #4C1D95;
  --purple-light: #A855F7;
  --yellow: #FACC15;
  --yellow-dark: #EAB308;
  --teal: #14B8A6;
  --teal-dark: #0F766E;
  --coral: #FB7185;
  --coral-dark: #E11D48;
  --pitch: #16A34A;
  --pitch-dark: #166534;
  --navy: #0F172A;
  --cream: #FFFBEB;
  --white: #FFFFFF;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-500: #6B7280;
  --gray-700: #374151;
  --gray-900: #111827;

  /* Semantic tokens */
  --bg-page: linear-gradient(135deg, #F5F3FF 0%, #FEF3C7 100%);
  --bg-card: #FFFFFF;
  --bg-muted: #F9FAFB;
  --text-primary: #111827;
  --text-secondary: #4B5563;
  --text-muted: #6B7280;
  --text-on-dark: #FFFFFF;
  --border: #E5E7EB;
  --border-strong: #D1D5DB;
  --shadow-sm: 0 2px 6px rgba(107, 33, 168, 0.08);
  --shadow-md: 0 4px 12px rgba(107, 33, 168, 0.12);
  --shadow-lg: 0 10px 25px rgba(107, 33, 168, 0.18);

  /* Radius & spacing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-8: 48px;
  --space-10: 64px;

  /* Typography */
  --font-heading: 'Fredoka One', 'Baloo 2', system-ui, sans-serif;
  --font-body: 'Nunito', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'Fira Code', ui-monospace, monospace;

  /* Layout */
  --topbar-h: 72px;
  --container-max: 1200px;
}

/* --------------- Reset --------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background: var(--bg-page);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; border: none; }
a { color: var(--purple); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --------------- Typography --------------- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  color: var(--purple);
  margin: 0 0 var(--space-3);
  line-height: 1.2;
  font-weight: normal; /* Fredoka One is already bold */
}
h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
h2 { font-size: clamp(1.5rem, 3vw, 2rem); }
h3 { font-size: clamp(1.2rem, 2.5vw, 1.5rem); }
h4 { font-size: 1.15rem; }
p { margin: 0 0 var(--space-3); }
.lead { font-size: 1.15rem; color: var(--text-secondary); }
.muted { color: var(--text-muted); font-size: 0.9rem; }

/* --------------- Layout shell --------------- */
.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-5);
}
.page {
  padding: calc(var(--topbar-h) + var(--space-6)) 0 var(--space-10);
}
.section { margin-bottom: var(--space-8); }
.section-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

/* --------------- Top bar --------------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: linear-gradient(90deg, var(--purple) 0%, var(--purple-dark) 100%);
  color: var(--white);
  z-index: 100;
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  box-shadow: var(--shadow-md);
  gap: var(--space-5);
}
.topbar__brand {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  color: var(--white);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  white-space: nowrap;
}
.topbar__brand:hover { text-decoration: none; color: var(--yellow); }
.topbar__ball {
  display: inline-block;
  animation: spin-slow 8s linear infinite;
  font-size: 1.5rem;
}
.topbar__nav {
  display: flex;
  gap: var(--space-4);
  flex: 1;
  margin-left: var(--space-5);
}
.topbar__nav a {
  color: var(--white);
  text-decoration: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-weight: 600;
  transition: background 0.2s;
  white-space: nowrap;
}
.topbar__nav a:hover { background: rgba(255,255,255,0.15); text-decoration: none; }
.topbar__nav a.active { background: var(--yellow); color: var(--purple-dark); }

.topbar__clock {
  background: rgba(0,0,0,0.2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}
.topbar__clock .clock__date { font-size: 0.75rem; opacity: 0.85; font-weight: 600; }
.topbar__clock .clock__time { font-variant-numeric: tabular-nums; }

.topbar__sound {
  background: rgba(255,255,255,0.15);
  color: var(--white);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background 0.2s, transform 0.2s;
}
.topbar__sound:hover { background: rgba(255,255,255,0.3); transform: scale(1.08); }

/* --------------- Gamification bar (below topbar) --------------- */
.gamebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  background: var(--white);
  border-bottom: 2px solid var(--yellow);
  padding: var(--space-2) var(--space-5);
  z-index: 90;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}
.gamebar__level {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  color: var(--purple);
}
.gamebar__level-badge {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--yellow), var(--yellow-dark));
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  color: var(--purple-dark);
  box-shadow: var(--shadow-sm);
}
.gamebar__xp {
  flex: 1;
  min-width: 180px;
  max-width: 400px;
}
.gamebar__xp-bar {
  height: 10px;
  background: var(--gray-200);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}
.gamebar__xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--pitch));
  border-radius: var(--radius-full);
  transition: width 0.6s ease-out;
}
.gamebar__xp-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 600;
}
.gamebar__streak, .gamebar__badges {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-weight: 700;
  color: var(--coral-dark);
  padding: var(--space-1) var(--space-3);
  background: #FEF3C7;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
}
.gamebar__badges { color: var(--purple); background: #F3E8FF; }

.page.with-gamebar { padding-top: calc(var(--topbar-h) + 56px + var(--space-5)); }

/* --------------- Utility --------------- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.text-center { text-align: center; }
.text-purple { color: var(--purple); }
.text-yellow { color: var(--yellow-dark); }
.text-teal { color: var(--teal); }
.text-coral { color: var(--coral-dark); }
.text-pitch { color: var(--pitch); }
.hidden { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* --------------- Footer --------------- */
.footer {
  margin-top: var(--space-10);
  padding: var(--space-6) 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  border-top: 1px solid var(--border);
}
.footer a { color: var(--purple); }

/* --------------- Mobile --------------- */
@media (max-width: 768px) {
  :root { --topbar-h: 60px; }
  .topbar { padding: 0 var(--space-3); gap: var(--space-3); }
  .topbar__brand { font-size: 1.1rem; }
  .topbar__nav { display: none; }
  .topbar__nav.mobile-open { display: flex; flex-direction: column; position: absolute; top: var(--topbar-h); left: 0; right: 0; background: var(--purple-dark); padding: var(--space-3); }
  .topbar__clock { font-size: 0.75rem; padding: var(--space-1) var(--space-2); }
  .topbar__clock .clock__date { font-size: 0.65rem; }
  .gamebar { padding: var(--space-2) var(--space-3); gap: var(--space-2); }
  .gamebar__xp { min-width: 120px; }
  .container { padding: 0 var(--space-3); }
}
