:root {
  color-scheme: light;
  --ink: #102331;
  --muted: #607283;
  --panel: #ffffff;
  --panel-2: #f4f8fb;
  --line: #d7e2eb;
  --blue: #1676d2;
  --teal: #0f9f9a;
  --green: #1a9a5b;
  --amber: #e58a00;
  --red: #d74646;
  --shadow: 0 18px 45px rgba(17, 42, 62, 0.14);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #eaf1f6;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 260px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  color: #ffffff;
  background: linear-gradient(135deg, #102331, #1676d2 54%, #0f9f9a);
  border-radius: 8px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.15;
}

.brand p,
.map-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.controls {
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.setup-label {
  display: flex;
  min-width: 170px;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 10px 12px;
  background: #102331;
  color: #ffffff;
}

.setup-label strong {
  font-size: 14px;
}

.setup-label span {
  color: rgba(255, 255, 255, 0.75);
  font-size: 12px;
}

.control {
  min-width: 168px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.toggle-control {
  justify-content: center;
  min-height: 58px;
  color: var(--ink);
  font-weight: 850;
  cursor: pointer;
}

.toggle-control[aria-pressed="true"] {
  color: #ffffff;
  background: var(--amber);
  border-color: #c97800;
}

.start-control {
  justify-content: center;
  min-height: 58px;
  color: #ffffff;
  background: var(--green);
  border-color: #127a46;
  font-weight: 900;
  cursor: pointer;
}

.start-control:disabled {
  color: #617485;
  background: #eef4f8;
  cursor: default;
}

.control span,
.control legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.speed-control {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 74px;
  gap: 10px;
  align-items: center;
}

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

output {
  font-weight: 800;
  text-align: right;
}

.band-control {
  border: 1px solid var(--line);
  margin: 0;
}

.band-control label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 8px;
}

.band-control label span {
  color: var(--ink);
  font-size: 14px;
  font-weight: 750;
  text-transform: none;
  letter-spacing: 0;
}

select {
  min-height: 36px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
}

.workspace {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(620px, 1fr) 360px;
  gap: 16px;
}

.map-panel,
.device-screen {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.map-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

.map-header h2,
.device-screen h2 {
  font-size: 16px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  width: 20px;
  height: 4px;
  display: inline-block;
  border-radius: 2px;
}

.legend-wall {
  background: #14364e;
}

.legend-noise {
  background: #f0a433;
}

.legend-ap {
  background: var(--red);
}

.legend-link {
  background: var(--teal);
}

.house-map {
  position: relative;
  flex: 1;
  min-height: 650px;
  overflow: hidden;
  touch-action: none;
  background: #dfeaf2;
}

.map-view-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 8;
  min-height: 36px;
  padding: 0 14px;
  color: #102331;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 8px 22px rgba(17, 42, 62, 0.14);
  font-weight: 850;
  cursor: pointer;
}

.map-view-toggle:hover {
  transform: translateY(-1px);
}

.first-run .house-map {
  cursor: default;
}

.setup-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 5;
  display: none;
  width: min(360px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  padding: 18px;
  color: #102331;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  text-align: center;
}

.setup-overlay strong,
.setup-overlay span {
  display: block;
}

.setup-overlay strong {
  font-size: 18px;
}

.setup-overlay span {
  margin-top: 8px;
  color: #526879;
  font-size: 13px;
  line-height: 1.45;
}

.first-run .setup-overlay {
  display: block;
}

.first-run .map-panel,
.first-run .device-screen {
  box-shadow: 0 18px 45px rgba(17, 42, 62, 0.08);
}

.first-run .node,
.first-run .coverage,
.first-run .link-line {
  opacity: 0.35;
}

.blueprint {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.side-blueprint {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
}

.side-view .blueprint {
  display: none;
}

.side-view .side-blueprint {
  display: block;
}

.house-boundary {
  fill: #f8fbfd;
  stroke: #14364e;
  stroke-width: 8;
}

.yard-path {
  fill: none;
  stroke: rgba(87, 130, 67, 0.45);
  stroke-width: 18;
  stroke-linecap: round;
  stroke-dasharray: 24 20;
}

.shed rect {
  fill: #d9e4c5;
  stroke: #6f844f;
  stroke-width: 4;
}

.shed path {
  fill: #b88b58;
  stroke: #6f844f;
  stroke-width: 4;
}

.shed text {
  font-size: 14px;
  font-weight: 900;
  text-anchor: middle;
  fill: #4f6138;
  pointer-events: none;
}

.side-house path {
  fill: #f2f5f7;
  stroke: #14364e;
  stroke-width: 7;
  stroke-linejoin: round;
}

.side-house rect {
  fill: #f8fbfd;
  stroke: #14364e;
  stroke-width: 7;
}

.side-house line {
  stroke: #14364e;
  stroke-width: 6;
}

.side-room-labels text,
.side-floor-loss text {
  font-size: 18px;
  font-weight: 850;
  fill: #526879;
  text-anchor: middle;
}

.side-floor-loss line {
  stroke: rgba(215, 70, 70, 0.5);
  stroke-width: 8;
  stroke-dasharray: 16 12;
}

.side-floor-loss text {
  font-size: 14px;
  fill: #9f2525;
}

.floor-plan {
  display: none;
}

.floor-plan.active {
  display: block;
}

.room-fill {
  opacity: 0.82;
  stroke: none;
}

.room-lounge {
  fill: #edf7f5;
}

.room-kitchen {
  fill: #f8f3e7;
}

.room-office {
  fill: #eef3fb;
}

.room-bedroom {
  fill: #f5eef8;
}

.room-bedroom-two {
  fill: #eff7ee;
}

.room-garage {
  fill: #f1f4f5;
}

.walls line {
  stroke: #14364e;
  stroke-width: 9;
  stroke-linecap: square;
  transition: stroke 180ms ease, stroke-width 180ms ease, opacity 180ms ease;
}

.doors path {
  fill: none;
  stroke: #7e98aa;
  stroke-width: 4;
  stroke-dasharray: 7 7;
}

.furniture rect {
  fill: #d6e0e7;
  stroke: #9fb1bf;
  stroke-width: 2;
}

.noise-zone circle {
  fill: rgba(229, 138, 0, 0.16);
  stroke: rgba(229, 138, 0, 0.72);
  stroke-width: 3;
  stroke-dasharray: 7 7;
}

.noise-zone text,
.room-label {
  font-size: 18px;
  font-weight: 800;
  fill: #47606f;
  pointer-events: none;
}

.noise-zone text {
  font-size: 14px;
  text-anchor: middle;
  fill: #a25f00;
}

.noise-zone,
.ethernet-emi,
.extra-interference circle {
  transition: filter 180ms ease, opacity 180ms ease, stroke-width 180ms ease;
}

.ethernet-emi {
  display: none;
  opacity: .78;
}

.ethernet-mode .ethernet-emi {
  display: block;
}

.ethernet-emi path {
  fill: none;
  stroke: #d74646;
  stroke-width: 5;
  stroke-dasharray: 10 7;
  stroke-linecap: round;
}

.ethernet-emi rect {
  fill: rgba(215, 70, 70, 0.14);
  stroke: rgba(215, 70, 70, 0.78);
  stroke-width: 3;
  stroke-dasharray: 7 7;
}

.ethernet-emi text {
  font-size: 13px;
  font-weight: 900;
  text-anchor: middle;
  fill: #9f2525;
  pointer-events: none;
}

.extra-interference {
  display: none;
}

.extra-interference.active {
  display: block;
}

.extra-interference circle {
  fill: rgba(215, 70, 70, 0.18);
  stroke: rgba(215, 70, 70, 0.82);
  stroke-width: 4;
}

.extra-interference text {
  font-size: 15px;
  font-weight: 900;
  text-anchor: middle;
  fill: #9f2525;
}

.coverage {
  position: absolute;
  width: 430px;
  height: 430px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  filter: blur(0.2px);
}

.ring {
  position: absolute;
  inset: 0;
  border: 2px solid rgba(15, 159, 154, 0.42);
  border-radius: 50%;
  animation: pulse 2.8s linear infinite;
}

.ring-2 {
  inset: 52px;
  animation-delay: 0.35s;
}

.ring-3 {
  inset: 104px;
  animation-delay: 0.7s;
}

.coverage-weak .ring {
  border-color: rgba(215, 70, 70, 0.42);
}

.coverage-fair .ring {
  border-color: rgba(229, 138, 0, 0.46);
}

.coverage.impact .ring {
  border-color: rgba(215, 70, 70, 0.82);
  border-width: 4px;
}

@keyframes pulse {
  0% {
    opacity: 0.2;
    transform: scale(0.86);
  }
  55% {
    opacity: 0.58;
  }
  100% {
    opacity: 0.08;
    transform: scale(1.04);
  }
}

.link-line {
  position: absolute;
  height: 4px;
  background: var(--teal);
  transform-origin: left center;
  border-radius: 4px;
  box-shadow: 0 0 16px rgba(15, 159, 154, 0.45);
  pointer-events: none;
}

.link-line.weak {
  background: var(--red);
  box-shadow: 0 0 16px rgba(215, 70, 70, 0.45);
}

.link-line.fair {
  background: var(--amber);
  box-shadow: 0 0 16px rgba(229, 138, 0, 0.45);
}

.link-line.wired {
  height: 5px;
  background: #102331;
  box-shadow: none;
}

.analysis-mode .walls line,
.analysis-mode .noise-zone,
.analysis-mode .ethernet-emi,
.analysis-mode .extra-interference circle {
  opacity: 0.28;
}

.analysis-mode .walls line.impact {
  opacity: 1;
  stroke: var(--red);
  stroke-width: 14;
}

.analysis-mode .noise-zone.impact,
.analysis-mode .ethernet-emi.impact,
.analysis-mode .extra-interference circle.impact {
  opacity: 1;
  filter: drop-shadow(0 0 10px rgba(215, 70, 70, 0.85));
}

.node {
  position: absolute;
  display: grid;
  place-items: center;
  gap: 4px;
  width: 86px;
  height: 74px;
  padding: 7px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  box-shadow: 0 12px 26px rgba(17, 42, 62, 0.26);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.node.selected {
  outline: 4px solid rgba(229, 138, 0, 0.9);
  outline-offset: 3px;
}

.node.remote-floor {
  opacity: 0.5;
  filter: grayscale(0.4);
}

.node:active {
  cursor: grabbing;
}

.router-node {
  background: #102331;
}

.client-node {
  background: #1676d2;
}

.node-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 28px;
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 5px;
  font-weight: 900;
}

.node-label {
  font-size: 12px;
  font-weight: 800;
}

.device-screen {
  min-width: 0;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.screen-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  padding: 0 2px 10px;
  border-bottom: 1px solid var(--line);
}

.screen-top > div {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 850;
}

.status-dot {
  width: 10px;
  height: 10px;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 0 5px rgba(26, 154, 91, 0.15);
}

.wifi-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 22px;
}

.wifi-bars i {
  width: 6px;
  background: #b9c6d1;
  border-radius: 4px 4px 0 0;
}

.wifi-bars i:nth-child(1) {
  height: 7px;
}

.wifi-bars i:nth-child(2) {
  height: 11px;
}

.wifi-bars i:nth-child(3) {
  height: 16px;
}

.wifi-bars i:nth-child(4) {
  height: 21px;
}

.wifi-bars[data-bars="1"] i:nth-child(-n + 1),
.wifi-bars[data-bars="2"] i:nth-child(-n + 2),
.wifi-bars[data-bars="3"] i:nth-child(-n + 3),
.wifi-bars[data-bars="4"] i:nth-child(-n + 4) {
  background: var(--green);
}

.wifi-bars[data-bars="0"] i {
  background: #d5dee6;
}

.metric-hero {
  display: grid;
  place-items: center;
  min-height: 92px;
  color: #ffffff;
  background: #1676d2;
  border-radius: 8px;
}

.metric-hero span {
  font-size: 42px;
  line-height: 1;
  font-weight: 900;
}

.metric-hero small {
  margin-top: -8px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric,
.explain-card,
.speed-test-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric {
  min-height: 72px;
  padding: 11px;
}

.metric span,
.speed-result span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.metric strong,
.speed-result strong {
  display: block;
  margin-top: 7px;
  font-size: 19px;
  line-height: 1.1;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
}

.disabled-control {
  opacity: 0.48;
}

.ethernet-only {
  border-color: rgba(15, 159, 154, 0.35);
}

.disabled-control select,
.disabled-control input {
  pointer-events: none;
}

.primary-action,
.secondary-action {
  min-height: 42px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-weight: 850;
  cursor: pointer;
}

.primary-action {
  color: #ffffff;
  background: var(--blue);
}

.secondary-action {
  color: var(--ink);
  background: #ffffff;
  border-color: var(--line);
}

.muted-action {
  min-height: 38px;
  color: #415565;
  background: #f8fbfd;
}

.primary-action:disabled,
.secondary-action:disabled {
  cursor: wait;
  opacity: 0.68;
  transform: none;
}

.primary-action:hover,
.secondary-action:hover {
  transform: translateY(-1px);
}

.speed-progress {
  height: 8px;
  overflow: hidden;
  background: #dce7ef;
  border-radius: 999px;
  opacity: 0;
}

.speed-progress span {
  display: block;
  width: 38%;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--blue));
  border-radius: inherit;
  transform: translateX(-120%);
}

.speed-progress.running {
  opacity: 1;
}

.speed-progress.running span {
  animation: speedSweep 1.15s ease-in-out infinite;
}

@keyframes speedSweep {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(280%);
  }
}

.explain-card,
.speed-test-card {
  padding: 12px;
}

.explain-card ul {
  margin: 10px 0 0;
  padding-left: 18px;
  color: #304757;
}

.explain-card p {
  margin-top: 8px;
  color: #526879;
  font-size: 13px;
  line-height: 1.45;
}

.explain-card li {
  margin: 8px 0;
  font-size: 13px;
}

.explain-card li strong {
  display: block;
  color: var(--ink);
}

.explain-card li span {
  display: block;
  margin-top: 3px;
  color: #526879;
}

.speed-result {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.speed-result:first-of-type {
  margin-top: 8px;
}

.speed-result strong {
  margin-top: 0;
  text-align: right;
}

@media (max-width: 1100px) {
  .topbar,
  .map-header {
    align-items: stretch;
    flex-direction: column;
  }

  .controls {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .device-screen {
    order: -1;
  }

  .house-map {
    min-height: 520px;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 10px;
  }

  .brand {
    min-width: 0;
  }

  .controls,
  .control {
    width: 100%;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .house-map {
    min-height: 430px;
  }

  .node {
    width: 74px;
    height: 66px;
  }
}
