:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #050505;
  color: #fff;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.camera-app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
  min-height: 420px;
  overflow: hidden;
  background: #050505;
}

.viewfinder {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #090909;
}

.viewfinder video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #090909;
}

.detection-canvas {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.motion-alert {
  position: absolute;
  z-index: 2;
  top: max(58px, calc(env(safe-area-inset-top) + 52px));
  left: 50%;
  padding: 9px 14px;
  border: 1px solid rgb(255 69 58 / 70%);
  border-radius: 999px;
  background: rgb(120 20 18 / 85%);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
}

.motion-alert[hidden] {
  display: none;
}

.motion-status {
  position: absolute;
  z-index: 2;
  bottom: 60px;
  left: 14px;
  max-width: calc(100% - 28px);
  padding: 6px 10px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 8px;
  background: rgb(0 0 0 / 52%);
  color: rgb(255 255 255 / 82%);
  font-size: 0.75rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: none;
}

.motion-status.is-detected {
  border-color: #ff453a;
  color: #ffb4ae;
}

.video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #090909;
  color: #aaa;
  text-align: center;
  font-size: 0.95rem;
}

.top-bar {
  position: absolute;
  z-index: 2;
  top: max(14px, env(safe-area-inset-top));
  right: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.badge {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 999px;
  background: rgb(0 0 0 / 48%);
  color: #eee;
  font-size: 0.78rem;
  font-weight: 600;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.badge::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8b8b8b;
  content: "";
}

.badge-connecting::before {
  background: #ffc247;
  animation: pulse 1s infinite;
}

.badge-live::before {
  background: #ff453a;
  animation: pulse 1.4s infinite;
}

.badge-error::before {
  background: #ff453a;
}

@keyframes pulse {
  50% { opacity: 0.4; }
}

.text-button,
.action-button {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 1px solid #505054;
  border-radius: 10px;
  background: #29292c;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.text-button:active,
.action-button:active:not(:disabled) {
  transform: scale(0.94);
}

.text-button {
  min-height: 40px;
  padding: 7px 14px;
  border-color: rgb(255 255 255 / 16%);
  background: rgb(0 0 0 / 50%);
  font-size: 0.85rem;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.settings-button {
  pointer-events: auto;
}

.stream-info {
  position: absolute;
  right: 14px;
  bottom: 14px;
  left: 14px;
  width: fit-content;
  max-width: calc(100% - 28px);
  margin: 0 auto;
  padding: 6px 10px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 8px;
  background: rgb(0 0 0 / 52%);
  color: rgb(255 255 255 / 75%);
  font-size: 0.78rem;
  text-align: center;
  overflow-wrap: anywhere;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: none;
}

.camera-controls {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  padding: 10px 24px max(22px, env(safe-area-inset-bottom));
  background: #050505;
}

.mode-label {
  display: flex;
  min-height: 26px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #ffd60a;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.mode-caption {
  color: #858585;
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0;
}

.shutter-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.shutter-position {
  display: flex;
  width: 100%;
}

.action-button {
  width: 100%;
  min-height: 54px;
  transition: transform 0.12s ease, opacity 0.16s ease;
}

.action-button[hidden] {
  display: none;
}

.start-button {
  border-color: #0a84ff;
  background: #0a84ff;
}

.stop-button {
  border-color: #ff453a;
  background: #ff453a;
}

.action-button:disabled {
  opacity: 0.48;
  cursor: default;
}

.secondary-button {
  border-color: #505054;
  background: #29292c;
}

.control-hint {
  min-height: 20px;
  margin: 0;
  color: #858585;
  font-size: 0.72rem;
  text-align: center;
}

.settings-panel {
  position: absolute;
  z-index: 4;
  inset: max(72px, calc(env(safe-area-inset-top) + 66px)) 12px 12px;
  overflow-y: auto;
  padding: 18px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 20px;
  background: rgb(26 26 28 / 94%);
  box-shadow: 0 12px 48px rgb(0 0 0 / 45%);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  overscroll-behavior: contain;
}

.settings-panel[hidden] {
  display: none;
}

.settings-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.settings-heading h2 {
  margin: 0;
  font-size: 1.1rem;
}

.close-button {
  min-height: 38px;
  background: #3a3a3c;
  font-size: 0.8rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  color: #b5b5b8;
  font-size: 0.82rem;
}

.form-group input {
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  border: 1px solid #48484a;
  border-radius: 10px;
  outline: none;
  background: #2c2c2e;
  color: #fff;
  font-size: 16px;
}

.form-group input:focus {
  border-color: #0a84ff;
}

.detection-setting > span:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
}

.form-group input[type="range"] {
  min-height: 32px;
  padding: 0;
  border: 0;
  accent-color: #0a84ff;
  background: transparent;
}

.setting-hint {
  color: #8e8e93;
  font-size: 0.75rem;
}

.alert-warning {
  margin-bottom: 18px;
  padding: 12px;
  border-radius: 10px;
  background: #482719;
  color: #ffd8a8;
  font-size: 0.82rem;
  line-height: 1.5;
}

.log-details {
  margin-top: 8px;
  border-top: 1px solid #48484a;
  color: #b5b5b8;
  font-size: 0.85rem;
}

.log-details summary {
  padding: 14px 0 8px;
  cursor: pointer;
}

.log-area {
  max-height: 150px;
  overflow-y: auto;
  padding: 10px;
  border-radius: 8px;
  background: #111;
  color: #c8c8cc;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-height: 560px) {
  .camera-controls {
    padding-top: 4px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .action-button {
    min-height: 48px;
  }
}

@media (orientation: landscape) and (min-width: 600px) {
  .camera-app {
    min-height: 0;
    flex-direction: row;
  }

  .viewfinder {
    flex: 1 1 auto;
  }

  .camera-controls {
    display: flex;
    width: clamp(176px, 29vw, 250px);
    flex: 0 0 clamp(176px, 29vw, 250px);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 18px 12px max(18px, env(safe-area-inset-bottom));
    border-left: 1px solid #242426;
  }

  .mode-label {
    flex-direction: column;
    gap: 3px;
  }

  .shutter-row {
    gap: 12px;
  }

  .side-control-placeholder {
    display: none;
  }

  .control-hint {
    max-width: 170px;
    line-height: 1.4;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
