/* NOTE: Colours are tokens. Dark mode follows the system setting. */
:root {
    color-scheme: light dark;
    --bg: #fff;
    --surface: #f4f4f4;
    --text: #1b1b1b;
    --text-muted: #5c5c5c;
    --border: #c4c4c4;
    --grid: #e4e4e4;
    --accent: #1f6fb4;
    --accent-soft: rgb(31 111 180 / 0.25);
    --focus: #0b5cad;
    --warn-bg: #fff6c2;
    --series-0: #1f6fb4;
    --series-1: #d9480f;
    --series-2: #2b8a3e;
    --series-3: #862e9c;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 1rem;
    --space-4: 2rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171a;
        --surface: #1e2328;
        --text: #e6e8ea;
        --text-muted: #a3abb2;
        --border: #3a424a;
        --grid: #2a3036;
        --accent: #5aa9e6;
        --accent-soft: rgb(90 169 230 / 0.3);
        --focus: #7dbdf0;
        --warn-bg: #4a4220;
        --series-0: #5aa9e6;
        --series-1: #ff8a5c;
        --series-2: #5fc77a;
        --series-3: #c78be0;
    }
}

body {
    font-family: system-ui, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    margin: var(--space-3);
    background: var(--bg);
    color: var(--text);
}

h1,
h2,
h3 {
    line-height: 1.2;
    margin: 0 0 var(--space-2);
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }

p {
    max-width: 65ch;
}

a {
    color: var(--accent);
    text-underline-offset: 0.2em;
}

pre,
code {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.875rem;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

button {
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    cursor: pointer;
}

button:hover:not(:disabled) {
    border-color: var(--accent);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

input,
select,
textarea {
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
}

/* NOTE: Every control shows a ring with keyboard navigation, in both colour schemes. */
:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

/* NOTE: Blazor focuses the page heading after navigation. It is not a control, so it gets no ring. */
h1[tabindex="-1"]:focus-visible {
    outline: none;
}

.dock-tab:focus-visible,
.dock-close:focus-visible {
    outline-offset: -2px;
}

.dock-splitter:focus-visible {
    outline-offset: 0;
}

.schematic-pins .pin:focus-visible,
.schematic-pins .part:focus-visible {
    outline-offset: 1px;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 0.5rem;
    background: var(--warn-bg);
    color: var(--text);
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    float: right;
}

.line-chart {
    display: block;
    max-width: 100%;
    height: auto;
    font-size: 10px;
}

.line-chart .plot-area {
    fill: none;
    stroke: var(--text-muted);
}

.line-chart .grid {
    stroke: var(--grid);
}

.line-chart .series {
    stroke-width: 1.5;
}

.line-chart .series-0 { stroke: var(--series-0); fill: var(--series-0); }
.line-chart .series-1 { stroke: var(--series-1); fill: var(--series-1); }
.line-chart .series-2 { stroke: var(--series-2); fill: var(--series-2); }
.line-chart .series-3 { stroke: var(--series-3); fill: var(--series-3); }

.line-chart path.series {
    fill: none;
}

.line-chart .legend text {
    stroke: none;
}

/* NOTE: The dock tree gives each tab strip, panel and splitter a place in percent of the layout. */
.dock-layout {
    --dock-tab-height: 2rem;
    position: relative;
    height: calc(100vh - 7rem);
    min-height: 30rem;
    margin-top: 0.5rem;
}

.dock-layout.resizing {
    user-select: none;
}

.dock-tabs {
    position: absolute;
    box-sizing: border-box;
    height: var(--dock-tab-height);
    display: flex;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-bottom: none;
    background: var(--surface);
}

.dock-tab-item {
    display: flex;
    white-space: nowrap;
}

.dock-tab,
.dock-close {
    border: none;
    border-radius: 0;
    background: none;
    padding: 0 0.5rem;
    cursor: pointer;
}

.dock-close {
    padding: 0 0.4rem 0 0;
    color: var(--text-muted);
}

.dock-tab[aria-selected="true"] {
    background: var(--bg);
    font-weight: 600;
}

.dock-panel {
    position: absolute;
    box-sizing: border-box;
    overflow: auto;
    padding: 0.5rem;
    border: 1px solid var(--border);
    background: var(--bg);
}

.dock-panel > textarea {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    resize: none;
}

.dock-panel-title {
    display: none;
    margin: 0 0 0.5rem;
    font-size: 1rem;
}

.dock-splitter {
    position: absolute;
    z-index: 2;
}

.dock-splitter.row {
    width: 6px;
    transform: translateX(-3px);
    cursor: col-resize;
}

.dock-splitter.column {
    height: 6px;
    transform: translateY(-3px);
    cursor: row-resize;
}

.dock-splitter:hover,
.dock-splitter:focus-visible {
    background: var(--accent);
}

/* NOTE: The drop zones show only while a tab is dragged. */
.dock-drop {
    position: absolute;
    display: none;
    z-index: 3;
}

.dock-layout.dragging .dock-drop {
    display: block;
}

.dock-zone {
    position: absolute;
}

.dock-zone:hover {
    background: var(--accent-soft);
}

.dock-zone.center { inset: 25%; }
.dock-zone.left { left: 0; top: 0; bottom: 0; width: 25%; }
.dock-zone.right { right: 0; top: 0; bottom: 0; width: 25%; }
.dock-zone.top { top: 0; left: 25%; right: 25%; height: 25%; }
.dock-zone.bottom { bottom: 0; left: 25%; right: 25%; height: 25%; }

.dock-closed {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.5rem;
}

/* NOTE: Narrow screens stack the panels in page order, each with all of its content. */
@media (max-width: 48rem) {
    .dock-layout {
        height: auto;
        min-height: 0;
    }

    .dock-tabs,
    .dock-splitter,
    .dock-drop {
        display: none !important;
    }

    .dock-panel,
    .dock-panel[hidden] {
        position: static;
        display: block;
        width: auto !important;
        height: auto !important;
        margin-bottom: 0.5rem;
    }

    .dock-panel-title {
        display: block;
    }

    .dock-panel > textarea {
        height: 16rem;
    }
}

.dc-nodes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0;
    list-style: none;
}

.dc-label {
    margin-left: 0.25rem;
    font-variant-numeric: tabular-nums;
}

.schematic svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* NOTE: The pin layer has the same view box as the schematic, so it sits on the pins. */
.schematic-editor .schematic {
    position: relative;
}

.schematic-pins .pin {
    fill: currentColor;
    fill-opacity: 0.25;
    stroke: currentColor;
    stroke-width: 1.5;
    cursor: pointer;
}

.schematic-pins .pin-hit {
    fill: transparent;
    cursor: pointer;
}

.schematic-pins .pin:hover,
.schematic-pins .pin.active {
    fill: currentColor;
}

.schematic-pins .part {
    fill: transparent;
    stroke: none;
    cursor: pointer;
}

.schematic-pins .part.selected {
    stroke: currentColor;
    stroke-width: 1;
    stroke-dasharray: 4 2;
}

.schematic-tools .tool-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding-right: 1rem;
}

.schematic-tools .tool-group + .tool-group {
    padding-left: 1rem;
    border-left: 1px solid currentColor;
}

.schematic-tools .tool-label {
    font-size: 0.85em;
    opacity: 0.75;
}

.schematic-hint {
    margin: 0.5rem 0;
    font-size: 0.9em;
}

.schematic-empty {
    margin: 1rem 0;
}

.schematic-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.schematic-tools [aria-pressed="true"] {
    font-weight: 600;
    border-color: var(--accent);
    background: var(--accent-soft);
}

.home-links {
    display: flex;
    gap: var(--space-3);
}

.home-versions {
    margin-top: 4rem;
}

/* NOTE: Toolbar, stacked option lists and panel hints (#152). Plain and dense, no decoration. */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    align-items: center;
    margin-bottom: var(--space-1);
}

.toolbar button {
    min-width: 5rem;
}

.toolbar button:disabled {
    background: transparent;
    color: var(--text-muted);
    border-style: dashed;
    opacity: 0.7;
}

.toolbar-hint,
.toolbar-status,
.panel-hint {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.toolbar-hint {
    margin-left: auto;
}

.panel-hint {
    margin: 0.25rem 0 0.5rem;
}

.run-errors {
    margin: 0 0 var(--space-1);
    padding-left: 1.25rem;
}

.run-errors .error,
.amp-error {
    color: var(--error, #b3261e);
}

.amp-stack,
.knobs {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.amp-stage {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.amp-stage select {
    width: 100%;
}

.knob {
    display: grid;
    grid-template-columns: 4rem 1fr auto auto;
    gap: 0.5rem;
    align-items: center;
}

.knob .position {
    min-width: 3rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.knob .taper {
    color: var(--text-muted);
}

.calculator-panel .input {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    margin-bottom: 0.5rem;
}

/* NOTE: A tab strip wraps its tabs in a scroll-free row at 1280 px; the labels stay short. */
.dock-tab {
    padding: 0 0.4rem;
    font-size: 0.875rem;
}

/* The palette is a column at the left of the canvas. Above 48rem it is a block of two columns, below it rows that wrap. It never scrolls. */
.schematic-body {
    display: flex;
    gap: var(--space-3, 0.75rem);
    align-items: stretch;
}

.schematic-body .schematic {
    flex: 1;
    min-width: 0;
    min-height: 18rem;
    height: 60vh;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

/* NOTE: The schematic and the pin layer are one pixel to one view box unit at 100%, and the transform places them. They stay hidden until the pane is measured and the view is set, so no frame shows a view that is then replaced. */
.schematic-editor .schematic > svg {
    position: absolute;
    top: 0;
    left: 0;
    max-width: none;
    transform-origin: 0 0;
    visibility: hidden;
}

.schematic-editor .schematic[data-view] > svg {
    visibility: visible;
    width: var(--w);
    height: var(--h);
    transform: translate(var(--x), var(--y)) scale(var(--z));
}

/* NOTE: A + dot lies one step beyond a lone part, outside the view box. The pin layer shows and hits it there. */
.schematic-pins {
    touch-action: none;
    overflow: visible;
}

.schematic-zoom {
    position: absolute;
    z-index: 1;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem;
    background: var(--bg, Canvas);
    border: 1px solid currentColor;
    border-radius: 0.25rem;
}

.schematic-zoom button {
    min-width: 2.75rem;
    min-height: 2.75rem;
}

.schematic-zoom .zoom-level {
    min-width: 3.25rem;
    text-align: center;
    font-size: 0.85em;
    font-variant-numeric: tabular-nums;
}

.palette {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 0.25rem;
    flex: none;
    width: 13.25rem;
}

.palette-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
    flex: 0 0 6.4rem;
    padding: 0.25rem;
    user-select: none;
    -webkit-user-select: none;
    font-size: 0.75rem;
}

.palette-item[aria-pressed="true"] {
    font-weight: 600;
    border-color: var(--accent);
    background: var(--accent-soft);
}

.palette-symbol svg {
    display: block;
    width: 3.5rem;
    height: 2rem;
}

.pin-add {
    cursor: pointer;
}

/* NOTE: The hit circle is 44 px across at any zoom. The dot inside it is the part that shows. */
.pin-add-hit {
    fill: transparent;
}

.pin-add-dot {
    fill: var(--accent, currentColor);
    stroke: var(--bg, Canvas);
    stroke-width: 1;
    pointer-events: none;
}

.pin-add.chosen .pin-add-dot {
    stroke: currentColor;
    stroke-width: 2;
}

.schematic-pins .pin.target {
    fill: var(--accent, currentColor);
    fill-opacity: 0.6;
    stroke-width: 2;
}

.schematic-pins .pin.open {
    fill-opacity: 0;
    stroke-dasharray: 2 2;
}

.schematic-pins .pin.open.active {
    fill-opacity: 1;
}

.pin-add-sign {
    fill: var(--bg, Canvas);
    font-weight: 700;
    pointer-events: none;
}

/* NOTE: Without a pixel position the picker sits at the top of the pane. With a view the style sets it under its dot. */
.pin-menu {
    position: absolute;
    left: 0.5rem;
    right: 0.5rem;
    top: 3.5rem;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.25rem;
    background: var(--bg, Canvas);
    border: 1px solid currentColor;
    border-radius: 0.25rem;
}

.pin-menu button {
    min-height: 2.75rem;
    min-width: 2.75rem;
}

.schematic-pins .part {
    touch-action: none;
}

.schematic-pins .part.ghost {
    stroke: currentColor;
    stroke-width: 1;
    stroke-dasharray: 4 2;
    fill: currentColor;
    fill-opacity: 0.1;
    pointer-events: none;
}

.schematic-blank {
    min-height: 12rem;
}

/* NOTE: In the dock the schematic fills its panel, so the bar and the menu at the bottom of the canvas are in view. The narrow layout keeps 60vh. */
@media (min-width: 48.01rem) {
    .dock-panel:has(.schematic-editor) {
        display: flex;
        flex-direction: column;
    }

    .dock-panel:has(.schematic-editor) .schematic-editor {
        display: flex;
        flex: 1;
        flex-direction: column;
        min-height: 0;
    }

    .dock-panel:has(.schematic-editor) .schematic-body {
        flex: 1;
        min-height: 0;
    }

    .dock-panel:has(.schematic-editor) .schematic-body .schematic {
        height: auto;
        min-height: 0;
    }
}

@media (max-width: 48rem) {
    .schematic-body {
        flex-direction: column;
    }

    .palette {
        width: auto;
    }

    .palette-item {
        flex: none;
        width: 5rem;
    }
}

/* NOTE: Selection bar and delete status (#190). Every button is 44 px or more. */
.schematic-pins .wire-hit {
    fill: none;
    stroke: transparent;
    stroke-width: 16;
    stroke-linecap: round;
    stroke-linejoin: round;
    cursor: pointer;
}

.schematic-pins .wire-hit.selected {
    stroke: currentColor;
    stroke-opacity: 0.35;
}

.part-actions {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

.part-action {
    position: absolute;
    width: 44px;
    height: 44px;
    padding: 0;
    transform: translate(-50%, -50%);
    pointer-events: auto;
    border-radius: 50%;
    border: 1px solid currentColor;
    background: var(--bg, Canvas);
    font-size: 1.25rem;
    line-height: 1;
}

/* NOTE: Before the pane is measured there is no pixel position, so the buttons sit in one row near the top of the pane. */
.part-action[data-action="delete"] { left: calc(50% - 4.5rem); top: 12%; }
.part-action[data-action="rotate"] { left: calc(50% - 1.5rem); top: 12%; }
.part-action[data-action="flip"] { left: calc(50% + 1.5rem); top: 12%; }
.part-action[data-action="duplicate"] { left: calc(50% + 4.5rem); top: 12%; }

.delete-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.delete-status button {
    min-height: 44px;
    min-width: 44px;
}

.jack-ring {
    fill: none;
    stroke: var(--accent, currentColor);
    stroke-width: 2;
    pointer-events: none;
}

.jack-label {
    fill: var(--accent, currentColor);
    font-weight: 700;
    pointer-events: none;
}

.schematic-editor { position: relative; }
/* NOTE: The box floats at the bottom of the canvas area, so a selection never moves the palette or the circuit. */
.value-edit-box { position: absolute; left: 8rem; bottom: 0.5rem; z-index: 3; margin: 0; }
.value-edit { width: 7rem; min-height: 44px; box-sizing: border-box; padding: 0 0.5rem; font: inherit; text-align: center; }
.value-edit[aria-invalid="true"] { border-color: #b00020; }
.value-error { position: absolute; left: 8rem; bottom: 3.5rem; z-index: 3; margin: 0; padding: 0.25rem 0.5rem; font-size: 0.85rem; color: #fff; background: #b00020; border-radius: 4px; }

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: 1rem;
    padding: 0;
    list-style: none;
}

.gallery .preview {
    margin: 0 0 0.5rem;
    aspect-ratio: 4 / 3;
    border: 1px solid currentColor;
    overflow: hidden;
}

.gallery .preview img {
    width: 100%;
    height: 100%;
    display: block;
}

.gallery .file {
    display: block;
    font-size: 0.8em;
    opacity: 0.75;
}

.first-run-hints {
    margin: 0.5rem 0;
    padding-left: 1.2rem;
    font-size: 0.9em;
}

.gallery li {
    display: flex;
    flex-direction: column;
}

.gallery .preview {
    order: -1;
/* NOTE: A problem shows in words in the list and as a ring on the part or pin that causes it. */
.schematic-editor .problems {
    list-style: none;
    margin: 0.25rem 0;
    padding: 0;
}

.schematic-editor .problem-item {
    display: block;
    width: 100%;
    min-height: 28px;
    padding: 0.15rem 0.5rem;
    font-size: 0.9em;
    text-align: left;
    background: var(--warn-bg);
    border: 1px solid var(--error, #b3261e);
    border-radius: 4px;
    cursor: pointer;
}

.schematic-pins .pin.problem {
    stroke: var(--error, #b3261e);
    stroke-width: 3px;
    vector-effect: non-scaling-stroke;
    fill: var(--error, #b3261e);
    fill-opacity: 0.5;
}

.schematic-pins .part.problem {
    stroke: var(--error, #b3261e);
    stroke-width: 2;
    stroke-dasharray: 6 3;
}

@media (pointer: coarse) {
    .schematic-editor .problem-item {
        min-height: 44px;
    }
}
