:root {
  --bg: #f3f6ff;
  --card: #ffffff;
  --ink: #0d1530;
  --muted: #5b6587;
  --line: #dfe5f5;
  --blue: #1f5eff;
  --blue-ink: #ffffff;
  --yellow: #ffd23f;
  --danger: #d93a3a;
  --ok: #18a058;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --card: #141b33;
    --ink: #eef2ff;
    --muted: #9aa6cc;
    --line: #26304f;
    --blue: #4c7dff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h2 { font: 800 1.15rem/1.2 'Bricolage Grotesque', Inter, sans-serif; margin: 0 0 .6rem; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: 12px 16px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font: 800 1.35rem 'Bricolage Grotesque', sans-serif; display: flex; align-items: center; gap: 8px; }
.drop { width: 18px; height: 24px; background: var(--blue); border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; transform: rotate(0deg); clip-path: path('M9 0 C9 0 18 11 18 16 A9 8 0 0 1 0 16 C0 11 9 0 9 0Z'); }
.room { display: flex; align-items: center; gap: 8px; }
.room label { font-weight: 600; color: var(--muted); }
.room input { width: 170px; }
.pill { font-size: .75rem; padding: 3px 9px; border-radius: 99px; font-weight: 600; }
.pill.on { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.off { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }

main { max-width: 760px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }

input, select {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; margin-top: 4px;
}
input:focus, select:focus { outline: 2px solid var(--blue); outline-offset: 0; }
label { display: block; font-size: .85rem; font-weight: 500; color: var(--muted); margin: 8px 0; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: .95rem; }
label.check input { width: auto; margin: 0; }

.btn {
  font: 600 .95rem Inter, sans-serif; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 12px; padding: 10px 14px; cursor: pointer; transition: transform .08s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--blue); color: var(--blue-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.big { padding: 13px 18px; font-size: 1rem; }
.btn.tiny { padding: 3px 8px; font-size: .75rem; }
.btn.danger { color: var(--danger); }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.row input { margin: 0; flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.partner { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.partner p { margin: 0; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab { flex: 1; font: 600 .9rem Inter, sans-serif; padding: 9px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--ink); color: var(--card); border-color: var(--ink); }

.cam { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 3/4; max-height: 420px; margin: 0 auto; }
.cam video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.cam video.back { transform: none; }
.rec { position: absolute; top: 10px; left: 10px; background: var(--danger); color: #fff; font-weight: 700; padding: 3px 10px; border-radius: 99px; font-size: .85rem; }

.drop-zone {
  display: grid; place-items: center; gap: 4px; text-align: center; padding: 34px 16px; margin: 0;
  border: 2px dashed var(--line); border-radius: 14px; cursor: pointer; color: var(--ink);
}
.drop-zone.over { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 8%, transparent); }

#srcPreview { width: 100%; max-height: 340px; background: #000; border-radius: 12px; margin-top: 12px; }

.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 14px; }
#barFill { height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), #48b6ff); transition: width .2s; }

.checker {
  background-color: #e9edf7;
  background-image: linear-gradient(45deg, #cfd6e8 25%, transparent 25%), linear-gradient(-45deg, #cfd6e8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #cfd6e8 75%), linear-gradient(-45deg, transparent 75%, #cfd6e8 75%);
  background-size: 18px 18px; background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  border-radius: 12px; display: grid; place-items: end center; overflow: hidden;
}
.result { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 14px; margin-top: 14px; }
.result .checker { min-height: 260px; }
.result img { max-width: 100%; max-height: 380px; display: block; }
.result-side { display: flex; flex-direction: column; gap: 8px; }

.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.clip { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.clip .checker { height: 150px; border-radius: 0; }
.clip img { max-height: 150px; max-width: 100%; }
.clip .meta { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.clip .name { font-weight: 600; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clip .acts { display: flex; gap: 6px; }
.clip .acts .btn { flex: 1; padding: 6px; font-size: .8rem; }

.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 260px; overflow: auto; }
.log li { font-size: .9rem; padding: 7px 10px; border-radius: 10px; background: var(--bg); }
.log time { color: var(--muted); font-size: .78rem; margin-right: 6px; }

.setup dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; }
.setup dt { font-weight: 600; color: var(--muted); }
.setup dd { margin: 0; word-break: break-all; }
code { background: var(--bg); padding: 2px 6px; border-radius: 6px; font-size: .9rem; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 20; box-shadow: 0 8px 30px rgba(0,0,0,.25); }

@media (max-width: 560px) {
  .result { grid-template-columns: 1fr; }
  .room input { width: 130px; }
  .partner .btn { width: 100%; }
}
