:root {
    color-scheme: dark light;
    --radius: 8px;
    --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-theme="dark"] {
    color-scheme: dark;
    --bg: #101011;
    --surface: #18191b;
    --surface2: #222326;
    --surface3: #2d2f33;
    --border: #3a3d42;
    --border-strong: #676c74;
    --accent: #2aa198;
    --accent2: #cc6677;
    --accent-soft: rgba(42, 161, 152, 0.18);
    --text: #f4f4f2;
    --text-dim: #c9cbc7;
    --text-soft: #969a9f;
    --shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
    --chart-bg: #121315;
    --grid: #33363a;
    --axis: #f4f4f2;
    --metric-a: #d55e00;
    --metric-t: #56b4e9;
    --metric-r: #009e73;
    --field-main: #cc79a7;
    --field-s: #56b4e9;
    --field-p: #f0e442;
    --layer-boundary: #b7bab6;
    --incident-boundary: #b7bab6;
    --substrate-boundary: #8b5cf6;
    --danger: #d55e00;
    --warning: #e69f00;
    --success: #009e73;
    --select-active: #2aa198;
    --select-active-text: #ffffff;
}

body[data-theme="light"] {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface2: #edf0f2;
    --surface3: #dde4e7;
    --border: #d0d5d8;
    --border-strong: #8b969d;
    --accent: #007f79;
    --accent2: #cc6677;
    --accent-soft: rgba(0, 127, 121, 0.12);
    --text: #171716;
    --text-dim: #50575a;
    --text-soft: #717a80;
    --shadow: 0 12px 28px rgba(17, 17, 17, 0.07);
    --chart-bg: #ffffff;
    --grid: #d7dde0;
    --axis: #171716;
    --metric-a: #d55e00;
    --metric-t: #0072b2;
    --metric-r: #009e73;
    --field-main: #cc79a7;
    --field-s: #0072b2;
    --field-p: #8f7600;
    --layer-boundary: #687179;
    --incident-boundary: #687179;
    --substrate-boundary: #5b45c6;
    --danger: #d55e00;
    --warning: #e69f00;
    --success: #009e73;
    --select-active: #007f79;
    --select-active-text: #ffffff;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    padding: 10px;
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text);
}

body.dialog-open {
    overflow: hidden;
    overscroll-behavior: contain;
}

.app-shell {
    max-width: 1520px;
    margin: 0 auto;
    width: 100%;
}

.skip-link {
    position: absolute;
    top: 4px;
    left: 4px;
    z-index: 100;
    padding: 6px 10px;
    border-radius: 6px;
    background: var(--accent);
    color: var(--select-active-text, #ffffff);
    font-size: 0.78rem;
    font-weight: 700;
    text-decoration: none;
    transform: translateY(-150%);
    transition: transform 0.12s ease;
}
.skip-link:focus {
    transform: translateY(0);
    outline: 2px solid var(--text);
    outline-offset: 2px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 10px;
    padding: 4px 2px;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    color: inherit;
    text-decoration: none;
    border-radius: 12px;
}
.app-brand:hover .app-title,
.app-brand:focus-visible .app-title {
    color: var(--accent);
}
.app-brand:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
}
.app-title {
    transition: color 0.12s ease;
}

.app-icon {
    width: 42px;
    height: 42px;
    display: block;
    flex: 0 0 auto;
    border-radius: 12px;
    box-shadow: 0 10px 22px rgba(16, 16, 17, 0.16);
}

.app-brand-copy {
    min-width: 0;
}

.app-title {
    margin: 0;
    color: var(--text);
    font-size: 0.94rem;
    font-weight: 750;
    letter-spacing: 0;
}

.app-subtitle {
    margin-top: 2px;
    color: var(--text-soft);
    font-size: 0.74rem;
}

.deployment-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 5px;
    color: var(--text-soft);
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.2;
}

.deployment-status-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-radius: 999px;
    background: var(--success);
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 46%, transparent);
    animation: service-pulse 3.2s ease-in-out infinite;
}

.deployment-status.is-warning .deployment-status-dot {
    background: var(--warning);
    box-shadow: none;
    animation: none;
}

.deployment-status.is-offline .deployment-status-dot {
    background: var(--danger);
    box-shadow: none;
    animation: none;
}

@keyframes service-pulse {
    0%,
    100% {
        opacity: 0.55;
        box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 42%, transparent);
    }
    50% {
        opacity: 1;
        box-shadow: 0 0 0 6px color-mix(in srgb, var(--success) 0%, transparent);
    }
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.nav-link,
.feedback-btn,
.theme-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 34px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-dim);
    font-size: 1rem;
    font-weight: 750;
    text-decoration: none;
    cursor: pointer;
    box-shadow: var(--shadow);
}

.nav-link {
    width: auto;
    min-width: 38px;
    padding: 0 11px;
    font-size: 0.72rem;
    letter-spacing: 0;
}

.nav-link[aria-current="page"] {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.feedback-btn {
    font-size: 1.24rem;
    line-height: 1;
}

.nav-link:hover,
.feedback-btn:hover,
.theme-switch:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.nav-link:focus-visible,
.feedback-btn:focus-visible,
.theme-switch:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.tutorial-menu {
    position: relative;
    display: inline-flex;
}

.tutorial-menu summary {
    list-style: none;
}

.tutorial-menu summary::-webkit-details-marker {
    display: none;
}

.tutorial-menu[open] summary {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.tutorial-menu-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 30;
    display: grid;
    gap: 4px;
    min-width: 236px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.tutorial-menu-dropdown .nav-link {
    width: 100%;
    justify-content: flex-start;
    box-shadow: none;
}

.feedback-btn::after,
.theme-switch::after {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 20;
    min-width: max-content;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.72rem;
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-3px);
    transition: opacity 0.08s ease, transform 0.08s ease;
    box-shadow: var(--shadow);
}

.feedback-btn:hover::after,
.feedback-btn:focus-visible::after,
.theme-switch:hover::after,
.theme-switch:focus-visible::after {
    opacity: 1;
    transform: translateY(0);
}

.theme-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.theme-icon::before {
    content: "☾";
    color: currentColor;
    font-size: 1.05rem;
    line-height: 1;
}

body[data-theme="light"] .theme-icon::before {
    content: "☀";
}

.layout {
    display: grid;
    grid-template-columns: minmax(792px, 1.485fr) minmax(478px, 1.065fr);
    gap: 14px;
    align-items: start;
}

.section-band {
    display: grid;
    gap: 8px;
    padding: 10px;
    border-left: 2px solid var(--section-accent);
    min-width: 0;
}

.section-heading {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--section-accent);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.section-heading > span {
    flex: 0 0 auto;
}

.share-results-btn {
    position: relative;
    flex: 0 0 auto;
    min-height: 24px;
    padding: 3px 9px;
    border: 1px solid color-mix(in srgb, var(--section-accent) 70%, var(--border));
    border-radius: 7px;
    background: transparent;
    color: var(--section-accent);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: none;
}

.share-results-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 0;
    top: calc(100% + 7px);
    z-index: 80;
    width: min(280px, 72vw);
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.35;
    text-align: left;
    text-transform: none;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-2px);
    transition: opacity 0.06s ease, transform 0.06s ease;
    box-shadow: var(--shadow);
}

.share-results-btn:hover:not(:disabled),
.share-results-btn:focus-visible:not(:disabled) {
    background: color-mix(in srgb, var(--section-accent) 18%, transparent);
    color: var(--text);
}

.share-results-btn:hover:not(:disabled)::after,
.share-results-btn:focus-visible:not(:disabled)::after {
    opacity: 1;
    transform: translateY(0);
}

.share-results-btn:disabled {
    cursor: progress;
    opacity: 0.64;
}

.share-copy-status {
    flex: 0 0 auto;
    min-height: 1.2em;
    color: var(--success);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: none;
}

.share-copy-status.error {
    color: var(--danger);
}

.share-copy-status:empty {
    display: none;
}

.section-heading::after {
    content: "";
    height: 1px;
    flex: 1;
    background: linear-gradient(90deg, var(--section-accent), transparent);
    opacity: 0.65;
}

.setup-band {
    --section-accent: var(--accent);
    background: transparent;
}

.results-band {
    --section-accent: var(--metric-r);
    background: transparent;
}

.about-band {
    --section-accent: var(--accent2);
    margin-top: 16px;
    background: transparent;
}

.parameters,
.results-grid {
    display: grid;
    gap: 12px;
    align-items: start;
    min-width: 0;
}

.parameters {
    grid-template-columns: minmax(0, 1fr);
}

.setup-mode-toggle {
    display: inline-grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 3px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface2);
    flex: 0 0 auto;
}

.setup-mode-btn {
    min-width: 58px;
    min-height: 24px;
    padding: 0 9px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-dim);
    font-size: 0.68rem;
    font-weight: 800;
    line-height: 1;
    text-transform: none;
}

.setup-mode-btn.is-active {
    background: var(--accent);
    color: #ffffff;
    box-shadow: var(--shadow);
}

.results-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
}

.simulation-panel,
.stack-panel,
.sweeps-panel {
    grid-column: 1;
    grid-row: auto;
}

.simulation-panel {
    order: 1;
}

.stack-panel {
    order: 2;
}

.sweeps-panel {
    order: 3;
}

.panel {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 2px solid var(--section-accent, var(--border));
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow);
}

.panel-title {
    margin-bottom: 9px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
    color: var(--accent);
}

.about-panel {
    display: grid;
    gap: 14px;
}

.about-lede {
    width: 100%;
    max-width: none;
    margin: 0;
    color: var(--text);
    font-size: 0.9rem;
    line-height: 1.55;
}

.about-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) minmax(0, 0.9fr);
    gap: 12px;
}

.about-item {
    min-width: 0;
}

.about-item h3 {
    margin: 0 0 6px;
    color: var(--text);
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.about-item p,
.about-list {
    margin: 0;
    color: var(--text-dim);
    font-size: 0.78rem;
    line-height: 1.5;
}

.about-list {
    padding-left: 18px;
}

.about-list li + li {
    margin-top: 4px;
}

.about-item p + p {
    margin-top: 8px;
}

.about-panel a {
    color: var(--accent);
    font-weight: 750;
    text-decoration: none;
}

.about-panel a:hover {
    text-decoration: underline;
}

.about-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.about-links a {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface2);
    color: var(--text);
    font-size: 0.74rem;
}

.ctrl-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.simulation-panel .ctrl-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.ctrl-grid .span-2 {
    grid-column: 1 / -1;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 28px;
    color: var(--text-dim);
    font-size: 0.78rem;
    font-weight: 700;
}

.toggle-row input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--accent);
}

label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0;
    color: var(--text-dim);
    margin-bottom: 2px;
}

input[type="email"],
input[type="number"],
input[type="text"],
select,
textarea {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 5px 8px;
    font-size: 0.8rem;
    outline: none;
    transition: border-color 0.16s ease, background 0.16s ease;
}

input[type="file"] {
    width: 100%;
    color: var(--text-dim);
    font-size: 0.8rem;
    font-weight: 650;
}

select {
    min-width: 0;
}

.native-select-hidden {
    position: absolute;
    width: 1px !important;
    height: 1px !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    margin: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

.custom-select {
    position: relative;
    width: 100%;
    min-width: 0;
}

.custom-select-button {
    width: 100%;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface2);
    color: var(--text);
    font-size: 0.8rem;
    text-align: left;
}

.custom-select-button-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.select-layer-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.select-layer-label-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.select-layer-badge {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    color: #fff;
    font-size: 0.62rem;
    font-weight: 800;
    flex: 0 0 auto;
}

.custom-select-button::after {
    content: "";
    width: 7px;
    height: 7px;
    flex: 0 0 auto;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
    opacity: 0.72;
}

.custom-select.is-open .custom-select-button {
    border-color: var(--accent);
    background: var(--surface3);
}

.custom-select.is-disabled .custom-select-button {
    cursor: not-allowed;
    color: var(--text-soft);
    opacity: 0.74;
}

.custom-select-menu {
    position: fixed;
    z-index: 120;
    top: 0;
    left: 0;
    width: var(--custom-select-width, 220px);
    max-width: calc(100vw - 16px);
    max-height: min(360px, 48vh);
    padding: 5px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: color-mix(in srgb, var(--surface) 96%, var(--bg));
    box-shadow: var(--shadow);
    overflow: auto;
}

.custom-select-menu[hidden] {
    display: none;
}

.custom-select-option,
.custom-select-divider {
    min-height: 30px;
    display: flex;
    align-items: center;
    border-radius: 6px;
}

.custom-select-option {
    width: 100%;
    padding: 6px 8px;
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 650;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.custom-select-option:hover,
.custom-select-option.is-active {
    background: var(--accent-soft);
    color: var(--text);
}

.custom-select-option[data-tooltip] {
    position: relative;
}

.custom-select-option.is-selected {
    background: var(--select-active);
    color: var(--select-active-text);
}

.custom-select-divider {
    padding: 8px 8px 4px;
    color: var(--text-soft);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0;
}

.custom-select-template-action {
    width: 100%;
    min-height: 30px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 6px 8px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-dim);
    font-size: 0.78rem;
    font-weight: 750;
    text-align: left;
}

.custom-select-template-action:hover,
.custom-select-template-action:focus-visible {
    background: var(--accent-soft);
    color: var(--accent);
}

textarea {
    min-height: 120px;
    resize: vertical;
    font-family: "SFMono-Regular", Consolas, monospace;
    line-height: 1.4;
}

input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    background: var(--surface3);
}

input:disabled,
select:disabled {
    cursor: not-allowed;
    color: var(--text-soft);
    opacity: 0.86;
}

button {
    font: inherit;
    border: 1px solid var(--border);
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ghost-btn {
    padding: 8px 12px;
    background: transparent;
    color: var(--text-dim);
    font-size: 0.8rem;
    font-weight: 700;
}

.ghost-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.run-btn {
    padding: 9px 14px;
    border: 0;
    background: var(--accent);
    color: white;
    font-size: 0.84rem;
    font-weight: 700;
    box-shadow: none;
}

.run-btn:hover:not(:disabled) {
    opacity: 0.92;
}

.run-btn:disabled,
.ghost-btn:disabled,
.icon-btn:disabled {
    cursor: progress;
    opacity: 0.58;
}

.stack-strip {
    display: flex;
    width: 100%;
    min-width: 0;
    height: 26px;
    margin-bottom: 9px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface2);
}

.stack-strip-segment {
    position: relative;
    isolation: isolate;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    padding: 0 10px;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0;
    color: rgba(255, 255, 255, 0.88);
    overflow: hidden;
    white-space: nowrap;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.stack-strip-label {
    position: relative;
    z-index: 2;
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.16);
}

.stack-strip-segment.is-truncated {
    padding-inline: 12px;
}

.stack-strip-segment.is-truncated .stack-strip-label {
    max-width: 100%;
    text-align: center;
}

.stack-strip-segment.is-roughness {
    background:
        repeating-linear-gradient(
            135deg,
            var(--roughness-top-color, rgba(255, 255, 255, 0.38)) 0,
            var(--roughness-top-color, rgba(255, 255, 255, 0.38)) var(--roughness-top-width, 4px),
            var(--roughness-bottom-color, rgba(0, 0, 0, 0.18)) var(--roughness-top-width, 4px),
            var(--roughness-bottom-color, rgba(0, 0, 0, 0.18)) var(--roughness-period, 10px)
        ),
        var(--roughness-base-color, transparent) !important;
}

.stack-strip-segment.is-roughness::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(0, 0, 0, 0.14));
    opacity: 0.48;
    pointer-events: none;
}

.stack-strip.is-dense .stack-strip-segment {
    padding-inline: 8px;
    font-size: 0.56rem;
}

.stack-strip.is-dense .stack-strip-segment.is-truncated .stack-strip-label {
    max-width: 100%;
}

.stack-mode-summary {
    min-height: 1.2em;
    margin: -2px 0 8px;
    color: var(--text-soft);
    font-size: 0.72rem;
}

.stack-options {
    display: grid;
    grid-template-columns: minmax(160px, 1fr);
    gap: 10px;
    align-items: end;
    margin-bottom: 10px;
}

.table-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin: 0;
    color: var(--text-dim);
    font-size: 0.64rem;
    font-weight: 800;
    letter-spacing: 0;
    white-space: nowrap;
}

.table-toggle input {
    width: 15px;
    height: 15px;
    margin: 0;
    accent-color: var(--accent);
}

.row-nk-toggle {
    min-height: 28px;
}

.nk-panel[hidden] {
    display: none;
}

.nk-panel {
    margin-top: 12px;
    box-shadow: none;
}

.nk-summary {
    color: var(--text-soft);
    font-size: 0.8rem;
}

.nk-row-heading {
    grid-column: 1 / -1;
    margin: 2px 0 8px;
    color: var(--text-soft);
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.35;
}

.nk-row-heading strong {
    color: var(--text-strong);
    font-weight: 850;
}

.nk-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.nk-chart-card {
    min-width: 0;
}

.nk-chart {
    display: block;
    width: 100%;
    height: auto;
    cursor: crosshair;
}

.chart-frame {
    position: relative;
}

.plot-export-controls {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 4;
    display: inline-flex;
    gap: 5px;
    opacity: 0;
    pointer-events: none;
}

.plot-save-btn {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    color: var(--text);
    font-size: 1rem;
    box-shadow: var(--shadow);
}

.plot-save-btn svg {
    width: 17px;
    height: 17px;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chart-frame:hover .plot-export-controls,
.chart-frame:focus-within .plot-export-controls {
    opacity: 1;
    pointer-events: auto;
}

.plot-save-btn:hover:not(:disabled) {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
}

.plot-save-btn:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.stack-table {
    --stack-row-min-width: 0px;
    --stack-row-grid: 26px minmax(108px, 0.9fr) minmax(136px, 1.06fr) minmax(50px, 0.48fr) minmax(50px, 0.48fr) minmax(84px, 0.72fr) minmax(70px, 0.58fr) minmax(64px, 0.54fr) 28px 28px 28px;
    --pair-marker-width: 54px;
    --stack-control-height: 28px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.stack-table.is-bragg-mode {
    padding-left: var(--pair-marker-width);
}

.stack-hdr,
.stack-row {
    display: grid;
    min-width: var(--stack-row-min-width);
    grid-template-columns: var(--stack-row-grid);
    gap: 4px;
    align-items: center;
}

.stack-hdr > *,
.stack-row > * {
    min-width: 0;
}

.stack-hdr {
    position: relative;
    padding: 6px 2px;
    margin-bottom: 7px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: color-mix(in srgb, var(--surface2) 86%, var(--surface));
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: none;
    color: var(--text-soft);
}

.stack-table.is-bragg-mode .stack-hdr::before {
    content: "#";
    position: absolute;
    top: -1px;
    bottom: -1px;
    left: calc(-1 * var(--pair-marker-width));
    width: var(--pair-marker-width);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-right: 0;
    border-radius: 10px 0 0 10px;
    background: color-mix(in srgb, var(--surface2) 86%, var(--surface));
    color: var(--text-soft);
    font-size: inherit;
    font-weight: 800;
}

.stack-table.is-bragg-mode .stack-hdr {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.stack-hdr > span,
.stack-hdr > label {
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.stack-hdr [data-tooltip] {
    position: relative;
}

.stack-hdr [data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 50%;
    top: calc(100% + 6px);
    z-index: 80;
    width: min(360px, 74vw);
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.35;
    text-align: left;
    text-transform: none;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -2px);
    transition: opacity 0.06s ease, transform 0.06s ease;
    box-shadow: var(--shadow);
}

.stack-hdr [data-tooltip]:hover::after,
.stack-hdr [data-tooltip]:focus-visible::after {
    opacity: 1;
    transform: translate(-50%, 0);
}

.stack-hdr .symbol-label {
    justify-content: center;
    letter-spacing: 0;
    text-transform: none;
}

.stack-hdr .thickness-label {
    white-space: nowrap;
}

.stack-hdr .table-toggle {
    font-size: inherit;
    text-transform: none;
    justify-content: center;
    padding-left: 0;
}

.stack-row {
    margin-bottom: 3px;
    border-radius: 8px;
    transition: background 0.16s ease, box-shadow 0.16s ease;
}

.stack-row:hover,
.stack-row:focus-within {
    background: color-mix(in srgb, var(--accent-soft) 54%, transparent);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent);
}

.stack-pair-group {
    display: grid;
    width: calc(100% + var(--pair-marker-width));
    min-width: var(--pair-marker-width);
    grid-template-columns: var(--pair-marker-width) minmax(0, 1fr);
    gap: 0;
    align-items: stretch;
    position: relative;
    margin: 0 0 3px calc(-1 * var(--pair-marker-width));
    padding: 0;
    border-radius: 0;
    background: transparent;
}

.stack-pair-group::before {
    content: "";
    position: absolute;
    inset: -2px 0;
    z-index: 0;
    border: 1px solid transparent;
    border-radius: 8px;
    background: color-mix(in srgb, var(--accent-soft) 54%, transparent);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.16s ease, border-color 0.16s ease;
}

.stack-pair-group:hover::before,
.stack-pair-group:focus-within::before {
    border-color: color-mix(in srgb, var(--accent) 28%, transparent);
    opacity: 1;
}

.stack-pair-group .stack-row:hover,
.stack-pair-group:hover .stack-row,
.stack-pair-group:focus-within .stack-row {
    background: transparent;
    box-shadow: none;
}

.stack-pair-brace {
    grid-column: 1;
    grid-row: 1;
    align-self: stretch;
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 2px;
    color: var(--accent);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 3.05rem;
    line-height: 0.9;
    opacity: 0.95;
    pointer-events: none;
}

.stack-pair-repeat-cell {
    grid-column: 1;
    grid-row: 1;
    align-self: center;
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-left: 0;
    padding-right: 6px;
}

.stack-pair-repeat {
    width: 100%;
    height: var(--stack-control-height);
    min-height: var(--stack-control-height);
    padding: 4px 7px;
    text-align: left;
    font-weight: 400;
    font-size: 0.76rem;
}

.stack-pair-rows {
    grid-column: 2;
    grid-row: 1;
    position: relative;
    z-index: 1;
    display: grid;
    gap: 3px;
}

.stack-pair-rows .stack-row {
    width: 100%;
    min-width: var(--stack-row-min-width);
    margin-bottom: 0;
}

.stack-pair-controls {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
    justify-self: end;
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(3, 28px);
    gap: 4px;
    align-items: center;
    align-content: center;
    justify-content: end;
    justify-items: start;
    margin-top: 0;
}

.stack-pair-controls .icon-btn {
    background: color-mix(in srgb, var(--surface) 88%, transparent);
}

.layer-badge {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 0.62rem;
    font-weight: 800;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.layer-name,
.layer-static,
.material-static {
    height: 28px;
    display: flex;
    align-items: center;
    border-radius: 6px;
}

.layer-name.fixed,
.layer-static {
    padding: 0 9px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.76rem;
    font-weight: 600;
}

.layer-name input,
.layer-static input {
    height: 100%;
}

.layer-name-field {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 5px;
}

.layer-name-field input {
    min-width: 0;
    flex: 1;
}

.coherence-switch,
.coherence-static {
    width: 100%;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 0.64rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: lowercase;
    white-space: nowrap;
}

.coherence-switch {
    position: relative;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text-dim);
    cursor: pointer;
    transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.coherence-switch:hover,
.coherence-switch:focus-within {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.coherence-switch input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.coherence-switch.is-coherent {
    color: var(--accent);
}

.coherence-switch.is-incoherent {
    color: var(--text-dim);
}

.coherence-static {
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text-soft);
}

.layer-static,
.material-static {
    justify-content: center;
    font-size: 0.74rem;
    letter-spacing: 0;
}

.material-cell {
    min-width: 0;
    display: flex;
    align-items: center;
}

.material-source-select {
    width: 100%;
    min-width: 0;
    height: var(--stack-control-height);
    padding: 4px 7px;
    background: var(--surface2);
    color: var(--text-dim);
    font-size: 0.72rem;
    font-weight: 700;
}

.material-source-select.has-material {
    border-color: rgba(25, 184, 154, 0.62);
    background: rgba(25, 184, 154, 0.09);
    color: #44d2b6;
}

.material-source-select.has-roughness {
    border-color: rgba(25, 184, 154, 0.62);
    background: rgba(25, 184, 154, 0.09);
    color: #44d2b6;
}

.custom-select.has-material .custom-select-button {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 750;
}

.custom-select.has-roughness .custom-select-button {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 750;
}

.custom-select.is-material-source.is-open {
    z-index: 3;
}

.roughness-nk-static {
    width: 100%;
    height: var(--stack-control-height);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface2);
    color: var(--text-dim);
    font-size: 0.72rem;
    font-weight: 800;
    white-space: nowrap;
}

.material-dialog[hidden] {
    display: none;
}

.material-dialog {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.material-dialog-backdrop {
    position: absolute;
    inset: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(8, 10, 15, 0.76);
}

.material-dialog-panel {
    position: relative;
    width: min(980px, 100%);
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 20px 56px rgba(0, 0, 0, 0.48);
}

#oscillator-dialog .material-dialog-panel {
    width: min(1180px, 100%);
    max-height: calc(100vh - 36px);
    margin: 0 auto;
    overflow: auto;
}

#oscillator-dialog {
    align-items: center;
}

.material-dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.material-dialog-title {
    margin-bottom: 0;
    letter-spacing: 0;
    text-transform: none;
}

.material-dialog-close {
    flex: 0 0 auto;
}

.feedback-dialog-panel {
    width: min(560px, 100%);
}

.roughness-dialog-panel {
    width: min(520px, 100%);
}

.roughness-editor {
    display: grid;
    gap: 12px;
}

.roughness-neighbor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.roughness-neighbor-card {
    display: grid;
    gap: 4px;
    min-width: 0;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface2);
}

.roughness-neighbor-card span:first-child {
    color: var(--text-soft);
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
}

.roughness-neighbor-card span:last-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 800;
}

.roughness-fraction-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.roughness-fraction-card {
    display: grid;
    gap: 6px;
    min-width: 0;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface2);
}

.roughness-fraction-card label {
    margin: 0;
    color: var(--text-soft);
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
}

.roughness-fraction-control {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
}

.roughness-fraction-control input {
    height: 34px;
    min-width: 0;
    font-size: 1rem;
    font-weight: 800;
}

.roughness-fraction-control span {
    color: var(--text-soft);
    font-weight: 800;
}

.roughness-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.roughness-model-note {
    color: var(--text-soft);
    font-size: 0.76rem;
    font-weight: 700;
    line-height: 1.35;
}

.feedback-form {
    display: grid;
    gap: 10px;
}

.required-mark {
    color: var(--danger);
    font-weight: 850;
}

.feedback-form textarea {
    min-height: 140px;
}

.feedback-form input[type="email"] {
    height: 28px;
}

.feedback-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.feedback-actions .ghost-btn,
.feedback-actions .run-btn {
    min-width: 112px;
    height: 38px;
}

.feedback-note.error {
    color: var(--danger);
}

.feedback-note.success {
    color: var(--success);
}

.material-picker {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.35fr);
    gap: 10px;
    align-items: end;
}

.material-picker-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.material-picker .span-3 {
    grid-column: 1 / -1;
}

.material-picker-actions .run-btn {
    min-width: 160px;
    height: 38px;
}

.material-note {
    grid-column: 1 / -1;
    min-height: 1.2em;
    margin-top: 0;
    color: var(--text-soft);
    font-size: 0.74rem;
}

.oscillator-editor {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
}

.oscillator-main-grid {
    display: grid;
    grid-template-columns: minmax(620px, 1fr) minmax(360px, 430px);
    gap: 12px;
    align-items: start;
}

.oscillator-config-column {
    min-width: 0;
    display: grid;
    gap: 10px;
}

.oscillator-equation {
    min-height: 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--chart-bg);
    color: var(--text);
    overflow: hidden;
}

.oscillator-equation-stack {
    display: grid;
    gap: 8px;
}

.oscillator-equation-primary {
    overflow: hidden;
}

.oscillator-equation-caption {
    color: var(--text-soft);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.oscillator-equation mjx-container {
    margin: 0 !important;
    max-width: 100%;
    overflow: visible !important;
    font-size: clamp(76%, 1.55vw, 96%) !important;
}

.oscillator-preview-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.oscillator-preview-card {
    min-width: 0;
    display: grid;
    gap: 7px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
}

#oscillator-dialog .chart-frame {
    width: 100%;
    background: var(--chart-bg);
}

#oscillator-dialog .nk-chart {
    height: auto;
    aspect-ratio: 860 / 420;
}

#oscillator-dialog .hover-readout {
    min-height: 30px;
    margin-top: 5px;
    font-size: 0.72rem;
}

.oscillator-preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.oscillator-preview-title {
    color: var(--text-dim);
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: none;
}

.oscillator-preview-legend {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.oscillator-legend-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-soft);
    font-size: 0.72rem;
    font-weight: 700;
}

.oscillator-legend-swatch {
    width: 10px;
    height: 10px;
    border-radius: 999px;
}

.oscillator-legend-swatch.eps-re {
    background: var(--metric-t);
}

.oscillator-legend-swatch.eps-im {
    background: var(--accent2);
}

.oscillator-legend-swatch.n {
    background: var(--metric-r);
}

.oscillator-legend-swatch.k {
    background: var(--metric-a);
}

.oscillator-terms-panel {
    display: grid;
    gap: 8px;
    min-height: 0;
    max-height: min(34vh, 360px);
    overflow: auto;
    padding-right: 2px;
}

.oscillator-terms-panel:empty {
    display: none;
}

.oscillator-term {
    display: grid;
    gap: 8px;
    padding: 9px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface2);
}

.oscillator-term-pending {
    border-style: dashed;
}

.oscillator-term-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    color: var(--text-soft);
    font-size: 0.76rem;
    font-weight: 700;
}

.oscillator-term-controls {
    display: flex;
    align-items: end;
    justify-content: end;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1 1 auto;
}

.oscillator-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
}

.oscillator-picker-field {
    min-width: 0;
}

.oscillator-picker-count {
    max-width: 160px;
}

.oscillator-param-table-wrap {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.oscillator-param-table {
    width: 100%;
    min-width: max(100%, var(--oscillator-param-min-width, 0px));
    border-collapse: collapse;
    table-layout: fixed;
}

.oscillator-param-table th,
.oscillator-param-table td {
    padding: 5px 5px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.oscillator-param-table th {
    color: var(--text-dim);
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: none;
    white-space: nowrap;
    vertical-align: bottom;
}

.oscillator-param-table th:not(:first-child) {
    min-width: 0;
}

.oscillator-param-table th:first-child {
    width: 44px;
}

.oscillator-param-table td:first-child {
    width: 44px;
    color: var(--text-soft);
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
}

.oscillator-param-table tr:last-child td {
    border-bottom: 0;
}

.oscillator-param-table input {
    width: 100%;
    min-width: 0;
    height: 28px;
}

.oscillator-param-header {
    display: inline-flex;
    align-items: baseline;
    flex-wrap: nowrap;
    gap: 3px;
    line-height: 1.2;
    white-space: nowrap;
}

.oscillator-param-symbol {
    display: inline-flex;
    flex: 0 0 auto;
}

.oscillator-param-unit {
    display: inline-flex;
    flex: 0 0 auto;
    color: var(--text-soft);
    font-size: 0.58rem;
    font-weight: 700;
    text-transform: none;
}

.oscillator-param-hint {
    display: inline-flex;
    flex: 0 1 auto;
    color: var(--text-soft);
    font-size: 0.56rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}

.oscillator-term-note {
    color: var(--text-soft);
    font-size: 0.7rem;
    line-height: 1.35;
}

.oscillator-term-note:empty {
    display: none;
}

.oscillator-preview-controls {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 10px;
}

.oscillator-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-top: 8px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.oscillator-footer-actions {
    display: flex;
    align-items: end;
    justify-content: flex-end;
    gap: 8px;
    margin-left: auto;
}

.oscillator-reset-btn {
    color: var(--text-dim);
}

.oscillator-reset-btn:hover:not(:disabled) {
    border-color: var(--danger);
    background: color-mix(in srgb, var(--danger) 14%, transparent);
    color: var(--danger);
}

.oscillator-footer-start {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.oscillator-inline-field {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text-soft);
    font-size: 0.76rem;
    font-weight: 700;
    white-space: nowrap;
}

.oscillator-inline-field input {
    width: 148px;
    min-width: 0;
}

#oscillator-note {
    flex: 1 1 auto;
    min-height: 1.2em;
    margin-top: 0;
}

.oscillator-footer > #add-oscillator-term {
    flex: 0 0 auto;
}

.oscillator-footer .ghost-btn {
    min-width: 104px;
}

.oscillator-footer .run-btn {
    min-width: 132px;
    height: 36px;
}

.stack-row input {
    padding: 4px 7px;
    font-size: 0.76rem;
}

.stack-row input[type="number"],
.stack-row input[type="text"],
.stack-row .custom-select-button,
.layer-name,
.layer-static,
.material-static,
.roughness-nk-static,
.coherence-switch,
.coherence-static,
.row-nk-toggle {
    height: var(--stack-control-height);
    min-height: var(--stack-control-height);
}

.stack-row .custom-select-button {
    padding: 4px 7px;
    color: var(--text-dim);
    font-size: 0.72rem;
    font-weight: 700;
}

.icon-btn {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-dim);
    font-size: 0.8rem;
}

.icon-btn:hover:not(:disabled) {
    background: var(--surface3);
    color: var(--text);
}

.icon-btn.del:hover:not(:disabled) {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.stack-actions {
    display: flex;
    gap: 8px;
    margin-top: 9px;
}

.stack-actions.has-pair-button .ghost-btn {
    flex: 1;
}

.stack-actions .ghost-btn,
.stack-actions .run-btn {
    flex: 1;
}

.status-region {
    margin-top: 10px;
    display: grid;
    gap: 8px;
}

.status {
    min-height: 1.2em;
    font-size: 0.76rem;
    color: var(--text-dim);
}

.status.success {
    color: var(--success);
}

.status.error {
    color: var(--danger);
}

.status.warning {
    color: var(--warning);
}

.progress-track {
    position: relative;
    height: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface2);
}

.progress-bar {
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 54%, white));
    transition: width 0.2s ease;
}

.result-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.result-heading {
    min-width: 0;
    display: grid;
    gap: 4px;
}

.result-head .panel-title {
    margin-bottom: 0;
}

.angle-controls,
.spectra-head-controls,
.polarization-tabs,
.angle-metric-tabs,
.angle-polarization-tabs,
.spectra-metric-tabs,
.spectra-x-axis-tabs {
    display: flex;
    gap: 6px;
}

.polarization-tabs,
.angle-metric-tabs,
.angle-polarization-tabs,
.spectra-metric-tabs,
.spectra-x-axis-tabs {
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface2);
}

.angle-controls,
.spectra-head-controls {
    margin-left: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
}

.spectra-x-axis-tabs[hidden] {
    display: none;
}

.polarization-tab,
.angle-metric-tab,
.angle-polarization-tab,
.spectra-metric-tab,
.spectra-x-axis-tab {
    min-width: 44px;
    padding: 6px 12px;
    background: transparent;
    color: var(--text-dim);
    font-size: 0.76rem;
    font-weight: 700;
}

.polarization-tab.active,
.angle-metric-tab.active,
.angle-polarization-tab.active,
.spectra-metric-tab.active,
.spectra-x-axis-tab.active {
    background: var(--surface);
    border-color: var(--accent);
    color: var(--text);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 32%, transparent);
}

.spectra-metric-tab[hidden] {
    display: none;
}

.chart-frame {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface2);
}

#metric-chart,
#layer-chart,
#n-chart,
#k-chart,
.angle-heatmap {
    display: block;
    width: 100%;
    height: auto;
    cursor: crosshair;
}

.heatmap-stack {
    display: grid;
    gap: 0;
}

.heatmap-panel {
    min-width: 0;
    padding: 10px 0 0;
    border-top: 1px solid var(--border);
}

.heatmap-panel:first-child {
    padding-top: 0;
    border-top: 0;
}

.heatmap-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px 0;
    color: var(--text-dim);
    font-size: 0.74rem;
    font-weight: 700;
}

.heatmap-title {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    color: var(--text);
    font-weight: 800;
}

.legend-row {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 10px;
    color: var(--text-dim);
    font-size: 0.74rem;
}

.results-grid .legend-row {
    gap: 16px;
    font-size: 0.78rem;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend-line {
    width: 18px;
    height: 3px;
    border-radius: 999px;
}

.results-grid .legend-line {
    width: 22px;
    height: 4px;
}

.hover-readout {
    min-height: 38px;
    margin-top: 10px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--text-dim);
    font-size: 0.78rem;
}

.results-grid .hover-readout {
    min-height: 42px;
    font-size: 0.82rem;
}

.hover-readout .hover-empty {
    color: var(--text-soft);
}

.hover-readout .hover-wavelength,
.hover-readout .hover-value {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 5px 9px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    color: #000000;
    font-weight: 700;
}

.hover-readout .hover-wavelength {
    color: #000000;
}

.hover-swatch {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.summary-note {
    margin-top: 8px;
    color: var(--text-soft);
    font-size: 0.74rem;
}

.selected-angle-label {
    color: var(--text-dim);
    font-size: 0.78rem;
    font-weight: 700;
}

.results-grid .selected-angle-label {
    font-size: 0.82rem;
}

.sweep-stepper-widget {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    vertical-align: middle;
}

.sweep-stepper-controls {
    display: inline-flex;
    flex-direction: column;
    gap: 1px;
    margin-left: 1px;
}

.sweep-stepper-btn {
    padding: 0;
    width: 16px;
    height: 11px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.55rem;
    line-height: 1;
    border-radius: 3px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sweep-stepper-btn:hover:not(:disabled) {
    background: var(--surface);
    color: var(--text);
    border-color: var(--accent);
}

.sweep-stepper-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#sweep-summary {
    display: none;
}

.option-list {
    display: grid;
    gap: 8px;
}

.option-row {
    display: grid;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.option-row:first-child {
    padding-top: 0;
    border-top: 0;
}

.option-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    align-items: end;
    padding-left: 24px;
}

.option-fields.option-fields-quad {
    grid-template-columns: minmax(148px, 1.2fr) repeat(3, minmax(116px, 1fr));
}

.option-fields .span-2 {
    grid-column: 1 / -1;
}

.option-fields[hidden] {
    display: none;
}

.option-note {
    grid-column: 1 / -1;
    color: var(--text-soft);
    font-size: 0.7rem;
    line-height: 1.35;
}

.sweep-material-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.sweep-material-title {
    color: var(--text-dim);
    font-size: 0.76rem;
    font-weight: 700;
}

.sweep-material-list {
    display: grid;
    gap: 8px;
}

.sweep-material-row {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.1fr) 86px 86px 34px;
    gap: 8px;
    align-items: center;
}

.sweep-material-row input,
.sweep-material-row select {
    min-width: 0;
}

.sweep-material-meta {
    min-height: 1.1em;
    margin-top: 4px;
    color: var(--text-soft);
    font-size: 0.68rem;
}

.sweep-material-empty {
    padding: 10px 12px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    color: var(--text-soft);
    font-size: 0.72rem;
}

.field-panel[hidden],
.color-panel[hidden],
.layer-panel[hidden],
#angle-sweep-panel[hidden] {
    display: none;
}

#field-chart {
    display: block;
    width: 100%;
    height: auto;
    cursor: crosshair;
}

.color-results {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.color-angle-strip {
    display: block;
    width: 100%;
    height: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--chart-bg);
    cursor: crosshair;
}

.appearance-block {
    display: grid;
    grid-template-columns: 104px minmax(0, 1fr);
    gap: 14px 16px;
    align-items: start;
    min-width: 0;
}

.color-swatch {
    width: 104px;
    aspect-ratio: 1;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background:
        linear-gradient(45deg, rgba(0, 0, 0, 0.08) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(0, 0, 0, 0.08) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(0, 0, 0, 0.08) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(0, 0, 0, 0.08) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.code-grid {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.code-row {
    display: grid;
    grid-template-columns: 78px minmax(0, 1fr);
    gap: 10px;
    min-height: 24px;
    align-items: baseline;
    color: var(--text-dim);
    font-size: 0.74rem;
    font-weight: 600;
}

.code-row span:first-child {
    color: inherit;
    font-weight: inherit;
}

.code-value {
    min-width: 0;
    color: inherit;
    font: inherit;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 1320px) {
    .layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 1080px) {
    .parameters,
    .results-grid {
        grid-template-columns: 1fr;
    }

    .oscillator-main-grid {
        grid-template-columns: 1fr;
    }

    .simulation-panel,
    .stack-panel,
    .sweeps-panel {
        grid-column: 1;
        grid-row: auto;
    }

    .simulation-panel {
        order: 1;
    }

    .stack-panel {
        order: 2;
    }

    .sweeps-panel {
        order: 3;
    }
}

@media (max-width: 960px) {
    body {
        padding: 8px;
    }

    .topbar {
        gap: 10px;
    }

    .app-brand {
        gap: 9px;
    }

    .app-icon {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }

    .app-title {
        font-size: 0.86rem;
    }

    .app-subtitle {
        font-size: 0.68rem;
    }

    .nav-link,
    .feedback-btn,
    .theme-switch {
        width: 34px;
        height: 32px;
    }

    .nav-link {
        width: auto;
        min-width: 34px;
        padding: 0 9px;
    }

    .tutorial-menu-dropdown {
        right: auto;
        left: 0;
    }

    .section-band {
        padding: 8px 0;
    }

    .panel {
        padding: 10px;
    }

    .simulation-panel .ctrl-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px;
    }

    .stack-table {
        --stack-row-min-width: 0px;
        --stack-row-grid: 24px minmax(68px, 0.9fr) minmax(96px, 1.05fr) minmax(38px, 0.5fr) minmax(38px, 0.5fr) minmax(68px, 0.72fr) minmax(62px, 0.64fr) minmax(42px, 0.42fr) 24px 24px 24px;
        --pair-marker-width: 50px;
        --stack-control-height: 26px;
        overflow-x: hidden;
        padding-bottom: 0;
    }

    .stack-hdr,
    .stack-row {
        width: 100%;
        min-width: 0;
        gap: 4px;
    }

    .stack-pair-group {
        min-width: 0;
    }

    .stack-hdr {
        padding: 5px 2px;
        font-size: 0.58rem;
    }

    .stack-hdr > span,
    .stack-hdr > label {
        min-height: 22px;
    }

    .stack-hdr .thickness-label {
        white-space: normal;
        line-height: 1.05;
    }

    .table-toggle {
        gap: 3px;
        font-size: 0.58rem;
    }

    .table-toggle input {
        width: 13px;
        height: 13px;
    }

    .layer-badge {
        width: 22px;
        height: 22px;
        border-radius: 5px;
        font-size: 0.56rem;
    }

    .layer-name,
    .layer-static,
    .material-static,
    .roughness-nk-static,
    .material-source-select,
    .stack-row .custom-select-button,
    .coherence-switch,
    .coherence-static {
        height: 26px;
        min-height: 26px;
    }

    .layer-name.fixed,
    .layer-static,
    .material-static,
    .roughness-nk-static,
    .material-source-select,
    .stack-row input {
        padding-inline: 5px;
        font-size: 0.68rem;
    }

    .coherence-switch,
    .coherence-static {
        font-size: 0.58rem;
    }

    .icon-btn {
        width: 24px;
        height: 24px;
        font-size: 0.72rem;
    }

    .stack-pair-repeat {
        width: 100%;
        height: 26px;
        padding: 4px 5px;
        font-size: 0.68rem;
    }

    .stack-pair-brace {
        font-size: 2.65rem;
    }

    .stack-pair-controls {
        grid-template-columns: repeat(3, 24px);
    }
}

@media (max-width: 700px) {
    body {
        padding: 0;
    }

    .app-shell {
        max-width: none;
        margin: 0;
    }

    .topbar {
        margin-bottom: 6px;
        padding: 12px 12px 0;
    }

    .layout {
        gap: 10px;
    }

    .section-band {
        padding: 0 12px 12px;
        border-left: 0;
    }

    .panel {
        padding: 12px;
    }

    .ctrl-grid {
        grid-template-columns: 1fr;
    }

    .simulation-panel .ctrl-grid {
        grid-template-columns: 1fr;
    }

    .option-fields,
    .about-grid,
    .color-results,
    .appearance-block {
        grid-template-columns: 1fr;
    }

    .option-fields.option-fields-quad {
        grid-template-columns: 1fr;
    }

    .sweep-material-row {
        grid-template-columns: 1fr;
    }

    .code-value {
        white-space: normal;
    }

    .about-band {
        margin-top: 10px;
    }

    .stack-options {
        grid-template-columns: 1fr;
    }

    .nk-grid {
        grid-template-columns: 1fr;
    }

    .stack-table {
        display: block;
        overflow-x: auto;
        padding-bottom: 4px;
        --stack-row-min-width: 788px;
        --stack-row-grid: 24px minmax(104px, 1fr) 140px 56px 56px 96px 74px 78px 28px 28px 28px;
        --pair-marker-width: 50px;
        --stack-control-height: 30px;
        -webkit-overflow-scrolling: touch;
    }

    #layers-list {
        display: block;
    }

    .stack-hdr {
        display: grid;
    }

    .stack-hdr,
    .stack-row {
        width: auto;
        min-width: 788px;
    }

    .stack-pair-group {
        min-width: calc(var(--stack-row-min-width) + var(--pair-marker-width));
    }

    .stack-pair-controls {
        grid-template-columns: repeat(3, 28px);
    }

    .layer-name-field input,
    .material-source-select,
    .stack-row input[type="number"],
    .stack-pair-repeat,
    .layer-static,
    .material-static,
    .roughness-nk-static,
    .coherence-switch,
    .coherence-static {
        min-height: 30px;
        height: 30px;
    }

    .layer-name.fixed,
    .layer-static,
    .material-static,
    .roughness-nk-static,
    .material-source-select,
    .stack-row input {
        font-size: 0.74rem;
    }

    .material-source-select.native-select-hidden {
        position: static;
        display: block;
        width: 100% !important;
        min-width: 0 !important;
        height: var(--stack-control-height) !important;
        min-height: var(--stack-control-height) !important;
        padding: 4px 7px !important;
        border: 1px solid var(--border) !important;
        margin: 0;
        overflow: visible;
        opacity: 1;
        pointer-events: auto;
        appearance: auto;
        -webkit-appearance: menulist;
    }

    .material-source-select.native-select-hidden + .custom-select {
        display: none;
    }

    .row-nk-toggle {
        min-height: 30px;
    }

    .row-nk-toggle input {
        flex: 0 0 auto;
    }

    .stack-actions {
        position: sticky;
        bottom: 0;
        z-index: 12;
        margin: 8px -12px -12px;
        padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--border);
        background: color-mix(in srgb, var(--surface) 94%, transparent);
        backdrop-filter: blur(12px);
    }

    .material-picker {
        display: grid;
        grid-template-columns: 1fr;
    }

    .material-picker-actions {
        justify-content: stretch;
    }

    .material-picker-actions .ghost-btn,
    .material-picker-actions .run-btn {
        flex: 1;
        min-width: 0;
    }

    #oscillator-dialog .material-dialog-panel {
        width: 100%;
        max-height: none;
    }

    .oscillator-main-grid {
        grid-template-columns: 1fr;
    }

    .oscillator-equation mjx-container {
        font-size: 62% !important;
    }

    #oscillator-dialog .chart-frame {
        max-height: none;
    }

    #oscillator-dialog .nk-chart {
        height: auto;
    }

    .oscillator-footer-actions {
        margin-left: 0;
    }

    .oscillator-preview-controls,
    .oscillator-footer-start {
        align-items: stretch;
        flex-direction: column;
    }

    .oscillator-inline-field {
        width: 100%;
        justify-content: space-between;
    }

    .oscillator-footer {
        align-items: stretch;
        flex-direction: column;
    }

    .oscillator-footer-actions {
        width: 100%;
    }

    .oscillator-footer-actions .ghost-btn,
    .oscillator-footer-actions .run-btn {
        flex: 1;
        min-width: 0;
    }

    .result-head {
        flex-direction: column;
        align-items: start;
    }
}

@media (max-width: 700px) and (orientation: landscape) {
    .simulation-panel .ctrl-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .stack-table {
        --stack-row-min-width: 0px;
        --stack-row-grid: 24px minmax(68px, 0.85fr) minmax(86px, 1fr) minmax(36px, 0.45fr) minmax(36px, 0.45fr) minmax(64px, 0.65fr) minmax(56px, 0.58fr) minmax(54px, 0.5fr) 24px 24px 24px;
        overflow-x: hidden;
        padding-bottom: 0;
    }

    .stack-hdr,
    .stack-row {
        width: 100%;
        min-width: 0;
    }

    .stack-pair-group {
        min-width: 0;
    }

    .stack-pair-controls {
        grid-template-columns: repeat(3, 24px);
    }

    .stack-hdr > span,
    .stack-hdr > label {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

[data-export-only="true"] {
    display: none;
}
