:root {
  color-scheme: dark;
  --bg: #090706;
  --chassis: #14100d;
  --panel: #1a130f;
  --panel-hi: #231811;
  --ink: #f4eadc;
  --muted: #a99988;
  --line: #37251b;
  --line-hot: #69402a;
  --cyan: #ff5a38;
  --cyan-soft: #ffc28a;
  --amber: #ffba5a;
  --coral: #ff3f2e;
  --acid: #ffd166;
  --shadow: none;
  --inset: none;
  --grain: url("data:image/svg+xml,%3Csvg viewBox='0 0 90 90' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.15' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='90' height='90' filter='url(%23n)' opacity='.42'/%3E%3C/svg%3E");
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  padding: 12px 0 28px;
  background:
    var(--grain),
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    var(--bg);
  background-size: 140px 140px, 34px 34px, 34px 34px, auto;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: 0.16;
  background-image: var(--grain);
  background-size: 110px 110px;
  mix-blend-mode: normal;
}

button,
input,
select {
  font: inherit;
}

button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line-hot);
  border-radius: 3px;
  padding: 0 13px;
  background:
    linear-gradient(180deg, rgba(255, 234, 210, 0.12), rgba(0, 0, 0, 0.18)),
    #1d1510;
  box-shadow:
    inset 0 1px 0 rgba(255, 236, 210, 0.13),
    inset 0 -2px 0 rgba(0, 0, 0, 0.34),
    0 4px 0 #0a0705,
    0 7px 13px rgba(0, 0, 0, 0.28);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

button span {
  display: inline-flex;
  width: 18px;
  justify-content: center;
}

button:hover:not(:disabled) {
  border-color: var(--cyan);
  color: var(--cyan-soft);
  background:
    linear-gradient(180deg, rgba(255, 234, 210, 0.16), rgba(0, 0, 0, 0.12)),
    #2a1b13;
}

button:active:not(:disabled) {
  transform: translateY(3px);
  filter: brightness(0.9);
  box-shadow:
    inset 0 1px 0 rgba(255, 236, 210, 0.08),
    inset 0 2px 5px rgba(0, 0, 0, 0.36),
    0 1px 0 #0a0705,
    0 3px 7px rgba(0, 0, 0, 0.22);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.app-shell {
  position: relative;
  width: min(560px, calc(100vw - 20px));
  margin: 0 auto;
  padding: 16px;
  border: 1px solid #3a261a;
  border-radius: 4px;
  background: var(--grain), var(--chassis);
  background-size: 120px 120px, auto;
  box-shadow: none;
}

.topbar {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px 12px 13px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--grain), #110c09;
  background-size: 120px 120px, auto;
  box-shadow: none;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(29px, 8.7vw, 54px);
  font-weight: 950;
  line-height: 1;
  letter-spacing: 0;
  text-shadow: none;
  white-space: nowrap;
}

.brand-subrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 7px;
}

.product-subtitle {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  color: var(--cyan);
  font-size: clamp(16px, 4.7vw, 26px);
  font-weight: 850;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.donation-button {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 186, 90, 0.72);
  border-radius: 3px;
  max-width: 52%;
  overflow: hidden;
  padding: 0 9px;
  background: var(--grain), rgba(255, 106, 54, 0.14);
  background-size: 110px 110px, auto;
  box-shadow: none;
  color: var(--amber);
  flex: 0 0 auto;
  font-size: clamp(8px, 2.1vw, 11px);
  font-weight: 900;
  letter-spacing: 0;
  text-decoration: none;
  text-transform: uppercase;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.donation-button:hover {
  border-color: var(--amber);
  color: #fff2cf;
  box-shadow: none;
}

.status {
  min-height: 38px;
  border: 1px solid #352116;
  border-radius: 3px;
  padding: 9px 11px;
  background: var(--grain), #0b0706;
  background-size: 110px 110px, auto;
  box-shadow: none;
  color: var(--acid);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: left;
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.panel,
.visual-panel {
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--grain), var(--panel);
  background-size: 115px 115px, auto;
  box-shadow: none;
}

.panel {
  padding: 13px;
}

.sample-module {
  display: grid;
  gap: 10px;
}

.drop-zone {
  position: relative;
  display: flex;
  min-height: 118px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  overflow: hidden;
  border: 1px solid #73462d;
  border-radius: 3px;
  background:
    linear-gradient(180deg, rgba(255, 234, 210, 0.08), rgba(0, 0, 0, 0.18)),
    #100b08;
  box-shadow:
    inset 0 1px 0 rgba(255, 236, 210, 0.1),
    inset 0 -2px 0 rgba(0, 0, 0, 0.32),
    0 4px 0 #090504,
    0 8px 14px rgba(0, 0, 0, 0.24);
  cursor: pointer;
  text-align: center;
}

.drop-zone::before {
  display: none;
}

.drop-zone.dragging {
  border-color: var(--cyan);
  background:
    linear-gradient(180deg, rgba(255, 234, 210, 0.13), rgba(0, 0, 0, 0.12)),
    #1a100b;
  box-shadow:
    inset 0 1px 0 rgba(255, 236, 210, 0.12),
    inset 0 -2px 0 rgba(0, 0, 0, 0.3),
    0 4px 0 #090504,
    0 10px 18px rgba(0, 0, 0, 0.3);
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.slot-label,
.drop-title,
.drop-meta {
  position: relative;
  z-index: 1;
}

.slot-label {
  color: var(--cyan);
  font-size: clamp(15px, 3.8vw, 22px);
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.drop-title {
  color: var(--ink);
  font-size: clamp(28px, 7.1vw, 42px);
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.drop-meta {
  max-width: 92%;
  overflow: hidden;
  color: var(--amber);
  font-size: clamp(14px, 3.5vw, 19px);
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 0;
}

.button-row button {
  flex: 1 1 0;
  min-width: 0;
}

.transport-actions button {
  min-height: 38px;
}

.primary-actions {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr) minmax(0, 1fr);
  align-items: stretch;
}

.primary-actions button {
  min-height: 46px;
}

.primary-actions .spin-button {
  min-height: 78px;
  border-color: rgba(255, 90, 56, 0.82);
  border-radius: 3px;
  background:
    linear-gradient(180deg, rgba(255, 238, 218, 0.18), rgba(0, 0, 0, 0.18)),
    #9a241b;
  color: #fff7f4;
  font-size: 18px;
  text-shadow: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 238, 218, 0.16),
    inset 0 -3px 0 rgba(0, 0, 0, 0.36),
    0 5px 0 #2d0906,
    0 9px 16px rgba(0, 0, 0, 0.32);
}

.primary-actions .spin-button span {
  width: 22px;
  font-size: 18px;
}

.primary-actions .spin-button:hover:not(:disabled) {
  border-color: var(--coral);
  color: #fff;
  background:
    linear-gradient(180deg, rgba(255, 238, 218, 0.21), rgba(0, 0, 0, 0.14)),
    #b02b20;
  box-shadow:
    inset 0 1px 0 rgba(255, 238, 218, 0.18),
    inset 0 -3px 0 rgba(0, 0, 0, 0.32),
    0 5px 0 #2d0906,
    0 10px 18px rgba(0, 0, 0, 0.34);
}

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

.machine-controls {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 12px;
}

.control label,
.control-row label,
.module-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.module-label {
  margin-bottom: 9px;
}

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

.phase-module {
  min-width: 0;
  padding: 10px;
  border: 1px solid #3a2519;
  border-radius: 3px;
  background: #100b08;
}

.slider-control {
  position: relative;
  width: 100%;
  padding: 8px 0 5px;
}

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

input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border: 1px solid #4a3021;
  border-radius: 999px;
  background: #24160f;
}

input[type="range"]::-webkit-slider-thumb {
  width: 22px;
  height: 22px;
  margin-top: -8px;
  border: 2px solid #130c08;
  border-radius: 50%;
  background: var(--cyan);
}

input[type="range"]::-moz-range-track {
  height: 8px;
  border: 1px solid #4a3021;
  border-radius: 999px;
  background: #24160f;
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 2px solid #130c08;
  border-radius: 50%;
  background: var(--cyan);
}

.control-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.control-row label {
  margin: 0;
}

select {
  min-width: 108px;
  border: 1px solid #553622;
  border-radius: 3px;
  padding: 8px 10px;
  background: #0d0907;
  color: var(--ink);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.fft-module {
  min-width: 0;
  padding: 10px;
  border: 1px solid #3a2519;
  border-radius: 3px;
  background: #100b08;
  box-shadow: none;
}

.fft-segment {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.fft-segment .module-label {
  grid-column: 1 / -1;
}

.fft-option {
  min-height: 34px;
  padding: 0 5px;
  border-color: #503321;
  font-size: 11px;
}

.fft-option.active {
  border-color: rgba(255, 90, 56, 0.78);
  background: #2b140e;
  color: var(--cyan-soft);
  box-shadow: none;
}

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

.visual-panel {
  overflow: hidden;
}

.visual-panel.wide {
  grid-column: 1 / -1;
}

.visual-head {
  display: flex;
  min-height: 37px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 8px 9px;
  background: var(--grain), #110c09;
  background-size: 110px 110px, auto;
}

h2 {
  margin: 0;
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1.2;
  text-transform: uppercase;
}

.visual-head span {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

canvas {
  display: block;
  max-width: 100%;
  width: 100%;
  height: 128px;
  background: var(--grain), #090605;
  background-size: 130px 130px, auto;
}

.wide canvas {
  height: 226px;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100vw - 20px, 560px);
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    padding: 11px;
  }

  .machine-controls {
    gap: 8px;
  }

  .phase-module,
  .fft-module {
    padding: 8px;
  }

  .fft-segment {
    gap: 5px;
  }

  .fft-option {
    min-height: 32px;
    font-size: 10px;
  }

  .primary-actions {
    gap: 6px;
  }

  .primary-actions .spin-button {
    min-height: 68px;
    font-size: 15px;
  }

  .visual-grid {
    gap: 7px;
  }

  .visual-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  h2 {
    font-size: 11px;
  }

  .visual-head span {
    font-size: 10px;
  }

  button {
    min-height: 42px;
    padding: 0 8px;
    font-size: 12px;
  }

  canvas {
    height: 108px;
  }

  .wide canvas {
    height: 206px;
  }
}
