.qpm-raw {
    --qpm-paper: #fffdf8;
    --qpm-surface: #ffffff;
    --qpm-surface-soft: #f5eee3;
    --qpm-border: #dccfc0;
    --qpm-text: #263334;
    --qpm-muted: #687576;
    --qpm-teal: #0d4b57;
    --qpm-teal-soft: #dbe8e8;
    --qpm-copper: #b9693f;
    --qpm-copper-soft: #f3dfd2;
    --qpm-gold: #bf913d;
    --qpm-success: #2d775e;
    --qpm-shadow: 0 18px 55px rgba(54, 42, 29, 0.13);
    --qpm-radius: 22px;
    --qpm-chart-bg: #fffdf8;
    --qpm-grid-color: rgba(13, 75, 87, 0.12);
    --qpm-axis-color: #5c6667;
    --qpm-curve-color: #0d4b57;
    --qpm-fill-color: rgba(13, 75, 87, 0.12);
    --qpm-event-color: #b9693f;
    --qpm-text-color: #263334;
    color: var(--qpm-text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.55;
    margin: 2rem auto;
    max-width: 1220px;
}

.qpm-raw *,
.qpm-raw *::before,
.qpm-raw *::after {
    box-sizing: border-box;
}

.qpm-raw button,
.qpm-raw input,
.qpm-raw output {
    font: inherit;
}

.qpm-shell {
    background:
        radial-gradient(circle at top right, rgba(185, 105, 63, 0.12), transparent 32%),
        linear-gradient(145deg, #f8f3ea 0%, #fffdf8 48%, #f3ece0 100%);
    border: 1px solid rgba(191, 145, 61, 0.24);
    border-radius: 30px;
    box-shadow: var(--qpm-shadow);
    overflow: hidden;
    padding: clamp(1rem, 2.8vw, 2.35rem);
}

.qpm-header {
    align-items: flex-start;
    display: flex;
    gap: 1.5rem;
    justify-content: space-between;
    margin-bottom: 1.4rem;
}

.qpm-header h2,
.qpm-panel h3 {
    color: var(--qpm-teal);
    line-height: 1.2;
    margin: 0;
}

.qpm-header h2 {
    font-size: clamp(1.55rem, 3vw, 2.55rem);
    letter-spacing: -0.035em;
}

.qpm-kicker {
    color: var(--qpm-copper);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.15em;
    margin: 0 0 0.35rem;
    text-transform: uppercase;
}

.qpm-intro {
    color: var(--qpm-muted);
    margin: 0.7rem 0 0;
    max-width: 760px;
}

.qpm-badge {
    align-items: center;
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid var(--qpm-border);
    border-radius: 18px;
    box-shadow: 0 8px 24px rgba(54, 42, 29, 0.08);
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    min-width: 118px;
    padding: 0.8rem 1rem;
}

.qpm-badge span {
    color: var(--qpm-muted);
    font-size: 0.82rem;
}

.qpm-badge strong {
    color: var(--qpm-copper);
    font-size: 1.45rem;
}

.qpm-grid {
    display: grid;
    gap: 1rem;
}

.qpm-grid-top {
    grid-template-columns: minmax(280px, 0.8fr) minmax(430px, 1.5fr);
}

.qpm-grid-bottom {
    grid-template-columns: minmax(480px, 1.45fr) minmax(300px, 0.75fr);
    margin-top: 1rem;
}

.qpm-panel {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--qpm-border);
    border-radius: var(--qpm-radius);
    box-shadow: 0 10px 30px rgba(54, 42, 29, 0.07);
    padding: clamp(1rem, 2vw, 1.35rem);
}

.qpm-panel h3 {
    font-size: 1.1rem;
}

.qpm-panel-heading {
    align-items: flex-start;
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.qpm-panel-heading p,
.qpm-matrix-caption {
    color: var(--qpm-muted);
    font-size: 0.88rem;
    margin: 0.25rem 0 0;
}

.qpm-controls {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

.qpm-control {
    display: block;
}

.qpm-control > span {
    align-items: baseline;
    display: flex;
    gap: 0.8rem;
    justify-content: space-between;
}

.qpm-control output {
    color: var(--qpm-copper);
    font-weight: 800;
}

.qpm-control small {
    color: var(--qpm-muted);
    display: block;
    font-size: 0.76rem;
    line-height: 1.35;
    margin-top: 0.25rem;
}

.qpm-control input[type="range"] {
    accent-color: var(--qpm-copper);
    cursor: pointer;
    margin: 0.55rem 0 0.1rem;
    width: 100%;
}

.qpm-presets,
.qpm-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.qpm-raw button {
    background: var(--qpm-surface-soft);
    border: 1px solid var(--qpm-border);
    border-radius: 999px;
    color: var(--qpm-teal);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 750;
    padding: 0.62rem 0.86rem;
    transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.qpm-raw button:hover {
    background: #fff;
    box-shadow: 0 6px 18px rgba(54, 42, 29, 0.1);
    transform: translateY(-1px);
}

.qpm-raw button:focus-visible,
.qpm-raw input:focus-visible {
    outline: 3px solid rgba(185, 105, 63, 0.32);
    outline-offset: 3px;
}

.qpm-raw .qpm-primary {
    background: var(--qpm-teal);
    border-color: var(--qpm-teal);
    color: #fff;
}

.qpm-raw .qpm-primary:hover {
    background: #123f48;
}

.qpm-state {
    background: var(--qpm-copper-soft);
    border: 1px solid rgba(185, 105, 63, 0.25);
    border-radius: 999px;
    color: #864523;
    flex: 0 0 auto;
    font-size: 0.76rem;
    font-weight: 800;
    padding: 0.42rem 0.72rem;
}

.qpm-interferometer {
    display: block;
    height: auto;
    max-height: 360px;
    width: 100%;
}

.qpm-interferometer text {
    fill: var(--qpm-muted);
    font-size: 14px;
    font-weight: 700;
}

.qpm-diagram-note {
    background: var(--qpm-teal-soft);
    border: 1px solid rgba(13, 75, 87, 0.13);
    border-radius: 12px;
    color: var(--qpm-muted);
    font-size: 0.8rem;
    margin: 0.35rem 0 0;
    padding: 0.65rem 0.8rem;
}

.qpm-diagram-note strong {
    color: var(--qpm-teal);
}

.qpm-source circle:first-child {
    fill: var(--qpm-teal-soft);
    stroke: var(--qpm-teal);
    stroke-width: 3;
}

.qpm-source circle:nth-child(2) {
    fill: var(--qpm-copper);
}

.qpm-splitter rect,
.qpm-recombiner rect,
.qpm-mirror rect {
    fill: #f0e4d5;
    stroke: var(--qpm-gold);
    stroke-width: 2;
}

.qpm-recombiner text {
    font-size: 12px;
}

.qpm-path {
    fill: none;
    stroke: url(#qpm-path-gradient);
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 4;
}

.qpm-path-a,
.qpm-path-b {
    /* La marcatura modifica la coerenza, non il peso dei due cammini. */
    opacity: 1;
}

.qpm-output-path {
    fill: none;
    stroke: var(--qpm-teal);
    stroke-linecap: round;
    stroke-width: 4;
}

.qpm-marker-coupling circle {
    fill: var(--qpm-copper);
    opacity: calc(0.35 + var(--qpm-marker-strength, 0.5) * 0.65);
}

.qpm-marker-coupling line {
    stroke: var(--qpm-copper);
    stroke-dasharray: 4 4;
    stroke-linecap: round;
    stroke-width: 2.5;
    opacity: calc(0.35 + var(--qpm-marker-strength, 0.5) * 0.65);
}

.qpm-marker-coupling text {
    fill: var(--qpm-copper);
    font-size: 12px;
}

.qpm-marker circle {
    fill: #fff8ef;
    stroke: var(--qpm-copper);
    stroke-width: 3;
}

.qpm-marker path,
.qpm-marker line {
    fill: none;
    stroke: var(--qpm-teal);
    stroke-linecap: round;
    stroke-width: 3;
}

.qpm-marker text[data-qpm-marker-theta] {
    fill: var(--qpm-copper);
    font-size: 12px;
    font-weight: 850;
}

.qpm-overlap-zone ellipse {
    fill: rgba(185, 105, 63, 0.08);
    stroke: var(--qpm-copper);
    stroke-dasharray: 5 5;
    stroke-width: 2.5;
}

.qpm-overlap-zone text {
    fill: var(--qpm-muted);
    font-size: 11px;
    font-weight: 750;
}

.qpm-screen > rect {
    fill: #f7efe4;
    stroke: var(--qpm-teal);
    stroke-width: 2.5;
}

.qpm-screen-axis {
    stroke: rgba(13, 75, 87, 0.18);
    stroke-width: 1;
}

.qpm-screen-bin {
    stroke: var(--qpm-copper);
    stroke-linecap: round;
    transition: x1 120ms linear, x2 120ms linear, stroke-opacity 120ms linear, stroke-width 120ms linear;
}

.qpm-screen-caption {
    fill: var(--qpm-copper);
    font-size: 11px;
    font-weight: 850;
}

.qpm-metrics {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    margin-top: 1rem;
}

.qpm-metrics article {
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid var(--qpm-border);
    border-radius: 18px;
    min-width: 0;
    padding: 0.9rem;
    text-align: center;
}

.qpm-metrics span,
.qpm-metrics small {
    color: var(--qpm-muted);
    display: block;
    font-size: 0.74rem;
}

.qpm-metrics strong {
    color: var(--qpm-teal);
    display: block;
    font-size: clamp(1.15rem, 2vw, 1.55rem);
    margin: 0.15rem 0;
}

.qpm-chart-panel {
    min-width: 0;
}

.qpm-canvas-wrap {
    background: var(--qpm-paper);
    border: 1px solid rgba(13, 75, 87, 0.14);
    border-radius: 16px;
    overflow: hidden;
}

.qpm-canvas-wrap canvas {
    display: block;
    height: 390px;
    max-width: 100%;
    width: 100%;
}

.qpm-live {
    background: var(--qpm-success);
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(45, 119, 94, 0.42);
    height: 10px;
    margin-top: 0.35rem;
    width: 10px;
    animation: qpm-pulse 2s infinite;
}

@keyframes qpm-pulse {
    0% { box-shadow: 0 0 0 0 rgba(45, 119, 94, 0.42); }
    70% { box-shadow: 0 0 0 9px rgba(45, 119, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(45, 119, 94, 0); }
}

.qpm-legend {
    color: var(--qpm-muted);
    display: flex;
    flex-wrap: wrap;
    font-size: 0.76rem;
    gap: 1rem;
    margin-top: 0.65rem;
}

.qpm-legend span {
    align-items: center;
    display: inline-flex;
    gap: 0.4rem;
}

.qpm-legend i {
    display: inline-block;
}

.qpm-legend-curve {
    background: var(--qpm-teal);
    height: 3px;
    width: 22px;
}

.qpm-legend-events {
    background: var(--qpm-copper);
    border-radius: 50%;
    height: 8px;
    width: 8px;
}

.qpm-matrix-panel {
    display: flex;
    flex-direction: column;
}

.qpm-matrix {
    align-items: stretch;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin: 1.25rem 0;
}

.qpm-bracket {
    color: var(--qpm-teal);
    display: flex;
    font-family: Georgia, serif;
    font-size: 5.5rem;
    font-weight: 300;
    line-height: 1;
}

.qpm-matrix-grid {
    display: grid;
    gap: 0.55rem;
    grid-template-columns: repeat(2, minmax(100px, 1fr));
}

.qpm-matrix-grid output {
    align-items: center;
    background: var(--qpm-surface-soft);
    border: 1px solid var(--qpm-border);
    border-radius: 12px;
    color: var(--qpm-text);
    display: flex;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.78rem;
    justify-content: center;
    min-height: 62px;
    padding: 0.5rem;
    text-align: center;
}

.qpm-meter-label {
    align-items: center;
    display: flex;
    font-size: 0.84rem;
    justify-content: space-between;
    margin-bottom: 0.45rem;
}

.qpm-meter-label strong {
    color: var(--qpm-copper);
}

.qpm-meter-track {
    background: #eadfd3;
    border-radius: 999px;
    height: 12px;
    overflow: hidden;
}

.qpm-meter-track > div {
    background: linear-gradient(90deg, var(--qpm-copper), var(--qpm-teal));
    border-radius: inherit;
    height: 100%;
    transition: width 180ms ease;
    width: 86.6%;
}

.qpm-matrix-relation {
    color: var(--qpm-muted);
    font-size: 0.78rem;
    margin: 0.65rem 0 0;
    text-align: center;
}

.qpm-equation {
    background: var(--qpm-teal-soft);
    border: 1px solid rgba(13, 75, 87, 0.13);
    border-radius: 14px;
    color: var(--qpm-teal);
    display: grid;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.78rem;
    gap: 0.25rem;
    margin-top: 1rem;
    padding: 0.8rem;
    text-align: center;
}

.qpm-explanation {
    margin-top: 1rem;
}

.qpm-explanation > p {
    margin-bottom: 0;
}

.qpm-note {
    background: var(--qpm-copper-soft);
    border-left: 4px solid var(--qpm-copper);
    border-radius: 0 14px 14px 0;
    color: #6c432f;
    font-size: 0.86rem;
    margin-top: 1rem !important;
    padding: 0.8rem 1rem;
}

.qpm-noscript {
    background: #fff4d8;
    border: 1px solid #e1bd5d;
    border-radius: 12px;
    color: #6f5210;
    margin: 1rem 0 0;
    padding: 0.8rem 1rem;
}

@media (max-width: 980px) {
    .qpm-grid-top,
    .qpm-grid-bottom {
        grid-template-columns: 1fr;
    }

    .qpm-metrics {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 660px) {
    .qpm-header {
        flex-direction: column;
    }

    .qpm-badge {
        align-self: stretch;
        flex-direction: row;
        justify-content: center;
        gap: 0.45rem;
    }

    .qpm-metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .qpm-panel-heading {
        flex-direction: column;
    }

    .qpm-matrix-grid {
        grid-template-columns: repeat(2, minmax(80px, 1fr));
    }

    .qpm-bracket {
        font-size: 4.8rem;
    }

    .qpm-canvas-wrap canvas {
        height: 330px;
    }
}

@media (max-width: 420px) {
    .qpm-shell {
        border-radius: 20px;
        padding: 0.8rem;
    }

    .qpm-metrics {
        grid-template-columns: 1fr;
    }

    .qpm-presets,
    .qpm-actions {
        flex-direction: column;
    }

    .qpm-raw button {
        width: 100%;
    }

    .qpm-matrix-grid output {
        font-size: 0.68rem;
        min-height: 56px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .qpm-raw *,
    .qpm-raw *::before,
    .qpm-raw *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.001ms !important;
    }
}
