/* imo_solver -- offline UI.  Light and dark, tuned for long reading. */

:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --panel-2: #fbfaf7;
  --ink: #1b1b1f;
  --ink-2: #55535e;
  --ink-3: #8b8894;
  --line: #e3e0d8;
  --accent: #8a1538;          /* AU red */
  --accent-soft: #f6e9ed;
  --blue: #1b4f72;
  --blue-soft: #e8f0f6;
  --good: #1e6b45;
  --good-soft: #e6f2eb;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --radius: 10px;
  --mono: "PT Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --serif: "STIX Two Text", Georgia, "Times New Roman", serif;
}

/* Dark mode has three states, and all three must work:
   - no choice made  -> follow the operating system (prefers-color-scheme)
   - explicitly dark -> dark, even on a light OS
   - explicitly light-> light, even on a dark OS
   So the dark palette is declared twice: once behind the media query guarded
   against an explicit light choice, once behind the explicit dark attribute. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141418;
    --panel: #1c1c22;
    --panel-2: #212128;
    --ink: #ece9e3;
    --ink-2: #b4b0ab;
    --ink-3: #807c7a;
    --line: #32323c;
    --accent: #e4718f;
    --accent-soft: #35202a;
    --blue: #7fb6dd;
    --blue-soft: #1d2a35;
    --good: #72c79b;
    --good-soft: #1b2b23;
    --warn: #e0ae55;
    --warn-soft: #302714;
  }
}

:root[data-theme="dark"] {
    --bg: #141418;
    --panel: #1c1c22;
    --panel-2: #212128;
    --ink: #ece9e3;
    --ink-2: #b4b0ab;
    --ink-3: #807c7a;
    --line: #32323c;
    --accent: #e4718f;
    --accent-soft: #35202a;
    --blue: #7fb6dd;
    --blue-soft: #1d2a35;
    --good: #72c79b;
    --good-soft: #1b2b23;
    --warn: #e0ae55;
    --warn-soft: #302714;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.55;
}

/* ------------------------------------------------------------- top bar */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; gap: 14px; align-items: center; }
.logo {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  font-size: 24px; font-weight: 700;
}
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: .2px; }
.topbar p { margin: 0; font-size: 12.5px; color: var(--ink-3); }
.topbar-right { display: flex; gap: 10px; align-items: center; }
.pill {
  font-family: var(--mono); font-size: 11px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--good-soft); color: var(--good);
  border: 1px solid transparent;
}
.pill.down { background: var(--warn-soft); color: var(--warn); }

/* --------------------------------------------------------------- tabs */
.tabs {
  display: flex; gap: 2px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  overflow-x: auto; position: sticky; top: 71px; z-index: 39;
}
.tabs button {
  border: 0; background: none; cursor: pointer;
  font-family: inherit; font-size: 14px; color: var(--ink-2);
  padding: 11px 15px; border-bottom: 2.5px solid transparent;
  white-space: nowrap;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 20px; max-width: 1700px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

.split { display: grid; grid-template-columns: minmax(330px, 410px) 1fr; gap: 20px; align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }

.pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.controls { position: sticky; top: 118px; max-height: calc(100vh - 140px); overflow-y: auto; }
.results { min-height: 320px; }

h2 { font-size: 17px; margin: 0 0 12px; letter-spacing: .2px; }
h3 { font-size: 13px; margin: 18px 0 8px; color: var(--ink-3);
     text-transform: uppercase; letter-spacing: .09em; font-weight: 600; }

label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 12px; }
label.small { font-size: 12px; }
input[type=text], input:not([type]), textarea, select {
  width: 100%; margin-top: 5px;
  font-family: var(--mono); font-size: 14px;
  padding: 9px 11px; border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel-2); color: var(--ink);
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 6px 0 14px; }
.checks label { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; }
.checks input { width: auto; margin: 0; }

button.primary, button:not(.ghost):not(.chip):not(.tabs button) {
  font-family: inherit; font-size: 14px; cursor: pointer;
  padding: 9px 16px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink);
}
button.primary {
  background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600;
  width: 100%;
}
button.primary:hover { filter: brightness(1.08); }
button.ghost { border: 0; background: none; color: var(--ink-2); cursor: pointer; font-size: 16px; }

.hint { font-size: 12px; color: var(--ink-3); margin: -4px 0 14px; line-height: 1.5; }
.hint code, code {
  font-family: var(--mono); font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 4px;
}

.examples { margin-top: 18px; }
.chip {
  font-family: var(--mono); font-size: 11.5px; cursor: pointer;
  padding: 4px 9px; margin: 0 5px 6px 0; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink-2);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

.placeholder { color: var(--ink-3); font-size: 14px; padding: 40px 10px; text-align: center; }

/* ---------------------------------------------------------- derivation */
.derivation { margin-bottom: 26px; }
.derivation > header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; padding-bottom: 10px; margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.derivation > header h3 {
  margin: 0; font-size: 16px; color: var(--ink); text-transform: none;
  letter-spacing: 0; font-weight: 600;
}
.derivation .problem { font-size: 13.5px; color: var(--ink-2); margin: 4px 0 0; }
.actions { display: flex; gap: 6px; flex-shrink: 0; }
.actions button { font-size: 12px; padding: 5px 10px; }

.step {
  border-left: 2.5px solid var(--line);
  padding: 2px 0 2px 16px; margin: 0 0 16px 4px;
  position: relative; cursor: pointer;
}
.step:hover { border-left-color: var(--accent); }
.step.open { border-left-color: var(--accent); }
.step-title {
  font-weight: 600; font-size: 14.5px;
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.step-n {
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 5px; padding: 0 5px;
}
.step-text { font-size: 14px; color: var(--ink-2); margin: 5px 0 0; }
.step-math { margin: 10px 0 2px; overflow-x: auto; }
.step-math .katex-display { margin: 8px 0; }
.step.warning { border-left-color: var(--warn); }
.step.warning .step-title { color: var(--warn); }
.step.result { border-left-color: var(--good); }
.step.branch { border-left-style: dashed; }

.cites { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.cite {
  font-family: var(--mono); font-size: 11px; cursor: pointer;
  padding: 2px 8px; border-radius: 5px;
  background: var(--blue-soft); color: var(--blue);
  border: 1px solid transparent;
}
.cite:hover { border-color: var(--blue); }
.cite.unknown { background: var(--panel-2); color: var(--ink-3); }

.detail {
  display: none; margin-top: 10px; padding: 11px 13px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 7px; font-size: 13.5px; color: var(--ink-2);
}
.step.open .detail { display: block; }

.conclusion {
  margin-top: 16px; padding: 13px 15px;
  background: var(--good-soft); border-radius: 8px;
  border-left: 3px solid var(--good);
  font-size: 14.5px;
}
.conclusion b, .conclusion strong { color: var(--good); }
.warnbox {
  margin-top: 12px; padding: 10px 13px; border-radius: 8px;
  background: var(--warn-soft); color: var(--warn); font-size: 13.5px;
  border-left: 3px solid var(--warn);
}
.errbox {
  padding: 14px 16px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent);
  font-family: var(--mono); font-size: 13px; white-space: pre-wrap;
}

/* ------------------------------------------------------------- plotting */
.plotwrap { margin: 10px 0 18px; }
.plotwrap svg { width: 100%; height: auto; display: block;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; }
.plot-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px;
  color: var(--ink-2); margin-top: 8px; }
.plot-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 5px; vertical-align: -1px; }
.mark { cursor: pointer; }
.mark:hover { stroke: var(--ink); stroke-width: 2; }

/* --------------------------------------------------------------- drawer */
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(560px, 92vw);
  background: var(--panel); border-left: 1px solid var(--line);
  transform: translateX(102%); transition: transform .22s ease;
  z-index: 60; display: flex; flex-direction: column;
  box-shadow: -10px 0 40px rgba(0,0,0,.12);
}
.drawer.open { transform: none; }
.drawer-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 15px 20px; border-bottom: 1px solid var(--line);
  font-weight: 600; font-size: 15px;
}
.drawer-body { padding: 18px 20px 60px; overflow-y: auto; font-size: 14.5px; }
.drawer-body h4 { margin: 18px 0 6px; font-size: 13px; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .08em; }
.drawer-body .stmt {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px 14px; margin: 6px 0 14px; overflow-x: auto;
}
#scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.28);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 55;
}
#scrim.on { opacity: 1; pointer-events: auto; }

/* ----------------------------------------------------------- book list */
.bookitem {
  padding: 13px 0; border-bottom: 1px solid var(--line); cursor: pointer;
}
.bookitem:hover .bi-title { color: var(--accent); }
.bi-head { display: flex; gap: 10px; align-items: baseline; }
.bi-key { font-family: var(--mono); font-size: 12px; color: var(--accent);
  background: var(--accent-soft); padding: 1px 7px; border-radius: 5px; }
.bi-title { font-weight: 600; font-size: 14.5px; }
.bi-ch { margin-left: auto; font-size: 11.5px; color: var(--ink-3); font-family: var(--mono); }
.bi-stmt { font-size: 13px; color: var(--ink-2); margin-top: 6px; overflow-x: auto; }

/* ------------------------------------------------------------ roadmap */
.soon { max-width: 820px; }
.demo-note {
  display: inline-block; font-family: var(--mono); font-size: 11.5px;
  background: var(--warn-soft); color: var(--warn);
  padding: 3px 10px; border-radius: 999px; margin: 0 0 16px;
}
.roadmap { padding-left: 20px; color: var(--ink-2); font-size: 14.5px; }
.roadmap li { margin-bottom: 9px; }
.roadmap b { color: var(--ink); }

/* -------------------------------------------------------- exam browser */
.examgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px,1fr)); gap: 14px; }
.examcard {
  border: 1px solid var(--line); border-radius: 9px; padding: 14px 16px;
  background: var(--panel-2);
}
.examcard h3 { margin: 0 0 4px; font-size: 14px; color: var(--ink);
  text-transform: none; letter-spacing: 0; }
.examcard .meta { font-size: 11.5px; color: var(--ink-3); font-family: var(--mono); margin-bottom: 9px; }
.examcard ul { margin: 0; padding-left: 17px; font-size: 13px; color: var(--ink-2); }
.examcard li { margin-bottom: 4px; }
.tagrow { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-family: var(--mono); font-size: 10.5px; padding: 2px 7px;
  border-radius: 4px; background: var(--blue-soft); color: var(--blue); }

.spinner { display: inline-block; width: 14px; height: 14px; vertical-align: -2px;
  border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.copied { color: var(--good) !important; }

/* ------------------------------------------------- per-step copy buttons */
.step { position: relative; }
.step-tools {
  position: absolute; top: 0; right: 0;
  display: flex; gap: 4px;
  opacity: 0; transition: opacity .15s;
}
.step:hover .step-tools, .step-tools:focus-within { opacity: 1; }
button.tiny {
  font-family: var(--mono); font-size: 10.5px; cursor: pointer;
  padding: 2px 7px; border-radius: 5px; line-height: 1.5;
  border: 1px solid var(--line); background: var(--panel);
  color: var(--ink-3);
}
button.tiny:hover { border-color: var(--accent); color: var(--accent); }
button.tiny.copied { color: var(--good) !important; border-color: var(--good); }
/* keep the heading clear of the buttons */
.step-title { padding-right: 150px; }
@media (hover: none) { .step-tools { opacity: 1; } }

/* --------------------------------------------------------- front door */
.confirm {
  border: 1px solid var(--warn); background: var(--warn-soft);
  border-radius: 10px; padding: 16px 18px; margin-bottom: 20px;
}
.confirm h3 { color: var(--warn); margin-top: 0; }
.cfield { margin-bottom: 14px; }
.cfield input { background: var(--panel); }
.cfield-tex { margin: 6px 0; overflow-x: auto; }
.conf {
  font-family: var(--mono); font-size: 10.5px; padding: 2px 8px;
  border-radius: 999px; text-transform: uppercase; letter-spacing: .06em;
}
.conf.ok   { background: var(--good-soft); color: var(--good); }
.conf.warn { background: var(--warn-soft); color: var(--warn);
             border: 1px solid var(--warn); }
.conf.bad  { background: var(--accent-soft); color: var(--accent);
             border: 1px solid var(--accent); }
.cnotes { margin: 7px 0 0; padding-left: 18px; font-size: 12px; color: var(--ink-2); }
.cnotes li.bad { color: var(--accent); font-weight: 600; }

.subq {
  border-left: 2.5px solid var(--line); padding: 4px 0 10px 16px;
  margin: 0 0 18px 4px;
}
.subq-head { display: flex; gap: 9px; align-items: baseline; }
.subq-letter {
  font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--accent);
  background: var(--accent-soft); border-radius: 5px; padding: 1px 7px; flex-shrink: 0;
}
.subq-text { font-size: 14px; color: var(--ink-2); }
.subq-routes { display: flex; flex-wrap: wrap; gap: 6px; margin: 9px 0 0; }
button.route {
  font-family: var(--mono); font-size: 11.5px; cursor: pointer;
  padding: 4px 10px; border-radius: 6px;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
button.route:hover { filter: brightness(1.1); }
button.route.advisory {
  background: var(--panel-2); color: var(--ink-3); border-color: var(--line);
  cursor: default;
}
.subq-why {
  font-family: var(--mono); font-size: 11px; color: var(--ink-3); margin-top: 6px;
}
.subq-out { margin-top: 14px; }
.subq-out:empty { margin: 0; }

/* ------------------------------------------------------- the ONLINE badge */
.pill.online {
  background: var(--accent); color: #fff; cursor: pointer;
  border-color: var(--accent); font-weight: 700; letter-spacing: .02em;
}
.pill.online:hover { filter: brightness(1.1); }

/* ========================================================================
   Phones and tablets.
   The desktop layout is a two-column split with a sticky control pane; on a
   narrow screen that becomes one column, the controls stop being sticky (a
   sticky sidebar on a phone just eats the viewport), and every wide thing --
   maths, matrices, tables, plots -- gets its own horizontal scroll so the
   page body itself never scrolls sideways.
   ====================================================================== */

/* wide content must scroll inside itself, at every width */
.step-math, .cfield-tex, .bi-stmt, .drawer-body .stmt, .conclusion {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.katex-display { overflow-x: auto; overflow-y: hidden; padding-bottom: 2px; }

@media (max-width: 1000px) {
  .controls { position: static; max-height: none; }
}

@media (max-width: 760px) {
  html, body { font-size: 15px; }
  main { padding: 12px 10px 40px; }
  .pane { padding: 14px 13px; border-radius: 9px; }
  .split { gap: 14px; }

  /* header: let the title shrink, keep the badge and toggle reachable */
  .topbar { padding: 10px 12px; gap: 8px; }
  .logo { width: 34px; height: 34px; font-size: 19px; border-radius: 10px; }
  .topbar h1 { font-size: 17px; }
  .topbar p { display: none; }
  .pill { font-size: 10px; padding: 4px 8px; }

  /* tabs scroll horizontally instead of wrapping into a tall block */
  .tabs { top: 57px; padding: 0 8px; }
  .tabs button { padding: 10px 11px; font-size: 13px; }
  .tabs::-webkit-scrollbar { height: 0; }

  /* comfortable touch targets, and no iOS zoom-on-focus (needs >= 16px) */
  input[type=text], input:not([type]), textarea, select {
    font-size: 16px; padding: 10px 11px;
  }
  button.primary, button:not(.ghost):not(.chip) { padding: 11px 16px; font-size: 15px; }
  .chip { padding: 6px 11px; font-size: 12px; }
  .checks { gap: 10px 14px; }
  .checks label { font-size: 14px; }
  .row { grid-template-columns: 1fr; gap: 0; }

  /* the per-step copy buttons are hover-only on desktop; show them here */
  .step-tools { position: static; opacity: 1; margin-bottom: 6px; }
  .step-title { padding-right: 0; }
  .step { padding-left: 12px; margin-left: 0; }

  /* the drawer becomes a bottom sheet */
  .drawer {
    width: 100vw; height: 88vh; top: auto; bottom: 0;
    border-left: 0; border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    transform: translateY(102%);
  }
  .drawer.open { transform: none; }
  .drawer-head { padding: 14px 16px; }
  .drawer-body { padding: 14px 16px 50px; }

  .derivation > header { flex-direction: column; gap: 8px; }
  .actions { flex-wrap: wrap; }
  .examgrid { grid-template-columns: 1fr; }
  .plotwrap svg { min-height: 220px; }
  .plot-legend { font-size: 11px; gap: 10px; }
}

@media (max-width: 420px) {
  .topbar h1 { font-size: 15px; }
  .logo { width: 30px; height: 30px; font-size: 17px; }
  .pill { font-size: 9.5px; padding: 3px 6px; }
  .tabs button { padding: 9px 9px; font-size: 12.5px; }
}

/* respect a reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  .drawer, #scrim, .step-tools { transition: none; }
  .spinner { animation: none; }
}
