:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --text: #172026;
  --muted: #66727a;
  --line: #dfe5e8;
  --accent: #0d7f78;
  --accent-strong: #095c57;
  --danger: #b42318;
  --danger-strong: #89190f;
  --warn: #a15c08;
  --ok: #187047;
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

.shell {
  width: min(1040px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 17px;
}

p,
.panel-title span {
  color: var(--muted);
}

.status {
  min-width: 168px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: center;
  color: var(--warn);
  background: #fffaf2;
}

.device-block {
  display: grid;
  gap: 8px;
  min-width: 240px;
}

.device-meta {
  max-width: 360px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  text-align: right;
  overflow-wrap: anywhere;
}

.status.online {
  color: var(--ok);
  background: #f1fbf5;
}

.status.running {
  color: #0a5b8f;
  background: #eef7ff;
}

.panel {
  margin-top: 14px;
  padding: 18px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.title-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.grid,
.pad {
  display: grid;
  gap: 10px;
}

.grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid.two,
.safety-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.safety-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.sonar-panel {
  border-color: #d6e2e6;
}

.sonar-card {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
}

.sonar-card.sonar-available {
  border-color: #b8dec8;
  background: #f4fbf6;
}

.sonar-card.sonar-unavailable {
  border-color: #efc7b8;
  background: #fff6f2;
}

.sonar-distance {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.sonar-distance strong {
  font-size: 36px;
  line-height: 1;
  letter-spacing: 0;
}

.sonar-distance span {
  color: var(--muted);
  font-size: 14px;
}

.sonar-meta,
.sonar-raw {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.sonar-raw {
  padding-top: 4px;
  border-top: 1px dashed var(--line);
}

.pad {
  width: min(520px, 100%);
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.settings-form,
.safety-grid {
  display: grid;
  gap: 10px;
}

.settings-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.settings-form label {
  display: grid;
  grid-template-columns: 1fr 90px 32px;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
}

.settings-form input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  color: var(--text);
  font-size: 16px;
  touch-action: manipulation;
}

.settings-form em {
  color: var(--muted);
  font-style: normal;
  text-align: right;
}

.toggle-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.toggle-line input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.rgb-panel {
  border-color: #d6e2e6;
}

.rgb-controls {
  display: grid;
  gap: 12px;
}

.rgb-picker-line {
  display: grid;
  grid-template-columns: 42px 1fr 132px;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
  color: var(--muted);
}

.rgb-swatch {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #000;
  box-shadow: inset 0 0 0 4px #fff;
}

.rgb-picker-line input[type="color"] {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px;
  background: #fff;
  cursor: pointer;
}

.rgb-settings {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.camera-preview {
  display: grid;
  grid-template-columns: minmax(220px, 360px) 1fr;
  align-items: center;
  gap: 14px;
}

.camera-preview.disabled {
  opacity: 0.56;
}

.camera-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #e8eef0;
}

.camera-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-symbol {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 44px;
  height: 34px;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: translateY(4px) scale(0.96);
  transition: opacity 160ms ease, transform 160ms ease;
}

.camera-symbol.active {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.camera-body {
  position: relative;
  width: 38px;
  height: 27px;
  border-radius: 5px;
  background: rgba(13, 127, 120, 0.92);
  box-shadow: 0 5px 14px rgba(9, 92, 87, 0.25);
}

.camera-body::before {
  content: "";
  position: absolute;
  left: 7px;
  top: -5px;
  width: 13px;
  height: 6px;
  border-radius: 3px 3px 0 0;
  background: rgba(13, 127, 120, 0.92);
}

.camera-lens {
  position: absolute;
  left: 13px;
  top: 7px;
  width: 13px;
  height: 13px;
  border: 2px solid #ffffff;
  border-radius: 50%;
}

.camera-status {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

#cameraCompareCanvas {
  display: none;
}

button {
  min-height: 52px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background 120ms ease,
    border-color 120ms ease,
    opacity 120ms ease,
    transform 80ms ease;
}

button:hover {
  background: var(--accent-strong);
}

button:active,
button.pressed {
  transform: translateY(1px) scale(0.985);
}

button.secondary {
  background: #ffffff;
  color: var(--accent);
}

button.secondary:hover {
  background: #edf8f7;
}

button.danger {
  border-color: var(--danger);
  background: var(--danger);
}

button.danger:hover {
  background: var(--danger-strong);
}

button.busy {
  opacity: 0.68;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

button.small {
  min-height: 42px;
  padding: 0 14px;
  font-size: 14px;
}

.tasks {
  display: grid;
  gap: 8px;
}

.task {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
}

.task code {
  color: var(--muted);
}

.task-log {
  grid-column: 1 / -1;
  max-height: 180px;
  margin: 2px 0 0;
  padding: 8px 10px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--muted);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.task-claimed,
.task-running {
  border-color: #9bc6e8;
  background: #f2f8fe;
}

.task-complete {
  border-color: #b8dec8;
  background: #f4fbf6;
}

.task-failed,
.task-expired {
  border-color: #efc7b8;
  background: #fff6f2;
}

@media (max-width: 720px) {
  .topbar,
  .panel-title {
    align-items: stretch;
    flex-direction: column;
  }

  .title-actions {
    width: 100%;
    justify-content: space-between;
  }

  .device-block {
    min-width: 0;
  }

  .device-meta {
    max-width: none;
    text-align: left;
  }

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

  .settings-form {
    grid-template-columns: 1fr;
  }

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

  .rgb-picker-line {
    grid-template-columns: 42px 1fr;
  }

  .rgb-picker-line input[type="color"] {
    grid-column: 1 / -1;
  }

  .camera-preview {
    grid-template-columns: 1fr;
  }
}
