:root {
  --bg: #08090b;
  --panel: #14171d;
  --panel2: #1d222b;
  --text: #f5f7fb;
  --muted: #aab2c0;
  --line: #2b323d;
  --red: #ff3b30;
  --green: #28c76f;
  --blue: #2f80ed;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a {
  color: var(--text);
  text-decoration: none;
}

input,
button {
  font: inherit;
}

.topbar {
  height: 66px;
  padding: 0 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(180deg, #15181d, #0d0f12);
  border-bottom: 1px solid var(--line);
}

.topbar strong {
  font-size: 22px;
  letter-spacing: 0.04em;
}

.topbar span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.topbar nav {
  display: flex;
  gap: 12px;
  align-items: center;
}

.topbar nav a {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #11141a;
}

.danger-link {
  color: #ff6b63 !important;
  border-color: #65201e !important;
}

.operator-body {
  height: 100vh;
  overflow: hidden;
}

.operator-layout {
  height: calc(100vh - 66px);
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 12px;
}

.video-panel {
  flex: 1;
  min-height: 0;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 12px 40px #0008;
}

.stream-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.no-stream {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 24px;
}

.distance-buttons {
  display: grid;
  grid-template-columns: repeat(var(--count), minmax(110px, 1fr));
  gap: 10px;
}

.distance-form {
  margin: 0;
}

.distance-btn {
  width: 100%;
  height: 96px;
  border: 0;
  border-radius: 15px;
  cursor: pointer;
  color: white;
  background: linear-gradient(
    135deg,
    hsl(var(--hue), 86%, 45%),
    hsl(var(--hue), 90%, 34%)
  );
  box-shadow: inset 0 1px 0 #ffffff44, 0 10px 24px #0008;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-shadow: 0 2px 8px #0008;
  transition: 0.15s transform, 0.15s filter;
}

.distance-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.07);
}

.distance-btn span {
  font-weight: 800;
  font-size: clamp(5px, 3vw, 28px);
  line-height: 1;
}

.distance-btn small {
  font-size: 12px;
  opacity: 0.9;
  margin-top: 8px;
}

.home-btn {
  background: linear-gradient(135deg, #404957, #161a21);
}

.toast,
.alert {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.toast {
  position: absolute;
  z-index: 3;
  right: 22px;
  top: 80px;
}

.ok {
  background: #143322;
  border-color: #265b3e;
  color: #b7ffd0;
}

.error {
  background: #3a1717;
  border-color: #733;
  color: #ffd0d0;
}

.last-command {
  background: #101319;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
}

.last-command code,
.debug-output code {
  word-break: break-all;
  color: #b9d7ff;
}

.settings-body {
  min-height: 100vh;
}

.settings-layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  gap: 18px;
}

.card {
  background: linear-gradient(180deg, var(--panel), #101218);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 12px 30px #0005;
}

.card h2 {
  margin: 0 0 14px;
}

.card h3 {
  margin: 18px 0 10px;
}

.hint {
  color: var(--muted);
  margin-top: -6px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
}

.grid-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0b0d11;
  color: var(--text);
}

button {
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #222936;
  color: var(--text);
  cursor: pointer;
}

.primary {
  background: linear-gradient(135deg, #2f80ed, #1e4fb2);
  border-color: #2f80ed;
  color: white;
  font-weight: 700;
}

.danger {
  background: #451a1a;
  border-color: #753030;
}

.small {
  padding: 8px 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}

th,
td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  font-weight: 600;
}

td input {
  padding: 9px;
}

.inline-add {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.debug-output {
  margin-top: 14px;
  padding: 12px;
  background: #0b0d11;
  border: 1px solid var(--line);
  border-radius: 12px;
}

pre {
  white-space: pre-wrap;
  color: #dce8ff;
}

.start-body {
  height: 100vh;
  overflow: hidden;
}

.start-screen {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.start-logo {
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  object-fit: contain;
  padding: 24px;
}

.start-btn {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 24px;
  padding: 28px;
  border-radius: 20px;
  background: linear-gradient(135deg, #2f80ed, #1e4fb2);
  color: #fff;
  font-size: clamp(28px, 8vw, 56px);
  font-weight: 800;
  letter-spacing: 0.05em;
  box-shadow: inset 0 1px 0 #ffffff44, 0 12px 30px #0008;
  text-shadow: 0 2px 8px #0008;
}

.start-btn:active {
  filter: brightness(1.1);
}

.settings-corner-link {
  position: absolute;
  right: 14px;
  top: 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #11141ac0;
  font-size: 13px;
  color: var(--muted);
}

.distances-screen {
  height: calc(100vh - 66px);
  padding: 10px 12px;
  overflow-y: auto;
}

.distance-buttons-vertical {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 100%;
}

.distance-buttons-vertical .distance-form {
  flex: 0 0 auto;
}

.distance-buttons-vertical .distance-btn {
  width: 100%;
  height: calc((100vh - 66px - 20px - 54px) / 11);
  min-height: 42px;
  flex-direction: row;
  justify-content: space-between;
  padding: 0 22px;
}

.distance-buttons-vertical .distance-btn span {
  font-size: clamp(14px, 2.6vw, 22px);
}

.distance-buttons-vertical .distance-btn small {
  margin-top: 0;
}

.change-btn {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 88px;
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 800;
  background: linear-gradient(135deg, #2f80ed, #1e4fb2);
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top, #1c2635, #050608);
}

.login-card {
  width: min(380px, calc(100vw - 32px));
  padding: 28px;
  border-radius: 20px;
  background: #11151c;
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px #0009;
}

.login-card h1 {
  margin: 0 0 8px;
}

.login-card p {
  color: var(--muted);
}

.login-card button {
  width: 100%;
  margin-top: 12px;
  background: #2f80ed;
  border-color: #2f80ed;
  font-weight: 700;
}

@media (max-width: 760px) {
  .topbar {
    height: auto;
    gap: 10px;
    padding: 12px;
    align-items: flex-start;
  }

  .topbar nav {
    flex-wrap: wrap;
  }

  .operator-layout {
    height: calc(100vh - 86px);
  }

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

  .distance-btn {
    height: 82px;
  }

  .grid-form,
  .inline-add {
    grid-template-columns: 1fr;
  }

  table {
    display: block;
    overflow-x: auto;
  }

  .operator-body {
    overflow: auto;
  }

  .operator-layout {
    height: auto;
    min-height: calc(100vh - 86px);
  }

  .video-panel {
    height: 55vh;
    flex: none;
  }

  .start-btn {
    padding: 20px;
  }

  .distances-screen {
    height: calc(100vh - 86px);
  }

  .distance-buttons-vertical .distance-btn {
    height: calc((100vh - 86px - 20px - 54px) / 11);
  }
}
