:root {
  --void: #030303;
  --panel: #111213;
  --panel-raised: #1B1D1F;
  --hairline: #2C2E30;
  --text-primary: #ECECEC;
  --text-dim: #8C9096;
  --text-faint: #4A4E52;
  --amber: #FFB000;
  --amber-dim: #6B4B12;
  --rec: #FF3B30;
  --live: #33D17A;
  --peak: #38E1FF;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--void);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  user-select: none;
}

.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.app {
  position: relative;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

#preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

/* ---------- viewfinder frame: the signature element ---------- */

.viewfinder {
  position: absolute;
  inset: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom)) 10px;
  pointer-events: none;
  z-index: 5;
}

.vf-corner {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 2px solid var(--amber);
  opacity: 0.85;
}
.vf-corner.tl { top: 0; left: 0; border-right: none; border-bottom: none; }
.vf-corner.tr { top: 0; right: 0; border-left: none; border-bottom: none; }
.vf-corner.bl { bottom: 0; left: 0; border-right: none; border-top: none; }
.vf-corner.br { bottom: 0; right: 0; border-left: none; border-top: none; }

.vf-grid {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.vf-grid.on { opacity: 0.45; }
.vf-grid-v1 { left: 33.333%; top: 0; bottom: 0; width: 1px; position: absolute; background: var(--text-primary); }
.vf-grid-v2 { left: 66.666%; top: 0; bottom: 0; width: 1px; position: absolute; background: var(--text-primary); }
.vf-grid-h1 { top: 33.333%; left: 0; right: 0; height: 1px; position: absolute; background: var(--text-primary); }
.vf-grid-h2 { top: 66.666%; left: 0; right: 0; height: 1px; position: absolute; background: var(--text-primary); }

/* ---------- top OSD ---------- */

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

.osd-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rec-tally {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.rec-tally .dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--text-faint);
}

.rec-tally.live { color: var(--rec); }
.rec-tally.live .dot {
  background: var(--rec);
  box-shadow: 0 0 10px var(--rec);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.timecode {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.03em;
}

.osd-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  text-align: right;
}

.osd-right .format-line {
  font-weight: 700;
  color: var(--text-primary);
}

.osd-right .link-line {
  display: flex;
  align-items: center;
  gap: 5px;
}

.link-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--text-faint);
}
.link-dot.connected { background: var(--live); box-shadow: 0 0 6px var(--live); }

/* ---------- parameter strip (ISO / WB / EXP / ZOOM / TORCH) ---------- */

.param-strip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 168px;
  z-index: 6;
  display: flex;
  gap: 8px;
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.param-strip::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 60px;
  background: rgba(17, 18, 19, 0.82);
  backdrop-filter: blur(6px);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 6px 10px;
  gap: 2px;
}

.chip .chip-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.chip .chip-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
}

.chip.enabled .chip-value { color: var(--amber); }
.chip.enabled { border-color: var(--amber-dim); }
.chip.active { background: var(--amber); }
.chip.active .chip-label,
.chip.active .chip-value { color: var(--void); }

.chip.disabled { opacity: 0.4; }

/* inline exposure slider, revealed under the strip when EXP chip is tapped */
.exp-popover {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 212px;
  z-index: 7;
  background: rgba(17, 18, 19, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 12px 14px;
  display: none;
}
.exp-popover.open { display: block; }
.exp-popover .exp-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.exp-popover input[type="range"] {
  flex: 1;
  accent-color: var(--amber);
}
.exp-popover .exp-value {
  width: 44px;
  text-align: right;
  font-size: 12px;
  color: var(--amber);
  font-weight: 700;
}

/* ---------- bottom sheet (pull / push URLs) ---------- */

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 72%;
  background: var(--panel);
  border-top: 1px solid var(--hairline);
  border-radius: 16px 16px 0 0;
  padding: 10px 16px max(20px, env(safe-area-inset-bottom));
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.22s ease;
  z-index: 20;
}
.sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--hairline);
  margin: 4px auto 14px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.sheet-header h2 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0;
  text-transform: uppercase;
}
.sheet-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.tab {
  flex: 1;
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.tab.active {
  color: var(--void);
  background: var(--amber);
  border-color: var(--amber);
}

.panel.hidden { display: none; }

.hint {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
  margin: 0 0 14px;
}

label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

input {
  display: block;
  width: 100%;
  margin-top: 4px;
  background: var(--void);
  border: 1px solid var(--hairline);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-family: ui-monospace, Menlo, monospace;
}

.primary {
  width: 100%;
  background: var(--amber);
  color: var(--void);
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-weight: 700;
  font-size: 14px;
  margin-top: 4px;
}

.primary.stop { background: var(--rec); color: var(--text-primary); }

.relay-status {
  margin-top: 10px;
  font-size: 12px;
  font-family: ui-monospace, Menlo, monospace;
  color: var(--text-dim);
}

.endpoint-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--hairline);
}

.proto-label {
  width: 48px;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
}

.endpoint-row code {
  flex: 1;
  font-size: 12px;
  color: var(--text-primary);
  overflow-x: auto;
  white-space: nowrap;
  font-family: ui-monospace, Menlo, monospace;
}

.copy {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11px;
}

.sheet-footer {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--hairline);
}

.sheet-footer button {
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
}

/* ---------- bottom control dock ---------- */

.dock {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 14px 28px max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(3,3,3,0.85), transparent);
}

.dock-side {
  display: flex;
  gap: 14px;
}
.dock-side.right { justify-content: flex-end; }

.iconbtn {
  width: 46px;
  height: 46px;
  border-radius: 999px;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  color: var(--text-primary);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.iconbtn.on { border-color: var(--amber); color: var(--amber); }

.shutter {
  width: 78px;
  height: 78px;
  border-radius: 999px;
  border: 4px solid var(--text-primary);
  background: transparent;
  position: relative;
  justify-self: center;
}
.shutter::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 999px;
  background: var(--rec);
  transition: border-radius 0.15s ease, inset 0.15s ease;
}
.shutter.live::before {
  border-radius: 6px;
  inset: 20px;
}

dialog {
  background: var(--panel);
  color: var(--text-primary);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 20px;
  width: min(360px, 90vw);
}

dialog h3 { margin-top: 0; }
dialog menu { display: flex; justify-content: flex-end; gap: 10px; padding: 0; }
dialog button { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--hairline); background: transparent; color: var(--text-primary); }
