/* Shared stylesheet for every lesson and reference page.
   Tufte-inspired: one reading column, notes in the right margin on wide screens. */
@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,400;0,8..60,600;0,8..60,700;1,8..60,400&family=Inter:wght@400;500;600&display=swap');

:root {
  --paper: #fffff8;
  --ink: #1f1e1b;
  --muted: #6b675f;
  --rule: #dcd8cb;
  --wash: #f4f1e6;
  --accent: #a3361f;        /* Spanish text: clay red */
  --link: #1f5f5b;          /* links: deep teal */
  --ok: #2f6b3a;
  --ok-wash: #e6f0e3;
  --bad: #a12a2a;
  --bad-wash: #f6e4e1;
  --serif: 'Source Serif 4', 'Iowan Old Style', Palatino, Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171614;
    --ink: #e9e5da;
    --muted: #a39e92;
    --rule: #3a3731;
    --wash: #22201c;
    --accent: #ec9a7c;
    --link: #7cc4bc;
    --ok: #8fd19a;
    --ok-wash: #1f2e21;
    --bad: #f0958c;
    --bad-wash: #35201e;
  }
}

* { box-sizing: border-box; }

html { font-size: 19px; }
@media (max-width: 600px) { html { font-size: 17px; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 62rem;
  margin: 0 auto;
  padding: 3rem 16px 5rem;
}

.col { max-width: 36rem; position: relative; }

/* ---------- Type ---------- */
h1, h2, h3 { font-weight: 600; line-height: 1.2; }
h1 { font-size: 2.1rem; margin: 0.3rem 0 1rem; letter-spacing: -0.01em; }
h2 { font-size: 1.35rem; margin: 2.8rem 0 0.8rem; }
h3 { font-size: 1.05rem; margin: 1.8rem 0 0.5rem; }
p, li { margin: 0 0 0.9rem; }
a { color: var(--link); text-underline-offset: 2px; }
.kicker {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.lead { font-size: 1.15rem; color: var(--muted); }
small, .small { font-size: 0.82rem; }
.muted { color: var(--muted); }

/* Spanish text */
.es { color: var(--accent); font-weight: 600; }
.gloss { color: var(--muted); font-style: italic; }

/* ---------- Margin notes ---------- */
.side {
  display: block;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--muted);
  border-left: 2px solid var(--rule);
  padding: 0.2rem 0 0.2rem 0.8rem;
  margin: 0.6rem 0 1.2rem;
}
@media (min-width: 980px) {
  .side {
    float: right;
    clear: right;
    width: 15rem;
    margin: 0.2rem -19rem 1rem 0;
  }
}

/* ---------- Boxes ---------- */
.win, .task, .source, .ask, .report {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1rem 1.2rem;
  margin: 1.6rem 0;
  background: var(--wash);
}
.win { border-left: 4px solid var(--accent); }
.task { border-left: 4px solid var(--link); }
.box-title {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.4rem;
}
.win p:last-child, .task p:last-child, .source p:last-child, .ask p:last-child { margin-bottom: 0; }

/* ---------- Tables (booktabs) ---------- */
table.book {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0 1.4rem;
  font-size: 0.95rem;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}
table.book th {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  font-weight: 600;
  border-bottom: 1px solid var(--ink);
  padding: 0.5rem 0.6rem 0.4rem 0;
}
table.book td { padding: 0.45rem 0.6rem 0.45rem 0; vertical-align: top; }
table.book tr.rebel td { border-top: 1px dashed var(--rule); }
table.book td .es { white-space: nowrap; }
.table-wrap { overflow-x: auto; }

/* ---------- Drills (see drills.js) ---------- */
.drill { counter-reset: none; }
.mcq, .typein {
  border-top: 1px solid var(--rule);
  padding: 1.1rem 0 0.4rem;
}
.prompt { margin-bottom: 0.7rem; }
.qn {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  margin-right: 0.5rem;
}
.options { display: grid; gap: 0.5rem; margin-bottom: 0.6rem; }
@media (min-width: 600px) { .options { grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); } }

button, .btn {
  font: inherit;
  cursor: pointer;
}
.opt {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:focus-visible, .btn:focus-visible, input:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.opt.right { background: var(--ok-wash); border-color: var(--ok); color: var(--ok); }
.opt.wrong { background: var(--bad-wash); border-color: var(--bad); color: var(--bad); text-decoration: line-through; }
.opt:disabled { cursor: default; }

.typein .row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.typein input {
  flex: 1 1 12rem;
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
}
.typein input.right { border-color: var(--ok); background: var(--ok-wash); }
.typein input.wrong { border-color: var(--bad); }

.btn {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
}
.btn:hover { border-color: var(--ink); }
.btn.quiet { color: var(--muted); }
[hidden] { display: none !important; }

.fb { font-family: var(--sans); font-size: 0.85rem; margin: 0 0 0.5rem; min-height: 1.2em; }
.fb.ok { color: var(--ok); }
.fb.no { color: var(--bad); }
.explain { display: none; font-size: 0.92rem; color: var(--ink); }
.done .explain { display: block; }

.progress { font-family: var(--sans); font-size: 0.8rem; color: var(--muted); }
.report output {
  display: block;
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
  font-size: 0.85rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.6rem 0.8rem;
  margin: 0.5rem 0;
  white-space: pre-wrap;
}

/* ---------- Listen buttons (see speak.js) ---------- */
.say-btn {
  display: none;
  vertical-align: -0.15em;
  margin-left: 0.25rem;
  padding: 0.1rem 0.25rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  line-height: 1;
}
.say-btn:hover { color: var(--accent); background: var(--wash); }
.say-btn svg { width: 0.95em; height: 0.95em; }
html.has-voice .say-btn { display: inline-block; }

/* ---------- Nav ---------- */
nav.foot {
  font-family: var(--sans);
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  border-top: 1px solid var(--rule);
  margin-top: 3rem;
  padding-top: 1rem;
}
nav.foot a { text-decoration: none; }
nav.foot .soon { color: var(--muted); }

/* ---------- Print ---------- */
@media print {
  :root { --paper: #fff; --ink: #000; --wash: #fff; }
  html { font-size: 11.5pt; }
  .page { padding: 0; max-width: none; }
  .col { max-width: none; }
  .side { float: none; width: auto; margin: 0.4rem 0 0.8rem; }
  .say-btn, .btn, nav.foot, .report { display: none !important; }
  .explain { display: block; }
  table.book, .win, .task, .source { break-inside: avoid; }
  a { color: inherit; }
}
