:root {
  --ink: #151515;
  --ink-soft: #272727;
  --paper: #e7e4de;
  --paper-deep: #d1cec7;
  --lavender: #b8a4ff;
  --lavender-bright: #cbbbff;
  --acid: #d9ff5a;
  --line: rgba(231, 228, 222, 0.22);
  --muted: #9b9892;
  --danger: #ff735c;
  --radius: 2px;
  --mono: "SFMono-Regular", "Roboto Mono", "Liberation Mono", monospace;
  --sans: Inter, "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

button,
select,
input {
  font: inherit;
}

button,
select,
input[type="range"],
input[type="checkbox"] + * {
  cursor: pointer;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--acid);
  outline-offset: 3px;
}

.ambient-grid {
  position: fixed;
  z-index: -1;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 64px 64px;
  pointer-events: none;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  border-inline: 1px solid var(--line);
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  min-height: 90px;
  background: rgba(21, 21, 21, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 28px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  background: var(--lavender);
  color: var(--ink);
  font-size: 23px;
  font-weight: 900;
  letter-spacing: -0.08em;
  transform: rotate(-3deg);
}

.brand-copy {
  display: grid;
  gap: 3px;
}

.brand-copy strong {
  font-size: 18px;
  letter-spacing: -0.03em;
}

.brand-copy small,
.status-copy small,
.select-field span,
.mode-toggle small,
.mode-button small,
.dice-button small {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.3;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.connection-panel {
  display: flex;
  align-items: stretch;
  border-left: 1px solid var(--line);
}

.connection-status {
  display: flex;
  min-width: 220px;
  align-items: center;
  gap: 12px;
  padding: 17px 24px;
  border-right: 1px solid var(--line);
}

.status-light {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  background: var(--danger);
  border-radius: 50%;
  box-shadow: 0 0 0 5px rgba(255, 115, 92, 0.1);
}

.connection-status.connected .status-light {
  background: var(--acid);
  box-shadow: 0 0 0 5px rgba(217, 255, 90, 0.1), 0 0 18px rgba(217, 255, 90, 0.45);
}

.connection-status.error .status-light {
  animation: pulse 1.8s infinite;
}

.status-copy {
  display: grid;
  gap: 4px;
}

.status-copy strong {
  max-width: 220px;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.select-field {
  display: grid;
  min-width: 280px;
  align-content: center;
  gap: 7px;
  padding: 14px 24px;
}

select {
  width: 100%;
  min-height: 34px;
  padding: 0 30px 0 0;
  background: transparent;
  color: var(--paper);
  border: 0;
  border-bottom: 1px solid var(--muted);
  border-radius: 0;
}

select option {
  background: var(--ink);
  color: var(--paper);
}

.identity-strip {
  display: grid;
  place-items: center;
  padding: clamp(18px, 3vw, 34px);
  background: #000;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.banner-image {
  display: block;
  width: auto;
  max-width: 100%;
  height: clamp(132px, 19vw, 245px);
  object-fit: contain;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--lavender-bright);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h2,
h3,
p {
  margin-top: 0;
}

.mode-rack,
.workspace {
  padding: clamp(36px, 5vw, 72px);
}

.mode-rack {
  background: var(--paper);
  color: var(--ink);
  border-bottom: 1px solid var(--ink);
}

.section-index {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 28px;
}

.section-index > span {
  color: #817d76;
  font-family: var(--mono);
  font-size: 10px;
}

.section-index .eyebrow {
  margin-bottom: 4px;
  color: #65578d;
}

.section-index h2,
.workspace-heading h2 {
  margin-bottom: 0;
  font-size: clamp(28px, 3vw, 46px);
  line-height: 0.95;
  letter-spacing: -0.05em;
}

.mode-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
}

.mode-toggle,
.mode-button {
  display: flex;
  min-height: 90px;
  align-items: center;
  gap: 14px;
  padding: 17px;
  background: transparent;
  color: var(--ink);
  border: 0;
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  text-align: left;
  transition: background-color 160ms ease, color 160ms ease;
}

.mode-toggle:hover,
.mode-button:hover,
.mode-toggle:has(input:checked),
.mode-button[aria-pressed="true"] {
  background: var(--lavender);
}

.mode-toggle > span:last-child,
.mode-button > span:last-child,
.dice-button > span:last-child {
  display: grid;
  gap: 5px;
}

.mode-toggle b,
.mode-button b {
  font-size: 13px;
}

.mode-toggle small,
.mode-button small {
  color: #6e6a64;
}

.mode-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.mode-toggle:has(input:focus-visible) {
  outline: 2px solid #65578d;
  outline-offset: -4px;
}

.toggle-track {
  position: relative;
  width: 38px;
  height: 20px;
  flex: 0 0 auto;
  border: 1px solid var(--ink);
  border-radius: 20px;
}

.toggle-track i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  background: var(--ink);
  border-radius: 50%;
  transition: transform 180ms ease;
}

.mode-toggle input:checked + .toggle-track i {
  transform: translateX(18px);
}

.button-state {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--ink);
  border-radius: 50%;
  font-family: var(--mono);
  font-size: 10px;
}

.workspace {
  background: var(--ink);
}

.workspace-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
}

.workspace-heading .section-index {
  margin-bottom: 0;
}

.workspace-heading .section-index .eyebrow {
  color: var(--lavender-bright);
}

.workspace-heading > p {
  max-width: 370px;
  margin-bottom: 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
}

.tab-list {
  display: flex;
  margin-top: 40px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}

.tabBtn {
  min-width: max-content;
  padding: 15px 24px;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-top: 1px solid transparent;
  border-right: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.tabBtn:first-child {
  border-left: 1px solid var(--line);
}

.tabBtn span {
  margin-right: 9px;
  color: #5e5b57;
}

.tabBtn:hover {
  color: var(--paper);
}

.tabBtn[aria-selected="true"] {
  background: var(--lavender);
  color: var(--ink);
  border-top-color: var(--lavender);
}

.tabBtn[aria-selected="true"] span {
  color: #5e527d;
}

.tab-content {
  min-height: 420px;
}

.tabPage {
  animation: reveal 260ms ease both;
}

.tabPage[hidden] {
  display: none;
}

.parameter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-left: 1px solid var(--line);
}

.parameter-card {
  position: relative;
  display: grid;
  min-height: 215px;
  align-content: space-between;
  gap: 26px;
  padding: 22px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.parameter-card::after {
  position: absolute;
  right: -17px;
  bottom: -28px;
  color: rgba(255,255,255,0.025);
  content: attr(data-index);
  font-size: 100px;
  font-weight: 900;
  letter-spacing: -0.09em;
  pointer-events: none;
}

.parameter-card:hover {
  background: rgba(255,255,255,0.025);
}

.parameter-heading {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.parameter-name {
  max-width: 250px;
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.parameter-number,
.parameter-id {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.parameter-number {
  flex: 0 0 auto;
  color: var(--lavender-bright);
}

.range-wrap {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 13px;
}

.range-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.range-value {
  min-width: 56px;
  padding: 5px 7px;
  background: var(--ink-soft);
  color: var(--acid);
  font-family: var(--mono);
  font-size: 11px;
  text-align: right;
}

input[type="range"] {
  width: 100%;
  height: 20px;
  margin: 0;
  appearance: none;
  background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: linear-gradient(90deg, var(--lavender) var(--range-progress, 0%), #4a4845 var(--range-progress, 0%));
}

input[type="range"]::-webkit-slider-thumb {
  width: 14px;
  height: 20px;
  margin-top: -8px;
  appearance: none;
  background: var(--paper);
  border: 0;
  border-radius: 0;
  box-shadow: 0 0 0 1px var(--ink);
}

input[type="range"]::-moz-range-track {
  height: 3px;
  background: #4a4845;
}

input[type="range"]::-moz-range-progress {
  height: 3px;
  background: var(--lavender);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 20px;
  background: var(--paper);
  border: 0;
  border-radius: 0;
}

.gesture-page {
  display: grid;
  grid-template-columns: minmax(360px, 1.15fr) minmax(340px, 0.85fr);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.camera-stage {
  padding: clamp(20px, 3vw, 40px);
  border-right: 1px solid var(--line);
}

.camera-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.camera-header h3 {
  margin-bottom: 0;
  font-size: 28px;
  letter-spacing: -0.04em;
}

.camera-container {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background:
    linear-gradient(90deg, transparent 49.8%, rgba(184,164,255,0.2) 50%, transparent 50.2%),
    linear-gradient(transparent 49.8%, rgba(184,164,255,0.2) 50%, transparent 50.2%),
    #0c0c0c;
  border: 1px solid var(--line);
}

#cameraCanvas {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

.camera-placeholder span {
  margin-bottom: 5px;
  color: var(--lavender);
  font-size: 28px;
}

.camera-placeholder strong {
  color: var(--paper);
  font-size: 13px;
  text-transform: uppercase;
}

.camera-placeholder small {
  max-width: 280px;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.45;
}

.camera-container.is-active .camera-placeholder {
  display: none;
}

.gesture-mappings {
  display: grid;
  align-content: start;
}

.gesture-control {
  display: grid;
  gap: 14px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.gesture-control:last-child {
  border-bottom: 0;
}

.gesture-control-header {
  display: grid;
  grid-template-columns: 72px 1fr;
  align-items: center;
  gap: 14px;
}

.gesture-control label {
  color: var(--lavender-bright);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
}

.gesture-control select {
  font-size: 11px;
}

.secondary-button {
  min-height: 42px;
  padding: 10px 16px;
  background: transparent;
  color: var(--paper);
  border: 1px solid #686561;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.secondary-button:hover,
.secondary-button[aria-pressed="true"] {
  background: var(--lavender);
  color: var(--ink);
  border-color: var(--lavender);
}

.utility-page {
  border-bottom: 1px solid var(--line);
}

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

.utility-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 24px;
  border-inline: 1px solid var(--line);
}

.utility-actions button span {
  margin-right: 7px;
  color: var(--lavender-bright);
}

.mutation-dock {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(40px, 6vw, 84px) clamp(28px, 5vw, 72px);
  background: var(--lavender);
  color: var(--ink);
}

.dice-button {
  display: flex;
  width: min(430px, 100%);
  align-items: center;
  gap: 18px;
  padding: 18px 22px;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 0;
  text-align: left;
  transition: transform 160ms ease, background-color 160ms ease;
}

.dice-button:hover {
  background: #26232b;
  transform: translateY(-3px);
}

.dice-button.is-rolling .dice-glyph {
  animation: roll 500ms cubic-bezier(.2,.8,.2,1);
}

.dice-glyph {
  display: grid;
  width: 55px;
  height: 55px;
  flex: 0 0 auto;
  place-items: center;
  background: var(--acid);
  color: var(--ink);
  font-size: 25px;
}

.dice-button b {
  font-size: 18px;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px;
  color: #716e69;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.footer p {
  margin: 0;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 24px;
  bottom: 24px;
  max-width: min(360px, calc(100vw - 48px));
  padding: 14px 17px;
  background: var(--acid);
  color: var(--ink);
  border: 1px solid var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.4;
  animation: toast-in 220ms ease both;
}

@keyframes reveal {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes roll {
  from { transform: rotate(0) scale(1); }
  45% { transform: rotate(150deg) scale(0.85); }
  to { transform: rotate(360deg) scale(1); }
}

@keyframes pulse {
  50% { opacity: 0.35; }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
}

@media (max-width: 1050px) {
  .topbar {
    position: relative;
  }

  .connection-status {
    min-width: 190px;
  }

  .select-field {
    min-width: 240px;
  }

  .mode-controls,
  .parameter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar,
  .connection-panel,
  .workspace-heading {
    display: block;
  }

  .brand {
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
  }

  .brand-mark {
    width: 43px;
    height: 43px;
  }

  .connection-panel {
    border-left: 0;
  }

  .connection-status {
    min-width: 0;
    padding: 14px 18px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .select-field {
    min-width: 0;
    padding: 14px 18px 18px;
  }

  .identity-strip {
    padding: 14px;
  }

  .banner-image {
    height: clamp(100px, 28vw, 150px);
  }

  .mode-rack,
  .workspace {
    padding: 36px 18px;
  }

  .mode-controls,
  .parameter-grid,
  .gesture-page {
    grid-template-columns: 1fr;
  }

  .mode-toggle,
  .mode-button {
    min-height: 76px;
  }

  .workspace-heading > p {
    margin-top: 18px;
  }

  .tab-list {
    margin-inline: -18px;
    padding-left: 18px;
  }

  .tabBtn {
    padding-inline: 17px;
  }

  .parameter-card {
    min-height: 180px;
  }

  .gesture-page {
    display: block;
  }

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

  .camera-header {
    display: grid;
  }

  .utility-actions {
    display: grid;
  }

  .mutation-dock {
    display: flex;
    padding: 36px 22px;
  }

  .footer {
    display: grid;
  }
}

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