:root {
  --bg: #101413;
  --panel: #f6f3ec;
  --panel-2: #e7edf2;
  --ink: #16211f;
  --muted: #61706b;
  --line: #cdd5cf;
  --accent: #007a75;
  --accent-2: #bd3f2f;
  --warn: #9a6b00;
  --ok: #0d6b3b;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.2);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  color: #f9fbf7;
  padding: 8px 0 18px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 2rem;
  font-weight: 760;
}

h2 {
  font-size: 1rem;
  font-weight: 760;
}

.meta-row,
.button-row,
.top-actions,
.zoom-row,
.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.top-actions {
  justify-content: flex-end;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1.1fr) minmax(280px, 1fr);
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.control-panel {
  grid-row: span 2;
}

.host-panel,
.state-panel {
  background: var(--panel-2);
}

.panel-title {
  justify-content: space-between;
  margin-bottom: 14px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #f9fbf7;
  font-size: 0.82rem;
  white-space: nowrap;
}

.status-pill.ok {
  background: rgba(13, 107, 59, 0.95);
}

.status-pill.warn {
  background: rgba(154, 107, 0, 0.95);
}

.status-pill.danger {
  background: rgba(189, 63, 47, 0.95);
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.pad-button {
  min-height: 42px;
  border-radius: 8px;
  font-weight: 760;
}

.primary-button {
  background: var(--accent);
  color: white;
  padding: 0 18px;
}

.secondary-button {
  background: #d8e0df;
  color: var(--ink);
  padding: 0 14px;
}

.danger-button {
  background: var(--accent-2);
  color: white;
  padding: 0 18px;
}

.icon-button {
  width: 44px;
  background: #1d2a28;
  color: white;
  font-size: 1.3rem;
}

.pad-wrap {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  grid-template-rows: repeat(3, minmax(70px, 1fr));
  gap: 9px;
  width: min(100%, 360px);
  aspect-ratio: 1;
  margin: 10px auto 18px;
}

.pad-button {
  background: #1d2a28;
  color: white;
  font-size: clamp(1.2rem, 5vw, 2rem);
  user-select: none;
  touch-action: none;
}

.pad-button.is-held {
  background: var(--accent-2);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.45);
}

.pad-button.home {
  background: var(--accent);
  font-size: 0.9rem;
}

.pad-button.blank {
  visibility: hidden;
}

.field {
  display: grid;
  gap: 6px;
}

.field span,
.quiet {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 680;
}

.field input,
.field select {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 8px 10px;
}

.field input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

.mini-field {
  min-width: 160px;
}

.grow {
  flex: 1 1 160px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 9px;
}

.preset-button {
  min-height: 58px;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  background: #1d2a28;
  color: white;
  font-weight: 760;
}

.preset-button small {
  display: block;
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 600;
}

.control-stack {
  display: grid;
  gap: 14px;
}

.host-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.save-grid {
  grid-template-columns: 1fr 1fr auto;
}

.raw-panel {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.compact {
  gap: 8px;
}

.readouts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.readouts div {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.55);
}

.readouts span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.readouts strong {
  display: block;
  margin-top: 4px;
}

.log-box {
  min-height: 140px;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1615;
  color: #dce7e4;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.78rem;
}

.log-line {
  margin-bottom: 7px;
  overflow-wrap: anywhere;
}

.login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(16, 20, 19, 0.88);
  padding: 18px;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  background: var(--panel);
  border-radius: 8px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

.error-text {
  min-height: 20px;
  color: var(--accent-2);
  margin: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: min(620px, calc(100% - 28px));
  padding: 11px 14px;
  border-radius: 8px;
  background: #0f1615;
  color: white;
  box-shadow: var(--shadow);
}

.setup-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(8, 12, 11, 0.88);
}

.setup-window {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(1040px, 100%);
  height: min(760px, calc(100vh - 36px));
  overflow: hidden;
  border: 1px solid #bec8c2;
  border-radius: 8px;
  background: #f7f8f5;
  box-shadow: var(--shadow);
}

.setup-header,
.setup-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 15px 18px;
  background: #182321;
  color: white;
}

.setup-header h2 {
  font-size: 1.2rem;
}

.setup-eyebrow {
  display: block;
  margin-bottom: 3px;
  color: #9fc1bb;
  font-size: 0.75rem;
  font-weight: 760;
  text-transform: uppercase;
}

.close-button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: transparent;
  color: white;
  font-size: 1.8rem;
  line-height: 1;
}

.close-button:hover,
.close-button:focus-visible {
  background: rgba(255, 255, 255, 0.12);
}

.setup-layout {
  display: grid;
  grid-template-columns: 196px minmax(0, 1fr);
  min-height: 0;
}

.setup-nav {
  display: grid;
  align-content: start;
  gap: 5px;
  padding: 14px;
  border-right: 1px solid var(--line);
  background: #e6ece9;
}

.setup-nav-button {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-height: 46px;
  padding: 7px 9px;
  border-radius: 6px;
  background: transparent;
  color: #35433f;
  font-size: 0.86rem;
  font-weight: 700;
  text-align: left;
}

.setup-nav-button span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid #aab7b1;
  border-radius: 50%;
  background: #f7f8f5;
}

.setup-nav-button.active {
  background: #cbdcd7;
  color: #0c4f4b;
}

.setup-nav-button.complete span {
  border-color: var(--ok);
  background: var(--ok);
  color: white;
}

.setup-content {
  min-width: 0;
  overflow: auto;
  padding: 24px;
}

.setup-step {
  display: none;
  width: min(720px, 100%);
  margin: 0 auto;
}

.setup-step.active {
  display: block;
}

.setup-copy {
  margin-bottom: 20px;
}

.setup-copy h3 {
  margin: 0 0 6px;
  font-size: 1.35rem;
  letter-spacing: 0;
}

.setup-copy p,
.camera-test-band p,
.tunnel-band p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.check-list {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.check-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  cursor: pointer;
}

.check-row input {
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  accent-color: var(--accent);
}

.check-row strong,
.check-row small,
.readiness-list strong,
.readiness-list small {
  display: block;
}

.check-row small,
.readiness-list small {
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.35;
}

.text-link {
  color: #006a78;
  font-weight: 720;
}

.segment-field,
.connection-fields {
  min-width: 0;
  margin: 0 0 16px;
  padding: 0;
  border: 0;
}

.segment-field legend {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 680;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #dce3df;
}

.segmented-control label {
  min-width: 0;
  cursor: pointer;
}

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

.segmented-control span {
  display: grid;
  place-items: center;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 5px;
  color: #40504b;
  font-size: 0.86rem;
  font-weight: 740;
}

.segmented-control input:checked + span {
  background: white;
  color: #075b56;
  box-shadow: 0 1px 4px rgba(16, 32, 29, 0.15);
}

.segmented-control input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.connection-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr 0.7fr 0.65fr;
  gap: 10px;
  align-items: end;
}

.protocol-field {
  margin: 0;
}

.port-guide {
  margin: -4px 0 16px;
  padding: 10px 12px;
  border-left: 4px solid #006a78;
  background: #e1ecee;
  color: #28464a;
  line-height: 1.45;
}

.setup-actions-inline,
.input-action-row,
.tunnel-heading {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.diagnostic-result {
  margin-top: 12px;
  padding: 11px 12px;
  border-left: 4px solid #7a8984;
  background: #e5eae7;
  color: #33413d;
  line-height: 1.4;
}

.diagnostic-result.ok {
  border-color: var(--ok);
  background: #dcecdf;
  color: #155d37;
}

.diagnostic-result.warn {
  border-color: var(--warn);
  background: #f2ead0;
  color: #70530a;
}

.diagnostic-result.danger {
  border-color: var(--accent-2);
  background: #f4dfdb;
  color: #853226;
}

.troubleshooting {
  margin-top: 14px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  color: #34423e;
}

.troubleshooting summary {
  cursor: pointer;
  color: #075f69;
  font-weight: 740;
}

.troubleshooting ol {
  margin: 10px 0 0 22px;
  padding: 0;
  line-height: 1.55;
}

.troubleshooting p {
  line-height: 1.5;
}

.troubleshooting.callout {
  padding: 13px;
  border: 1px solid #d4b368;
  border-radius: 6px;
  background: #f6efd9;
}

.camera-test-band,
.tunnel-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.tunnel-band {
  display: grid;
  margin: 16px 0;
}

.tunnel-heading {
  justify-content: space-between;
}

.copy-field {
  margin-top: 14px;
}

.input-action-row {
  flex-wrap: nowrap;
}

.input-action-row input {
  min-width: 0;
  flex: 1 1 auto;
}

.readiness-list {
  display: grid;
  gap: 7px;
  margin-bottom: 16px;
}

.readiness-list > div {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  min-height: 54px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

.ready-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #dce3df;
  color: #45534f;
  font-size: 0.75rem;
  font-weight: 800;
}

.readiness-list > div.ready .ready-mark {
  background: var(--ok);
  color: white;
}

.readiness-list > div.pending .ready-mark {
  background: #eadcae;
  color: #664b08;
}

.safety-band {
  margin-bottom: 14px;
  background: #f5e9e6;
  border-color: #dfb6ae;
}

.finish-button {
  width: 100%;
}

.setup-footer {
  background: #e6ece9;
  color: var(--ink);
  border-top: 1px solid var(--line);
}

.setup-footer .quiet {
  flex: 1;
  text-align: center;
}

@media (max-width: 820px) {
  h1 {
    font-size: 1.4rem;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1;
  }

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

  .control-panel {
    grid-row: auto;
  }

  .host-grid,
  .save-grid {
    grid-template-columns: 1fr;
  }

  .readouts {
    grid-template-columns: repeat(2, 1fr);
  }

  .setup-screen {
    padding: 0;
  }

  .setup-window {
    width: 100%;
    height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .setup-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .setup-nav {
    display: flex;
    overflow-x: auto;
    padding: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .setup-nav-button {
    flex: 0 0 52px;
    display: grid;
    grid-template-columns: 1fr;
    place-items: center;
    min-height: 42px;
    padding: 5px;
    color: transparent;
    font-size: 0;
  }

  .setup-nav-button span {
    font-size: 0.78rem;
  }

  .setup-content {
    padding: 18px;
  }

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

  .camera-test-band,
  .tunnel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .camera-test-band button {
    width: 100%;
  }

  .setup-footer {
    padding: 10px 12px;
  }

  .setup-footer .quiet {
    display: none;
  }
}

@media (max-width: 480px) {
  .connection-grid {
    grid-template-columns: 1fr;
  }

  .setup-header {
    padding: 12px 14px;
  }

  .setup-content {
    padding: 15px;
  }

  .input-action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .input-action-row button {
    width: 100%;
  }
}
