*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── theme tokens ── */

:root {
  --card-width: 560px;
  --bg:               #111;
  --surface:          #1a1a1a;
  --border:           #2a2a2a;
  --text:             #eee;
  --text-dim:         #666;
  --control-bg:       #222;
  --control-border:   #444;
  --control-hover:    #333;
  --control-text:     #eee;
  --ctrl-inactive:    #888;
  --error:            #f87171;
}

[data-theme="light"] {
  --bg:               #f0f0f0;
  --surface:          #ffffff;
  --border:           #ddd;
  --text:             #111;
  --text-dim:         #999;
  --control-bg:       #f8f8f8;
  --control-border:   #ccc;
  --control-hover:    #e8e8e8;
  --control-text:     #111;
  --ctrl-inactive:    #666;
  --error:            #dc2626;
}

/* ── base ── */

body {
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── top bar ── */

#top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.title {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  margin-right: 0.5rem;
  white-space: nowrap;
  color: var(--text);
}

#top-bar select,
#top-bar > button {
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  border-radius: 5px;
  border: 1px solid var(--control-border);
  background: var(--control-bg);
  color: var(--control-text);
  cursor: pointer;
}

#top-bar select { min-width: 200px; }

#add-btn {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  font-weight: 500;
}

#add-btn:hover { background: #1d4ed8; border-color: #1d4ed8; }
#add-btn:disabled { background: var(--control-bg); border-color: var(--control-border); color: var(--ctrl-inactive); cursor: default; }

#grant-btn {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
  font-weight: 500;
}

#grant-btn:hover { background: #15803d; border-color: #15803d; }

/* ── view controls (theme + size) ── */

#view-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-left: auto;
}

#theme-btns,
#size-btns {
  display: flex;
  gap: 0.2rem;
}

/* shared small control button */
.ctrl-btn {
  height: 1.9rem;
  min-width: 1.9rem;
  padding: 0 0.3rem;
  border-radius: 4px;
  border: 1px solid var(--control-border);
  background: var(--control-bg);
  color: var(--ctrl-inactive);
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.ctrl-btn:hover:not(.active):not(:disabled) { background: var(--control-hover); }
.ctrl-btn:active:not(:disabled) { transform: scale(0.85); }

.ctrl-btn.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.ctrl-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

#size-dec, #size-inc { font-size: 1rem; }

#github-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 4px;
  color: var(--ctrl-inactive);
  text-decoration: none;
  margin-left: 0.4rem;
  transition: color 0.15s, background 0.15s;
}

#github-link:hover {
  color: var(--text);
  background: var(--control-hover);
}

.theme-btn { padding: 0 0.55rem; }

/* ── status ── */

#status {
  font-size: 0.82rem;
  color: var(--text-dim);
  padding: 0.4rem 1rem;
  min-height: 1.8rem;
}

#status.error { color: var(--error); }
#status:empty { min-height: 0; padding: 0; }

/* ── grid ── */

#grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.75rem;
  align-items: start;
}

/* ── camera card ── */

.card {
  position: relative;
  flex: 0 0 var(--card-width);
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

.card video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.card video.mirrored { transform: scaleX(-1); }

.card-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1.5rem 0.6rem 0.4rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
  font-size: 0.75rem;
  color: #ddd;
  pointer-events: none;
}

.mirror-btn,
.remove-btn {
  position: absolute;
  top: 0.5rem;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}

.remove-btn { right: 0.5rem; }
.mirror-btn { left: 0.5rem; font-size: 0.85rem; }

.card:hover .mirror-btn,
.card:hover .remove-btn { opacity: 1; }

.remove-btn:hover { background: rgba(220, 38, 38, 0.8); }
.mirror-btn:hover { background: rgba(0, 0, 0, 0.8); }
.mirror-btn.active { background: #2563eb; opacity: 1; }
