/* =====================================================================
   tools.css: the shared parts of the interactive tools (tools/*.html): the
   page's header, the layout of a stage beside a panel of controls, the
   stage itself, the panel's sections and gold labels, pill buttons in the
   Pauli colours, segmented choices, sliders and fields, stat tiles, the
   legend, notes and banners. Every value is a token from css/theme.css.
   Loaded after pages.css; a tool's own <style> adds what only it draws.

   Markup, in short:
     <main class="tool-page">
       <a class="back-link">            <header class="page-hero tool-hero">
       <div class="tool-layout">
         <div class="tool-stage"> picture, .stage-bar, .stage-foot </div>
         <aside class="tool-panel"> .panel-section > .panel-title ... </aside>
       </div>
   ===================================================================== */

/* ── The page ── */
.tool-page {
    max-width: 1360px;
    margin: 0 auto;
    padding: 96px 2rem 3rem;
}
.tool-hero {
    margin-bottom: 1.6rem;
    padding: 1.7rem 2.2rem 1.6rem;
}
.tool-hero h1 {
    font-size: clamp(1.7rem, 3.4vw, 2.4rem);
}
.tool-hero .page-lead {
    margin-top: 0.8rem;
    max-width: 90ch;
    font-size: 0.98rem;
    line-height: 1.65;
}
.tool-hero .page-lead strong {
    color: var(--ink);
    font-weight: 700;
}
.tool-hero .page-lead code,
.tool-panel code,
.tool-note code {
    padding: 0.05rem 0.4rem;
    border-radius: var(--radius-xs);
    background: rgba(var(--deep-rgb), 0.55);
    border: 1px solid var(--tile-line);
    color: var(--color-title);
    font-family: var(--font-mono);
    font-size: 0.88em;
}

/* ── The layout: the stage, then the controls; one column on a tablet ── */
.tool-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 1.4rem;
    align-items: start;
}
.tool-layout.wide-panel {
    grid-template-columns: minmax(0, 1.05fr) minmax(380px, 1fr);
}

/* ── The stage: the picture on the brand's dark field, pinned while the
      controls scroll past ── */
.tool-stage {
    position: sticky;
    top: 88px;
    overflow: hidden;
    border-radius: var(--radius-xl);
    background: var(--stage-fill);
    border: 1px solid var(--stage-line);
    box-shadow: var(--stage-shadow);
}
/* The lattice behind the picture, faint. */
.tool-stage::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--lattice-fine);
    -webkit-mask-image: radial-gradient(ellipse 70% 70% at 50% 45%, #000 0%, transparent 85%);
    mask-image: radial-gradient(ellipse 70% 70% at 50% 45%, #000 0%, transparent 85%);
    pointer-events: none;
}
.tool-stage::after {
    content: '';
    position: absolute;
    left: 24px;
    right: 24px;
    top: 0;
    height: 2px;
    border-radius: 2px;
    background: var(--edge);
    opacity: 0.85;
    pointer-events: none;
}
.tool-stage > * {
    position: relative;
    z-index: 1;
}
.tool-stage svg,
.tool-stage canvas {
    display: block;
}
/* A row of small controls along the top or the bottom of the stage. */
.stage-bar,
.stage-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.6rem;
    padding: 0.6rem 0.9rem;
    background: rgba(var(--deep-rgb), 0.35);
    font-size: 0.78rem;
    color: var(--ink-3);
}
.stage-bar {
    border-bottom: 1px solid var(--hairline);
}
.stage-foot {
    border-top: 1px solid var(--hairline);
}
.stage-bar .bar-label,
.stage-foot .bar-label {
    margin-right: 0.3rem;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--gold-ink);
}
/* A floating caption on the picture. */
.stage-badge {
    position: absolute;
    left: 12px;
    bottom: 10px;
    z-index: 3;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-pill);
    background: rgba(var(--deep-rgb), 0.6);
    border: 1px solid rgba(var(--accent-rgb), 0.25);
    color: var(--ink-3);
    font-size: 0.72rem;
    pointer-events: none;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* ── The panel of controls ── */
.tool-panel {
    position: relative;
    padding: 1.3rem 1.3rem 1.4rem;
    border-radius: var(--radius-xl);
    background: var(--glass-fill);
    border: 1px solid var(--glass-line);
    box-shadow: var(--glass-shadow);
}
.tool-panel::before {
    content: '';
    position: absolute;
    left: 24px;
    right: 24px;
    top: 0;
    height: 2px;
    border-radius: 2px;
    background: var(--edge);
    opacity: 0.85;
    pointer-events: none;
}
.tool-panel.stack,
.tool-cards {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.tool-cards {
    background: none;
    border: 0;
    box-shadow: none;
    padding: 0;
}
.tool-cards::before {
    content: none;
}
.tool-card {
    position: relative;
    padding: 1.1rem 1.2rem 1.2rem;
    border-radius: var(--radius-xl);
    background: var(--glass-fill);
    border: 1px solid var(--glass-line);
    box-shadow: var(--glass-shadow);
}
.panel-section {
    margin-bottom: 1.15rem;
}
.panel-section:last-child {
    margin-bottom: 0;
}
/* The part's name in gold, with a fading rule after it. */
.panel-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0 0 0.75rem;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--gold-ink);
}
.panel-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, var(--hairline-gold), transparent);
}
.panel-title .tag-mn,
.panel-title small {
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    color: var(--ink-4);
    font-size: 0.78rem;
}
.panel-text,
.instruction-text {
    margin: 0 0 0.8rem;
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--ink-2);
}

/* ── Buttons: pills; the primary one filled with teal, the Pauli ones in
      their colours, a danger one in red ── */
.tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.55rem 1rem;
    border-radius: var(--radius-pill);
    border: 1px solid rgba(var(--accent-rgb), 0.45);
    background: rgba(var(--deep-rgb), 0.4);
    color: var(--color-light-teal);
    font: inherit;
    font-size: 0.86rem;
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: transform var(--t-fast) ease, box-shadow var(--t-fast) ease, border-color var(--t-fast) ease, background-color var(--t-fast) ease, color var(--t-fast) ease;
}
.tool-btn svg {
    width: 16px;
    height: 16px;
    flex: none;
}
.tool-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    border-color: var(--color-light-teal);
    background: rgba(var(--accent-rgb), 0.12);
}
.tool-btn:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
}
.tool-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.tool-btn.block {
    width: 100%;
}
.tool-btn.small {
    padding: 0.36rem 0.75rem;
    font-size: 0.78rem;
}
.tool-btn.primary,
.tool-btn.on {
    color: var(--color-black);
    background: var(--accent-fill);
    border-color: transparent;
    box-shadow: var(--accent-glow);
}
.tool-btn.primary:hover:not(:disabled),
.tool-btn.on:hover:not(:disabled) {
    background: var(--accent-fill);
    box-shadow: var(--accent-glow-hover);
}
.tool-btn.gold {
    color: var(--gold-ink);
    background: var(--gold-fill);
    border-color: var(--gold-line);
}
.tool-btn.gold:hover:not(:disabled) {
    background: rgba(var(--gold-rgb), 0.2);
    border-color: var(--color-yellow);
}
.tool-btn.gold.on {
    color: var(--color-black);
    background: var(--color-yellow);
    border-color: transparent;
    box-shadow: 0 8px 22px rgba(var(--gold-rgb), 0.3);
}
.tool-btn.danger {
    color: var(--bad);
    border-color: rgba(var(--bad-rgb), 0.5);
    background: rgba(var(--bad-rgb), 0.08);
}
.tool-btn.danger:hover:not(:disabled) {
    color: var(--color-white);
    background: var(--bad);
    border-color: transparent;
}
.tool-btn.ghost {
    color: var(--ink-3);
    border-color: var(--tile-line);
    background: transparent;
}
.tool-btn.ghost:hover:not(:disabled) {
    color: var(--ink);
    border-color: var(--color-light-teal);
}
/* The Pauli colours: outlined, filled when chosen. */
.tool-btn.pauli-x { color: var(--pauli-x); border-color: rgba(var(--pauli-x-rgb), 0.5); background: rgba(var(--pauli-x-rgb), 0.08); }
.tool-btn.pauli-z { color: var(--pauli-z); border-color: rgba(var(--pauli-z-rgb), 0.5); background: rgba(var(--pauli-z-rgb), 0.08); }
.tool-btn.pauli-y { color: var(--pauli-y); border-color: rgba(var(--pauli-y-rgb), 0.5); background: rgba(var(--pauli-y-rgb), 0.08); }
.tool-btn.pauli-x:hover:not(:disabled) { background: rgba(var(--pauli-x-rgb), 0.18); border-color: var(--pauli-x); }
.tool-btn.pauli-z:hover:not(:disabled) { background: rgba(var(--pauli-z-rgb), 0.18); border-color: var(--pauli-z); }
.tool-btn.pauli-y:hover:not(:disabled) { background: rgba(var(--pauli-y-rgb), 0.18); border-color: var(--pauli-y); }
.tool-btn.pauli-x.on { color: var(--color-black); background: var(--pauli-x); border-color: transparent; box-shadow: 0 8px 22px rgba(var(--pauli-x-rgb), 0.35); }
.tool-btn.pauli-z.on { color: var(--color-white); background: var(--pauli-z); border-color: transparent; box-shadow: 0 8px 22px rgba(var(--pauli-z-rgb), 0.35); }
.tool-btn.pauli-y.on { color: var(--color-white); background: var(--pauli-y); border-color: transparent; box-shadow: 0 8px 22px rgba(var(--pauli-y-rgb), 0.35); }
.tool-btn.on:hover:not(:disabled) {
    transform: none;
}
.btn-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}
.btn-row.stacked {
    flex-direction: column;
    align-items: stretch;
}

/* A segmented choice: pills in one row, the chosen one filled. */
.seg {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 0.7rem;
}
.seg .tool-btn {
    flex: 1;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.5rem 0.4rem;
    border-radius: var(--radius-md);
}
.seg .tool-btn small {
    font-weight: 600;
    font-size: 0.68rem;
    opacity: 0.8;
}
/* A grid of equal pills: the gates, the presets. */
.btn-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.4rem;
}
.btn-grid.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.btn-grid.cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
.btn-grid .tool-btn {
    padding: 0.55rem 0.3rem;
}

/* ── Sliders and fields ── */
.slider-row {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    margin-bottom: 0.6rem;
}
.slider-row label,
.slider-row .slider-label {
    flex: 0 0 auto;
    min-width: 0;
    font-size: 0.84rem;
    color: var(--ink-2);
}
.slider-row .val {
    flex: none;
    min-width: 2.6em;
    text-align: right;
    font-family: var(--font-mono);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--gold-ink);
}
.tool-range,
.slider-row input[type=range] {
    flex: 1;
    min-width: 60px;
    height: 6px;
    margin: 0;
    border-radius: 3px;
    background: linear-gradient(90deg, rgba(var(--accent-rgb), 0.35), var(--color-light-teal));
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}
.tool-range::-webkit-slider-thumb,
.slider-row input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--color-yellow);
    border: 3px solid rgb(var(--deep-rgb));
    box-shadow: 0 0 0 2px var(--color-yellow), var(--gold-glow);
    cursor: grab;
}
.tool-range::-moz-range-thumb,
.slider-row input[type=range]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-yellow);
    border: 3px solid rgb(var(--deep-rgb));
    box-shadow: 0 0 0 2px var(--color-yellow), var(--gold-glow);
    cursor: grab;
}
.tool-range:focus-visible,
.slider-row input[type=range]:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 4px;
}
.tool-field:not(select),
.tool-panel input[type=number],
.tool-panel input[type=text],
.tool-panel textarea {
    padding: 0.45rem 0.7rem;
    border-radius: var(--radius-md);
    background: var(--field-fill);
    border: 1px solid var(--field-line);
    color: var(--ink);
    font: inherit;
    font-size: 0.9rem;
    transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease, background-color var(--t-fast) ease;
}
.tool-panel input[type=number] {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--gold-ink);
    text-align: center;
}
.tool-field:not(select):hover,
.tool-panel input:hover,
.tool-panel textarea:hover {
    border-color: var(--field-line-hover);
}
.tool-field:not(select):focus,
.tool-panel input:focus,
.tool-panel textarea:focus {
    outline: none;
    border-color: var(--color-light-teal);
    background: var(--field-fill-focus);
    box-shadow: var(--field-ring);
}
/* A select is the site's dropdown (base.css); a tool sets only its size. */
.tool-panel select {
    font-size: 0.88rem;
}
.tool-panel input[type=checkbox],
.tool-panel input[type=radio] {
    accent-color: var(--color-light-teal);
}
.check-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.86rem;
    color: var(--ink-2);
    cursor: pointer;
}

/* ── Stat tiles: a label over a number ── */
.stat-tiles {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
}
.stat-tiles.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.stat-tiles.cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}
.stat {
    padding: 0.6rem 0.5rem 0.55rem;
    border-radius: var(--radius-md);
    background: var(--tile-fill);
    border: 1px solid var(--tile-line);
    text-align: center;
}
.stat-label {
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-4);
}
.stat-value {
    margin-top: 0.1rem;
    font-family: var(--font-mono);
    font-size: 1.25rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}
.stat-value.gold { color: var(--gold-ink); }
.stat-value.teal { color: var(--color-light-teal); }
.stat-value.syn-x, .stat-value.x { color: var(--pauli-x); }
.stat-value.syn-z, .stat-value.z { color: var(--pauli-z); }
.stat-value.ok { color: var(--ok); }
.stat-value.bad { color: var(--bad); }

/* ── The legend: a swatch and its name ── */
.legend {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    font-size: 0.82rem;
    color: var(--ink-2);
}
.legend.inline {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
/* The swatch takes its colour from --c (a colour) and its shape from a class. */
.swatch {
    flex: none;
    width: 14px;
    height: 14px;
    border-radius: 2px;
    background: var(--c, var(--color-light-teal));
}
.swatch.circle {
    border-radius: 50%;
    background: var(--qubit-fill);
    border: 2px solid var(--c, var(--qubit-line));
}
.swatch.hollow {
    border-radius: 50%;
    background: transparent;
    border: 2px solid var(--c, var(--qubit-line));
}
.swatch.diamond {
    transform: rotate(45deg) scale(0.85);
}
.swatch.line {
    width: 18px;
    height: 3px;
    border-radius: 2px;
}
.swatch.dash {
    width: 18px;
    height: 0;
    border-top: 3px dashed var(--c, var(--color-light-teal));
    background: none;
}
.swatch.x { --c: var(--pauli-x); }
.swatch.z { --c: var(--pauli-z); }
.swatch.y { --c: var(--pauli-y); }
.swatch.ok { --c: var(--ok); }

/* ── Notes and banners ── */
.tool-note,
.hint {
    position: relative;
    padding: 0.65rem 0.85rem 0.65rem 1rem;
    border-radius: var(--radius-md);
    background: var(--tile-fill);
    border: 1px solid var(--tile-line);
    font-size: 0.8rem;
    line-height: 1.55;
    color: var(--ink-3);
}
.tool-note::before,
.hint::before {
    content: '';
    position: absolute;
    left: 0;
    top: 9px;
    bottom: 9px;
    width: 3px;
    border-radius: 3px;
    background: var(--rule-v);
}
.tool-note strong,
.hint strong {
    color: var(--ink-2);
}
.result-banner {
    display: none;
    margin-top: 0.7rem;
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-weight: 700;
    text-align: center;
}
.result-banner.ok {
    display: block;
    color: var(--ok);
    background: rgba(var(--ok-rgb), 0.1);
    border: 1px solid rgba(var(--ok-rgb), 0.5);
}
.result-banner.bad {
    display: block;
    color: var(--bad);
    background: rgba(var(--bad-rgb), 0.1);
    border: 1px solid rgba(var(--bad-rgb), 0.5);
}
.result-banner.info {
    display: block;
    color: var(--gold-ink);
    background: var(--gold-fill);
    border: 1px solid var(--gold-line);
}
kbd,
.kbd {
    display: inline-block;
    padding: 0.05rem 0.4rem;
    border-radius: var(--radius-xs);
    background: rgba(var(--deep-rgb), 0.55);
    border: 1px solid rgba(var(--accent-rgb), 0.35);
    box-shadow: 0 1px 0 rgba(var(--accent-rgb), 0.35);
    font-family: var(--font-mono);
    font-size: 0.78em;
    color: var(--color-title);
}

/* ── Narrower screens ── */
@media (max-width: 1024px) {
    .tool-layout,
    .tool-layout.wide-panel {
        grid-template-columns: 1fr;
    }
    .tool-stage {
        position: static;
    }
}
@media (max-width: 768px) {
    .tool-page {
        padding: 76px 1rem 2.4rem;
    }
    .tool-hero {
        padding: 1.5rem 1.2rem 1.4rem;
    }
    .tool-panel,
    .tool-card {
        padding: 1.1rem 1rem 1.15rem;
        border-radius: var(--radius-xl);
    }
    .btn-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}
@media (prefers-reduced-motion: reduce) {
    .tool-btn {
        transition: none;
    }
    .tool-btn:hover:not(:disabled) {
        transform: none;
    }
}
