/* ===========================================================
   The Grove Schoolhouse — design system
   Calm, clear, low-clutter. Warm but mature palette.
   Built for neurodivergent preteens/teens: predictable layout,
   strong contrast, minimal motion, big click targets.
   Vanilla CSS, no build step, no external fonts.
   =========================================================== */

:root {
  /* base palette — muted, high-contrast */
  --cream: #f7f2e7;
  --parchment: #efe6d2;
  --parchment-dark: #ddccaa;
  --ink: #2c2419;
  --ink-soft: #5a4f3d;
  --forest: #2c5440;
  --forest-dark: #1e3d2d;
  --forest-light: #4a7259;
  --amber: #c98a2e;
  --amber-dark: #a86e20;
  --amber-light: #eecf98;
  --white: #fffdf9;

  /* subject colors — used as subtle accents only (borders/chips), never large blocks */
  --subj-math: #2f5fb0;
  --subj-math-bg: #e4eaf7;
  --subj-reading_writing: #b5641f;
  --subj-reading_writing-bg: #f3e5d4;
  --subj-science: #34753a;
  --subj-science-bg: #e2eee2;
  --subj-social_studies: #a3402f;
  --subj-social_studies-bg: #f2e0db;
  --subj-elective: #6b4a96;
  --subj-elective-bg: #e8e0f2;

  /* status */
  --success: #2f7a3a;
  --success-bg: #e2f0e3;
  --danger: #a3392a;
  --danger-bg: #f5e1dd;
  --warn: #a86e20;
  --warn-bg: #f2e6cd;
  --info: #2f5fb0;
  --info-bg: #e4eaf7;

  /* structure */
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(44, 36, 25, 0.08);
  --shadow: 0 2px 8px rgba(44, 36, 25, 0.10);
  --shadow-lg: 0 6px 20px rgba(44, 36, 25, 0.14);
  --focus-ring: 0 0 0 3px rgba(201, 138, 46, 0.55);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji", sans-serif;

  --fs-base: 18px;
  --maxw: 1100px;
  --measure: 70ch;
}

* { box-sizing: border-box; }

html { font-size: var(--fs-base); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  text-align: left;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-sans);
  color: var(--forest-dark);
  line-height: 1.3;
  margin: 0 0 0.5em;
  font-weight: 800;
  text-align: left;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }

p { margin: 0 0 0.9em; max-width: var(--measure); }

a { color: var(--forest); }
a:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; border-radius: 4px; }

img { max-width: 100%; }

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

/* visible keyboard focus everywhere */
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible,
.interest-chip:focus-visible,
.choice-row:focus-within {
  outline: 3px solid var(--amber-dark);
  outline-offset: 2px;
}

/* minimal motion: only animate when the user hasn't asked to reduce it */
@media (prefers-reduced-motion: no-preference) {
  .progress-fill { transition: width 0.4s ease; }
  .toast { animation: toast-in 0.2s ease; }
  .card-link:hover, .today-item:hover, .module-row.clickable:hover {
    transition: box-shadow 0.12s ease;
  }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- layout ---------- */

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 20px 60px;
}

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.spacer { flex: 1; }

.content-measure { max-width: var(--measure); }

/* ---------- header / nav (consistent placement on every page) ---------- */

.site-header {
  background: var(--forest);
  color: var(--white);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 40;
}

.site-header .wrap {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--white);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.2px;
}

.brand:focus-visible { outline: 3px solid var(--amber-light); outline-offset: 3px; }

.header-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.header-nav a {
  color: var(--white);
  text-decoration: none;
  background: rgba(255,255,255,0.12);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.92rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.header-nav a:hover { background: rgba(255,255,255,0.2); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.14);
  padding: 6px 12px 6px 8px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  min-height: 44px;
}

.user-chip .avatar-sm {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--amber);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.btn-logout {
  background: rgba(255,255,255,0.16);
  color: var(--white);
  border: none;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  font-size: 0.9rem;
  min-height: 44px;
}

.btn-logout:hover { background: rgba(255,255,255,0.26); }

/* ---------- buttons (large, unambiguous click targets) ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius);
  padding: 12px 22px;
  min-height: 48px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: var(--white);
  background: var(--forest);
}

@media (prefers-reduced-motion: no-preference) {
  .btn { transition: background 0.12s ease, box-shadow 0.12s ease; }
}

.btn:hover { background: var(--forest-dark); box-shadow: var(--shadow); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--forest); color: var(--white); }
.btn-primary:hover { background: var(--forest-dark); }

.btn-amber { background: var(--amber); color: var(--ink); }
.btn-amber:hover { background: var(--amber-dark); color: var(--white); }

.btn-outline {
  background: var(--white);
  color: var(--forest);
  border: 2px solid var(--forest);
  box-shadow: none;
}
.btn-outline:hover { background: var(--parchment); }

.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover { background: #8a2f22; }

.btn-sm { padding: 8px 14px; font-size: 0.88rem; border-radius: var(--radius-sm); min-height: 44px; }
.btn-block { width: 100%; }
.btn-icon {
  padding: 8px 10px;
  min-height: 44px;
  min-width: 44px;
  border-radius: var(--radius-sm);
  background: var(--parchment);
  color: var(--ink);
  box-shadow: none;
  border: 1px solid var(--parchment-dark);
}
.btn-icon:hover { background: var(--parchment-dark); }

/* ---------- cards ---------- */

.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 22px;
  border: 1px solid rgba(44,36,25,0.08);
}

.card-sm { padding: 16px; border-radius: var(--radius); }

.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
}
.card-link:hover { box-shadow: var(--shadow-lg); }

/* ---------- forms ---------- */

label {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--forest-dark);
}

input[type="text"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 12px 14px;
  min-height: 48px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--parchment-dark);
  background: var(--white);
  color: var(--ink);
  margin-bottom: 16px;
}

input:focus, textarea:focus, select:focus {
  outline: 3px solid var(--amber-dark);
  outline-offset: 1px;
  border-color: var(--amber-dark);
}

textarea { min-height: 100px; resize: vertical; font-family: inherit; }

.field { margin-bottom: 4px; }
.help-text { color: var(--ink-soft); font-size: 0.9rem; margin: -10px 0 16px; max-width: var(--measure); }

fieldset { border: none; padding: 0; margin: 0 0 16px; }
legend { font-weight: 700; color: var(--forest-dark); margin-bottom: 8px; padding: 0; }

/* ---------- badges / chips (subtle, not loud) ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 700;
  background: var(--parchment);
  color: var(--ink-soft);
}

.chip-success { background: var(--success-bg); color: var(--success); }
.chip-warn { background: var(--warn-bg); color: var(--warn); }
.chip-danger { background: var(--danger-bg); color: var(--danger); }
.chip-info { background: var(--info-bg); color: var(--info); }

.subject-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: capitalize;
  border: 1px solid currentColor;
}

.subject-math { background: var(--subj-math-bg); color: var(--subj-math); }
.subject-reading_writing { background: var(--subj-reading_writing-bg); color: var(--subj-reading_writing); }
.subject-science { background: var(--subj-science-bg); color: var(--subj-science); }
.subject-social_studies { background: var(--subj-social_studies-bg); color: var(--subj-social_studies); }
.subject-elective { background: var(--subj-elective-bg); color: var(--subj-elective); }

.subject-border-math { border-left: 5px solid var(--subj-math); }
.subject-border-reading_writing { border-left: 5px solid var(--subj-reading_writing); }
.subject-border-science { border-left: 5px solid var(--subj-science); }
.subject-border-social_studies { border-left: 5px solid var(--subj-social_studies); }
.subject-border-elective { border-left: 5px solid var(--subj-elective); }

/* ---------- progress bars ---------- */

.progress-track {
  width: 100%;
  height: 12px;
  background: var(--parchment);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--forest);
  border-radius: 999px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-top: 4px;
  font-weight: 600;
}

.mastery-track {
  width: 100%;
  height: 10px;
  background: var(--parchment);
  border-radius: 999px;
  overflow: hidden;
}
.mastery-fill { height: 100%; border-radius: 999px; background: var(--forest); }

/* progress dots (one-question-at-a-time flows) */
.progress-dots {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.progress-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--parchment-dark);
  flex-shrink: 0;
}

.progress-dot.is-current { background: var(--amber); width: 12px; height: 12px; }
.progress-dot.is-done { background: var(--forest); }

.progress-count {
  font-weight: 700;
  color: var(--forest-dark);
  font-size: 0.95rem;
  margin-left: 4px;
}

/* ---------- avatars ---------- */

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--amber-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
  border: 1px solid var(--parchment-dark);
}

.avatar-lg { width: 76px; height: 76px; font-size: 2.3rem; }
.avatar-sm-lg { width: 44px; height: 44px; font-size: 1.3rem; }

/* ---------- checklist / today items ---------- */

.today-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: inherit;
  border: 1px solid rgba(44,36,25,0.08);
  min-height: 44px;
}

.today-item:hover { box-shadow: var(--shadow); }
.today-item.is-done { border-color: var(--success); }
.today-item.is-locked { opacity: 0.7; cursor: default; }

.today-item-icon {
  font-size: 1.5rem;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--parchment);
}

.today-item-body { flex: 1; min-width: 0; }
.today-item-title { font-weight: 700; margin-bottom: 2px; }
.today-item-meta { font-size: 0.86rem; color: var(--ink-soft); }

.today-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  font-weight: 700;
  color: var(--forest-dark);
}

/* ---------- interest chips (onboarding) ---------- */

.interest-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  background: var(--white);
  border: 2px solid var(--parchment-dark);
  cursor: pointer;
  font-weight: 700;
  user-select: none;
}

.interest-chip:hover { border-color: var(--amber); }

.interest-chip.selected {
  background: var(--forest);
  border-color: var(--forest);
  color: var(--white);
}

.interest-grid { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- toast ---------- */

#toast-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
  max-width: min(360px, calc(100vw - 32px));
}

.toast {
  background: var(--forest-dark);
  color: var(--white);
  padding: 14px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
}

.toast.toast-error { background: var(--danger); }
.toast.toast-success { background: var(--success); }

/* ---------- misc states ---------- */

.state-box {
  text-align: left;
  padding: 40px 20px;
  color: var(--ink-soft);
}

.state-box .state-emoji { font-size: 2.4rem; display: block; margin-bottom: 10px; }

.skeleton {
  background: var(--parchment);
  border-radius: var(--radius);
  min-height: 60px;
}

.divider { height: 1px; background: var(--parchment-dark); margin: 20px 0; border: none; }

/* markdown content rendering */
.md-content { max-width: var(--measure); }
.md-content h1, .md-content h2, .md-content h3 { margin-top: 1.3em; }
.md-content ul, .md-content ol { padding-left: 1.4em; }
.md-content em { font-style: normal; font-weight: 700; } /* no italics for long text */
.md-content code {
  background: var(--parchment);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.92em;
}
.md-content pre {
  background: var(--forest-dark);
  color: var(--white);
  padding: 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.md-content pre code { background: none; padding: 0; color: inherit; }
.md-content blockquote {
  border-left: 4px solid var(--amber);
  margin: 0 0 1em;
  padding: 2px 16px;
  color: var(--ink-soft);
  background: var(--parchment);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.md-content img { border-radius: var(--radius-sm); }

/* ---------- page hero ---------- */

.hero { padding: 30px 0 6px; }
.hero-title { font-size: 1.85rem; margin-bottom: 4px; }
.hero-sub { color: var(--ink-soft); font-size: 1rem; max-width: var(--measure); }

/* ---------- login page ---------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  text-align: left;
}

.login-title { font-size: 1.6rem; margin-bottom: 4px; }
.login-sub { color: var(--ink-soft); margin-bottom: 24px; }
.login-form { text-align: left; }

.form-error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  margin-bottom: 16px;
  display: none;
}

.form-error.show { display: block; }

/* ---------- question cards (one at a time) ---------- */

.question-card { margin-bottom: 18px; }
.question-prompt { font-weight: 700; margin-bottom: 14px; font-size: 1.1rem; max-width: var(--measure); }
.choice-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--parchment-dark);
  margin-bottom: 8px;
  cursor: pointer;
}
.choice-row:hover { border-color: var(--amber); }
.choice-row input { width: auto; min-height: auto; margin: 0; }
.choice-row label { margin: 0; font-weight: 500; color: var(--ink); flex: 1; cursor: pointer; }

.question-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 20px; gap: 10px; }

/* ---------- chat panel ---------- */

.module-layout {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .module-layout { grid-template-columns: 1fr; }
}

.chat-panel {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  height: 560px;
  position: sticky;
  top: 84px;
  overflow: hidden;
  border: 1px solid rgba(44,36,25,0.08);
}

@media (max-width: 900px) {
  .chat-panel { position: static; height: 480px; }
}

.chat-header {
  padding: 14px 18px;
  background: var(--forest);
  color: var(--white);
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  max-width: 85%;
  font-size: 0.96rem;
}

.chat-bubble.student {
  align-self: flex-end;
  background: var(--amber-light);
  color: var(--ink);
  border-bottom-right-radius: 4px;
}

.chat-bubble.tutor {
  align-self: flex-start;
  background: var(--parchment);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}

.chat-bubble.thinking { color: var(--ink-soft); }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--parchment-dark);
}

.chat-input-row textarea {
  margin-bottom: 0;
  min-height: 48px;
  max-height: 100px;
}

/* ---------- module list ---------- */

.module-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  border: 1px solid rgba(44,36,25,0.08);
}

.module-row.clickable { text-decoration: none; color: inherit; cursor: pointer; }
.module-row.clickable:hover { box-shadow: var(--shadow); }

.module-pos {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--parchment);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--forest-dark);
  flex-shrink: 0;
}

/* ---------- skills bars ---------- */

.skill-row { margin-bottom: 12px; }
.skill-row-top { display: flex; justify-content: space-between; font-size: 0.9rem; margin-bottom: 5px; }
.skill-name { font-weight: 700; }
.skill-mastery { color: var(--ink-soft); }

/* ---------- utility ---------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.visually-hidden:focus-visible + label.interest-chip,
.visually-hidden:focus-visible + .choice-row-label {
  outline: 3px solid var(--amber-dark);
  outline-offset: 2px;
}

.text-left { text-align: left; }
.text-muted { color: var(--ink-soft); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.small { font-size: 0.86rem; }
.pill-count {
  background: var(--danger);
  color: var(--white);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.78rem;
  font-weight: 800;
  margin-left: 4px;
}

@media (max-width: 640px) {
  h1 { font-size: 1.5rem; }
  .card { padding: 16px; }
  .site-header .wrap { padding: 10px 14px; }
}
