/* ModulationToy — self-contained styles, light/dark */
:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #8a8984;
  --accent: #2a78d6;
  --accent-soft: #cde2fb;
  --grid: #ecebe7;
  /* plot series */
  --s-a: #2a78d6;        /* leg a */
  --s-b: #eb6834;        /* leg b */
  --s-c: #1baf7a;        /* leg c */
  --s-carrier: #8a8984;
  --s-out: #0b0b0b;
  --s-fund: #e34948;
  --s-avg: #4a3aa7;
  --s-spec: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --border: #33332f;
    --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #3987e5; --accent-soft: #1c3a5f; --grid: #2a2a27;
    --s-a: #3987e5; --s-b: #d95926; --s-c: #199e70; --s-carrier: #8f8e86; --s-out: #ffffff;
    --s-fund: #e66767; --s-avg: #9085e9; --s-spec: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --border: #33332f;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #3987e5; --accent-soft: #1c3a5f; --grid: #2a2a27;
  --s-a: #3987e5; --s-b: #d95926; --s-c: #199e70; --s-carrier: #8f8e86; --s-out: #ffffff;
  --s-fund: #e66767; --s-avg: #9085e9; --s-spec: #3987e5;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
header {
  display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap;
  height: 48px; padding: 0.7rem 16px 0;
}
header h1 { font-size: 1.2rem; margin: 0; }
header .sub { color: var(--text-2); }
header .spacer { flex: 1; }
button, select, input { font: inherit; color: inherit; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 0.2rem 0.6rem; cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.sq { padding: 0; width: 2rem; height: 2rem; display: inline-grid; place-items: center; flex: none; }
.icon-btn[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent); }

/* ---- three-column layout: side | plots | readings; plots fill the viewport height */
main {
  --h: calc(100vh - 48px - 24px);
  display: grid; grid-template-columns: 290px minmax(0, 1fr) 215px; gap: 12px;
  padding: 12px 16px;
}
.side, .readings { max-height: var(--h); overflow-y: auto; }
.side { display: flex; flex-direction: column; gap: 12px; }
.plots { display: flex; flex-direction: column; gap: 12px; height: var(--h); min-height: 720px; }
.plot { padding: 4px; min-height: 0; }
.plot-time { flex: 2 1 0; display: flex; flex-direction: column; }
.plot-spec { flex: 1 1 0; display: flex; flex-direction: column; }
#timePlot { flex: 1 1 0; min-height: 0; }
.spec-row { flex: 1 1 0; min-height: 0; display: flex; gap: 4px; }
#specPlot { flex: 1 1 0; min-width: 0; }
/* short confirmation message (image copied / downloaded) */
.toast {
  position: fixed; z-index: 30; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--surface); padding: 0.5rem 0.9rem; border-radius: 6px;
  font-size: 0.9rem; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* floating, draggable, resizable space-vector panel */
.float {
  position: fixed; z-index: 14; width: 440px; height: 470px; min-width: 260px; min-height: 290px;
  max-width: calc(100vw - 16px); max-height: calc(100vh - 16px);
  resize: both; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
}
.float-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
  padding: 0.35rem 0.4rem 0.35rem 0.7rem; font-weight: 600; cursor: move; user-select: none; touch-action: none;
  border-bottom: 1px solid var(--border); }
#svPlot { flex: 1 1 0; min-height: 0; }
.check { display: inline-flex; gap: 0.3rem; align-items: center; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.6rem; margin-top: 0.4rem; }
.grid2 .span2 { grid-column: 1 / -1; }
.metric.section { border-bottom: 0; padding-top: 0.8rem; font-weight: 600; font-size: 0.8em;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

@media (max-width: 1100px) {
  main { grid-template-columns: 290px minmax(0, 1fr); }
  .readings { grid-column: 1 / -1; max-height: none; }
  #metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); }
}
@media (max-width: 860px) {
  main { grid-template-columns: minmax(0, 1fr); }
  .side { max-height: none; }
  .plots { height: auto; min-height: 0; }
  .plot-time { height: 620px; flex: none; }
  .plot-spec { height: 360px; flex: none; }
}

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.legend-h, .controls legend {
  font-weight: 600; font-size: 0.8em; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted); margin-bottom: 0.35rem;
}

/* preset panel */
.preset-panel { padding: 0.8rem 0.9rem; flex: none; }
.preset-panel select { width: 100%; }
.look { margin-top: 0.6rem; padding-left: 0.6rem; border-left: 3px solid var(--accent); color: var(--text-2); }

/* controls */
.controls { padding: 0.8rem 0.9rem; flex: none; }
.controls fieldset { border: 0; padding: 0; margin: 0 0 0.9rem; }
.field { margin-bottom: 0.55rem; }
.field > label { display: inline-block; color: var(--text-2); margin-bottom: 0.15rem; }
select { padding: 0.25rem 0.3rem; background: var(--bg); border: 1px solid var(--border); border-radius: 5px; }
.field select { width: 100%; }
.with-btn { display: flex; gap: 0.4rem; align-items: center; }
.with-btn select { flex: 1; min-width: 0; }
.slider-row { display: grid; grid-template-columns: minmax(0, 1fr) 4.6rem; gap: 0.5rem; align-items: center; }
.slider-row input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="number"] { width: 100%; padding: 0.2rem 0.3rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: 5px; }
.hint { color: var(--muted); font-size: 0.85em; margin-top: 0.1rem; }
[hidden] { display: none !important; }

/* readings */
.readings { padding: 0.8rem 0.9rem; align-self: start; }
.metric { padding: 0.4rem 0; border-bottom: 1px solid var(--grid); }
.metric:last-child { border-bottom: 0; }
.metric .k { color: var(--muted); font-size: 0.82em; }
.metric .v { font-variant-numeric: tabular-nums; font-size: 1.05em; }
.metric .v small { color: var(--text-2); font-size: 0.8em; }
.readings .foot { color: var(--muted); font-size: 0.8em; margin: 0.8rem 0 0; }

.plot-bar { display: flex; gap: 0.8rem; align-items: center; justify-content: flex-end;
  padding: 0.3rem 0.6rem 0; color: var(--text-2); flex: none; }

/* hoverable symbols and tooltip */
.sym { text-decoration: underline dotted var(--muted); text-underline-offset: 3px; cursor: help; }
[data-tip]:not(.sym):not(button) { cursor: help; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.tip {
  position: fixed; z-index: 20; max-width: 20rem; padding: 0.5rem 0.65rem;
  background: var(--text); color: var(--surface); border-radius: 6px;
  font-size: 0.86rem; line-height: 1.4; pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* schematic popover */
.schem {
  position: fixed; z-index: 15; width: min(460px, calc(100vw - 32px)); padding: 0.6rem 0.8rem 0.4rem;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
}
.schem-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 0.2rem; }
.schem svg { width: 100%; height: auto; display: block; font: 14px system-ui, sans-serif; }
.schem svg text { fill: var(--text); }
.schem svg text.small { font-size: 12px; fill: var(--text-2); }
.schem svg text.pol { font-size: 16px; font-weight: 600; }
.schem svg text.out { font-weight: 600; }
.schem .wire { fill: none; stroke: var(--text-2); stroke-width: 1.6; }
.schem .plate { stroke: var(--text); stroke-width: 2.4; }
.schem .load { fill: var(--bg); stroke: var(--text); stroke-width: 1.4; }
.schem .node { fill: var(--text); }
.schem .contact { fill: var(--surface); stroke-width: 1.4; }
.schem .blade { stroke-width: 2; }
.schem .leg-a .wire, .schem .leg-a .blade, .schem .leg-a .contact { stroke: var(--s-a); }
.schem .leg-b .wire, .schem .leg-b .blade, .schem .leg-b .contact { stroke: var(--s-b); }
.schem .leg-c .wire, .schem .leg-c .blade, .schem .leg-c .contact { stroke: var(--s-c); }
.schem .leg-a text, .schem text.leg-a-text { fill: var(--s-a); font-weight: 600; }
.schem .leg-b text, .schem text.leg-b-text { fill: var(--s-b); font-weight: 600; }
.schem .leg-c text, .schem text.leg-c-text { fill: var(--s-c); font-weight: 600; }
