:root {
  --bg: #ffffff;
  --panel: #fafafa;
  --fg: #111111;
  --muted: #666666;
  --line: #e4e4e4;
  --line-strong: #cfcfcf;
  --hover: #f3f3f3;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: auto; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main { flex: 1; }

.wrap {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ---------- Header & navigation ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 48px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--fg);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}

.brand img { border-radius: 4px; }

.nav { display: flex; gap: 0.25rem; }

.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
  border-radius: 5px;
}

.nav-link:hover { background: var(--hover); color: var(--fg); }

.nav-link.active {
  background: var(--fg);
  color: var(--bg);
}

/* ---------- Page Head ---------- */

.page {
  padding: 0.85rem 0 1.25rem;
}

.page[hidden] {
  display: none !important;
}

.page-head {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.lede {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- 3-Column Workspace ---------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 1.1fr) minmax(300px, 1fr) minmax(290px, 0.95fr);
  gap: 1.15rem;
  align-items: start;
}

/* Column 1: Stage */
.stage {
  display: flex;
  flex-direction: column;
}

.screen {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--line-strong);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  width: 100%;
}

.screen canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#tx-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  z-index: 2;
}

#tx-video[hidden] {
  display: none !important;
}

.screen-cam-bar {
  position: absolute;
  bottom: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.5rem;
  z-index: 4;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.screen-cam-bar[hidden] {
  display: none !important;
}

.screen-cam-bar #tx-cam-snap {
  background: #ffffff;
  color: #000000;
  border: 1px solid #ffffff;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.screen-cam-bar #tx-cam-snap:hover {
  background: #ebebeb;
}

.screen-cam-bar #tx-cam-cancel {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  font-weight: 500;
}

.screen-cam-bar #tx-cam-cancel:hover {
  background: rgba(255, 255, 255, 0.28);
  border-color: rgba(255, 255, 255, 0.6);
}

.screen-cam-bar .btn:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

#dropzone { cursor: pointer; }
#dropzone:focus-visible { outline: 2px solid var(--fg); outline-offset: 4px; }
.screen.dragover { outline: 2px dashed var(--fg); outline-offset: 4px; }

.screen-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8a8a8a;
  font-size: 0.85rem;
  border: 1px dashed #444;
  border-radius: var(--radius);
  pointer-events: none;
  text-align: center;
  padding: 1rem;
}

.screen-empty[hidden] { display: none; }

.progress {
  height: 3px;
  margin-top: 0.5rem;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--fg);
  transition: width 0.25s linear;
}

.transport {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.65rem;
}

.transport .ghost { margin-left: auto; }

.status {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

/* Column 2: Monitor */
.monitor {
  display: flex;
  flex-direction: column;
}

.monitor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.55rem;
}

.monitor-head .card-title { margin: 0; }

.meter { display: flex; align-items: center; gap: 0.45rem; }

.meter-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  min-width: 52px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.meter-bar {
  width: 80px;
  height: 5px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: var(--fg);
  transition: width 0.05s ease-out;
}

.monitor-stack {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.scope { margin: 0; }

.scope figcaption {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
  font-weight: 500;
}

.scope-wrap {
  position: relative;
  background: #0a0a0a;
  border-radius: 5px;
  overflow: hidden;
  line-height: 0;
  box-shadow: 0 0 0 1px #222;
}

.scope-wrap canvas { display: block; width: 100%; height: auto; }

.wf-ticks {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2px;
  height: 12px;
  pointer-events: none;
}

.wf-ticks span {
  position: absolute;
  transform: translateX(-50%);
  font-size: 8.5px;
  font-family: var(--mono);
  color: rgba(255, 255, 255, 0.85);
  background: rgba(0, 0, 0, 0.7);
  padding: 0 2px;
  border-radius: 2px;
  line-height: 1.15;
}

/* Column 3: Controls (Sidebar) */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ---------- Cards ---------- */

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 0.75rem 0.85rem;
}

.card-title {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.card-row .card-title { margin: 0; }

.thumb-header {
  margin: 0.45rem 0 0.35rem;
}

.hint {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
}

/* ---------- Buttons & inputs ---------- */

.btn {
  font: inherit;
  font-size: 0.82rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  transition: background 0.1s;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { background: var(--hover); }

.btn.primary {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
  min-width: 6.5rem;
  font-weight: 550;
}

.btn.primary:hover:not(:disabled) { background: #333; }

.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { color: var(--fg); }

.btn.block { width: 100%; }

.btn.small {
  font-size: 0.75rem;
  padding: 0.25rem 0.55rem;
}

.btn.tiny {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
}

.btn-group {
  display: flex;
  gap: 0.35rem;
}

.btn:disabled { opacity: 0.4; cursor: default; }

.btn:focus-visible,
.nav-link:focus-visible,
.thumb:focus-visible,
.input:focus-visible,
.segmented input:focus-visible + span {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.input {
  width: 100%;
  font: inherit;
  font-size: 0.82rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 0.35rem 0.55rem;
}

select.input {
  cursor: pointer;
  appearance: auto;
}

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.field.stack {
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
}

.field-label { font-size: 0.75rem; color: var(--muted); }

.field.disabled { opacity: 0.35; pointer-events: none; }

.segmented {
  display: flex;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 2px;
  gap: 2px;
}

.segmented label { flex: 1; }

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  text-align: center;
  font-size: 0.78rem;
  padding: 0.25rem 0.45rem;
  border-radius: 3px;
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}

.segmented span:hover { background: var(--hover); color: var(--fg); }

.segmented input:checked + span {
  background: var(--fg);
  color: var(--bg);
}

.segmented.small span { font-size: 0.72rem; padding: 0.2rem 0.4rem; }

.overlay-row {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.overlay-row .input { flex: 1; }

/* ---------- Test image thumbnails ---------- */

.thumbs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

.thumb {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.65rem;
  color: var(--muted);
  text-align: center;
}

.thumb canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
}

.thumb:hover canvas { border-color: var(--muted); }
.thumb.active canvas { outline: 2px solid var(--fg); outline-offset: 1px; }
.thumb.active { color: var(--fg); font-weight: 550; }

/* ---------- Signal stats ---------- */

.stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 0.75rem;
  margin: 0;
  font-size: 0.8rem;
}

.stats dt { color: var(--muted); }

.stats dd {
  margin: 0;
  text-align: right;
  font-family: var(--mono);
  font-size: 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- History gallery ---------- */

.history-card {
  display: flex;
  flex-direction: column;
}

.rx-history-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 140px;
  overflow-y: auto;
  padding-right: 2px;
}

.rx-history-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.25rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.1s, background 0.1s;
}

.rx-history-item:hover {
  background: var(--hover);
  border-color: var(--line-strong);
}

.rx-history-item.active {
  border-color: var(--fg);
}

.rx-hist-thumb {
  width: 36px;
  height: 27px;
  border-radius: 3px;
  object-fit: cover;
  background: #000;
  border: 1px solid var(--line-strong);
  flex-shrink: 0;
}

.rx-hist-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.rx-hist-time {
  font-size: 0.72rem;
  font-family: var(--mono);
  font-weight: 550;
  color: var(--fg);
}

.rx-hist-detail {
  font-size: 0.68rem;
  color: var(--muted);
}

.rx-hist-actions {
  display: flex;
  gap: 0.2rem;
}

.rx-hist-actions .btn {
  padding: 0.15rem 0.35rem;
  font-size: 0.68rem;
  line-height: 1;
}

/* ---------- Guide ---------- */

.guide-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.prose ol,
.prose ul { margin: 0; padding-left: 1.15rem; font-size: 0.82rem; }

.prose li + li { margin-top: 0.35rem; }

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: auto;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.35rem 1rem;
  min-height: 38px;
  padding: 0.5rem 0;
  line-height: 1.4;
}

.site-footer a { color: var(--fg); }
.site-footer a:hover { text-decoration: none; }

/* ---------- Responsive Breakpoints ---------- */

/* Laptop / Desktop (Standard widescreen) */
@media (min-width: 992px) {
  /* Fits cleanly in typical laptop viewport */
  .page { padding-top: 0.75rem; padding-bottom: 0.75rem; }
}

/* Medium screens: 2 columns (e.g. tablet, half-window) */
@media (max-width: 991px) and (min-width: 681px) {
  .workspace {
    grid-template-columns: 1fr 1fr;
  }
  .monitor {
    grid-column: 1 / 2;
  }
  .stage {
    grid-column: 1 / 2;
  }
  .sidebar {
    grid-column: 2 / 3;
    grid-row: 1 / 3;
  }
  .guide-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Mobile: 1 column stacked */
@media (max-width: 680px) {
  .wrap { padding: 0 0.85rem; }
  .page-head { flex-direction: column; gap: 0.15rem; margin-bottom: 0.65rem; }
  .workspace { grid-template-columns: 1fr; gap: 0.85rem; }
  .guide-grid { grid-template-columns: 1fr; }
  .brand span { display: none; }
  .transport .btn { flex: 1 1 auto; }
  .transport .ghost { margin-left: 0; }
  .footer-inner {
    flex-direction: column;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.75rem 0;
    text-align: center;
  }
}
