:root {
  color-scheme: dark;
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  background: #07100d;
  color: #d7e6db;
  --phosphor: #91ffb5;
  --dim: #82938a;
  --panel: #17201c;
  --brass: #a78f5d;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  min-height: 100%;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 45% 20%, #183226 0, transparent 38rem),
    linear-gradient(145deg, #040806, #0d1712 60%, #050907);
}

.mobile-only {
  display: none;
}

main {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 52px 0 34px;
}

header {
  margin-bottom: 28px;
}

.eyebrow,
.deck,
footer,
.message {
  color: var(--dim);
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: #f0f5ed;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3.5rem, 9vw, 7.5rem);
  font-weight: 400;
  letter-spacing: -0.055em;
  line-height: 0.88;
}

.deck {
  max-width: 680px;
  margin: 18px 0 0;
  font-size: clamp(0.9rem, 2vw, 1.1rem);
  line-height: 1.55;
}

.machine {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 22px;
  align-items: stretch;
}

.scope-frame,
.console {
  border: 1px solid #334239;
  background: linear-gradient(160deg, #1b241f, #101713);
  box-shadow: 0 28px 80px rgb(0 0 0 / 42%);
}

.advanced-panel {
  display: contents;
}

.scope-frame {
  padding: clamp(14px, 2.5vw, 28px);
  border-radius: 28px;
}

.scope-glass {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  border: 2px solid #4b5a50;
  border-radius: 16%;
  background: #010503;
  box-shadow:
    inset 0 0 80px #000,
    inset 0 0 18px rgb(97 255 143 / 10%),
    0 0 0 8px #0b110e;
}

canvas,
.light-pen-surface,
.graticule {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

canvas,
.light-pen-surface {
  cursor: crosshair;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

#scope {
  z-index: 0;
  pointer-events: none;
}

.beam-head {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  width: clamp(2px, 0.38%, 4px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #e6f8ff;
  box-shadow:
    0 0 3px 1px rgb(192 235 255 / 90%),
    0 0 9px 3px rgb(91 179 255 / 55%);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
  will-change: left, top, opacity;
}

.light-pen-surface {
  z-index: 3;
}

.graticule {
  z-index: 1;
  pointer-events: none;
  opacity: 0.14;
  background:
    linear-gradient(90deg, transparent calc(50% - 0.5px), var(--phosphor) 50%, transparent calc(50% + 0.5px)),
    linear-gradient(transparent calc(50% - 0.5px), var(--phosphor) 50%, transparent calc(50% + 0.5px));
}

.scope-label {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 22px;
  color: #aeb9b2;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
}

.console {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 18px;
  border-radius: 12px;
}

.readout {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 4px;
  border-bottom: 1px solid #2b3730;
  font-size: 0.8rem;
}

.readout-label {
  color: var(--dim);
}

.readout strong {
  color: var(--phosphor);
  font-weight: 500;
}

.controls {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.knobs {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 14px;
  border: 1px solid #334239;
}

.external-input {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 14px;
  border: 1px solid #334239;
}

.knobs legend,
.external-input legend,
.knob span,
.knob output,
.meta-control {
  color: #aeb9b2;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
}

.knob {
  display: grid;
  grid-template-columns: 24px 1fr 32px;
  gap: 8px;
  align-items: center;
}

.knob input {
  width: 100%;
  accent-color: var(--phosphor);
}

.knob output {
  text-align: right;
}

.meta-control {
  display: flex;
  gap: 8px;
  align-items: center;
}

.external-input p {
  margin: 0 0 4px;
  color: var(--dim);
  font-size: 0.62rem;
  line-height: 1.4;
}

.switch-rows {
  display: grid;
  gap: 3px;
}

.switch-row {
  display: grid;
  grid-template-columns: 22px repeat(9, minmax(0, 1fr));
  gap: 2px;
  align-items: center;
}

.switch-row span {
  color: #aeb9b2;
  font-size: 0.58rem;
}

button.external-button {
  min-height: 26px;
  padding: 0;
  font-size: 0.58rem;
  letter-spacing: 0;
  touch-action: none;
}

button.external-button.held {
  border-color: var(--phosphor);
  background: #31513e;
  color: var(--phosphor);
  box-shadow: inset 0 0 10px rgb(145 255 181 / 18%);
}

button.external-meta {
  width: 100%;
  letter-spacing: 0.08em;
}

button,
.file-control {
  min-height: 46px;
  border: 1px solid #536159;
  border-radius: 3px;
  background: #222d27;
  color: #e2ebe5;
  font: inherit;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  cursor: pointer;
}

button:hover:not(:disabled),
.file-control:hover {
  border-color: var(--phosphor);
  color: var(--phosphor);
}

button:disabled {
  cursor: wait;
  opacity: 0.45;
}

.file-control {
  display: grid;
  place-items: center;
  text-align: center;
}

.file-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.message {
  min-height: 4.5em;
  margin: auto 2px 0;
  padding-top: 24px;
  font-size: 0.72rem;
  line-height: 1.55;
}

.message.error {
  color: #ff9e91;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 30px;
  margin-top: 24px;
  font-size: 0.68rem;
  line-height: 1.5;
}

footer p {
  max-width: 500px;
  margin: 0;
}

@media (max-width: 820px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
    inset: 0;
  }

  body {
    background:
      radial-gradient(circle at 50% 30%, #142b21 0, transparent 30rem),
      #050a08;
  }

  .mobile-only {
    display: flex;
  }

  main {
    width: 100%;
    height: 100dvh;
    margin: 0;
    padding:
      max(6px, env(safe-area-inset-top))
      max(6px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom))
      max(6px, env(safe-area-inset-left));
  }

  header,
  footer {
    display: none;
  }

  .machine {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 6px;
    height: 100%;
    min-height: 0;
  }

  .scope-frame {
    display: flex;
    min-height: 0;
    flex-direction: column;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .scope-topbar {
    min-height: 42px;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
  }

  .mobile-brand {
    display: grid;
    gap: 2px;
    font-size: 0.7rem;
    letter-spacing: 0.14em;
  }

  .mobile-state {
    color: var(--phosphor);
    font-size: 0.56rem;
    letter-spacing: 0.09em;
  }

  .mobile-state::before {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: 6px;
    border-radius: 50%;
    background: currentColor;
    content: "";
    box-shadow: 0 0 8px currentColor;
  }

  .scope-glass {
    width: min(100%, calc(100dvh - 208px));
    max-height: 100%;
    margin: auto;
    border-color: #53665b;
    border-radius: 13%;
    box-shadow:
      inset 0 0 60px #000,
      inset 0 0 18px rgb(97 255 143 / 12%),
      0 0 0 5px #0b110e;
  }

  .scope-label {
    display: none;
  }

  .console {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .readout {
    display: grid;
    gap: 3px;
    min-width: 0;
    padding: 6px 8px;
    border: 1px solid #2b3730;
    border-radius: 8px;
    background: rgb(16 23 19 / 88%);
    font-size: 0.61rem;
  }

  .readout strong {
    overflow: hidden;
    font-size: 0.66rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .readout-label {
    font-size: 0.5rem;
    letter-spacing: 0.08em;
  }

  .tool-hud {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    padding: 4px;
    border: 1px solid #34443b;
    border-radius: 12px;
    background: rgb(11 17 14 / 94%);
  }

  button.tool-button {
    display: grid;
    min-width: 0;
    min-height: 54px;
    place-items: center;
    gap: 2px;
    padding: 4px 1px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: #9caaa2;
    font-size: 0.55rem;
    letter-spacing: 0.05em;
    touch-action: manipulation;
  }

  button.tool-button.active {
    border-color: #527260;
    background: #1b3125;
    color: var(--phosphor);
    box-shadow: inset 0 0 14px rgb(145 255 181 / 8%);
  }

  .tool-mark {
    color: inherit;
    font-family: Georgia, serif;
    font-size: 1.2rem;
    line-height: 1;
  }

  .mobile-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 5px;
    align-items: center;
  }

  .mobile-actions p {
    overflow: hidden;
    margin: 0;
    padding-left: 5px;
    color: var(--dim);
    font-size: 0.56rem;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-actions p.error {
    color: #ff9e91;
  }

  button.compact-button {
    min-height: 34px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: 0.56rem;
    touch-action: manipulation;
  }

  .advanced-panel {
    position: fixed;
    z-index: 20;
    inset: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    padding:
      max(14px, env(safe-area-inset-top))
      max(14px, env(safe-area-inset-right))
      max(18px, env(safe-area-inset-bottom))
      max(14px, env(safe-area-inset-left));
    background: rgb(7 16 13 / 98%);
    transform: translateY(105%);
    transition: transform 180ms ease-out;
    visibility: hidden;
  }

  .advanced-panel.open {
    transform: translateY(0);
    visibility: visible;
  }

  .sheet-heading {
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid #334239;
  }

  .sheet-heading div {
    display: grid;
    gap: 4px;
  }

  .sheet-heading strong {
    color: #eef5f0;
    font-size: 0.78rem;
    letter-spacing: 0.1em;
  }

  .sheet-heading span {
    color: var(--dim);
    font-size: 0.62rem;
  }

  .knobs,
  .external-input {
    flex: 0 0 auto;
    margin: 0;
    background: #111a15;
  }

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

  .file-control {
    grid-column: 1 / -1;
  }

  .message {
    min-height: 0;
    margin: 0 2px;
    padding-top: 4px;
  }

  @media (orientation: landscape) {
    .machine {
      grid-template-columns: minmax(0, 1fr) minmax(270px, 42vw);
      grid-template-rows: 1fr;
      gap: 10px;
    }

    .scope-glass {
      width: min(100%, calc(100dvh - 58px));
    }

    .console {
      align-self: center;
    }
  }
}
