: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,
select {
  font: inherit;
}

[hidden] {
  display: none !important;
}

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

.app {
  position: relative;
  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: 10px;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
}

.topbar-spacer {
  width: 58px;
  flex: 0 0 58px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.status {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 124px);
  z-index: 30;
  max-width: min(80vw, 280px);
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  background: rgba(5, 7, 10, 0.88);
  color: var(--text);
  font-size: 13px;
  line-height: 1.3;
  text-align: center;
  pointer-events: none;
  opacity: 1;
  transform: translate(-50%, 0);
  transition: opacity 220ms ease;
}

.status.is-hiding {
  opacity: 0;
}

.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;
}

.fx-loader {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  text-align: center;
  background: rgba(5, 7, 10, 0.62);
  backdrop-filter: blur(2px);
}

.fx-loader[hidden] {
  display: none;
}

.fx-spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  animation: fx-spin 0.85s linear infinite;
}

.fx-loader-text {
  color: var(--text);
  font-size: 13px;
  max-width: 80%;
  line-height: 1.35;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

.camera-flip {
  position: absolute;
  z-index: 4;
  top: 8px;
  right: max(0px, calc(50% - min(50%, 160px, 19svh) - 50px));
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 50%;
  background: rgba(5, 7, 10, 0.58);
  color: #f4f7f8;
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(8px);
}

.camera-flip:disabled {
  opacity: 0.48;
}

[data-mode="recording"] .camera-flip,
[data-mode="preview"] .camera-flip,
[data-mode="importing"] .camera-flip {
  display: none;
}

@keyframes fx-spin {
  to {
    transform: rotate(360deg);
  }
}

.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);
  }
}

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

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

.pack {
  min-width: 0;
  min-height: 54px;
  display: grid;
  align-content: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  padding: 8px 10px;
}

.pack span {
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
}

.pack small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
}

.pack.is-active {
  border-color: transparent;
  background: linear-gradient(135deg, var(--teal), var(--amber));
  color: var(--ink);
}

.pack.is-active small {
  color: rgba(5, 7, 10, 0.7);
}

.effect-strip {
  flex: 0 0 auto;
  display: grid;
  gap: 8px;
}

.effect-head,
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.effect-head {
  color: var(--muted);
  font-size: 13px;
}

.effect-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 0 0 2px;
  scrollbar-width: none;
}

.effect-tabs::-webkit-scrollbar {
  display: none;
}

.effect-tab {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

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

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

.effect-list::-webkit-scrollbar {
  display: none;
}

.effect-item {
  position: relative;
  min-width: 0;
}

.effect-main {
  width: 100%;
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 5px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: #24303b;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  padding: 9px 30px 9px 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.effect-main span {
  font-size: 14px;
  font-weight: 850;
  line-height: 1;
}

.effect-main small {
  color: #c0ccd4;
  font-size: 11px;
  line-height: 1;
}

.effect-main.is-active {
  border-color: transparent;
  background: linear-gradient(135deg, var(--teal), var(--amber));
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(67, 214, 181, 0.2);
}

.effect-main.is-active small {
  color: rgba(5, 7, 10, 0.7);
}

.effect-favorite {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(244, 247, 248, 0.82);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.effect-favorite.is-active {
  color: var(--amber);
  text-shadow: 0 0 12px rgba(244, 196, 95, 0.72);
}

.layer-tile {
  min-width: 0;
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 5px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: #24303b;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  padding: 9px 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.layer-tile span {
  font-size: 14px;
  font-weight: 850;
  line-height: 1;
}

.layer-tile small {
  color: #c0ccd4;
  font-size: 11px;
  line-height: 1;
}

.layer-tile.is-active {
  border-color: transparent;
  background: linear-gradient(135deg, var(--teal), var(--amber));
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(67, 214, 181, 0.2);
}

.layer-tile.is-active small {
  color: rgba(5, 7, 10, 0.7);
}

.layer-tile.is-none {
  grid-auto-columns: 64px;
  color: var(--muted);
}

.layer-screen {
  display: grid;
  gap: 12px;
}

.screen-sub {
  display: grid;
  gap: 6px;
}

.screen-sub-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.layer-brand {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.brand-sub {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.brand-sub-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.brand-sub #brandRing {
  min-width: 0;
}

#brandUsername {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: #24303b;
  color: var(--text);
  font-size: 14px;
}

.brand-style-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.brand-chip {
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

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

.badge-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

#badgeText,
#geoText {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: #24303b;
  color: var(--text);
  font-size: 14px;
}

.badge-chip {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

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

.ring-controls {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.ring-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ring-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
}

.ring-row input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
}

.ring-row input[type="color"] {
  width: 44px;
  height: 30px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.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 rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  color: var(--text);
  background: #24303b;
  cursor: pointer;
}

.filter {
  padding: 0 12px;
  white-space: nowrap;
  color: #d6e0e6;
}

.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 rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: #24303b;
  color: #f4f7f8;
  cursor: pointer;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 18;
  border: 0;
  background: rgba(0, 0, 0, 0.46);
  opacity: 0;
  transition: opacity 180ms ease;
}

.sheet-backdrop.is-open {
  opacity: 1;
}

.settings-sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 19;
  width: min(100vw, 430px);
  max-height: min(78svh, 700px);
  display: grid;
  gap: 12px;
  padding: 14px 16px max(16px, env(safe-area-inset-bottom));
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  background: rgba(23, 29, 36, 0.98);
  box-shadow: 0 -18px 60px rgba(0, 0, 0, 0.46);
  overflow-y: auto;
  transform: translate(-50%, 105%);
  transition: transform 210ms ease;
}

.settings-sheet.is-open {
  transform: translate(-50%, 0);
}

.sheet-head {
  color: var(--text);
}

.sheet-head div {
  display: grid;
  gap: 4px;
}

.sheet-head span {
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
}

.sheet-head small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.settings-sheet .filters {
  margin-bottom: 0;
}

.settings-sheet .adjustments {
  border: 0;
  background: transparent;
  padding: 0;
}

.settings-sheet .slider-grid {
  padding-bottom: 2px;
}

.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;
}

.morph-row {
  grid-column: 1 / -1;
}

.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;
}

.morph-lab {
  flex: 0 0 auto;
  border: 1px solid rgba(244, 196, 95, 0.32);
  border-radius: 8px;
  background: rgba(23, 29, 36, 0.9);
  padding: 10px;
}

.lab-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 8px;
}

.lab-sliders {
  margin-top: 10px;
}

.lab-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.lab-json {
  width: 100%;
  min-height: 120px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  color: var(--text);
  padding: 10px;
  resize: vertical;
  font: 11px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  flex: 0 0 auto;
  position: relative;
  min-height: 80px;
}

.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;
}

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

.secondary {
  background: #2b3744;
}

.ghost {
  background: transparent;
}

.controls .control.primary,
.controls .control.danger {
  width: 72px;
  height: 72px;
  min-height: 72px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  border: 3px solid rgba(255, 255, 255, 0.94);
  color: transparent;
  font-size: 0;
  position: relative;
}

.controls .control.primary:disabled,
.controls .control.danger:disabled {
  border-color: rgba(255, 255, 255, 0.32);
  background: transparent;
}

.controls .control.primary::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--coral);
}

.controls .control.primary:disabled::after {
  background: rgba(255, 107, 95, 0.42);
}

.controls .control.danger::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: var(--coral);
}

.controls .control.danger:disabled::after {
  background: rgba(255, 107, 95, 0.42);
}

.controls .file-control {
  position: absolute;
  right: 4px;
  top: 50%;
  width: 48px;
  height: 48px;
  min-height: 48px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.22);
  transform: translateY(-50%);
  overflow: hidden;
}

.controls .file-control .file-control-label {
  font-size: 0;
  color: transparent;
}

.controls .file-control::after {
  content: "+";
  font-size: 28px;
  line-height: 1;
  color: var(--text);
  font-weight: 300;
}

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

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

.download {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #24303b;
  color: var(--text);
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.22);
  cursor: pointer;
  font: inherit;
}

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

[data-mode="recording"] .effect-strip,
[data-mode="recording"] #recordButton,
[data-mode="recording"] .file-control {
  display: none;
}

.controls .convert-button {
  display: none;
  min-height: 48px;
  padding: 0 24px;
  border-radius: 999px;
  background: var(--teal);
  color: var(--ink);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 800;
}

[data-mode="import-preview"] #recordButton,
[data-mode="import-preview"] #stopButton {
  display: none;
}

[data-mode="import-preview"] .convert-button {
  display: inline-flex;
}

@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) {
  .lab-actions {
    grid-template-columns: 1fr;
  }

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

  h1 {
    font-size: 24px;
  }
}
