/* WePeak Learn shared design tokens and components.
   Used by the student home page, the quiz viewer and the teacher page.
   Teacher-only styles live in /teacher/teacher.css. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light dark;

  /* Brand */
  --brand: #404040;          /* header band */
  --accent: #119ed6;         /* focus ring, bars, decoration */

  /* Surfaces and text (light) */
  --bg: #f3f5f7;
  --card: #ffffff;
  --field: #ffffff;
  --fg: #1d2328;
  --muted: #56616b;
  --line: #d5dce2;
  --link: #0b6f97;
  --btn-bg: #0b78a6;         /* darker accent so white text passes contrast */
  --btn-bg-hover: #096489;
  --btn-fg: #ffffff;
  --bad: #b3261e;
  --bad-bg: #fbeae7;
  --ok: #17703d;
  --ok-bg: #e3f4ea;
  --chip-bg: #e8edf1;
  --skeleton: #e3e8ec;

  /* Spacing scale */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;

  /* Shape */
  --radius: 8px;
  --radius-lg: 12px;
  --tap: 44px;               /* minimum tap target; student pages use 48px */
  --focus: 0 0 0 3px var(--card), 0 0 0 5px var(--accent);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181c;
    --card: #1e2429;
    --field: #161b1f;
    --fg: #e7ecef;
    --muted: #a3afb9;
    --line: #37414a;
    --link: #62c3ec;
    --btn-bg: #119ed6;       /* brand accent with dark text in dark mode */
    --btn-bg-hover: #3bb2e2;
    --btn-fg: #04202c;
    --bad: #ff9d92;
    --bad-bg: #3a1d1a;
    --ok: #7fd6a2;
    --ok-bg: #173324;
    --chip-bg: #2b343b;
    --skeleton: #2a3239;
  }
}
.student { --tap: 48px; }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.5 var(--font); }
h1 { font-size: 24px; line-height: 1.25; margin: 0 0 var(--s2); }
h2 { font-size: 18px; line-height: 1.3; margin: 0 0 var(--s2); }
h3 { font-size: 16px; line-height: 1.3; margin: 0; }
p { margin: 0 0 var(--s3); }
a { color: var(--link); }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.muted, p.sub { color: var(--muted); }
p.sub { margin: 0 0 var(--s4); }
.small { font-size: 14px; }

/* ---------- Header band ---------- */
.band {
  background: var(--brand); color: #fff;
  min-height: 56px; padding: var(--s2) var(--s4);
  padding-left: max(var(--s4), env(safe-area-inset-left));
  padding-right: max(var(--s4), env(safe-area-inset-right));
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
}
.band .brand { color: #fff; text-decoration: none; font-weight: 700; display: inline-flex; align-items: center; gap: var(--s2); white-space: nowrap; }
.band .brand img { height: 28px; width: auto; display: block; }
.band .who { font-size: 14px; color: #dde2e6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.band .band-btn {
  background: transparent; border: 1px solid #9aa2a8; color: #fff; border-radius: var(--radius);
  min-height: 44px; padding: 0 var(--s3); cursor: pointer; font: inherit; font-size: 14px;
  display: inline-flex; align-items: center; text-decoration: none; white-space: nowrap;
}
.band .band-btn:hover { background: rgba(255, 255, 255, .12); }
.band :focus-visible { box-shadow: 0 0 0 3px var(--brand), 0 0 0 5px #fff; }

/* ---------- Layout ---------- */
main { max-width: 720px; margin: 0 auto; padding: var(--s5) var(--s4) 64px; }
main.narrow { max-width: 480px; }
.row { display: flex; gap: var(--s3); flex-wrap: wrap; align-items: center; }
.stack > * + * { margin-top: var(--s4); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--s5); }
@media (max-width: 400px) { .card { padding: var(--s4); } }

/* ---------- Forms ---------- */
label, .label { display: block; font-size: 14px; font-weight: 600; margin: 0 0 var(--s1); }
.field { margin-bottom: var(--s4); }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select {
  width: 100%; min-height: var(--tap); font: inherit; font-size: 16px; /* 16px stops iOS zooming in */
  padding: var(--s2) var(--s3); border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--field); color: var(--fg);
}
input:focus-visible, select:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
input[aria-invalid=true], select[aria-invalid=true] { border-color: var(--bad); }
input::placeholder { color: var(--muted); opacity: .8; }
.hint { font-size: 14px; color: var(--muted); margin: var(--s1) 0 0; }
.field-error { font-size: 14px; color: var(--bad); margin: var(--s1) 0 0; }
.msg { font-size: 14px; margin: var(--s3) 0 0; padding: var(--s2) var(--s3); border-radius: var(--radius); }
.msg.err { color: var(--bad); background: var(--bad-bg); }
.msg.ok { color: var(--ok); background: var(--ok-bg); }
.msg.info { color: var(--fg); background: var(--chip-bg); }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 700; border: 1px solid transparent; border-radius: var(--radius);
  min-height: var(--tap); padding: 0 var(--s5); background: var(--btn-bg); color: var(--btn-fg); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); text-decoration: none;
}
.btn:hover { background: var(--btn-bg-hover); }
.btn.ghost { background: transparent; color: var(--link); border-color: var(--line); font-weight: 600; }
.btn.ghost:hover { background: var(--chip-bg); }
.btn.danger { background: var(--bad); color: var(--card); }
.btn.block { width: 100%; }
.btn.compact { padding: 0 var(--s3); font-size: 14px; }
.btn:disabled, .btn[aria-disabled=true] { opacity: .55; cursor: default; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-size: 14px; color: var(--link); text-decoration: underline; cursor: pointer; min-height: 0; }
/* Small text links still get a comfortable tap area. */
.link-btn.tap { min-height: var(--tap); padding: 0 var(--s2); }

/* ---------- Chips ---------- */
.chip { display: inline-flex; align-items: center; gap: var(--s1); background: var(--chip-bg); color: var(--fg); border-radius: 999px; padding: 2px var(--s3); font-size: 14px; white-space: nowrap; }
.chip.mono, code { font-family: var(--mono); border-radius: 6px; letter-spacing: .02em; }
code { background: var(--chip-bg); padding: 1px 6px; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.off { color: var(--muted); }

/* ---------- Spinner and skeleton ---------- */
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor; animation: spin .8s linear infinite; flex: none; }
.spinner.lg { width: 36px; height: 36px; border-width: 4px; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: var(--skeleton); border-radius: var(--radius); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* ---------- Empty / status blocks ---------- */
.empty { text-align: center; padding: var(--s6) var(--s4); color: var(--muted); }
.empty h2, .empty h3 { color: var(--fg); margin-bottom: var(--s2); }
.empty .row { justify-content: center; margin-top: var(--s4); }

/* ---------- Banner (in-flow notice) ---------- */
.banner { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; padding: var(--s2) var(--s4); font-size: 15px; }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.err { background: var(--bad-bg); color: var(--bad); }
.banner a, .banner .link-btn { color: inherit; font-size: inherit; font-weight: 600; }
.banner .grow { flex: 1; min-width: 0; }

/* ---------- Toasts ---------- */
.toast-region { position: fixed; z-index: 50; left: 0; right: 0; bottom: max(var(--s4), env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: var(--s2); padding: 0 var(--s3); pointer-events: none; }
.toast { pointer-events: auto; max-width: 520px; width: 100%; background: var(--fg); color: var(--bg); border-radius: var(--radius-lg); padding: var(--s3) var(--s4); display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); animation: toast-in .2s ease-out; }
.toast .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast.err { background: var(--bad); color: var(--card); }
.toast button { font: inherit; font-size: 14px; font-weight: 700; min-height: 36px; padding: 0 var(--s3); border-radius: var(--radius); border: 1px solid currentColor; background: transparent; color: inherit; cursor: pointer; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  /* A frozen spinner looks broken, so keep it turning slowly instead. */
  .spinner { animation: spin 2.4s linear infinite !important; }
}
