/* The Study Journal (GCSE) — styles.
   Screen styles first, print styles at the bottom. */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --ink: #1c2333;
  --ink-soft: #5a6478;
  --line: #e2e6ef;
  --brand: #3a5bd9;
  --brand-dark: #2b46ad;
  --eng: #c0392b;
  --mat: #1f8a70;
  --sci: #7b4bc4;
  --review: #b8860b;
  --higher: #d35400;
  --ok: #1f8a4c;
  --bad: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 8px 24px rgba(20, 30, 60, .06);
  --maxw: 980px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  font-size: 17px;
}

h1, h2, h3 { line-height: 1.25; }

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

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--brand); color: #fff;
  padding: 10px 16px; z-index: 100;
  border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

/* ---- Header ---- */
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: var(--maxw); margin: 0 auto; padding: 20px 20px 12px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  display: grid; place-items: center; width: 46px; height: 46px;
  background: var(--brand); color: #fff; font-weight: 800;
  border-radius: 12px; letter-spacing: .5px;
}
.brand-text h1 { margin: 0; font-size: 1.35rem; }
.brand-sub { margin: 0; color: var(--ink-soft); font-size: .85rem; }

.streak {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 16px; box-shadow: var(--shadow);
}
.streak-count { font-weight: 800; font-size: 1.2rem; }
.streak-label { color: var(--ink-soft); font-size: .85rem; }
.streak.cold { opacity: .65; }

/* ---- Controls bar (board / tier) ---- */
.controls-bar {
  max-width: var(--maxw);
  margin: 0 auto 4px;
  padding: 4px 20px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 22px;
  align-items: center;
}
.control {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px 10px;
  box-shadow: var(--shadow);
}
.control-label {
  font-size: .8rem; color: var(--ink-soft); font-weight: 600;
}
.control select {
  font: inherit; font-weight: 600; border: 0; background: transparent;
  padding: 4px 6px; color: var(--ink); cursor: pointer;
}
.control select:focus-visible { outline: 3px solid var(--brand); border-radius: 4px; }
.control-note {
  margin: 0; color: var(--ink-soft); font-size: .8rem;
  flex: 1 1 280px;
}

/* ---- API health indicator ---- */
.health {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .8rem; font-weight: 600; color: var(--ink-soft);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px;
  box-shadow: var(--shadow);
}
.health-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ink-soft); flex: 0 0 auto;
}
.health.ok .health-dot { background: var(--ok); }
.health.down .health-dot { background: var(--bad); }
.health.checking .health-dot { background: var(--review); animation: pulse 1.1s ease-in-out infinite; }
.health.ok { color: var(--ok); }
.health.down { color: var(--bad); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---- Account / sync bar ---- */
.account-bar {
  max-width: var(--maxw);
  margin: 0 auto 4px;
  padding: 0 20px 10px;
}
.account-form {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
}
.account-label, .account-who { color: var(--ink-soft); font-size: .85rem; }
.account-who strong { color: var(--ink); }
.account-form input {
  font: inherit; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  flex: 0 1 200px;
}
.account-form input:focus-visible { outline: 3px solid var(--brand); outline-offset: 1px; }
.account-form .btn { padding: 7px 14px; }
.account-msg { font-size: .82rem; }
.account-msg.err { color: var(--bad); }
.account-msg.ok { color: var(--ink-soft); }
.sync-status { color: var(--ink-soft); font-size: .82rem; }

/* ---- Tabs ---- */
.tab-bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; gap: 4px;
  max-width: var(--maxw); margin: 0 auto;
  padding: 8px 16px;
  background: rgba(244, 246, 251, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab {
  flex: 0 0 auto; border: none; background: transparent;
  color: var(--ink-soft); font: inherit; font-weight: 600;
  padding: 10px 16px; border-radius: 10px; cursor: pointer;
}
.tab:hover { background: rgba(58, 91, 217, .08); color: var(--ink); }
.tab[aria-current="page"] { background: var(--brand); color: #fff; }
.tab:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

main { max-width: var(--maxw); margin: 0 auto; padding: 24px 20px 60px; }
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.btn {
  font: inherit; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 10px 16px; border-radius: 10px; cursor: pointer;
  transition: transform .05s ease, background .15s ease;
}
.btn:hover { background: #f0f3fb; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { background: #fff; border-color: var(--bad); color: var(--bad); }
.btn-danger:hover { background: #fdeceb; }
.btn-ghost { background: transparent; border-style: dashed; color: var(--ink-soft); }
.btn-ghost:hover { background: #f0f3fb; color: var(--ink); }

/* ---- Pills / tags ---- */
.subject-tag {
  display: inline-block;
  font-size: .75rem; font-weight: 800; letter-spacing: .6px;
  text-transform: uppercase; color: #fff;
  padding: 4px 10px; border-radius: 999px;
}
.tag-eng { background: var(--eng); }
.tag-mat { background: var(--mat); }
.tag-sci { background: var(--sci); }
.pill {
  display: inline-block; margin-left: 8px;
  font-size: .7rem; font-weight: 800; letter-spacing: .5px;
  padding: 3px 8px; border-radius: 999px;
}
.pill-higher { background: rgba(211, 84, 0, .12); color: var(--higher); border: 1px solid rgba(211, 84, 0, .35); }
.pill-corner { position: absolute; top: 12px; right: 56px; margin-left: 0; }

.lesson-code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  color: var(--ink-soft); font-size: .8rem; margin-left: 8px;
}

/* ---- Today ---- */
.today-date { color: var(--ink-soft); font-weight: 600; margin: 0 0 12px; }
.today-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px;
}
.today-card.review-day { border-left: 5px solid var(--review); }
.today-card h3 { margin: 14px 0 6px; font-size: 1.5rem; }
.today-summary { color: var(--ink-soft); margin: 0 0 6px; }
.spec-ref { margin: 6px 0 18px; color: var(--ink-soft); font-size: .9rem; }
.today-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.review-note { margin: 0 0 14px; color: var(--review); font-weight: 600; }

/* Week strip */
.week-strip {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px;
  margin-top: 22px;
}
.week-day {
  text-align: center; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 4px;
}
.week-day .dow { font-size: .7rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .5px; }
.week-day .subj { font-size: .8rem; font-weight: 700; margin-top: 4px; }
.week-day.is-today { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(58,91,217,.25); }
.week-day .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; }
.dot-eng { background: var(--eng); } .dot-mat { background: var(--mat); }
.dot-sci { background: var(--sci); } .dot-review { background: var(--review); }

/* ---- Curriculum ---- */
.subject-switcher { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.subject-switcher .btn[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.subject-meta { color: var(--ink-soft); font-size: .9rem; margin: 0 0 18px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}
.lesson-card {
  position: relative; text-align: left;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
  cursor: pointer; display: flex; flex-direction: column; gap: 6px;
  box-shadow: var(--shadow);
  transition: transform .08s ease, border-color .15s ease;
}
.lesson-card:hover { transform: translateY(-2px); border-color: var(--brand); }
.lesson-card:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.lesson-card .lc-code {
  font-family: Consolas, Menlo, monospace; font-size: .72rem; color: var(--ink-soft);
}
.lesson-card .lc-title { font-weight: 700; font-size: 1.05rem; }
.lesson-card .lc-meta { color: var(--ink-soft); font-size: .82rem; margin-top: auto; }
.done-stamp {
  position: absolute; top: 12px; right: 12px;
  background: var(--ok); color: #fff;
  font-size: .65rem; font-weight: 800; letter-spacing: 1px;
  padding: 3px 8px; border-radius: 6px;
}
.lesson-card.done { border-color: rgba(31,138,76,.45); }

/* ---- Lesson detail ---- */
.lesson-head { margin-bottom: 8px; }
.lesson-detail h2 { margin: 10px 0 4px; font-size: 1.7rem; }
.lesson-detail .ld-summary { color: var(--ink-soft); margin: 0 0 8px; }
.cmd-words { color: var(--ink-soft); font-size: .85rem; margin: 0 0 22px; }
.cmd-words .cmd {
  display: inline-block; background: rgba(58,91,217,.08); color: var(--brand-dark);
  border-radius: 6px; padding: 2px 8px; margin: 0 4px 4px 0; font-weight: 600; font-size: .8rem;
}
.lesson-block { margin-bottom: 26px; }
.lesson-block h3 {
  font-size: .8rem; text-transform: uppercase; letter-spacing: 1px;
  color: var(--brand-dark); margin: 0 0 10px;
}
.concept-text {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.concept-text p { margin: 0; }
.example {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: 10px; padding: 14px 16px; margin-bottom: 10px;
}
.example .ex-label { font-weight: 700; color: var(--brand-dark); margin-right: 6px; }

.question, .extended {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px; margin-bottom: 12px;
}
.question .q-text, .extended .q-text { font-weight: 600; margin: 0 0 6px; }
.q-num { color: var(--ink-soft); margin-right: 6px; }
.q-meta {
  display: flex; align-items: center; gap: 6px;
  color: var(--ink-soft); font-size: .8rem; margin-bottom: 10px;
}
.q-meta .marks { font-weight: 700; }
.answer-row { display: flex; gap: 8px; flex-wrap: wrap; }
.answer-row input, .open-answer {
  flex: 1 1 200px; font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px;
}
.open-answer { width: 100%; resize: vertical; margin-bottom: 8px; }
.answer-row input:focus-visible, .open-answer:focus-visible {
  outline: 3px solid var(--brand); outline-offset: 1px;
}
.feedback { margin: 10px 0 0; font-weight: 600; }
.feedback.correct { color: var(--ok); }
.feedback.incorrect { color: var(--bad); }
.feedback .reveal { color: var(--ink); font-weight: 600; }
.markscheme {
  background: #f7faff; border: 1px dashed rgba(58,91,217,.35);
  padding: 12px 14px; border-radius: 8px; margin-top: 10px;
  color: var(--ink); font-size: .95rem;
}
.extended { border-left: 4px solid var(--higher); }

.lesson-actions {
  display: flex; flex-wrap: wrap; gap: 10px;
  margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line);
}
.complete-banner {
  background: #e8f6ee; border: 1px solid rgba(31,138,76,.35);
  color: var(--ok); font-weight: 700;
  padding: 10px 14px; border-radius: 10px; margin-bottom: 16px;
}

/* ---- Progress ---- */
.progress-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  margin-bottom: 24px;
}
.progress-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.progress-card h3 { margin: 0 0 4px; }
.progress-card .pc-count { color: var(--ink-soft); font-size: .9rem; }
.progress-card .pc-pct { font-size: 2rem; font-weight: 800; margin: 6px 0; }
.bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; transition: width .4s ease; }
.bar-eng { background: var(--eng); } .bar-mat { background: var(--mat); } .bar-sci { background: var(--sci); }

/* ---- How It Works ---- */
.how-list { counter-reset: step; list-style: none; padding: 0; display: grid; gap: 14px; }
.how-list li {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px 18px 64px;
  position: relative; box-shadow: var(--shadow);
}
.how-list li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 18px; top: 18px;
  width: 32px; height: 32px; display: grid; place-items: center;
  background: var(--brand); color: #fff; font-weight: 800; border-radius: 50%;
}
.how-list h3 { margin: 0 0 6px; }
.how-list p { margin: 0; color: var(--ink-soft); }

.site-footer { text-align: center; color: var(--ink-soft); font-size: .8rem; padding: 24px 20px 40px; }
.site-footer .disclaimer { opacity: .8; margin-top: 6px; }

/* ---- Print: clean A4 worksheet, no nav, answers/marks hidden ---- */
@media print {
  body { background: #fff; font-size: 12pt; color: #000; }
  .site-header, .tab-bar, .controls-bar, .site-footer, .skip-link,
  .lesson-actions, .week-strip,
  .no-print, .feedback, .markscheme,
  .view[hidden] { display: none !important; }
  main { max-width: none; padding: 0; }
  .concept-text, .example, .question, .extended, .today-card { box-shadow: none; }
  .concept-text, .question, .extended { border-color: #999; }
  .question, .extended, .example { break-inside: avoid; }
  /* Replace inputs with handwriting space */
  .answer-row::after, .extended::after {
    content: ""; display: block; height: 60px;
    border-bottom: 1px solid #999; margin-top: 4px;
  }
  a[href]::after { content: ""; }
}
