:root {
  --bg: #eef0f3;
  --surface: #ffffff;
  --ink: #1d2330;
  --ink-2: #4a5263;
  --muted: #6c7484;
  --line: #d5d9e0;
  --accent: #2b5ea7;
  --accent-ink: #ffffff;
  --error-bg: #fbe9e7;
  --error-ink: #8a1c10;
  --grid: #e6e8ec;
  /* the printed page always stays light, like paper */
  --paper: #f6f3ea;
  --paper-ink: #1a1a1a;
  --paper-rule: #2a2a2a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171c;
    --surface: #1d2129;
    --ink: #e6e8ec;
    --ink-2: #b9bfca;
    --muted: #8d95a3;
    --line: #353b46;
    --accent: #7aa7e8;
    --accent-ink: #0d1422;
    --error-bg: #3a1d1a;
    --error-ink: #f3b4aa;
    --grid: #2a2f38;
  }
}
:root[data-theme="dark"] {
  --bg: #14171c; --surface: #1d2129; --ink: #e6e8ec; --ink-2: #b9bfca; --muted: #8d95a3;
  --line: #353b46; --accent: #7aa7e8; --accent-ink: #0d1422; --error-bg: #3a1d1a;
  --error-ink: #f3b4aa; --grid: #2a2f38;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
button, input, select { font: inherit; color: inherit; }

.topbar {
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 18px; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.layout { display: flex; align-items: flex-start; gap: 16px; padding: 16px; }
.panel {
  flex: 0 0 300px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}
main { flex: 1 1 auto; min-width: 0; }

fieldset { border: 0; margin: 0 0 12px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
legend { font-weight: 600; padding: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-2); }
label.wide { grid-column: 1 / -1; }
label.check { flex-direction: row; align-items: center; gap: 6px; }
.u { color: var(--muted); }
.preset-note { margin: 0; font-size: 12px; color: var(--muted); }
.preset-note:empty { display: none; }
[hidden] { display: none !important; }
#compare-card { margin-top: 16px; }
input, select {
  width: 100%;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--bg);
  min-width: 0;
}
input[type="checkbox"] { width: auto; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; width: 100%; }
button[disabled] { opacity: .6; cursor: progress; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 14px; color: var(--ink-2); }
.tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }

.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.spacer { flex: 1; }
.status { color: var(--ink-2); }
.hint { margin: 0 0 10px; color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }
.error { background: var(--error-bg); color: var(--error-ink); padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; }
.warn { background: var(--error-bg); color: var(--error-ink); padding: 6px 10px; border-radius: 6px; font-size: 12px; margin: 0 0 8px; }

/* ------------------------------------------------------------------ */
/* Book spread imitating a printed firing table                        */
/* ------------------------------------------------------------------ */
.book-scroll { overflow-x: auto; padding-bottom: 8px; }
.book {
  display: flex;
  width: max-content;
  margin: 0 auto;
  color: var(--paper-ink);
  font-family: "Times New Roman", "Liberation Serif", Times, serif;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .25);
}
.page {
  position: relative;
  background: var(--paper);
  padding: 28px 22px 34px;
  width: 600px;
  min-height: 760px;
}
.page.left { background: linear-gradient(to right, var(--paper) 92%, #e3dfd2 100%); padding-left: 30px; }
.page.right { background: linear-gradient(to left, var(--paper) 88%, #e3dfd2 100%); padding-right: 80px; }

.corner { font: 11px/1.25 "Times New Roman", serif; text-align: center; width: 190px; height: 66px; }
.corner.right { margin-left: auto; text-align: right; width: auto; }
.corner .big { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
.corner em { display: block; margin-top: 4px; }

.title {
  font: 700 17px/1.2 "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  font-stretch: condensed;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
  height: 22px;
}
.sub { font-size: 14px; height: 19px; white-space: nowrap; }
.left .title, .left .sub { text-align: right; padding-right: 2px; }
.right .title, .right .sub { text-align: left; padding-left: 2px; }
.pb { font-size: 14px; height: 60px; white-space: nowrap; letter-spacing: .02em; }
.left .pb { text-align: right; padding-top: 2px; }
.left .pb span { letter-spacing: .18em; }
.right .pb { padding-top: 2px; line-height: 19px; }

table.ft {
  border-collapse: collapse;
  table-layout: fixed;
  width: 100%;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.ft th {
  font: 10px/1.15 "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  font-stretch: condensed;
  font-weight: 400;
  border: 1px solid var(--paper-rule);
  padding: 2px 2px;
  vertical-align: middle;
}
.ft thead tr:first-child th { border-top: 2px solid var(--paper-rule); }
.ft tr.h1 { height: 50px; }
.ft tr.h2 { height: 40px; }
.ft tr.sym th { font: italic 12px "Times New Roman", serif; height: 20px; }
.ft tr.unit th { font: italic 11px "Times New Roman", serif; height: 18px; border-bottom: 2px solid var(--paper-rule); }
.ft td {
  font-size: 13px;
  text-align: center;
  padding: 0 3px;
  height: 18px;
  line-height: 18px;
  border-left: 1px solid var(--paper-rule);
  border-right: 1px solid var(--paper-rule);
  white-space: nowrap;
}
.ft td.r { text-align: right; padding-right: 8px; }
.ft td.l { text-align: right; padding-right: 4px; }
.ft tbody tr:first-child td { padding-top: 9px; height: 27px; }
.ft tbody:last-child tr:last-child td { border-bottom: 2px solid var(--paper-rule); }
.ft tbody tr { cursor: pointer; }
.ft tbody tr:hover td { background: rgba(43, 94, 167, .10); }
.ft tbody tr.selected td { background: rgba(43, 94, 167, .18); }
.ft td.na { color: #777; font-style: italic; font-size: 11px; }

.notes { font-size: 11px; line-height: 1.35; margin-top: 10px; color: #333; }
.pageno { position: absolute; bottom: 12px; font-size: 13px; }
.left .pageno { left: 30px; }
.right .pageno { right: 80px; }

/* thumb tab on the outer edge of the right page */
.edge {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 60px;
  border-left: 1px solid #b9b4a6;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.edge .tabname {
  font: 700 9px/1.2 "Arial Narrow", Arial, sans-serif;
  font-stretch: condensed;
  text-transform: uppercase;
  text-align: center;
  padding: 116px 3px 6px;
  overflow-wrap: anywhere;   /* only splits a word that is wider than the tab */
}
.edge .bar { width: 100%; height: 34px; background: #151515; }
.edge .cut {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font: 700 12px "Arial Narrow", Arial, sans-serif;
  letter-spacing: .04em;
  margin: auto 0 60px;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ */
/* Trajectory tab                                                      */
/* ------------------------------------------------------------------ */
.traj-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; align-items: end; margin-bottom: 6px; }
.traj-form button.primary { width: auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 14px; }
details.card summary { cursor: pointer; font-weight: 600; }
details.card[open] summary { margin-bottom: 8px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile .v small { font-size: 12px; font-weight: 400; color: var(--muted); }

.plot-wrap { position: relative; }
#plot { width: 100%; height: 340px; display: block; }
#plot .grid line { stroke: var(--grid); }
#plot .axis text { fill: var(--muted); font-size: 11px; }
#plot .axis line, #plot .axis path { stroke: var(--line); }
#plot .axis .axis-title { fill: var(--ink-2); font-size: 12px; }
#plot .series { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
#plot .marker { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
#plot .label { fill: var(--ink-2); font-size: 11px; }
#plot .cross { stroke: var(--ink-2); stroke-dasharray: 3 3; }
#plot .hover-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tip b { font-weight: 600; }

.scroll { overflow-x: auto; }
.scroll.tall { max-height: 420px; overflow-y: auto; }
table.data { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 13px; }
table.data th, table.data td { padding: 4px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { color: var(--ink-2); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
table.data tr.final td { font-weight: 600; }

@media (max-width: 900px) {
  .layout { flex-direction: column; align-items: stretch; padding: 16px; }
  .panel { position: static; flex: none; width: 100%; max-height: none; }
  main { width: 100%; }
}
@media (max-width: 520px) {
  .layout { padding: 16px 16px; gap: 12px; }
  .traj-form { grid-template-columns: 1fr 1fr; }
}

.topbar .site-links { margin: 0 0 4px; font-size: 12px; }
.topbar .site-links a { color: var(--accent); text-decoration: none; }
.topbar .site-links a:hover { text-decoration: underline; }
.print-only { display: none; }
#traj-out > .toolbar { margin-bottom: 10px; }

@media print {
  @page { size: landscape; margin: 8mm; }
  body { background: #fff; }
  .topbar, .panel, .tabs, .toolbar, .hint, .error, #tab-traj { display: none !important; }
  .layout { padding: 0; display: block; }
  .book-scroll { overflow: visible; }
  .book { box-shadow: none; zoom: .82; }
  .ft tbody tr:hover td, .ft tbody tr.selected td { background: none; }
  /* Print on the Trajectory tab: the shot, its plot, the runs and (if opened) the step listing */
  body.print-traj #tab-table { display: none !important; }
  body.print-traj #tab-traj { display: block !important; }
  body.print-traj .traj-form, body.print-traj #tip { display: none !important; }
  body.print-traj .print-only { display: block; color: #000; margin-bottom: 8px; }
  body.print-traj .print-only h2 { margin: 0 0 4px; font-size: 16px; }
  body.print-traj .print-only p { margin: 2px 0; font-size: 12px; }
  body.print-traj .card, body.print-traj .tile { background: #fff; color: #000; border-color: #999; box-shadow: none; }
  body.print-traj .scroll, body.print-traj .scroll.tall { max-height: none; overflow: visible; }
  body.print-traj .plot-wrap { break-inside: avoid; }
}
