/* ===========================================================================
   Setswana Learner — design system
   Palette draws on the Botswana flag: light blue (sky/water), black & white
   (pula bands), warmed with sand/ochre accents for a friendly learning feel.
   =========================================================================== */

:root {
  --blue: #5aa9e6;
  --blue-deep: #2f7dc0;
  --ochre: #e0a458;
  --ochre-deep: #c8842f;
  --green: #3fb37f;
  --red: #e2675f;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  --maxw: 1080px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
}

/* Dark (default) */
:root,
[data-theme="dark"] {
  --bg: #11161d;
  --bg-2: #1a212b;
  --surface: #202935;
  --surface-2: #28323f;
  --border: #33404f;
  --text: #eef3f8;
  --text-dim: #9fb0c0;
  --accent: var(--blue);
  --accent-text: #08121c;
}

[data-theme="light"] {
  --bg: #f4f7fb;
  --bg-2: #eaf1f8;
  --surface: #ffffff;
  --surface-2: #f0f5fa;
  --border: #d7e0ea;
  --text: #1a2530;
  --text-dim: #5a6b7b;
  --accent: var(--blue-deep);
  --accent-text: #ffffff;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; }

/* ---- Top bar / nav ------------------------------------------------------ */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
}
.brand-name { font-size: 1.05rem; }

.nav {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
  flex-wrap: wrap;
}
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 500;
}
.nav-link:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent); color: var(--accent-text); }
.nav-icon { font-size: 1rem; }

.nav-toggle {
  display: none;
  margin-left: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.2rem;
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.6rem;
  cursor: pointer;
}

/* ---- Layout ------------------------------------------------------------- */
.app {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.6rem 1rem 3rem;
  outline: none;
}

.footer {
  border-top: 1px solid var(--border);
  padding: 1rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.loading { color: var(--text-dim); padding: 2rem; text-align: center; }

/* ---- Cards & generic ---------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.card.error { border-color: var(--red); }

.page-head { margin-bottom: 1.3rem; }
.page-head h1 { font-size: 1.7rem; }
.page-head p { color: var(--text-dim); margin: 0; }

.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.muted { color: var(--text-dim); }
.center { text-align: center; }

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.chip {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-dim);
  cursor: pointer;
}
.chip.active { background: var(--accent); color: var(--accent-text); border-color: transparent; }

select, input[type="text"], input[type="search"], textarea {
  font: inherit;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---- Dashboard / gamification ------------------------------------------- */
.dash { display: grid; gap: 0.8rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  text-align: center;
}
.stat .num { font-size: 1.7rem; font-weight: 800; }
.stat .lbl { color: var(--text-dim); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }

.progress {
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--green));
  width: 0;
  transition: width 0.4s ease;
}

.badges { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}
.badge.locked { opacity: 0.4; filter: grayscale(1); }
.badge .b-icon { font-size: 1.3rem; }

/* ---- Flashcard ---------------------------------------------------------- */
.flashcard {
  perspective: 1200px;
  width: 100%;
  max-width: 460px;
  height: 260px;
  margin: 0 auto 1.2rem;
  cursor: pointer;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.flashcard-face.back { transform: rotateY(180deg); background: var(--surface-2); }
.flashcard-term { font-size: 2rem; font-weight: 800; }
.flashcard-sub { color: var(--text-dim); margin-top: 0.4rem; }

.rate-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; max-width: 460px; margin: 0 auto; }
.rate-btn { padding: 0.6rem 0.3rem; text-align: center; }
.rate-btn.again { border-color: var(--red); }
.rate-btn.hard { border-color: var(--ochre); }
.rate-btn.good { border-color: var(--blue); }
.rate-btn.easy { border-color: var(--green); }

/* ---- Quiz --------------------------------------------------------------- */
.quiz-q { font-size: 1.5rem; font-weight: 700; text-align: center; margin: 1rem 0 1.4rem; }
.choices { display: grid; gap: 0.6rem; }
.choice { text-align: left; padding: 0.75rem 1rem; }
.choice.correct { border-color: var(--green); background: rgba(63, 179, 127, 0.15); }
.choice.wrong { border-color: var(--red); background: rgba(226, 103, 95, 0.15); }

/* ---- Dictionary --------------------------------------------------------- */
.dict-controls { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.dict-controls input[type="search"] { flex: 1; min-width: 200px; }
.entry {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-bottom: 0.6rem;
  overflow: hidden;
}
.entry summary {
  list-style: none;
  cursor: pointer;
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.entry summary::-webkit-details-marker { display: none; }
.entry .se { font-weight: 700; font-size: 1.05rem; }
.entry .en { color: var(--text-dim); }
.entry .body { padding: 0 1rem 0.9rem; border-top: 1px solid var(--border); }
.entry .body p { margin: 0.6rem 0 0; }
.tag { font-size: 0.72rem; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim); }

.speak-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  cursor: pointer;
  flex: none;
}
.speak-btn:hover { border-color: var(--accent); }

/* ---- Lessons / Listening ------------------------------------------------ */
.lesson-list { display: grid; gap: 0.6rem; }
.lesson-item { display: flex; align-items: center; gap: 0.8rem; padding: 0.9rem 1rem; }
.lesson-num {
  width: 36px; height: 36px; flex: none;
  border-radius: 9px;
  background: var(--surface-2);
  display: grid; place-items: center; font-weight: 700;
}
.lesson-item.done .lesson-num { background: var(--green); color: #06281b; }
audio { width: 100%; margin-top: 0.5rem; }

.lesson-note { font-size: 0.88rem; margin: 0.2rem 0 0.6rem; font-style: italic; }

.phrase-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0 1.2rem;
  font-size: 0.95rem;
}
.phrase-table thead th {
  text-align: left;
  padding: 0.45rem 0.8rem;
  background: var(--surface-2);
  border-bottom: 2px solid var(--accent);
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.phrase-table thead th:first-child { border-radius: var(--radius-sm) 0 0 0; }
.phrase-table thead th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }
.phrase-table tbody tr { border-bottom: 1px solid var(--border); }
.phrase-table tbody tr:last-child { border-bottom: none; }
.phrase-table tbody tr:hover { background: var(--surface-2); }
.phrase-table td { padding: 0.55rem 0.8rem; vertical-align: top; }
.ph-se { font-weight: 600; color: var(--text); width: 45%; }
.ph-en { color: var(--text-dim); }

/* ---- Translation box ---------------------------------------------------- */
.xlate { display: grid; gap: 0.7rem; }
.xlate textarea { width: 100%; min-height: 90px; resize: vertical; }
.xlate .dir { display: flex; align-items: center; gap: 0.6rem; justify-content: center; }
.xlate .out {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem;
  min-height: 60px;
  white-space: pre-wrap;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.xlate .out .out-text { flex: 1; }

/* Small inline loading spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Speaking ----------------------------------------------------------- */
.rec-btn {
  width: 90px; height: 90px; border-radius: 50%;
  border: none; cursor: pointer; font-size: 2rem;
  background: var(--accent); color: var(--accent-text);
  box-shadow: var(--shadow);
}
.rec-btn.recording { background: var(--red); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

/* ---- Toast -------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%) translateY(120%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 100;
  max-width: 90vw;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ---- Home hero ---------------------------------------------------------- */
.hero {
  background: linear-gradient(135deg, var(--blue-deep), #1d2b3a);
  color: #fff;
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  margin-bottom: 1.4rem;
}
.hero h1 { font-size: 2rem; }
.hero p { color: #d8e8f6; max-width: 60ch; }
.hero .row { margin-top: 1rem; }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 820px) {
  .brand-name { display: none; }
  .nav-toggle { display: block; }
  .nav {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    flex-direction: column;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem;
    display: none;
  }
  .nav.open { display: flex; }
  .nav-link { width: 100%; }
}
