:root {
  color-scheme: dark;
  --bg: #0d1013;
  --panel: #151a1f;
  --panel-2: #1b2128;
  --line: #262e37;
  --text: #dfe6ed;
  --muted: #8593a1;
  --tx: #f0a04b;
  --rx: #4bd0a0;
  --fx: #e0569b;
  --accent: #5aa9f0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, -apple-system, "SF Pro Text", system-ui, sans-serif;
  padding-block: 0 40px;
}

header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}
h1 { font-size: 20px; margin: 0; letter-spacing: 0.04em; }
h1 span {
  font-weight: 400;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.02em;
  margin-left: 10px;
}
.ctx-info { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

main {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
  padding: 16px 24px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
}
.panel h2 {
  margin: 0 0 14px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.tx { background: var(--tx); }
.dot.rx { background: var(--rx); }
.dot.fx { background: var(--fx); }

/* --- interference panel --- */
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.presets button { padding: 4px 10px; font-size: 12px; border-radius: 20px; }
.presets button.on { background: var(--fx); border-color: var(--fx); color: #16060f; font-weight: 500; }
.fx-group {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #6c7885;
  margin: 12px 0 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
#fxPanel .row label { width: 68px; font-size: 11px; }
#fxPanel input[type='range'] { accent-color: var(--fx); }
#fxPanel output { width: 62px; }
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.check input { accent-color: var(--fx); }
#fxBar { background: var(--fx); }
.dot.live { box-shadow: 0 0 0 0 currentColor; animation: pulse 1.4s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(75, 208, 160, 0.6); }
  70% { box-shadow: 0 0 0 8px rgba(75, 208, 160, 0); }
  100% { box-shadow: 0 0 0 0 rgba(75, 208, 160, 0); }
}

/* --- transmit preview / drop target --- */
.drop {
  position: relative;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  display: grid;
  place-items: center;
  min-height: 190px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop:hover, .drop:focus-visible, .drop.over { border-color: var(--tx); background: #1f252c; outline: none; }
.drop canvas { max-width: 100%; height: auto; border-radius: 4px; display: none; image-rendering: pixelated; }
.drop.has-image canvas { display: block; }
.drop.has-image .drop-hint { display: none; }
.drop-hint { text-align: center; color: var(--muted); display: grid; gap: 4px; }
.drop-hint strong { color: var(--text); font-weight: 500; }
.drop-hint span { font-size: 12px; }

/* --- receive view --- */
.rx-view {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
  margin-bottom: 14px;
}
#rxCanvas {
  width: 100%;
  background: #000;
  border-radius: 6px;
  border: 1px solid var(--line);
  image-rendering: pixelated;
  aspect-ratio: 320 / 256;
  max-width: 100%;
}
#waterfall {
  width: 110px;
  height: 140px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #05070a;
}

/* --- controls --- */
.row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.row label { width: 62px; flex: none; color: var(--muted); font-size: 12px; }
select, input[type='range'] { flex: 1; min-width: 0; }
select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
}
input[type='range'] { accent-color: var(--accent); }
output { width: 58px; flex: none; text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.meta {
  margin: 12px 0;
  padding: 8px 10px;
  background: var(--panel-2);
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-height: 33px;
}

.buttons { display: flex; flex-wrap: wrap; gap: 8px; }
button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 13px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
button:hover:not(:disabled) { background: #232b33; border-color: #38434f; }
button.primary { background: var(--accent); border-color: var(--accent); color: #06121e; font-weight: 500; }
button.primary:hover:not(:disabled) { background: #74baf5; border-color: #74baf5; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.progress { height: 3px; background: var(--line); border-radius: 2px; margin-top: 12px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.1s linear; }
#txBar { background: var(--tx); }
#rxBar { background: var(--rx); }

.level { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin-bottom: 4px; }
#levelBar { height: 100%; width: 0; background: var(--rx); transition: width 0.08s; }

.log-wrap { padding: 0 24px; }
.log-wrap h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin: 8px 0;
}
#log {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin: 0;
  max-height: 180px;
  overflow: auto;
  font: 12px/1.6 ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--muted);
  white-space: pre-wrap;
}

footer { padding: 16px 24px 0; color: var(--muted); font-size: 12px; max-width: 900px; }
footer em { color: var(--text); font-style: normal; }
footer code { background: var(--panel-2); padding: 1px 5px; border-radius: 3px; }

@media (max-width: 520px) {
  header, main, .log-wrap, footer { padding-inline: 16px; }
  .rx-view { grid-template-columns: 1fr; }
  #waterfall { width: 100%; height: 90px; }
  .row label { width: 54px; }
}
