:root {
  --bg: #0b0f14;
  --panel: #12171f;
  --panel-2: #161d27;
  --line: #232b36;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #ffb000;
  --accent-dim: #8a6d1a;
  --blue: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --magenta: #bc8cff;
  --cyan: #39c5cf;
  --amber-bg: #1c1610;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Segoe UI", Tahoma, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: linear-gradient(180deg, #182230, #0f1620);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 14px; }

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: radial-gradient(circle at 30% 30%, #3a3f15, #171a0a);
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 1px;
  font-size: 15px;
  box-shadow: 0 0 18px rgba(255, 176, 0, 0.25);
}

.brand-text h1 { margin: 0; font-size: 17px; font-weight: 700; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------- layout ---------- */
.layout {
  flex: 1;
  display: flex;
  gap: 14px;
  padding: 14px;
  min-height: 0;
}

.screen {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.screen-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}

#measurement-label { color: var(--accent); font-weight: 600; }

.canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

#trace { display: block; width: 100%; height: 100%; cursor: crosshair; }

.cursor-readout {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 12.5px;
  color: var(--muted);
  flex-shrink: 0;
}

.cursor-readout b { color: var(--text); font-family: ui-monospace, Consolas, monospace; }
.cursor-readout span:nth-child(1) b { color: var(--blue); }
.cursor-readout span:nth-child(2) b { color: var(--green); }
.cursor-readout span:nth-child(3) b { color: var(--text); }

/* ---------- side panel ---------- */
.panel {
  width: 300px;
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  overflow-y: auto;
}

.panel h2 {
  margin: 16px 0 10px;
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}
.panel h2:first-child { margin-top: 0; }

.field {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px 10px;
  margin-bottom: 12px;
  font-size: 12.5px;
  color: var(--text);
}

.field span { grid-column: 1 / -1; }

.field select {
  grid-column: 1 / -1;
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

.field input[type="range"] {
  grid-column: 1;
  width: 100%;
  accent-color: var(--accent);
}

.field output {
  grid-column: 2;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  color: var(--accent);
  background: var(--amber-bg);
  border: 1px solid var(--accent-dim);
  border-radius: 5px;
  padding: 2px 7px;
  min-width: 48px;
  text-align: center;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  margin-bottom: 14px;
  cursor: pointer;
  color: var(--text);
}

.check input { accent-color: var(--accent); width: 15px; height: 15px; }

button#regenerate {
  width: 100%;
  background: linear-gradient(180deg, #d99a00, #b57f00);
  color: #1a1200;
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s;
}

button#regenerate:hover { filter: brightness(1.12); }
button#regenerate:active { transform: translateY(1px); }

.info { display: grid; gap: 7px; }
.info div {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--muted);
  border-bottom: 1px dashed var(--line);
  padding-bottom: 5px;
}
.info b {
  font-family: ui-monospace, Consolas, monospace;
  color: var(--text);
  font-size: 12.5px;
}

/* ---------- events table ---------- */
.events {
  margin: 0 14px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
  max-height: 34vh;
  display: flex;
  flex-direction: column;
}

.events-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}

.events-head h2 { margin: 0; font-size: 14px; color: var(--text); }

.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 5px; }

.dot {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  display: inline-block;
}
.dot-refl { background: var(--red); }
.dot-loss { background: var(--magenta); }
.dot-end { background: var(--cyan); }

.table-wrap { overflow-y: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  text-align: right;
  padding: 8px 12px;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}

tbody td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-family: ui-monospace, Consolas, monospace;
}

tbody tr:hover td { background: rgba(255, 176, 0, 0.05); }

td.type-refl { color: var(--red); }
td.type-loss { color: var(--magenta); }
td.type-end { color: var(--cyan); }

.empty-row td { color: var(--muted); text-align: center !important; font-family: inherit; }

/* ---------- scrollbars ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: var(--panel); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #33404f; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .panel { width: 100%; }
  body { overflow: auto; }
  .screen { min-height: 60vh; }
}
