:root {
  --bg: #0b0f17;
  --panel-bg: #10151f;
  --border: #202a3a;
  --text: #e6ebf5;
  --text-dim: #8a97ab;
  --accent: #4fd1c5;
  --accent-dim: rgba(79, 209, 197, 0.15);
  --danger: #ff5d6c;
  --danger-dim: rgba(255, 93, 108, 0.15);
  --radius: 10px;
}

* { box-sizing: border-box; }

/* Author rules below set `display` on elements also toggled via the
   `hidden` attribute. Author CSS always beats the UA stylesheet's
   `[hidden]{display:none}` regardless of specificity, so without this
   override those elements would stay visible while "hidden". */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 600; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px 2px var(--accent-dim);
}

.stats { display: flex; gap: 26px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; align-items: flex-end; min-width: 64px; }
.stat-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.stat span:last-child { font-size: 18px; font-weight: 600; }

.layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
  padding: 16px;
  min-height: calc(100vh - 64px);
}

.layout > * { min-height: 0; }

.charts-pane { display: flex; flex-direction: column; gap: 16px; }

.chart-panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.chart-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 6px;
}

.chart-panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 10px;
}
.chart-header h2 { margin: 0; }

.chart-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
}

.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 3px;
  border-radius: 2px;
  margin-left: 8px;
}
.legend-swatch:first-child { margin-left: 0; }
.legend-swatch.line { background: var(--accent); }
.legend-swatch.drop { background: var(--danger); }

.hint-text {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0;
}

#lineChart, #histogram { width: 100%; display: block; }
#lineChart { height: 260px; }
#histogram { height: 200px; }

.session-stats .session-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.session-stat {
  background: #182333;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.session-stat span:last-child { font-size: 16px; font-weight: 600; }

.control-pane {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 10px;
}

.field {
  display: block;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--text-dim);
}
.field span { display: block; margin-bottom: 6px; }
.field b { color: var(--text); }

.select, .text-input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #182333;
  color: var(--text);
  font-size: 13px;
}
.select { cursor: pointer; }
.select:focus, .text-input:focus { outline: 1px solid var(--accent); }

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

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #182333;
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06231f;
  font-weight: 600;
}

.btn-ghost { background: transparent; }

/* ---------- Chart SVG elements ---------- */

.chart-grid-line { stroke: var(--border); stroke-width: 1; }
.chart-axis-label { fill: var(--text-dim); font-size: 11px; }

.latency-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.latency-area { fill: var(--accent-dim); stroke: none; }

.drop-tick { stroke: var(--danger); stroke-width: 2; }

.hist-bar { fill: var(--accent); opacity: 0.85; }
.hist-bar:hover { opacity: 1; }
.hist-empty-label { fill: var(--text-dim); font-size: 13px; text-anchor: middle; }

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .session-stats .session-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Rotate-device prompt (mobile portrait only) ---------- */

.rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(11, 15, 23, 0.97);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
  padding: 24px;
}

@media (max-width: 700px) and (orientation: portrait) {
  .rotate-overlay:not(.dismissed) {
    display: flex;
  }
}

.rotate-overlay .phone-icon {
  width: 64px;
  height: 64px;
  color: var(--accent);
}

.rotate-overlay .phone-shape {
  animation: rotate-phone 1.8s ease-in-out infinite;
  transform-origin: 24px 24px;
}

@keyframes rotate-phone {
  0%, 15% { transform: rotate(0deg); }
  50%, 65% { transform: rotate(90deg); }
  100% { transform: rotate(0deg); }
}

.rotate-overlay .rotate-arrow {
  opacity: 0.7;
}

.rotate-overlay p {
  max-width: 260px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  margin: 0;
}
