:root {
  --ink: #eaf8fb;
  --ink-strong: #ffffff;
  --muted: #a8c3ca;
  --panel: rgba(6, 24, 34, 0.76);
  --panel-strong: rgba(8, 31, 43, 0.92);
  --line: rgba(171, 220, 232, 0.26);
  --line-strong: rgba(171, 220, 232, 0.48);
  --accent: #12a7bd;
  --accent-strong: #087f93;
  --accent-ink: #f4feff;
  --danger: #ff7770;
  --ok: #7de0b2;
  --shadow: 0 24px 60px rgba(0, 15, 24, 0.32);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, rgba(18, 167, 189, 0.18), transparent 34%),
    linear-gradient(180deg, #061621 0%, #dcebf0 100%);
  font-family: var(--font);
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

.camera-app {
  min-height: 100dvh;
  padding: 0.8rem;
}

.stage-shell {
  position: relative;
  min-height: calc(100dvh - 1.6rem);
  overflow: hidden;
  border: 1px solid rgba(208, 240, 247, 0.28);
  border-radius: var(--radius);
  background: #041018;
  box-shadow: var(--shadow);
  isolation: isolate;
}

.media-toggle {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
  background: #041018;
  color: inherit;
  cursor: pointer;
}

.stream-image,
.stream-video,
.pause-canvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.pause-canvas {
  position: absolute;
  inset: 0;
}

.media-toggle::after {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(2, 12, 18, 0.58), transparent 22%, transparent 62%, rgba(2, 12, 18, 0.48)),
    linear-gradient(90deg, rgba(2, 12, 18, 0.32), transparent 28%, transparent 72%, rgba(2, 12, 18, 0.24));
}

.stream-badge,
.pause-hint,
.top-bar,
.ptz-cluster,
.quick-actions {
  position: absolute;
  z-index: 2;
}

.stream-badge,
.pause-hint {
  display: inline-flex;
  align-items: center;
  min-height: 1.8rem;
  padding: 0 0.62rem;
  border: 1px solid rgba(208, 240, 247, 0.22);
  border-radius: 999px;
  background: rgba(3, 14, 22, 0.68);
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 800;
  backdrop-filter: blur(12px);
}

.stream-badge {
  right: 0.75rem;
  top: 0.75rem;
}

.pause-hint {
  left: 50%;
  bottom: 0.8rem;
  transform: translateX(-50%);
  color: rgba(234, 248, 251, 0.82);
}

.top-bar {
  top: 0.75rem;
  left: 0.75rem;
  right: 5.1rem;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 0.75rem;
  pointer-events: none;
}

.top-bar h1 {
  color: var(--ink-strong);
  font-size: clamp(1.15rem, 2vw, 1.8rem);
  line-height: 1;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.42);
}

.top-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  gap: 0.45rem;
  justify-content: flex-end;
  pointer-events: auto;
}

.camera-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}

.quality-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid rgba(208, 240, 247, 0.22);
  border-radius: var(--radius);
  background: rgba(3, 16, 25, 0.56);
  backdrop-filter: blur(12px);
}

.camera-tabs button,
.quality-switch button,
.quick-actions button,
.sheet-close,
.secondary-command,
.modal-actions button,
.preset-list button,
.preset-save-list button,
.scan-actions button {
  min-height: 2.15rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(248, 253, 255, 0.92);
  color: #082333;
  cursor: pointer;
  font-weight: 850;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.camera-tabs button {
  min-height: 1.95rem;
  padding: 0 0.62rem;
  background: rgba(3, 16, 25, 0.56);
  color: var(--ink);
  backdrop-filter: blur(12px);
}

.quality-switch button {
  min-width: 3.2rem;
  min-height: 1.95rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 0.78rem;
  padding: 0 0.55rem;
}

.quality-switch button + button {
  border-left: 1px solid rgba(208, 240, 247, 0.18);
}

.camera-tabs button.active,
.quality-switch button.active {
  border-color: rgba(18, 167, 189, 0.72);
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: var(--accent-ink);
}

button:not(:disabled):active {
  transform: translateY(1px);
}

.ptz-cluster {
  left: 0.8rem;
  bottom: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.ptz-pad {
  width: 6.7rem;
  height: 6.7rem;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 0.1rem;
  overflow: hidden;
  border: 1px solid rgba(208, 240, 247, 0.34);
  border-radius: 999px;
  background:
    radial-gradient(circle at center, rgba(248, 253, 255, 0.16), transparent 38%),
    rgba(4, 18, 27, 0.72);
  box-shadow: 0 12px 34px rgba(0, 18, 28, 0.34);
  backdrop-filter: blur(16px);
}

.ptz-pad button {
  border: 0;
  background: transparent;
  color: rgba(234, 248, 251, 0.86);
  cursor: pointer;
  font-size: 1.04rem;
  font-weight: 900;
}

.ptz-pad button:not(:disabled):hover {
  background: rgba(18, 167, 189, 0.24);
}

.ptz-pad .stop::before {
  width: 0.8rem;
  height: 0.8rem;
  display: block;
  margin: auto;
  border-radius: 999px;
  background: var(--danger);
  content: "";
  box-shadow: 0 0 0 0.35rem rgba(255, 119, 112, 0.12);
}

.zoom-control {
  width: 7.8rem;
  display: grid;
  gap: 0.28rem;
  padding: 0.58rem 0.65rem;
  border: 1px solid rgba(208, 240, 247, 0.28);
  border-radius: var(--radius);
  background: rgba(4, 18, 27, 0.72);
  box-shadow: 0 12px 34px rgba(0, 18, 28, 0.24);
  backdrop-filter: blur(16px);
}

.zoom-control span {
  color: rgba(234, 248, 251, 0.82);
  font-size: 0.7rem;
  font-weight: 900;
}

.zoom-control input {
  width: 100%;
  accent-color: var(--accent);
}

.quick-actions {
  right: 0.8rem;
  bottom: 0.8rem;
  display: flex;
  gap: 0.45rem;
}

.quick-actions button {
  min-width: 5.8rem;
  padding: 0 0.8rem;
  background: rgba(248, 253, 255, 0.94);
  box-shadow: 0 12px 30px rgba(0, 18, 28, 0.26);
}

.quick-actions button:not(:disabled):hover,
.preset-list button:not(:disabled):hover,
.preset-save-list button:not(:disabled):hover,
.scan-actions button:not(:disabled):hover,
.secondary-command:not(:disabled):hover {
  border-color: var(--line-strong);
  background: #ffffff;
}

.sheet {
  position: fixed;
  right: 0.8rem;
  bottom: 4.3rem;
  z-index: 5;
  width: min(24rem, calc(100vw - 1.6rem));
  max-height: min(34rem, calc(100dvh - 6rem));
  overflow: auto;
  padding: 0.8rem;
  border: 1px solid rgba(208, 240, 247, 0.36);
  border-radius: var(--radius);
  background: rgba(247, 252, 254, 0.96);
  color: #082333;
  box-shadow: var(--shadow);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  margin-bottom: 0.7rem;
}

.sheet h2 {
  font-size: 1rem;
  line-height: 1.1;
}

.sheet h3 {
  font-size: 0.84rem;
}

.sheet-close {
  min-height: 1.9rem;
  padding: 0 0.6rem;
  background: #edf7fa;
}

.preset-list,
.preset-save-list,
.scan-list {
  display: grid;
  gap: 0.45rem;
}

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

.preset-list button,
.preset-save-list button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 2.35rem;
  padding: 0 0.62rem;
  text-align: left;
}

.preset-list span,
.preset-save-list span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-presets {
  margin-top: 0.9rem;
  padding-top: 0.8rem;
  border-top: 1px solid #d0e4ea;
}

.save-presets h3 {
  margin-bottom: 0.5rem;
}

.empty,
.sheet-note {
  color: #55717a;
  font-size: 0.84rem;
  font-weight: 700;
}

.scan-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
  align-items: center;
  padding: 0.65rem;
  border: 1px solid #d0e4ea;
  border-radius: var(--radius);
  background: #ffffff;
}

.scan-row p {
  margin-top: 0.2rem;
  color: #55717a;
  font-size: 0.78rem;
  line-height: 1.3;
}

.scan-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.scan-actions button {
  min-height: 1.95rem;
  padding: 0 0.55rem;
}

.secondary-command {
  width: 100%;
  margin-top: 0.65rem;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: var(--accent-ink);
}

.sheet-note {
  margin-top: 0.5rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(2, 12, 18, 0.62);
  backdrop-filter: blur(8px);
}

.modal-card {
  width: min(22rem, 100%);
  display: grid;
  gap: 0.8rem;
  padding: 1rem;
  border: 1px solid rgba(208, 240, 247, 0.42);
  border-radius: var(--radius);
  background: #f7fcfe;
  color: #082333;
  box-shadow: var(--shadow);
}

.modal-card p {
  margin-top: 0.25rem;
  color: #55717a;
  font-size: 0.86rem;
}

.modal-card input {
  min-height: 2.45rem;
  border: 1px solid #bcd4dc;
  border-radius: var(--radius);
  padding: 0 0.75rem;
  outline: none;
}

.modal-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 167, 189, 0.14);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

.text-button {
  background: #edf7fa;
}

.primary-button {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: var(--accent-ink);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  z-index: 20;
  max-width: min(28rem, calc(100vw - 2rem));
  transform: translateX(-50%);
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius);
  background: rgba(4, 18, 27, 0.94);
  color: var(--ink-strong);
  box-shadow: var(--shadow);
  font-weight: 850;
}

.hidden {
  display: none !important;
}

@media (max-width: 700px) {
  .camera-app {
    padding: 0;
  }

  .stage-shell {
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .top-bar {
    top: calc(0.55rem + env(safe-area-inset-top));
    left: 0.55rem;
    right: 0.55rem;
    align-items: start;
    flex-direction: column;
    gap: 0.45rem;
  }

  .top-bar h1 {
    font-size: 1.1rem;
  }

  .top-controls {
    justify-content: flex-start;
    max-width: calc(100vw - 5.6rem);
  }

  .camera-tabs {
    justify-content: flex-start;
  }

  .camera-tabs button,
  .quality-switch button {
    min-height: 1.8rem;
    padding: 0 0.55rem;
    font-size: 0.78rem;
  }

  .stream-badge {
    right: 0.55rem;
    top: calc(0.55rem + env(safe-area-inset-top));
  }

  .pause-hint {
    display: none;
  }

  .ptz-cluster {
    left: 0.55rem;
    bottom: calc(0.55rem + env(safe-area-inset-bottom));
    gap: 0.42rem;
  }

  .ptz-pad {
    width: 5.4rem;
    height: 5.4rem;
  }

  .ptz-pad button {
    font-size: 0.9rem;
  }

  .zoom-control {
    width: 5.8rem;
    padding: 0.48rem 0.52rem;
  }

  .quick-actions {
    right: 0.55rem;
    bottom: calc(0.55rem + env(safe-area-inset-bottom));
    flex-direction: column;
    gap: 0.35rem;
  }

  .quick-actions button {
    min-width: 4.9rem;
    min-height: 2rem;
    padding: 0 0.58rem;
    font-size: 0.78rem;
  }

  .sheet {
    left: 0.55rem;
    right: 0.55rem;
    bottom: calc(3.1rem + env(safe-area-inset-bottom));
    width: auto;
    max-height: 52dvh;
  }

  .preset-list {
    grid-template-columns: 1fr 1fr;
  }

  .scan-row {
    grid-template-columns: 1fr;
  }
}
