@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800;900&display=swap');

:root {
  --bg: #101113;
  --panel: #191b1e;
  --panel-2: #202327;
  --line: #34383e;
  --text: #f3f0e8;
  --muted: #a7a096;
  --soft: #d8d0c2;
  --accent: #21d0a2;
  --accent-2: #ff6b4a;
  --accent-3: #ffd166;
  --danger: #ff4f69;
  --shadow: 0 18px 50px rgb(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 {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button, input, select { font: inherit; }
button { color: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(0, 1fr) minmax(230px, 300px);
  gap: 14px;
  min-height: 100vh;
  padding: 14px;
}

.side-panel, .stage {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  border-radius: 12px;
}

.side-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px;
}

.left-panel { gap: 18px; }
.right-panel { gap: 16px; }

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 2px solid var(--accent);
  border-radius: 10px;
  background: linear-gradient(135deg, #111c19, #0d2a22);
  color: var(--accent);
  font-weight: 900;
  letter-spacing: 0;
}

h1, h2, p { margin: 0; }

h1 {
  font-size: 1.08rem;
  line-height: 1.1;
}

.brand p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.84rem;
}

.control-group {
  display: grid;
  gap: 10px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading h2 {
  color: var(--soft);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

#faceCount {
  min-width: 34px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--accent-3);
  text-align: center;
  font-size: 0.78rem;
  font-weight: 800;
}

/* ── Category Tabs ── */
.category-tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  background: #141619;
  border: 1px solid var(--line);
}

.category-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 36px;
  padding: 0 6px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
  transition: all 180ms ease;
}

.category-tab:hover {
  color: var(--soft);
  background: rgb(255 255 255 / 5%);
}

.category-tab.is-active {
  background: var(--panel-2);
  color: var(--accent);
  box-shadow: 0 2px 8px rgb(0 0 0 / 22%);
}

.category-tab .tab-icon {
  font-size: 0.92rem;
  line-height: 1;
}

.category-tab .tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 99px;
  background: rgb(255 255 255 / 8%);
  font-size: 0.68rem;
  font-weight: 800;
}

.category-tab.is-active .tab-count {
  background: rgb(33 208 162 / 18%);
  color: var(--accent);
}

/* ── Filter Grid ── */
.filter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  max-height: calc(100vh - 440px);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.filter-grid::-webkit-scrollbar { width: 4px; }
.filter-grid::-webkit-scrollbar-track { background: transparent; }
.filter-grid::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.filter-card {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #141619;
  cursor: pointer;
  text-align: left;
  transition: border-color 150ms ease, background 150ms ease, transform 120ms ease, box-shadow 150ms ease;
}

.filter-card:hover {
  border-color: #5f6873;
  background: #181b1f;
}

.filter-card.is-active {
  border-color: var(--accent);
  background: #10221e;
  box-shadow: 0 0 0 1px rgb(33 208 162 / 15%), 0 4px 12px rgb(0 0 0 / 18%);
}

.filter-card:active { transform: translateY(1px); }

.filter-swatch {
  position: relative;
  width: 36px;
  height: 36px;
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
}

.filter-swatch .swatch-emoji {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  line-height: 1;
  text-shadow: 0 1px 3px rgb(0 0 0 / 40%);
}

.filter-title {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-note {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-status {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: #595f66;
  flex-shrink: 0;
}

.filter-card.is-active .filter-status { background: var(--accent); }

/* ── Settings Controls ── */
.range-control, .select-control, .setting-row {
  display: grid;
  gap: 9px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #141619;
}

.range-control {
  grid-template-columns: auto 1fr auto;
  align-items: center;
}

.range-control span, .select-control span, .setting-row span {
  color: var(--soft);
  font-size: 0.85rem;
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

output {
  min-width: 30px;
  color: var(--accent-3);
  font-weight: 800;
  text-align: right;
}

.setting-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.segmented-button, .text-button, .tool-button, .primary-action {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  cursor: pointer;
  font-weight: 800;
}

.segmented-button {
  min-width: 72px;
  padding: 7px 10px;
}

.segmented-button.is-on {
  border-color: rgb(33 208 162 / 60%);
  background: #112a24;
  color: var(--accent);
}

.select-control select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101113;
  color: var(--text);
}

/* ── Stage ── */
.stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: calc(100vh - 28px);
  overflow: hidden;
}

.stage-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #151719;
  border-radius: 12px 12px 0 0;
}

.status-cluster {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  color: var(--soft);
  font-size: 0.9rem;
  font-weight: 800;
}

.status-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 99px;
  background: #6c7177;
  transition: background 300ms ease, box-shadow 300ms ease;
}

.status-dot.is-live {
  background: var(--accent);
  box-shadow: 0 0 0 5px rgb(33 208 162 / 12%);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 4px rgb(33 208 162 / 12%); }
  50% { box-shadow: 0 0 0 8px rgb(33 208 162 / 6%); }
}

.status-dot.is-error {
  background: var(--danger);
  box-shadow: 0 0 0 5px rgb(255 79 105 / 12%);
}

.meter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101113;
}

.meter span { color: var(--muted); font-size: 0.72rem; font-weight: 800; }
.meter strong { min-width: 28px; color: var(--accent-3); text-align: right; }

.camera-area {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 420px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgb(255 255 255 / 3%) 1px, transparent 1px),
    linear-gradient(0deg, rgb(255 255 255 / 3%) 1px, transparent 1px),
    #0b0c0d;
  background-size: 34px 34px;
}

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

#fxCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.permission-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  width: min(430px, calc(100% - 32px));
  gap: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgb(25 27 30 / 93%);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  transform: translate(-50%, -50%);
}

.permission-panel.is-hidden { display: none; }

.permission-copy { display: grid; gap: 6px; }
.permission-copy strong { color: var(--text); font-size: 1.12rem; }
.permission-copy span { color: var(--muted); line-height: 1.45; }

.primary-action {
  min-height: 46px;
  border-color: rgb(33 208 162 / 70%);
  background: linear-gradient(135deg, #21d0a2, #1ab88e);
  color: #061512;
  border-radius: 10px;
  transition: transform 100ms ease, box-shadow 200ms ease;
}

.primary-action:hover {
  box-shadow: 0 4px 20px rgb(33 208 162 / 25%);
}

.primary-action:active { transform: scale(0.98); }

.capture-bar {
  display: grid;
  grid-template-columns: 1fr 90px 1fr 1fr;
  align-items: center;
  gap: 10px;
  min-height: 92px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  background: #151719;
  border-radius: 0 0 12px 12px;
}

.tool-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 10px;
  transition: background 150ms ease, border-color 150ms ease;
}

.tool-button span:first-child {
  min-width: 22px;
  color: var(--accent-3);
  text-align: center;
}

.tool-button.is-recording {
  border-color: rgb(255 79 105 / 72%);
  background: #2a1419;
}

.tool-button.is-recording span:first-child { color: var(--danger); }

.shutter {
  position: relative;
  width: 72px;
  height: 72px;
  margin: 0 auto;
  border: 3px solid var(--text);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  transition: transform 100ms ease;
}

.shutter:active { transform: scale(0.92); }

.shutter span {
  position: absolute;
  inset: 8px;
  border-radius: inherit;
  background: var(--text);
  transition: inset 100ms ease;
}

.shutter:hover span { inset: 6px; }

button:disabled, select:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.countdown {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgb(0 0 0 / 30%);
  color: var(--text);
  font-size: clamp(5rem, 16vw, 12rem);
  font-weight: 900;
}

.countdown.is-active { display: grid; }

/* ── Gallery ── */
.gallery {
  display: grid;
  grid-auto-rows: max-content;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.empty-gallery {
  display: grid;
  place-items: center;
  min-height: 150px;
  border: 1px dashed #555b62;
  border-radius: 10px;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}

.gallery-item {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #141619;
  overflow: hidden;
}

.gallery-item img, .gallery-item video {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #050607;
}

.gallery-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 8px;
}

.gallery-actions a, .gallery-actions button, .text-button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.gallery-actions a { display: grid; place-items: center; }
.text-button { min-height: 32px; }

/* ── Responsive ── */
@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: minmax(210px, 260px) minmax(0, 1fr);
  }
  .right-panel {
    grid-column: 1 / -1;
    min-height: 220px;
  }
  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 10px;
  }
  .side-panel, .stage { box-shadow: none; }
  .left-panel { order: 2; }
  .stage { order: 1; min-height: 72vh; }
  .right-panel { order: 3; }
  .filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: none;
  }
  .filter-card { grid-template-columns: 30px 1fr; }
  .filter-status { display: none; }
  .camera-area { min-height: 380px; }
  .capture-bar {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    min-height: 78px;
    gap: 8px;
  }
  .tool-button { min-height: 46px; padding: 0 8px; }
  .tool-button span:last-child { display: none; }
  .shutter { width: 60px; height: 60px; }
  .category-tabs { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .filter-grid { grid-template-columns: 1fr; }
  .stage-topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }
  .capture-bar { padding: 10px; }
}
