/* Physics Learning Lab — styles
   Palette: blue, white, subtle gold. Mobile first. */

:root {
  --blue-900: #0a2f6e;
  --blue: #0b3d91;
  --blue-600: #1557c0;
  --blue-100: #e6eefb;
  --gold: #c9a227;
  --gold-100: #fbf4dc;
  --bg: #f5f8fd;
  --card: #ffffff;
  --ink: #142033;
  --ink-2: #4a5872;
  --line: #d9e2f0;
  --ok: #1e8a4c;
  --ok-bg: #e5f5ec;
  --bad: #c0392b;
  --bad-bg: #fbe9e7;
  --accent: var(--blue-600);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(10, 47, 110, .06), 0 4px 14px rgba(10, 47, 110, .06);
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --blue-100: #16264a;
    --gold-100: #2e2814;
    --bg: #0c1424;
    --card: #131e35;
    --ink: #e8eef9;
    --ink-2: #a7b5cf;
    --line: #26355a;
    --ok-bg: #12301f;
    --bad-bg: #3a1a17;
    --accent: #6ea2ff;
    --gold: #e0bd4f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --blue-100: #16264a;
  --gold-100: #2e2814;
  --bg: #0c1424;
  --card: #131e35;
  --ink: #e8eef9;
  --ink-2: #a7b5cf;
  --line: #26355a;
  --ok-bg: #12301f;
  --bad-bg: #3a1a17;
  --accent: #6ea2ff;
  --gold: #e0bd4f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
}
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
a { color: var(--accent); }
img, svg, canvas { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 99; background: var(--card); padding: 8px; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
main:focus, main:focus-visible { outline: none; } /* main is focused on navigation for screen readers only */

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--blue); color: #fff;
  border-bottom: 3px solid var(--gold);
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-size: 1.02rem; white-space: nowrap; }
.brand img { border-radius: 8px; background: #fff; }
.brand-text { line-height: 1.15; }
.brand-text small { display: block; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--gold); font-weight: 700; }
.top-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 10px; border: 0; background: transparent; color: #fff; cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, .12); }
.icon-btn svg, .tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Layout ---------- */
.layout { display: block; }
.sidenav { display: none; }
main {
  max-width: 1100px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  min-height: 70vh;
  outline: none;
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -2px 10px rgba(10, 47, 110, .06);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .72rem; color: var(--ink-2); text-decoration: none; font-weight: 600;
}
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { stroke: var(--gold); }

@media (min-width: 900px) {
  .tabbar { display: none; }
  .layout { display: grid; grid-template-columns: 230px 1fr; }
  .sidenav {
    display: flex; flex-direction: column; gap: 2px;
    position: sticky; top: 59px; height: calc(100vh - 59px);
    padding: 16px 10px; background: var(--card); border-right: 1px solid var(--line);
  }
  .sidenav a { padding: 10px 12px; border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 600; }
  .sidenav a:hover { background: var(--blue-100); }
  .sidenav a.active { background: var(--blue-100); color: var(--accent); box-shadow: inset 3px 0 0 var(--gold); }
  .sidenote { margin-top: auto; font-size: .78rem; color: var(--ink-2); padding: 0 12px; }
  main { padding: 24px 28px 48px; }
}

/* ---------- Building blocks ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.card > :last-child { margin-bottom: 0; }
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .grid.two, .grid.three { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { .grid.three { grid-template-columns: 1fr 1fr 1fr; } }
.tile {
  display: block; text-decoration: none; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); transition: transform .12s, border-color .12s;
}
.tile:hover { border-color: var(--accent); transform: translateY(-1px); }
.tile h3 { margin: 0 0 4px; color: var(--accent); }
.tile p { margin: 0; color: var(--ink-2); font-size: .92rem; }
.tile .ic { font-size: 1.6rem; line-height: 1; margin-bottom: 6px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--ink-2); }
.small { font-size: .88rem; }
.center { text-align: center; }
.hidden { display: none !important; }

.hero {
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-600) 100%);
  color: #fff; border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
  position: relative; overflow: hidden;
}
.hero h1 { font-size: 1.45rem; }
.hero p { opacity: .92; }
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px;
  border-radius: 50%; border: 18px solid rgba(201, 162, 39, .35);
}
.hero .btn { position: relative; z-index: 1; }

.badge {
  display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 999px; background: var(--blue-100); color: var(--accent);
}
.badge.gold { background: var(--gold-100); color: #8a6d0f; }
:root[data-theme="dark"] .badge.gold { color: var(--gold); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.gold { color: var(--gold); } }
.badge.ok { background: var(--ok-bg); color: var(--ok); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  font-weight: 600; text-decoration: none;
}
.btn:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #1d1600; }
.btn.light { background: #fff; color: var(--blue); border-color: #fff; }
.btn.sm { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: .9rem; min-height: 36px;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.crumbs { font-size: .88rem; margin-bottom: 10px; color: var(--ink-2); }
.crumbs a { text-decoration: none; }

/* Forms */
label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input[type="number"], input[type="text"], input[type="search"], input[type="password"], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg);
}
textarea { min-height: 90px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--blue-100); }
.inline { display: grid; grid-template-columns: 1fr 112px; gap: 6px; }
.err { color: var(--bad); font-size: .85rem; margin-top: 4px; }

input[type="range"] { width: 100%; accent-color: var(--accent); height: 32px; }
.slider-row { margin-bottom: 10px; }
.slider-row .spread label { margin: 0; }
.slider-row output { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--card); padding: 8px 14px; cursor: pointer; min-height: 40px; }
.seg button.active { background: var(--accent); color: #fff; }

/* Rich lesson content */
.prose ul { padding-left: 1.2em; margin: 0 0 .8em; }
.prose li { margin-bottom: .3em; }
.defs dt { font-weight: 700; color: var(--accent); }
.defs dd { margin: 0 0 8px; }
.eq {
  background: var(--blue-100); border-left: 4px solid var(--gold); border-radius: 8px;
  padding: 8px 12px; margin-bottom: 8px; overflow-x: auto;
}
.eq .note { font-size: .85rem; color: var(--ink-2); }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0 0 8px; }
.steps li { counter-increment: s; position: relative; padding: 6px 0 6px 34px; border-bottom: 1px dashed var(--line); overflow-x: auto; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 6px;
  width: 24px; height: 24px; border-radius: 50%; background: var(--gold); color: #1d1600;
  font-weight: 700; font-size: .8rem; display: grid; place-items: center;
}
.answer { background: var(--ok-bg); border-radius: 8px; padding: 8px 12px; font-weight: 600; overflow-x: auto; }
details.reveal summary { cursor: pointer; font-weight: 600; color: var(--accent); min-height: 36px; display: flex; align-items: center; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* Diagrams */
.diagram { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin-bottom: 8px; }
.dg { width: 100%; height: auto; display: block; }
.dg text { fill: var(--ink); font-size: 11px; font-family: inherit; }
.dg .t-s { font-size: 9.5px; fill: var(--ink-2); }
.dg .ln { stroke: var(--ink); fill: none; stroke-width: 1.8; }
.dg .thin { stroke: var(--ink-2); fill: none; stroke-width: 1; }
.dg .dash { stroke-dasharray: 4 3; }
.dg .bl { stroke: var(--accent); fill: none; stroke-width: 2.2; }
.dg .gd { stroke: var(--gold); fill: none; stroke-width: 2.2; }
.dg .rd { stroke: var(--bad); fill: none; stroke-width: 2.2; }
.dg .fill-bl { fill: var(--blue-100); stroke: var(--accent); stroke-width: 1.5; }
.dg .fill-gd { fill: var(--gold-100); stroke: var(--gold); stroke-width: 1.5; }
.dg .fill-ink { fill: var(--ink); }
.dg .fill-acc { fill: var(--accent); }
.dg .fill-gold { fill: var(--gold); }
.dg .fill-red { fill: var(--bad); }
.diagram figcaption { font-size: .82rem; color: var(--ink-2); text-align: center; }

/* Simulations */
.sim-wrap { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .sim-wrap { grid-template-columns: 1.4fr 1fr; align-items: start; } }
/* Phones: show animation, then readings, then the controls, so learners see what each slider does */
@media (max-width: 899px) {
  #simRoot .sim-wrap { display: flex; flex-direction: column; gap: 0; }
  #simRoot .sim-wrap > div { display: contents; }
  #simRoot .sim-wrap > div > * { order: 4; }
  #simRoot .sim-wrap .stage { order: 1; margin-bottom: 0; }
  #simRoot .sim-wrap .readouts { order: 2; }
  #simRoot .sim-wrap > div:last-child > .card:first-child { order: 3; }
}
.stage { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.stage canvas { display: block; width: 100%; touch-action: pan-y; border-radius: 8px; }
.readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 10px 0; }
.readout { background: var(--blue-100); border-radius: 10px; padding: 8px 10px; }
.readout .k { font-size: .75rem; color: var(--ink-2); font-weight: 600; }
.readout .v { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-box { position: relative; height: 220px; }
.assume { font-size: .86rem; background: var(--gold-100); border-radius: 10px; padding: 10px 12px; border-left: 4px solid var(--gold); }
.assume ul { margin: 4px 0 0; padding-left: 1.1em; }

table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.data th { color: var(--ink-2); font-weight: 600; font-size: .8rem; }
.table-scroll { overflow-x: auto; }

/* Quiz */
.q-opts { display: grid; gap: 8px; margin: 10px 0; }
.q-opt {
  text-align: left; border: 1.5px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 10px 12px; cursor: pointer; min-height: 48px; display: flex; gap: 10px; align-items: center;
}
.q-opt .l { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--blue-100); color: var(--accent); font-weight: 700; }
.q-opt.sel { border-color: var(--accent); background: var(--blue-100); }
.q-opt.right { border-color: var(--ok); background: var(--ok-bg); }
.q-opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.q-opt:disabled { cursor: default; color: var(--ink); }
.feedback { border-radius: 12px; padding: 12px; margin-top: 10px; }
.feedback.ok { background: var(--ok-bg); border-left: 4px solid var(--ok); }
.feedback.bad { background: var(--bad-bg); border-left: 4px solid var(--bad); }
.progress { height: 8px; background: var(--blue-100); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--gold)); border-radius: 99px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: 4px 10px; border-radius: 8px; background: var(--gold-100); }
.timer.low { background: var(--bad-bg); color: var(--bad); }
.score-ring { font-size: 2.4rem; font-weight: 800; color: var(--accent); }

/* Formula library */
.f-item summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 44px; }
.f-item summary::-webkit-details-marker { display: none; }
.f-item summary .nm { font-weight: 700; }
.f-item[open] summary { margin-bottom: 8px; }

/* Password screen */
html.locked .topbar, html.locked .layout, html.locked .tabbar { display: none; }
.gate {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 100; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(160deg, var(--blue) 0%, var(--blue-600) 100%);
}
.gate-card {
  width: 100%; max-width: 380px; background: var(--card); color: var(--ink);
  border-radius: 18px; padding: 24px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
  border-top: 5px solid var(--gold); text-align: center;
}
.gate-card img { border-radius: 14px; margin-bottom: 8px; }
.gate-card h1 { font-size: 1.35rem; margin-bottom: 2px; }
.gate-card label { text-align: left; margin-top: 16px; }
.gate-card .err { min-height: 1.2em; text-align: left; }

/* Dashboard */
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .n { font-size: 1.6rem; font-weight: 800; color: var(--accent); }
.stat .k { font-size: .8rem; color: var(--ink-2); font-weight: 600; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.bar-row { margin-bottom: 10px; }
.bar-row .spread { font-size: .9rem; margin-bottom: 3px; }
.activity li { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.activity { list-style: none; padding: 0; margin: 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 50;
  font-size: .92rem; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}
@media (min-width: 900px) { .toast { bottom: 24px; } }

.list-link { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); min-height: 52px; }
.list-link:last-child { border-bottom: 0; }
.list-link .t { font-weight: 600; }
.list-link .chev { color: var(--ink-2); }
.done-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.done-dot.on { background: var(--ok); }
.done-dot.seen { background: var(--gold); }
