/* ==========================================================================
   Physics of Motion — shared book stylesheet
   Identity: a lab notebook on graph paper. Navy ink, a night-sky sidebar,
   and arrows whose colours always mean the same quantity.
   ========================================================================== */

:root {
  /* Page chrome (never used for physical quantities) */
  --paper: #f4f3ee;
  --paper-2: #ebe9e1;
  --card: #ffffff;
  --ink: #17223b;
  --ink-2: #3b4760;
  --muted: #687187;
  --line: #d8dbe2;
  --line-2: #c4c9d4;
  --navy: #16213a;
  --navy-2: #22305a;
  --brass: #c99a2e;

  /* Fixed meanings: one colour = one quantity, everywhere in the book */
  --vel: #1c7ed6;     /* velocity */
  --acc: #7048e8;     /* acceleration */
  --force: #e03131;   /* force (thick = net force) */
  --mom: #0c8599;     /* momentum */
  --ke: #f59f00;      /* kinetic energy */
  --gpe: #2f9e44;     /* gravitational energy */
  --epe: #d6336c;     /* elastic (spring) energy */
  --heat: #8b5e3c;    /* thermal energy */
  --path: #868e96;    /* trails & strobe paths */

  --canvas: #fcfcfa;
  --space: #0d1626;

  --f-head: 'Fraunces', Georgia, 'Times New Roman', serif;
  --f-body: 'Source Sans 3', 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
  --f-mono: 'IBM Plex Mono', Consolas, 'Courier New', monospace;

  --sidebar-w: 286px;
  --measure: 46rem;
  --wide: 58rem;
  --r: 14px;
  --r-sm: 9px;
  --shadow: 0 1px 2px rgba(23, 34, 59, 0.06), 0 8px 28px rgba(23, 34, 59, 0.07);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

body {
  margin: 0;
  font-family: var(--f-body);
  line-height: 1.68;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(23, 34, 59, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 34, 59, 0.035) 1px, transparent 1px);
  background-size: 28px 28px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--navy-2); text-decoration: underline; text-decoration-color: rgba(34, 48, 90, 0.35); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--brass); }
:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; border-radius: 4px; }

/* ---------- Reading progress ---------- */
.reading-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: linear-gradient(90deg, var(--navy-2), var(--brass));
  z-index: 200;
}

/* ---------- Layout ---------- */
.book { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--navy);
  background-image: radial-gradient(circle at 20% 8%, rgba(201, 154, 46, 0.14), transparent 45%);
  color: #dfe5f2;
  padding: 1.4rem 1rem 2.4rem;
  z-index: 120;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 9px; }

.brand { display: flex; gap: 0.7rem; align-items: center; color: #fff; text-decoration: none; padding: 0.2rem 0.3rem 1rem; border-bottom: 1px solid rgba(255, 255, 255, 0.1); }
.brand-mark { width: 38px; height: 38px; flex-shrink: 0; }
.brand-title { font-family: var(--f-head); font-weight: 600; font-size: 1.12rem; line-height: 1.1; display: block; }
.brand-sub { font-size: 0.72rem; color: #9fb0cf; display: block; margin-top: 3px; letter-spacing: 0.02em; }

.side-progress { margin: 1rem 0.3rem 0.4rem; font-size: 0.74rem; color: #9fb0cf; }
.side-progress .row { display: flex; justify-content: space-between; margin-bottom: 0.35rem; }
.track { height: 6px; border-radius: 9px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.track > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #6d8fd6, var(--brass)); border-radius: 9px; transition: width 0.3s ease; }

.toc-part { font-size: 0.66rem; letter-spacing: 0.13em; text-transform: uppercase; color: #8193b6; font-weight: 700; margin: 1.1rem 0.4rem 0.35rem; }
.toc { list-style: none; margin: 0; padding: 0; }
.toc a {
  display: flex; gap: 0.6rem; align-items: baseline; padding: 0.4rem 0.55rem; border-radius: 8px;
  color: #c9d3e8; text-decoration: none; font-size: 0.9rem; line-height: 1.3;
}
.toc a:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.toc a.active { background: rgba(201, 154, 46, 0.18); color: #fff; font-weight: 600; }
.toc .n { font-family: var(--f-mono); font-size: 0.72rem; color: #7f90b3; width: 1.4rem; flex-shrink: 0; }
.toc a.active .n { color: var(--brass); }
.toc .tick { margin-left: auto; color: #8fd19e; font-size: 0.8rem; visibility: hidden; }
.toc a.done .tick { visibility: visible; }

.topbar {
  display: none; position: sticky; top: 0; z-index: 110;
  background: rgba(22, 33, 58, 0.96); color: #fff;
  padding: 0.6rem 1rem; align-items: center; justify-content: space-between; gap: 0.8rem;
}
.topbar a { color: #fff; text-decoration: none; font-family: var(--f-head); font-weight: 600; }
.menu-btn {
  font: inherit; font-size: 0.88rem; color: #fff; background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 8px; padding: 0.35rem 0.75rem; cursor: pointer;
}
.backdrop { display: none; }

.main { flex: 1; min-width: 0; padding: 2.6rem clamp(1rem, 4vw, 3.4rem) 4rem; }
.main > * { max-width: var(--measure); margin-left: auto; margin-right: auto; }
.main > .figure, .main > .wide, .main > .hero, .main > .parts, .main > .banner, .main > .legend-card { max-width: var(--wide); }

@media (max-width: 1023px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; height: auto;
    transform: translateX(-105%); transition: transform 0.25s ease;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.25);
  }
  .sidebar.open { transform: none; }
  .topbar { display: flex; }
  .backdrop.open { display: block; position: fixed; inset: 0; background: rgba(10, 16, 30, 0.45); z-index: 115; }
  .main { padding-top: 1.6rem; }
}

/* ---------- Typography ---------- */
h1, h2, h3 { font-family: var(--f-head); color: var(--ink); line-height: 1.18; font-weight: 600; }
h1 { font-size: clamp(2rem, 5vw, 2.9rem); margin: 0.2rem 0 0.8rem; letter-spacing: -0.01em; }
h2 { font-size: clamp(1.4rem, 3.2vw, 1.75rem); margin: 2.8rem auto 0.8rem; }
h3 { font-size: 1.18rem; margin: 1.8rem auto 0.5rem; }
p { margin: 0 auto 1.05rem; }
ul, ol { padding-left: 1.3rem; }
li { margin-bottom: 0.4rem; }
strong { font-weight: 700; }
em { font-style: italic; }

.eyebrow {
  font-family: var(--f-mono); font-size: 0.74rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted); font-weight: 500;
}
.chapter-head { margin-bottom: 2.2rem; padding-bottom: 1.6rem; border-bottom: 1px solid var(--line); }
.subtitle { font-size: 1.16rem; color: var(--ink-2); line-height: 1.6; margin: 0; }

/* Quantity colour words */
.c-vel { color: var(--vel); font-weight: 700; }
.c-acc { color: var(--acc); font-weight: 700; }
.c-force { color: var(--force); font-weight: 700; }
.c-mom { color: var(--mom); font-weight: 700; }
.c-ke { color: #c77d00; font-weight: 700; }
.c-gpe { color: var(--gpe); font-weight: 700; }
.c-epe { color: var(--epe); font-weight: 700; }
.c-heat { color: var(--heat); font-weight: 700; }
.c-path { color: #5f676f; font-weight: 700; }

/* ---------- Interactive figure ---------- */
.figure {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow); margin: 2rem auto 2.2rem; overflow: hidden;
}
.figure-head { padding: 0.95rem 1.15rem 0.7rem; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.3rem 1rem; align-items: baseline; }
.figure-num { font-family: var(--f-mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); display: block; }
.figure-title { font-family: var(--f-head); font-weight: 600; font-size: 1.15rem; color: var(--ink); }
.figure-hint { font-size: 0.86rem; color: var(--muted); font-style: italic; }
.canvas-wrap { position: relative; background: var(--canvas); border-bottom: 1px solid var(--line); }
.canvas-wrap.space { background: var(--space); }
.canvas-wrap canvas { display: block; width: 100%; height: 300px; }
.canvas-wrap canvas.grab { cursor: grab; }

.controls { display: flex; flex-wrap: wrap; gap: 0.7rem 1.3rem; padding: 0.9rem 1.15rem 0.4rem; align-items: center; }
.control { display: flex; align-items: center; gap: 0.55rem; flex: 1 1 15rem; min-width: 0; }
.control label { font-size: 0.86rem; color: var(--ink-2); font-weight: 600; white-space: nowrap; }
.control output, .control .val { font-family: var(--f-mono); font-size: 0.8rem; color: var(--ink); min-width: 4.6rem; text-align: right; white-space: nowrap; }
input[type="range"] { flex: 1; min-width: 5rem; accent-color: var(--navy-2); height: 1.6rem; cursor: pointer; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.btn {
  font: inherit; font-size: 0.86rem; font-weight: 600; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 0.42rem 0.85rem; cursor: pointer; line-height: 1.25; white-space: nowrap;
}
.btn:hover { border-color: var(--navy-2); }
.btn.primary, .btn[aria-pressed="true"] { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-2); }
.toggle { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.86rem; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.toggle input { width: 1.05rem; height: 1.05rem; accent-color: var(--navy-2); }

.readout {
  margin: 0.4rem 1.15rem 0.2rem; padding: 0.55rem 0.8rem; border-radius: 8px;
  background: #f3f5f9; border: 1px solid var(--line);
  font-family: var(--f-mono); font-size: 0.8rem; line-height: 1.55; color: var(--ink);
  min-height: 2.4rem;
}
.readout b { font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; padding: 0.6rem 1.15rem 0; font-size: 0.8rem; color: var(--ink-2); }
.key { display: inline-flex; align-items: center; gap: 0.35rem; }
.sw { width: 18px; height: 4px; border-radius: 3px; display: inline-block; }
.sw.box { width: 11px; height: 11px; border-radius: 3px; }
.caption { padding: 0.7rem 1.15rem 1rem; font-size: 0.92rem; color: var(--ink-2); line-height: 1.55; }
.caption strong { color: var(--ink); }

/* ---------- Callouts ---------- */
.principle {
  border-left: 5px solid var(--navy); background: var(--card); border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: 1rem 1.2rem; margin: 1.8rem auto; box-shadow: var(--shadow);
}
.principle .label, .note .label, .trap .label {
  font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 600; color: var(--muted); display: block; margin-bottom: 0.25rem;
}
.principle p { margin: 0; font-family: var(--f-head); font-size: 1.12rem; line-height: 1.45; }
.note, .trap { border-radius: var(--r-sm); padding: 0.9rem 1.15rem; margin: 1.6rem auto; font-size: 0.97rem; }
.note { background: #eef2f8; border: 1px solid #d5ddeb; }
.trap { background: #fbf3e4; border: 1px solid #ecd9b3; }
.trap .label { color: #8a6514; }
.note p:last-child, .trap p:last-child { margin-bottom: 0; }

.formula {
  text-align: center; margin: 1.5rem auto; padding: 1rem; background: var(--card); border: 1px dashed var(--line-2); border-radius: var(--r-sm);
}
.formula .math { font-family: var(--f-head); font-size: 1.45rem; font-style: italic; letter-spacing: 0.02em; }
.formula .aloud { font-size: 0.92rem; color: var(--muted); margin-top: 0.3rem; }

/* ---------- Quiz ---------- */
.quiz { background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--brass); border-radius: var(--r); padding: 1.2rem 1.3rem; margin: 2.4rem auto; box-shadow: var(--shadow); }
.quiz h3 { margin: 0 0 0.5rem; font-size: 1.12rem; }
.quiz .q { margin-bottom: 0.9rem; }
.quiz-options { display: grid; gap: 0.5rem; }
.quiz-option {
  font: inherit; text-align: left; font-size: 0.97rem; color: var(--ink); background: var(--paper);
  border: 1px solid var(--line-2); border-radius: 9px; padding: 0.65rem 0.9rem; cursor: pointer; line-height: 1.45;
}
.quiz-option:hover { border-color: var(--navy-2); }
.quiz-option.right { border-color: #2f9e44; background: #ebf7ee; }
.quiz-option.wrong { border-color: #c92a2a; background: #fdeeee; }
.quiz-feedback { margin-top: 0.8rem; font-size: 0.95rem; min-height: 1.2rem; }
.quiz-feedback.right { color: #22743a; }
.quiz-feedback.wrong { color: #a51d1d; }

/* ---------- Connections & recap ---------- */
.connections { border: 1px solid var(--line); background: #f9f8f4; border-radius: var(--r-sm); padding: 1rem 1.2rem; margin: 2.2rem auto; font-size: 0.96rem; }
.connections h3 { margin: 0 0 0.4rem; font-size: 1.02rem; }
.connections p:last-child, .connections ul:last-child { margin-bottom: 0; }
.recap { background: var(--navy); color: #e7ecf6; border-radius: var(--r); padding: 1.3rem 1.5rem; margin: 2.4rem auto 1rem; }
.recap h2 { color: #fff; margin: 0 0 0.6rem; font-size: 1.35rem; }
.recap ul { margin: 0; padding-left: 1.2rem; }
.recap li { margin-bottom: 0.45rem; }
.recap strong { color: #fff; }

/* ---------- Chapter footer ---------- */
.chapter-footer { margin-top: 2.4rem; }
.complete-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.8rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 1rem 1.2rem; }
.complete-bar p { margin: 0; color: var(--ink-2); }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; margin-top: 1rem; }
.pager a { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 0.9rem 1.1rem; text-decoration: none; color: var(--ink); }
.pager a:hover { border-color: var(--navy-2); }
.pager .dir { font-family: var(--f-mono); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); display: block; }
.pager .t { font-family: var(--f-head); font-weight: 600; }
.pager .next { text-align: right; }
@media (max-width: 560px) { .pager { grid-template-columns: 1fr; } .pager .next { text-align: left; } }

/* ---------- Book home ---------- */
.hero { display: grid; grid-template-columns: 1.05fr 1fr; gap: 2rem; align-items: center; margin-bottom: 2rem; }
.hero h1 { font-size: clamp(2.3rem, 6vw, 3.5rem); margin-bottom: 0.6rem; }
.hero .lead { font-size: 1.15rem; color: var(--ink-2); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1.2rem; }
.btn.lg { font-size: 0.98rem; padding: 0.65rem 1.15rem; text-decoration: none; display: inline-block; }
.hero .figure { margin: 0; }
@media (max-width: 900px) { .hero { grid-template-columns: 1fr; } }

.banner { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between; background: var(--navy); color: #e7ecf6; border-radius: var(--r); padding: 1rem 1.3rem; margin: 0 auto 2rem; }
.banner .track { flex: 1 1 12rem; max-width: 22rem; }
.banner .btn { background: var(--brass); border-color: var(--brass); color: var(--navy); text-decoration: none; }

.legend-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 1rem 1.3rem; margin: 0 auto 2.4rem; box-shadow: var(--shadow); }
.legend-card h2 { margin: 0 0 0.5rem; font-size: 1.15rem; }
.legend-card .legend { padding: 0; font-size: 0.9rem; gap: 0.5rem 1.4rem; }
.legend-card p { font-size: 0.92rem; color: var(--ink-2); margin: 0.6rem 0 0; }

.part-head { display: flex; align-items: baseline; gap: 0.8rem; margin: 2.2rem 0 0.9rem; border-bottom: 1px solid var(--line); padding-bottom: 0.4rem; }
.part-head .tag { font-family: var(--f-mono); font-size: 0.72rem; letter-spacing: 0.12em; color: var(--muted); text-transform: uppercase; white-space: nowrap; }
.part-head h2 { margin: 0; font-size: 1.4rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr)); gap: 0.9rem; }
.card { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 1rem 1.1rem; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); transition: transform 0.15s ease, border-color 0.15s ease; }
.card:hover { transform: translateY(-2px); border-color: var(--navy-2); }
.card .top { display: flex; justify-content: space-between; font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.08em; color: var(--muted); text-transform: uppercase; }
.card .done { color: #2f9e44; }
.card h3 { margin: 0.35rem 0 0.35rem; font-size: 1.1rem; }
.card p { font-size: 0.9rem; color: var(--ink-2); margin: 0 0 0.6rem; line-height: 1.5; }
.card .sim { margin-top: auto; font-size: 0.8rem; color: var(--navy-2); font-weight: 600; }
.site-foot { text-align: center; color: var(--muted); font-size: 0.85rem; margin-top: 3rem; }

/* ---------- Small screens ---------- */
@media (max-width: 560px) {
  html { font-size: 16px; }
  .main { padding-left: 0.85rem; padding-right: 0.85rem; }
  .figure-head, .controls, .caption, .legend { padding-left: 0.85rem; padding-right: 0.85rem; }
  .readout { margin-left: 0.85rem; margin-right: 0.85rem; }
  .control { flex-basis: 100%; }
  .control label { min-width: 5.6rem; white-space: normal; line-height: 1.2; }
  .control output, .control .val { min-width: 3.9rem; }
}
