:root {
  --ink: #eef2f6;       /* latar halaman */
  --panel: #ffffff;     /* kartu */
  --raise: #f1f4f8;     /* isian, tile */
  --line: #dbe2ea;
  --text: #142030;
  --muted: #5d6b7c;
  --accent: #2b59e0;    /* biru sinyal */
  --accent-hover: #1f47c2;
  --accent-ink: #ffffff;
  --ok: #12996a;
  --err: #d9443b;
  --shadow: 0 1px 2px rgba(20, 32, 48, .05), 0 4px 16px rgba(20, 32, 48, .05);
  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 8px;
  --font: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background: var(--ink);
  color: var(--text);
  font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand-mark { width: 26px; height: 26px; color: var(--accent); }
.brand-name { font-size: 18px; font-weight: 500; letter-spacing: -0.01em; }
.brand-name b { font-weight: 800; }

.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 13px; font-weight: 500; color: var(--muted);
}
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip[data-state="loading"] i { background: #e2a21b; animation: pulse 1.2s ease-in-out infinite; }
.chip[data-state="ready"] { color: var(--text); }
.chip[data-state="ready"] i { background: var(--ok); }
.chip[data-state="error"] { color: var(--err); }
.chip[data-state="error"] i { background: var(--err); }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- layout ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  padding: 20px clamp(16px, 3vw, 32px);
  width: 100%; max-width: 1480px; margin: 0 auto;
}
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------- viewfinder ---------- */
.stage { min-width: 0; }
.viewfinder {
  position: relative;
  aspect-ratio: 16 / 10;
  max-height: calc(100dvh - 160px);
  width: 100%;
  border-radius: var(--r-lg);
  background:
    radial-gradient(circle at 50% 45%, #22324a 0%, #0f1824 78%);
  overflow: hidden;
  isolation: isolate;
  box-shadow: 0 10px 30px rgba(20, 32, 48, .14);
}
@media (max-width: 640px) {
  .viewfinder { aspect-ratio: 3 / 4; max-height: 72dvh; border-radius: var(--r-md); }
}
.viewfinder video, .viewfinder canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
}
.viewfinder video { object-fit: cover; opacity: 0; transition: opacity .3s; }
.viewfinder[data-camera="on"] video { opacity: 1; }
.viewfinder[data-mirror="true"] video { transform: scaleX(-1); }
.viewfinder[data-sync="true"] video { opacity: 0; }
.viewfinder canvas { pointer-events: none; }

/* viewfinder frame corners — the signature element */
.vf-corner {
  position: absolute; width: 34px; height: 34px; z-index: 2;
  border: 0 solid rgba(230, 236, 242, .55); pointer-events: none;
}
.vf-corner.tl { top: 14px; left: 14px; border-top-width: 2px; border-left-width: 2px; border-top-left-radius: 8px; }
.vf-corner.tr { top: 14px; right: 14px; border-top-width: 2px; border-right-width: 2px; border-top-right-radius: 8px; }
.vf-corner.bl { bottom: 14px; left: 14px; border-bottom-width: 2px; border-left-width: 2px; border-bottom-left-radius: 8px; }
.vf-corner.br { bottom: 14px; right: 14px; border-bottom-width: 2px; border-right-width: 2px; border-bottom-right-radius: 8px; }

.hud {
  position: absolute; z-index: 3; display: flex; gap: 8px; align-items: center;
  opacity: 0; transition: opacity .25s;
}
.viewfinder[data-camera="on"] .hud { opacity: 1; }
.hud-top { top: 22px; left: 60px; right: 60px; }
.live, .hud-stat {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(10, 15, 21, .62); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-size: 13px; font-weight: 500; color: #dfe6ed;
  font-variant-numeric: tabular-nums;
}
.hud-stat b { font-weight: 700; color: #fff; }
.live { color: #fff; font-weight: 600; }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--err); animation: pulse 1.4s infinite; }

.empty {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 24px; text-align: center;
}
.viewfinder[data-camera="on"] .empty { display: none; }
.empty { color: #eef3f8; }
.empty svg { width: 52px; height: 52px; color: #8fb0ff; margin-bottom: 4px; }
.empty h1 {
  margin: 0; max-width: 22ch;
  font-size: clamp(22px, 3.2vw, 34px); line-height: 1.15; font-weight: 700; letter-spacing: -0.02em;
}
.empty p { margin: 0 0 10px; max-width: 46ch; color: #a9b7c6; }

.btn {
  border: 0; cursor: pointer; border-radius: 999px;
  padding: 12px 22px; font-weight: 600; font-size: 15px;
  transition: transform .12s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { cursor: progress; opacity: .6; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:not(:disabled):hover { background: var(--accent-hover); }

/* dock */
.dock {
  position: absolute; z-index: 5; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  padding: 8px; border-radius: 999px;
  background: rgba(10, 15, 21, .62); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, .08);
}
.viewfinder[data-camera="off"] .dock { display: none; }
.dock-btn {
  width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .08); color: #fff;
  transition: background .15s, transform .12s, opacity .15s;
}
.dock-btn svg { width: 22px; height: 22px; }
.dock-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .16); }
.dock-btn:active:not(:disabled) { transform: scale(.92); }
.dock-btn:disabled { opacity: .35; cursor: not-allowed; }
.dock-power { width: 58px; height: 58px; background: var(--accent); color: var(--accent-ink); }
.dock-power svg { width: 26px; height: 26px; }
.dock-power:hover:not(:disabled) { background: var(--accent-hover); }
.dock-power[aria-pressed="true"] { background: var(--err); color: #fff; }
.dock-power[aria-pressed="true"]:hover { background: #ff8780; }

.facing-tag {
  position: absolute; z-index: 5; right: 22px; bottom: 34px;
  font-size: 12px; font-weight: 500; color: #cfd8e1;
  padding: 4px 10px; border-radius: 999px; background: rgba(10, 15, 21, .62);
}
@media (max-width: 640px) { .facing-tag { display: none; } }

/* ---------- panel ---------- */
.panel { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 16px 18px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -0.005em; }
.count {
  min-width: 28px; padding: 2px 9px; border-radius: 999px; text-align: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.card-results { flex: 1; min-height: 200px; }
.det-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; max-height: 340px; overflow: auto; }
.det-empty { color: var(--muted); font-size: 14px; padding: 10px 0; }
.det-item { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 10px; }
.det-dot { width: 10px; height: 10px; border-radius: 3px; }
.det-name { font-weight: 600; text-transform: capitalize; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.det-meta { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.det-meta b { color: var(--text); font-weight: 700; }
.det-bar { grid-column: 2 / 4; height: 4px; border-radius: 4px; background: var(--raise); overflow: hidden; margin-top: -4px; }
.det-bar i { display: block; height: 100%; border-radius: inherit; transition: width .25s ease-out; }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0; }
.metrics div { background: var(--raise); border-radius: var(--r-sm); padding: 10px 12px; min-width: 0; }
.metrics dt { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.metrics dd { margin: 0; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.metrics dd small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.metrics .dd-text { font-size: 15px; padding-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text); }
.field-row { display: flex; justify-content: space-between; align-items: baseline; }
.field-row output { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.field-hint { font-size: 12px; color: var(--muted); }
select {
  appearance: none; -webkit-appearance: none;
  width: 100%; padding: 10px 36px 10px 12px; border-radius: var(--r-sm);
  background: var(--raise) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%238a9bad' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center / 12px;
  border: 1px solid var(--line); cursor: pointer;
}
select:disabled { opacity: .55; cursor: not-allowed; }
select option { background: var(--panel); }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: var(--raise); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--raise); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: var(--accent); border: 3px solid var(--panel); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 3px solid var(--panel); }

.progress { display: block; height: 4px; border-radius: 4px; background: var(--raise); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-ui { width: 38px; height: 22px; border-radius: 999px; background: var(--raise); position: relative; flex: none; border: 1px solid var(--line); transition: background .15s; }
.toggle-ui::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform .18s, background .18s; }
.toggle input:checked + .toggle-ui { background: rgba(43, 89, 224, .14); border-color: var(--accent); }
.toggle input:checked + .toggle-ui::after { transform: translateX(16px); background: var(--accent); }
.toggle input:focus-visible + .toggle-ui { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- footer & toast ---------- */
.foot {
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; justify-content: center;
  padding: 18px 16px 24px; color: var(--muted); font-size: 13px;
}
.foot b { color: var(--text); font-weight: 600; }
.foot-sep { width: 4px; height: 4px; border-radius: 50%; background: var(--line); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: min(92vw, 460px); z-index: 50;
  padding: 12px 16px; border-radius: var(--r-md);
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  box-shadow: 0 12px 32px rgba(20, 32, 48, .16); font-size: 14px;
}
.toast[data-kind="error"] { border-color: var(--err); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.toggle-hint { padding-left: 48px; }
