:root {
  --bg: #0b0f14;
  --bg-2: #111823;
  --card: #141c28;
  --card-2: #1a2434;
  --line: #24303f;
  --text: #e6edf3;
  --muted: #8b9bb0;
  --accent: #38bdf8;
  --accent-2: #22d3ee;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: radial-gradient(1200px 600px at 20% -10%, #16233a 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(11, 15, 20, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  letter-spacing: 0.2px;
}

.brand-mark {
  width: 10px;
  height: 22px;
  border-radius: 5px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.45);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.room-badge {
  color: var(--muted);
  font-size: 13px;
  background: var(--card);
  border: 1px solid var(--line);
  padding: 4px 10px;
  border-radius: 999px;
}
.room-badge b {
  color: var(--text);
  font-weight: 600;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--card);
  padding: 4px 11px;
  border-radius: 999px;
  white-space: nowrap;
}
.conn .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.conn[data-state='live'] .dot {
  background: var(--good);
  box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6);
  animation: pulse 2s infinite;
}
.conn[data-state='connecting'] .dot {
  background: var(--warn);
}
.conn[data-state='error'] .dot {
  background: var(--bad);
}
@keyframes pulse {
  70% {
    box-shadow: 0 0 0 7px rgba(52, 211, 153, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(52, 211, 153, 0);
  }
}

/* ------------------------------------------------------------------ main */

main {
  max-width: 1160px;
  margin: 0 auto;
  padding: 22px 18px 40px;
}

.view {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 18px;
  align-items: start;
}
.view.hidden {
  display: none;
}
.hidden {
  display: none !important;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

#view-choose {
  display: block;
  max-width: 820px;
  margin: 0 auto;
}
#view-choose.hidden {
  display: none;
}

.hero {
  text-align: center;
  padding: 26px 0 10px;
}
.hero h1 {
  margin: 0 0 10px;
  font-size: 34px;
  letter-spacing: -0.5px;
}
.hero .sub {
  margin: 0 auto;
  max-width: 560px;
  color: var(--muted);
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin: 26px 0;
}

.role-card {
  appearance: none;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--card-2), var(--card));
  color: var(--text);
  transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}
.role-card:hover,
.role-card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  outline: none;
}
.role-icon svg {
  width: 30px;
  height: 30px;
  color: var(--accent);
}
.role-title {
  font-size: 19px;
  font-weight: 650;
}
.role-desc {
  color: var(--muted);
  font-size: 14px;
}

.room-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  color: var(--muted);
}
.room-picker input {
  width: 180px;
}
.room-picker .hint {
  width: 100%;
  text-align: center;
  margin: 6px 0 0;
}

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.card h2 {
  margin: 0 0 14px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  font-weight: 650;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.field {
  margin-bottom: 14px;
  min-width: 0;
}
.field:last-child {
  margin-bottom: 0;
}
.field > label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}
.field > label b {
  color: var(--text);
  font-family: var(--mono);
  font-weight: 500;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0 14px;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.row > select,
.row > input {
  flex: 1;
  min-width: 0;
}

select,
input[type='text'] {
  width: 100%;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
select:focus,
input:focus {
  outline: 2px solid rgba(56, 189, 248, 0.5);
  outline-offset: 1px;
}
input[readonly] {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12.5px;
}

input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
  height: 26px;
}

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13.5px;
  color: var(--text);
  margin-bottom: 10px;
  cursor: pointer;
}
.check input {
  margin-top: 3px;
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  flex: none;
}
.check small {
  color: var(--muted);
  display: block;
}

.hint {
  color: var(--muted);
  font-size: 12.5px;
  margin: 6px 0 0;
}
.hint code {
  font-family: var(--mono);
  background: var(--bg-2);
  padding: 1px 5px;
  border-radius: 5px;
}

.status {
  margin: 14px 0 0;
  font-size: 13.5px;
  color: var(--muted);
  min-height: 20px;
}
.status.err {
  color: var(--bad);
}
.status.ok {
  color: var(--good);
}

/* --------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: background 0.13s ease, border-color 0.13s ease, opacity 0.13s ease;
  white-space: nowrap;
}
.btn:hover:not(:disabled) {
  border-color: var(--accent);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: linear-gradient(180deg, var(--accent), #0ea5e9);
  border-color: transparent;
  color: #04121c;
}
.btn-danger {
  background: #3b1d1d;
  border-color: #6b2b2b;
  color: #fecaca;
}
.btn-ghost {
  background: transparent;
}
.btn-lg {
  padding: 13px 24px;
  font-size: 15px;
}
.btn-sm {
  padding: 5px 11px;
  font-size: 12.5px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.actions.right {
  justify-content: flex-end;
  margin-top: 12px;
}

.listen-card {
  text-align: left;
}
.btn-listen {
  width: 100%;
  padding: 18px;
  font-size: 17px;
  border-radius: 12px;
}
.btn-listen.live {
  background: #3b1d1d;
  border-color: #6b2b2b;
  color: #fecaca;
}

/* ----------------------------------------------------------------- meter */

.meter {
  position: relative;
  height: 12px;
  margin-top: 16px;
  border-radius: 6px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.meter-bar {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, var(--good) 0%, var(--good) 62%, var(--warn) 84%, var(--bad) 100%);
  background-size: 100vw 100%;
  transition: width 0.06s linear;
}
.meter-peak {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  left: 0;
  background: #fff;
  opacity: 0.85;
  transition: left 0.1s linear;
}
.meter-scale {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10.5px;
  font-family: var(--mono);
  margin-top: 4px;
}

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

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
}
.stat {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.stat.wide {
  grid-column: 1 / -1;
}
.stat .k {
  color: var(--muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat .v {
  font-family: var(--mono);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.stat .v.big {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.5px;
}
.stat .v.small {
  font-size: 12.5px;
}
.stat .v.warn {
  color: var(--warn);
}
.stat .v.bad {
  color: var(--bad);
}
.stat .v.good {
  color: var(--good);
}

canvas#chart {
  width: 100%;
  height: 180px;
  display: block;
  border-radius: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
}

.legend {
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  font-weight: 400;
  display: flex;
  gap: 10px;
  align-items: center;
}
.sw {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  margin-right: 4px;
}
.sw-lat {
  background: var(--accent);
}
.sw-buf {
  background: var(--good);
}
.sw-loss {
  background: var(--bad);
}

/* ---------------------------------------------------------------- footer */

.footer {
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 18px 28px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

@media (max-width: 640px) {
  main {
    padding: 14px 12px 30px;
  }
  .hero h1 {
    font-size: 26px;
  }
  .card {
    padding: 15px;
  }
  .stats {
    grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  }
  .stat .v.big {
    font-size: 26px;
  }
  .topbar {
    padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top));
  }
  .brand-name {
    display: none;
  }
}
