:root {
  color-scheme: dark;
  --bg: #101419;
  --panel: #171d24;
  --panel-strong: #202833;
  --text: #f4f7f8;
  --muted: #9aa8b2;
  --line: rgba(255, 255, 255, 0.12);
  --teal: #43d6b5;
  --coral: #ff6b5f;
  --amber: #f4c45f;
  --ink: #05070a;
  --shadow: rgba(0, 0, 0, 0.38);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100svh;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: stretch;
  background: #070a0d;
  color: var(--text);
  overflow: hidden;
}

button,
input {
  font: inherit;
}

[hidden] {
  display: none !important;
}

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

.app {
  width: min(100vw, 430px);
  min-height: 100svh;
  max-height: 100svh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg);
  scrollbar-width: none;
}

.app::-webkit-scrollbar {
  display: none;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1;
  letter-spacing: 0;
}

.status {
  max-width: 46vw;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
  text-align: center;
}

.stage {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: 4px 0;
}

.lens {
  width: min(100%, 320px, 38svh);
  aspect-ratio: 1;
  position: relative;
  border-radius: 50%;
  overflow: hidden;
  background: #05070a;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 18px 70px var(--shadow), inset 0 0 0 12px rgba(255, 255, 255, 0.035);
}

#sourceVideo {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#cameraCanvas,
.preview {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  background: var(--ink);
}

.preview {
  display: none;
}

[data-mode="preview"] #cameraCanvas {
  display: none;
}

[data-mode="preview"] .preview {
  display: block;
}

.timer {
  position: absolute;
  top: 10px;
  z-index: 2;
  min-width: 68px;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(5, 7, 10, 0.76);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.record-dot {
  position: absolute;
  top: 20px;
  right: calc(50% - min(43vw, 29svh, 280px) + 20px);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 0 0 0 rgba(255, 107, 95, 0.58);
  opacity: 0;
}

[data-mode="recording"] .record-dot {
  opacity: 1;
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  70% {
    box-shadow: 0 0 0 13px rgba(255, 107, 95, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 107, 95, 0);
  }
}

.filters {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 96px;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 4px;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar {
  display: none;
}

.filter,
.control {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel);
  cursor: pointer;
}

.filter {
  padding: 0 12px;
  white-space: nowrap;
  color: var(--muted);
}

.filter.is-active {
  color: var(--ink);
  border-color: transparent;
  background: var(--teal);
}

.adjustments {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(23, 29, 36, 0.86);
  padding: 10px;
}

.adjustments-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.mini-button {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.debug-panel {
  flex: 0 0 auto;
  border: 1px solid rgba(67, 214, 181, 0.34);
  border-radius: 8px;
  background: rgba(9, 18, 22, 0.92);
  padding: 10px;
  color: var(--muted);
  font-size: 11px;
}

.debug-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
}

.debug-panel dl {
  display: grid;
  grid-template-columns: minmax(86px, 0.8fr) minmax(0, 1.4fr);
  gap: 5px 8px;
  margin: 0;
}

.debug-panel dt {
  color: rgba(244, 247, 248, 0.66);
}

.debug-panel dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

.debug-events {
  display: grid;
  gap: 4px;
  max-height: 84px;
  overflow: auto;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.35;
}

.slider-grid {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}

.slider-grid::-webkit-scrollbar {
  display: none;
}

.slider-row {
  display: grid;
  gap: 6px;
  min-width: 120px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.slider-row span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.slider-row output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.slider-row input {
  width: 100%;
  accent-color: var(--teal);
}

.option-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.option-row {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.option-row:first-child {
  min-width: 0;
}

.option-row input,
.option-row select {
  min-width: 0;
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  padding: 0 10px;
}

.controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.control {
  min-width: 0;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.1;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.control:active {
  transform: translateY(1px);
}

.control:disabled {
  cursor: not-allowed;
  opacity: 1;
  background: var(--panel);
  border-color: var(--line);
  color: var(--muted);
}

.primary {
  background: var(--teal);
  color: var(--ink);
  border-color: transparent;
}

.send {
  background: var(--amber);
  color: var(--ink);
  border-color: transparent;
}

.danger {
  background: var(--coral);
  color: var(--ink);
  border-color: transparent;
}

.secondary {
  background: var(--panel-strong);
}

.ghost {
  background: transparent;
}

.file-control {
  position: relative;
  overflow: hidden;
}

.file-control input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.download {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
}

@media (min-width: 760px) {
  body {
    align-items: center;
  }

  .app {
    width: 430px;
    min-height: min(900px, calc(100svh - 32px));
    max-height: calc(100svh - 32px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 28px;
    box-shadow: 0 24px 90px rgba(0, 0, 0, 0.5);
  }
}

@media (max-height: 760px) {
  .lens {
    width: min(100%, 280px, 36svh);
  }

  .adjustments {
    padding: 8px;
  }
}

@media (max-width: 759px) {
  body {
    background: var(--bg);
  }
}

@media (max-width: 390px) {
  .controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  h1 {
    font-size: 24px;
  }
}
