:root {
  color-scheme: dark;
  --bg: #14110e;
  --ink: #f4efe8;
  --muted: #b7aa9c;
  --line: rgba(244, 239, 232, 0.16);
  --accent: #e7b07a;
  --danger: #e07a6a;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  min-height: 100dvh;
}

button, a {
  color: inherit;
  font: inherit;
}

.camera-app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  overflow: hidden;
}

.topbar, .controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  background: rgba(20, 17, 14, 0.86);
}

.topbar {
  padding-top: calc(0.75rem + env(safe-area-inset-top));
  justify-content: space-between;
  z-index: 2;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.brand {
  letter-spacing: 0.14em;
  text-transform: lowercase;
  font-weight: 650;
}

.stage {
  position: relative;
  min-height: 0;
  background: #000;
  touch-action: none;
}

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

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.filters {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding: 0 1rem 0.85rem;
  background: rgba(20, 17, 14, 0.86);
  scrollbar-width: none;
}

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

.chip, .icon-btn, .lens, .shutter, .text-link, .card-open {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  text-decoration: none;
  touch-action: manipulation;
}

.chip, .icon-btn {
  min-height: 2.4rem;
  padding: 0.35rem 0.8rem;
}

.chip[aria-pressed="true"],
.lens[aria-pressed="true"] {
  background: var(--accent);
  color: #24180f;
  border-color: transparent;
}

.controls {
  display: grid;
  gap: 0.7rem;
  justify-content: stretch;
  padding-bottom: 0.45rem;
}

.lenses, .shutter-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.lens {
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0.2rem 0.55rem;
  color: var(--ink);
}

.shutter-row { justify-content: space-between; }

.side, .icon-btn {
  width: 2.8rem;
  height: 2.8rem;
}

.icon-btn {
  display: grid;
  place-items: center;
  padding: 0;
}

.upload {
  width: 1.4rem;
  height: 1.4rem;
}

.spinner {
  display: block;
  width: 1.15rem;
  height: 1.15rem;
  border: 2px solid rgba(244, 239, 232, 0.28);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.shutter {
  width: 4.4rem;
  height: 4.4rem;
  border-width: 3px;
  border-color: var(--ink);
  background: radial-gradient(circle, var(--ink) 0 38%, transparent 40% 100%);
}

.shutter:disabled { opacity: 0.4; }

.shutter-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}

.frame-counter {
  width: 2.8rem;
  height: 2.8rem;
  display: grid;
  place-items: center;
  border-radius: 0.35rem;
  background: linear-gradient(#3a3228, #16130f);
  box-shadow: inset 0 0 0 1px rgba(243, 226, 184, 0.35), inset 0 2px 5px rgba(0, 0, 0, 0.65);
  color: #f3e2b8;
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.frame-counter.empty { color: var(--danger); }

.status {
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  margin: 0;
  text-align: center;
  color: var(--danger);
  text-shadow: 0 1px 2px #000;
}

.gallery-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
}

.gallery-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin-bottom: 1rem;
}

h1 {
  font-size: 1.4rem;
  font-weight: 650;
  margin: 0;
}

.note, .empty { color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.6rem;
}

.card {
  margin: 0;
  background: #000;
  border-radius: 0.7rem;
  overflow: hidden;
}

.card-open {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  cursor: zoom-in;
}

.card-time {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.2rem 0.4rem;
  border-radius: 0.35rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  font-size: 0.78rem;
  line-height: 1.2;
  pointer-events: none;
}

.card img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: #221c17;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.94);
  touch-action: none;
}

.lightbox-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
}

.lightbox-track {
  position: absolute;
  inset: 0;
  will-change: transform;
}

.lightbox-slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-close {
  position: absolute;
  top: calc(0.4rem + env(safe-area-inset-top));
  right: 0.4rem;
  z-index: 5;
  width: 3.4rem;
  height: 3.4rem;
  font-size: 1.8rem;
  line-height: 1;
  touch-action: manipulation;
  background: rgba(20, 17, 14, 0.55);
}

body.lightbox-open { overflow: hidden; }
