@font-face { font-family: ETbb; src: url("fonts/ETbb-Regular.otf") format("opentype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: ETbb; src: url("fonts/ETbb-Bold.otf") format("opentype"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: ETbb; src: url("fonts/ETbb-Italic.otf") format("opentype"); font-weight: 400; font-style: italic; font-display: swap; }

/* Standalone palette. Mirrors the shared theme in lab_html/assets/theme.css;
   update both together so the site and this portable app stay consistent. */
:root, :root[data-theme="light"] {
  color-scheme: light;
  --bg: #fffff8;
  --panel: rgba(255, 255, 248, .94);
  --card: #f7f5ec;
  --input: #fffef8;
  --line: rgba(30, 27, 22, .18);
  --control-line: #827d73;
  --muted: #68635b;
  --text: #171512;
  --label: #302c27;
  --accent: #8a1f7a;
  --secondary: #315f65;
  --button: #f0ede2;
  --button-hover: #e7e2d4;
  --shadow: rgba(60, 48, 30, .08);
  --tooltip-bg: #201e1a;
  --tooltip-text: #fffff8;
  font-family: ETbb, Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #151410;
    --panel: rgba(29, 28, 23, .94);
    --card: #24221c;
    --input: #191814;
    --line: rgba(255, 251, 235, .14);
    --control-line: #827d73;
    --muted: #aaa397;
    --text: #f5f0e4;
    --label: #ded7ca;
    --accent: #c6a6e8;
    --secondary: #80c8ce;
    --button: #29271f;
    --button-hover: #343127;
    --shadow: rgba(0, 0, 0, .28);
    --tooltip-bg: #f6f1e5;
    --tooltip-text: #171512;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151410;
  --panel: rgba(29, 28, 23, .94);
  --card: #24221c;
  --input: #191814;
  --line: rgba(255, 251, 235, .14);
  --control-line: #827d73;
  --muted: #aaa397;
  --text: #f5f0e4;
  --label: #ded7ca;
  --accent: #c6a6e8;
  --secondary: #80c8ce;
  --button: #29271f;
  --button-hover: #343127;
  --shadow: rgba(0, 0, 0, .28);
  --tooltip-bg: #f6f1e5;
  --tooltip-text: #171512;
}

* { box-sizing: border-box; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.skip-link {
  position: fixed; z-index: 100; top: .75rem; left: .75rem; padding: .6rem .8rem;
  color: var(--bg); background: var(--text); transform: translateY(calc(-100% - 1rem));
}
.skip-link:focus { transform: translateY(0); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-size: 1rem;
  line-height: 1.45;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures contextual;
  font-feature-settings: "kern" 1, "liga" 1;
  text-rendering: optimizeLegibility;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .18;
  background-image: radial-gradient(rgba(90, 70, 40, .12) .45px, transparent .45px);
  background-size: 5px 5px;
}

header, main, footer { position: relative; width: min(1480px, calc(100% - 40px)); margin-inline: auto; }
header { display: flex; justify-content: space-between; align-items: end; padding: 48px 0 28px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
h1 { margin: 2px 0 4px; font-size: clamp(2.35rem, 4vw, 4.25rem); font-weight: 400; letter-spacing: -.035em; line-height: .98; }
h2 { margin: 0; font-size: 1.15rem; font-weight: 700; }
.eyebrow { color: var(--accent); font: 700 .68rem ui-monospace, monospace; letter-spacing: .15em; }
.lede, .section-heading > span, footer { color: var(--muted); }
.lede { margin: 12px 0 0; font-style: italic; }
button, select {
  color: var(--text); background: var(--button); border: 1px solid var(--control-line);
  border-radius: 3px; padding: 8px 11px; cursor: pointer; font: inherit;
}
button:hover, select:hover { background: var(--button-hover); }

main { display: grid; grid-template-columns: 23.75rem minmax(0, 1fr); gap: 1.25rem; }
.panel {
  border: 1px solid var(--line); border-radius: 4px; background: var(--panel);
  box-shadow: 0 12px 40px var(--shadow);
}
.controls { padding: 22px; }
.section-heading { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 18px; }
.section-heading > span, .section-heading div > span { font-size: .82rem; color: var(--muted); }
fieldset { border: 0; border-top: 1px solid var(--line); padding: 17px 0 4px; margin: 12px 0 0; }
legend { padding: 0 8px 0 0; color: var(--accent); font: 700 .67rem ui-monospace, monospace; letter-spacing: .09em; text-transform: uppercase; }
label { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 9px 0; color: var(--label); font-size: .86rem; }
label > span:last-child { color: var(--muted); white-space: nowrap; }
.label-text { display: inline-flex; align-items: center; min-width: 0; }
input, select {
  width: 5.5rem; padding: .44rem .5rem; color: var(--text); background: var(--input);
  border: 1px solid var(--control-line); border-radius: 3px; font: 500 .76rem ui-monospace, monospace;
}
select { width: 7rem; }
input:focus, select:focus { border-color: var(--accent); }
.assumption { margin: 15px 0 0; color: var(--muted); font-size: .76rem; font-style: italic; line-height: 1.45; }

.help {
  display: inline-grid; place-items: center; flex: 0 0 auto; width: 1.5rem; height: 1.5rem; margin-left: .3rem;
  color: var(--accent); border: 1px solid currentColor; border-radius: 50%; cursor: help;
  font: 700 .7rem/1 ui-monospace, monospace; font-style: normal;
}
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; z-index: 20; left: 50%; bottom: calc(100% + .56rem); width: 15rem;
  padding: 9px 11px; color: var(--tooltip-text); background: var(--tooltip-bg); border-radius: 3px;
  box-shadow: 0 8px 24px var(--shadow); font: 400 .8rem/1.4 ETbb, Georgia, serif;
  text-align: left; white-space: normal; pointer-events: none; opacity: 0;
  transform: translate(-50%, 4px); transition: opacity .14s, transform .14s;
}
[data-tip]:hover::after, [data-tip]:focus::after { opacity: 1; transform: translate(-50%, 0); }
.help:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

.workspace { min-width: 0; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.125rem, 1fr)); gap: .625rem; margin-bottom: .625rem; }
.metrics article { padding: 13px 14px; border: 1px solid var(--line); border-radius: 3px; background: var(--card); }
.metrics article > span { display: flex; align-items: center; color: var(--muted); font-size: .75rem; margin-bottom: 5px; }
.metrics strong { font: 700 clamp(.76rem, 1.1vw, .95rem) ui-monospace, monospace; white-space: nowrap; }
.visual { padding: 20px; }
.legend { display: flex; align-items: center; gap: 7px; }
.legend i { width: 15px; height: 10px; border: 1.5px solid #63e6ff; border-radius: 1px; }
.touch-reading {
  margin: .75rem 0 0; padding: .55rem .7rem; color: var(--text); background: var(--card);
  border-left: 3px solid var(--accent); font: .75rem/1.45 ui-monospace, monospace;
}
.plot { position: relative; width: min(100%, 750px); margin: auto; aspect-ratio: 1; }
canvas { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: pan-y pinch-zoom; }
canvas:focus-visible { outline-offset: 4px; }
.tooltip {
  position: absolute; z-index: 3; pointer-events: none; min-width: min(11.125rem, calc(100% - .5rem));
  max-width: calc(100% - .5rem); padding: .56rem .69rem; color: #fffff8; background: rgba(5,8,14,.94); border: 1px solid rgba(255,255,255,.16); border-radius: 3px;
  box-shadow: 0 10px 28px rgba(0,0,0,.45); font: 400 .7rem/1.55 ui-monospace, monospace; white-space: pre-line;
}
.marker { position: absolute; z-index: 2; width: 9px; height: 9px; transform: translate(-50%, -50%); border: 1.5px solid white; border-radius: 50%; box-shadow: 0 0 10px white; pointer-events: none; }
.scale { display: flex; align-items: center; gap: 9px; max-width: 290px; margin: 10px auto 0; color: var(--muted); font: .75rem ui-monospace, monospace; }
.scale i { flex: 1; height: 6px; border-radius: 9px; background: linear-gradient(90deg, #08112a, #542b7c, #bd3754, #f98e08, #fcffa4); }
.diagram-notes { display: flex; justify-content: space-between; gap: 20px; margin-top: 11px; color: var(--muted); font: .75rem ui-monospace, monospace; }
.diagram-notes [data-tip] { cursor: help; border-bottom: 1px dotted currentColor; }
footer { padding: 22px 0 35px; text-align: right; font-size: .78rem; font-style: italic; }

@media (max-width: 980px) {
  main { grid-template-columns: 1fr; }
  .controls { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .controls > .section-heading, .controls > .assumption { grid-column: 1 / -1; }
  fieldset { margin: 0; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 650px) {
  header, main, footer { width: min(100% - 24px, 1480px); }
  header { padding-top: 30px; align-items: start; gap: 20px; }
  header button { font-size: .72rem; }
  .controls { display: block; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .diagram-notes { flex-direction: column; gap: 5px; }
  .visual { padding: 14px; }
  [data-tip]::after {
    position: fixed; left: 1rem; right: 1rem; bottom: 1rem; width: auto;
    transform: translateY(4px);
  }
  [data-tip]:hover::after, [data-tip]:focus::after { transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  [data-tip]::after { transition: none; }
}
