:root {
    color-scheme: light;
    --panel: #f7f8fb;
    --ink: #18202a;
    --muted: #637083;
    --line: #d9dee8;
    --a: #1d72d2;
    --c: #d33f49;
    --total: #198754;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
}

body {
    font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
    color: var(--ink);
    background: #edf1f6;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(320px, 390px) 1fr;
}

.control-panel {
    background: var(--panel);
    border-right: 1px solid var(--line);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 22px;
    overflow-y: auto;
}

.title-block h1 {
    margin: 0 0 8px;
    font-size: 25px;
    letter-spacing: 0;
}

.title-block p {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
    font-size: 14px;
}

.controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

label {
    display: grid;
    gap: 7px;
    font-size: 13px;
    color: #354052;
}

input {
    width: 100%;
    height: 38px;
    border: 1px solid #cbd3df;
    border-radius: 6px;
    padding: 0 10px;
    font: inherit;
    color: var(--ink);
    background: #fff;
}

input[type="range"] {
    padding: 0;
}

.wide-control {
    grid-column: 1 / -1;
    grid-template-columns: 1fr auto;
    align-items: center;
}

.wide-control input {
    grid-column: 1 / -1;
}

output {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.readout {
    display: grid;
    gap: 10px;
}

.readout div {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 13px 14px;
    display: grid;
    gap: 6px;
}

.readout strong {
    font-size: 14px;
}

.readout span {
    font-size: 19px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.readout small {
    color: var(--muted);
    line-height: 1.45;
}

.readout .result {
    border-color: rgba(25, 135, 84, 0.35);
    box-shadow: inset 4px 0 0 var(--total);
}

.scene-wrap {
    position: relative;
    min-height: 100vh;
    background: radial-gradient(circle at 50% 42%, #ffffff 0, #eef4fb 52%, #dbe4ef 100%);
}

#scene {
    position: absolute;
    inset: 0;
}

.scene-label {
    padding: 5px 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid rgba(188, 198, 211, 0.9);
    color: #1f2937;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    box-shadow: 0 5px 14px rgba(36, 48, 67, 0.13);
}

.label-a {
    color: var(--a);
}

.label-c {
    color: var(--c);
}

.label-total {
    color: var(--total);
}

.label-origin {
    padding: 3px 6px;
    color: #111827;
}

.legend {
    position: absolute;
    left: 22px;
    bottom: 18px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid rgba(190, 199, 212, 0.85);
    border-radius: 8px;
    color: #2f3b4c;
    font-size: 13px;
    backdrop-filter: blur(8px);
}

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

.magnetic-entry {
    position: fixed;
    z-index: 10;
    top: 16px;
    right: 16px;
    padding: 8px 12px;
    border: 1px solid rgba(190, 199, 212, 0.95);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    color: #1d4ed8;
    font-size: 13px;
    text-decoration: none;
    backdrop-filter: blur(8px);
}

.diffraction-entry {
    position: fixed;
    z-index: 10;
    top: 60px;
    right: 16px;
    padding: 8px 12px;
    border: 1px solid rgba(190, 199, 212, 0.95);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    color: #7c3aed;
    font-size: 13px;
    text-decoration: none;
    backdrop-filter: blur(8px);
}

.swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.swatch-a {
    background: var(--a);
}

.swatch-c {
    background: var(--c);
}

.swatch-total {
    background: var(--total);
}

@media (max-width: 850px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .control-panel {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .scene-wrap {
        min-height: 64vh;
    }
}

@media (max-width: 480px) {
    .control-panel {
        padding: 18px;
    }

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

    .title-block h1 {
        font-size: 22px;
    }
}

.field-lab {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(340px, 420px) 1fr;
    background: #e8edf4;
}

.field-panel {
    background: #f8fafc;
    border-right: 1px solid var(--line);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
}

.field-title h1 {
    margin: 8px 0 8px;
    font-size: 25px;
    letter-spacing: 0;
}

.field-title p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.55;
}

.back-link {
    color: #1d4ed8;
    font-size: 13px;
    text-decoration: none;
}

.tool-block {
    display: grid;
    gap: 10px;
}

.tool-block h2 {
    margin: 0;
    font-size: 15px;
}

.block-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.source-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

button {
    height: 36px;
    border: 1px solid #cbd3df;
    border-radius: 6px;
    background: #fff;
    color: #18202a;
    font: inherit;
    cursor: pointer;
}

button:hover {
    border-color: #92a1b7;
    background: #f4f7fb;
}

.ghost-button {
    width: 64px;
    color: #b42318;
}

.source-list {
    display: grid;
    gap: 8px;
    max-height: 180px;
    overflow-y: auto;
}

.source-item {
    display: grid;
    grid-template-columns: 10px 1fr auto;
    align-items: center;
    gap: 9px;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    text-align: left;
}

.source-item.active {
    border-color: #2563eb;
    box-shadow: inset 3px 0 0 #2563eb;
}

.source-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.source-item small {
    color: var(--muted);
}

.inspector-grid,
.probe-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 9px;
}

.inspector-grid label {
    min-width: 0;
}

.inspector-grid .wide-field {
    grid-column: 1 / -1;
}

.field-readout {
    display: grid;
    gap: 9px;
}

.field-readout div {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    display: grid;
    gap: 5px;
}

.field-readout strong {
    font-size: 13px;
}

.field-readout span {
    color: #111827;
    font-size: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.field-scene-wrap {
    position: relative;
    min-height: 100vh;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(224, 232, 242, 0.35)),
        radial-gradient(circle at 52% 35%, #ffffff 0, #eef4fb 48%, #d6e0ec 100%);
}

#fieldScene {
    position: absolute;
    inset: 0;
}

.scene-toolbar,
.field-legend {
    position: absolute;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid rgba(190, 199, 212, 0.9);
    border-radius: 8px;
    backdrop-filter: blur(8px);
}

.scene-toolbar {
    top: 16px;
    right: 16px;
}

.scene-toolbar button {
    width: 62px;
}

.scene-toolbar button.active {
    border-color: #2563eb;
    color: #1d4ed8;
    background: #eff6ff;
}

.field-legend {
    left: 18px;
    bottom: 18px;
    align-items: center;
    color: #2f3b4c;
    font-size: 13px;
}

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

.wire-swatch {
    background: #2563eb;
}

.coil-swatch {
    background: #dc2626;
}

.plate-swatch {
    background: #0891b2;
}

.uniform-swatch {
    background: #16a34a;
}

@media (max-width: 900px) {
    .field-lab {
        grid-template-columns: 1fr;
    }

    .field-panel {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .field-scene-wrap {
        min-height: 68vh;
    }
}

@media (max-width: 520px) {
    .field-panel {
        padding: 16px;
    }

    .source-buttons,
    .probe-grid {
        grid-template-columns: 1fr;
    }

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

.grating-body {
    min-height: 100%;
    background:
        radial-gradient(circle at 80% 12%, rgba(20, 184, 166, 0.2), transparent 28%),
        radial-gradient(circle at 42% 85%, rgba(99, 102, 241, 0.18), transparent 32%),
        #050814;
    color: #e5edf8;
}

.grating-lab {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(340px, 420px) 1fr;
}

.grating-panel {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    background: rgba(8, 13, 30, 0.86);
    border-right: 1px solid rgba(148, 163, 184, 0.22);
    box-shadow: 18px 0 50px rgba(0, 0, 0, 0.22);
    overflow-y: auto;
}

.grating-title a,
.stage-topbar a {
    color: #67e8f9;
    font-size: 13px;
    text-decoration: none;
}

.grating-title h1 {
    margin: 10px 0 8px;
    font-size: 28px;
    letter-spacing: 0;
}

.grating-title p,
.stage-topbar p {
    margin: 0;
    color: #9fb0c8;
    font-size: 14px;
    line-height: 1.55;
}

.grating-controls {
    display: grid;
    gap: 14px;
}

.grating-controls label {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    color: #d7e4f5;
}

.grating-controls input {
    grid-column: 1 / -1;
    height: 34px;
    border-color: rgba(125, 211, 252, 0.25);
    background: rgba(15, 23, 42, 0.92);
    accent-color: #22d3ee;
}

.grating-controls output {
    color: #67e8f9;
    font-weight: 700;
}

.grating-readout {
    display: grid;
    gap: 10px;
}

.grating-readout div {
    padding: 13px 14px;
    border: 1px solid rgba(125, 211, 252, 0.18);
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(17, 24, 39, 0.82));
    display: grid;
    gap: 6px;
}

.grating-readout strong {
    color: #bfd3ea;
    font-size: 13px;
}

.grating-readout span {
    color: #f8fafc;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.45;
}

.grating-stage {
    position: relative;
    height: 100vh;
    min-height: 0;
    padding: 18px 24px 42px;
    display: grid;
    grid-template-rows: auto 112px minmax(190px, 1fr) 138px;
    gap: 12px;
    overflow: hidden;
}

.stage-topbar {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 18px;
}

.stage-topbar h2 {
    margin: 0 0 6px;
    font-size: 22px;
    letter-spacing: 0;
}

#layoutCanvas,
#screenCanvas,
#curveCanvas {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 1px solid rgba(125, 211, 252, 0.18);
    border-radius: 8px;
    background: rgba(3, 7, 18, 0.64);
    box-shadow: inset 0 0 35px rgba(34, 211, 238, 0.05), 0 18px 48px rgba(0, 0, 0, 0.24);
}

#screenCanvas {
    min-height: 190px;
}

.signature {
    position: absolute;
    right: 22px;
    bottom: 16px;
    color: rgba(226, 232, 240, 0.92);
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0;
    text-shadow: 0 0 14px rgba(34, 211, 238, 0.65);
}

@media (max-width: 940px) {
    .grating-lab {
        grid-template-columns: 1fr;
    }

    .grating-panel {
        border-right: 0;
        border-bottom: 1px solid rgba(148, 163, 184, 0.22);
    }

    .grating-stage {
        height: auto;
        min-height: 82vh;
        grid-template-rows: auto 110px 220px 140px;
        overflow: visible;
    }
}

@media (min-width: 941px) and (max-height: 760px) {
    .grating-stage {
        padding-top: 14px;
        padding-bottom: 36px;
        grid-template-rows: auto 86px minmax(150px, 1fr) 112px;
        gap: 10px;
    }

    .stage-topbar h2 {
        font-size: 19px;
        margin-bottom: 3px;
    }

    .stage-topbar p {
        font-size: 12px;
    }

    #screenCanvas {
        min-height: 150px;
    }

    .signature {
        bottom: 10px;
    }
}

@media (max-width: 560px) {
    .grating-panel,
    .grating-stage {
        padding: 16px;
    }

    .stage-topbar {
        display: grid;
    }
}
