* {
    box-sizing: border-box;
}

:root {
    --bg: #f7f7f5;
    --card: #fff;
    --ink: #111;
    --muted: #646464;
    --line: #d9d9d4;
    --soft-line: #ececea;
    --panel-bg: #fafaf8;
    /* functional screen colors */
    --green: #5ee28f;
    --cyan: #2bb7bf;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--bg);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    width: min(1280px, calc(100% - 48px));
    margin: 0 auto;
    padding: 24px 0 18px;
}

h1,
h2,
h3,
p {
    margin: 0;
}

.top-bar h1 {
    font-size: 30px;
    line-height: 1.15;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.home-link {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid #d8d2c0;
  border-radius: 50%;
  color: #2f5d4f;
  background: #faf8f1;
  box-shadow: 0 1px 2px rgba(28,43,37,.05), 0 12px 32px -16px rgba(28,43,37,.28);
  text-decoration: none;
  transition: transform .2s ease, border-color .2s ease;
}
.home-link:hover,
.home-link:focus-visible {
  border-color: #8a9a5b;
  color: #3f7060;
  transform: translateY(-2px);
  outline: none;
}
.home-link svg { display: block; }

.lede {
    max-width: 700px;
    color: var(--muted);
    line-height: 1.55;
}

.layout {
    display: grid;
    grid-template-columns: 350px minmax(0, 1fr);
    gap: 22px;
    width: min(1280px, calc(100% - 48px));
    margin: 0 auto;
    padding: 0 0 8px;
}

.panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
}

.controls-panel {
    display: grid;
    gap: 18px;
    padding: 20px;
}

.screen-panel {
    padding: 18px;
}

.beam-panel {
    grid-column: 1 / -1;
    padding: 18px;
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
}

.controls-panel .section-title {
    margin-bottom: 2px;
}

h2 {
    font-size: 18px;
    line-height: 1.3;
    font-weight: 700;
}

h3 {
    margin-bottom: 10px;
    font-size: 15px;
    font-weight: 700;
}

.ghost-button {
    min-height: 34px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink);
    background: #fff;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.ghost-button:hover {
    background: var(--soft-line);
}

.preset-group {
    display: grid;
    gap: 8px;
}

.preset-group > span {
    color: var(--ink);
    font-size: 13px;
    font-weight: 700;
}

.segmented-control {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-bg);
}

.mode-button {
    min-height: 36px;
    border: 0;
    border-left: 1px solid var(--line);
    color: var(--muted);
    background: transparent;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.mode-button:first-child {
    border-left: 0;
}

.mode-button.active {
    color: #ffffff;
    background: var(--ink);
}

.slider-row {
    display: grid;
    grid-template-columns: minmax(92px, auto) minmax(0, 1fr) 62px;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-bg);
    font-size: 14px;
    font-weight: 600;
}

.slider-row output {
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--ink);
}

input[type="range"]:disabled {
    opacity: 0.72;
}

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

.check-row {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 34px;
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
}

.check-row input {
    width: 17px;
    height: 17px;
    accent-color: var(--ink);
}

.formula-box {
    padding: 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--panel-bg);
}

.formula-box p {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 8px;
    color: var(--muted);
    line-height: 1.35;
}

.formula-box strong {
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.formula-box .note {
    display: block;
    margin-top: 13px;
    color: var(--muted);
    font-size: 13px;
}

.legend,
.beam-readout {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
}

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

.spot-swatch,
.trace-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
}

.spot-swatch {
    background: var(--green);
    box-shadow: 0 0 10px rgba(94, 226, 143, 0.9);
}

.trace-swatch {
    border: 2px solid var(--cyan);
    background: rgba(43, 183, 191, 0.16);
}

.scope-shell {
    display: grid;
    place-items: center;
    min-height: 520px;
    overflow: hidden;
    border-radius: 8px;
    background: linear-gradient(145deg, #1c2935, #10171e);
    border: 1px solid #0b1118;
}

canvas {
    display: block;
    width: 100%;
}

#screenCanvas {
    max-width: 720px;
    height: auto;
    aspect-ratio: 720 / 520;
}

#beamCanvas {
    height: 360px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
}

footer {
    width: min(1280px, calc(100% - 48px));
    margin: 0 auto;
    padding: 6px 0 26px;
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 900px) {
    .top-bar,
    .layout,
    footer {
        width: calc(100% - 32px);
    }

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

    .scope-shell {
        min-height: auto;
        padding: 8px;
    }
}

@media (max-width: 560px) {
    .top-bar h1 {
        font-size: 24px;
    }

    .slider-row {
        grid-template-columns: 1fr 64px;
    }

    .slider-row span {
        grid-column: 1 / -1;
    }

    .section-title {
        align-items: flex-start;
        flex-direction: column;
    }

    .beam-readout,
    .legend {
        justify-content: flex-start;
    }
}
