/* ==========================================================================
   Gesture Slide Controller — design tokens
   ========================================================================== */
:root {
  --bg: #0b0e14;
  --panel: #12161f;
  --panel-raised: #171c27;
  --border: #232a38;
  --border-soft: #1a2029;

  --text: #e7ecf3;
  --text-dim: #8b93a3;
  --text-faint: #565f70;

  --accent-next: #8cff9b;
  --accent-next-dim: #2c4a30;
  --accent-back: #ffb454;
  --accent-back-dim: #4a3a20;
  --accent-data: #5cc8ff;
  --accent-danger: #ff6b6b;
  --accent-danger-dim: #4a2323;

  --font-display: "Space Grotesk", "Inter", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    linear-gradient(var(--border-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--border-soft) 1px, transparent 1px);
  background-size: 42px 42px;
  background-position: center;
  background-attachment: fixed;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

button, input, textarea { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--accent-data);
  outline-offset: 2px;
  border-radius: 4px;
}

.mono { font-family: var(--font-mono); }

/* ==========================================================================
   Shell
   ========================================================================== */
.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 26px 22px 40px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.topbar__brand { display: flex; align-items: center; gap: 14px; }

.topbar__mark {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 8px;
  background:
    radial-gradient(circle at 32% 30%, var(--accent-next) 0 3px, transparent 3.5px),
    radial-gradient(circle at 68% 30%, var(--accent-data) 0 3px, transparent 3.5px),
    radial-gradient(circle at 50% 68%, var(--accent-back) 0 3px, transparent 3.5px);
  border: 1px solid var(--border);
  background-color: var(--panel-raised);
}

.topbar__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 1.1;
  margin: 0;
  letter-spacing: -0.01em;
}

.topbar__subtitle { margin: 3px 0 0; font-size: 0.8rem; color: var(--text-dim); }

.topbar__status {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: var(--panel);
  font-size: 0.78rem;
  color: var(--text-dim);
}

.topbar__status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); flex-shrink: 0; }
.topbar__status[data-state="loading"] .dot { background: var(--accent-data); animation: pulse 1.1s ease-in-out infinite; }
.topbar__status[data-state="ready"] .dot { background: var(--accent-next); }
.topbar__status[data-state="error"] .dot { background: var(--accent-danger); }
.topbar__status[data-state="ready"] { color: var(--text); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* ---------- Layout grid ---------- */
.layout {
  display: grid;
  grid-template-columns: 300px 1fr 300px;
  gap: 18px;
  align-items: start;
}

@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr 1fr; }
  .stage-panel { grid-column: 1 / -1; order: -1; }
}

@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .stage-panel { order: 0; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  margin: 0;
  color: var(--text);
}

/* ==========================================================================
   Camera panel
   ========================================================================== */
.monitor__frame {
  position: relative;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-raised);
}

.bracket {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid var(--accent-data);
  opacity: 0.7;
}
.bracket--tl { top: 5px; left: 5px; border-right: none; border-bottom: none; }
.bracket--tr { top: 5px; right: 5px; border-left: none; border-bottom: none; }
.bracket--bl { bottom: 5px; left: 5px; border-right: none; border-top: none; }
.bracket--br { bottom: 5px; right: 5px; border-left: none; border-top: none; }

.monitor__viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 4px;
  overflow: hidden;
  background: #05070a;
  isolation: isolate;
}

#webcam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  z-index: 1;
}

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  transform: scaleX(-1);
}

.monitor__scanline {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.025) 0px,
    rgba(255, 255, 255, 0.025) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
}

.monitor__placeholder,
.monitor__error {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  padding: 18px;
  color: var(--text-dim);
  background: #0d1017;
}

.monitor__placeholder svg { color: var(--text-faint); margin-bottom: 2px; }
.monitor__placeholder p { margin: 0; color: var(--text); font-weight: 500; font-size: 0.9rem; }
.monitor__placeholder span { font-size: 0.78rem; max-width: 220px; }
.monitor__placeholder strong { color: var(--accent-data); font-weight: 600; }

.monitor__error { color: var(--accent-danger); }
.monitor__error svg { color: var(--accent-danger); margin-bottom: 2px; }
.monitor__error p { margin: 0; color: var(--text); font-weight: 500; font-size: 0.82rem; max-width: 240px; line-height: 1.4; }

/* ---------- Camera status line ---------- */
.camera-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-dim);
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-raised);
}

.camera-status__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex-shrink: 0; }
.camera-status[data-state="on"] .camera-status__dot { background: var(--accent-next); }
.camera-status[data-state="on"] { color: var(--accent-next); }
.camera-status[data-state="error"] .camera-status__dot { background: var(--accent-danger); }
.camera-status[data-state="error"] { color: var(--accent-danger); }
.camera-status[data-state="connecting"] .camera-status__dot { background: var(--accent-data); animation: pulse 1s ease-in-out infinite; }

/* ---------- Readout ---------- */
.readout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.readout__cell { background: var(--panel-raised); padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.readout__label { font-size: 0.64rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; }
.readout__value { font-family: var(--font-display); font-weight: 600; font-size: 0.86rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.readout__value.mono { font-family: var(--font-mono); font-weight: 500; }

#gestureCell[data-gesture="open"] .readout__value { color: var(--accent-next); }
#gestureCell[data-gesture="fist"] .readout__value { color: var(--accent-back); }
#actionCell[data-action="next"] .readout__value { color: var(--accent-next); }
#actionCell[data-action="back"] .readout__value { color: var(--accent-back); }

/* ---------- Instructions ---------- */
.instructions {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

.instructions p { margin: 0; font-size: 0.8rem; color: var(--text-dim); display: flex; align-items: center; gap: 7px; }
.instructions strong { color: var(--text); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.controls { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-raised);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}

.btn:hover:not(:disabled) { border-color: var(--text-faint); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn--primary { background: var(--accent-next); border-color: var(--accent-next); color: #0b1a0f; }
.btn--primary:hover:not(:disabled) { background: #a3ffb0; border-color: #a3ffb0; }

.btn--danger { color: var(--accent-danger); }
.btn--danger:hover:not(:disabled) { border-color: var(--accent-danger); }

.btn--ghost { color: var(--text-dim); }
.btn--wide { width: 100%; }
.btn--small { padding: 6px 10px; font-size: 0.75rem; }

/* ==========================================================================
   Stage / slide preview
   ========================================================================== */
.stage-panel { min-height: 520px; }

.stage-panel__head { display: flex; align-items: center; justify-content: space-between; }
.page-indicator { font-size: 0.8rem; color: var(--text-dim); }

.stage {
  position: relative;
  flex: 1;
  min-height: 360px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 20% 15%, rgba(92, 200, 255, 0.06), transparent 45%),
    var(--panel-raised);
  overflow: hidden;
}

.stage__empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-dim);
  text-align: center;
  padding: 24px;
}
.stage__empty p { margin: 0; color: var(--text); font-weight: 500; }
.stage__empty span { font-size: 0.85rem; }
.stage__empty strong { color: var(--accent-data); }

.slide-card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 40px 46px;
  opacity: 0;
  transform: translateX(24px);
  transition: opacity 0.28s ease, transform 0.28s ease;
  pointer-events: none;
  overflow-y: auto;
}

.slide-card[data-active="true"] { opacity: 1; transform: translateX(0); pointer-events: auto; }

.slide-card__eyebrow { font-family: var(--font-mono); font-size: 0.7rem; color: var(--accent-data); margin: 0 0 8px; }
.slide-card__title { font-family: var(--font-display); font-weight: 700; font-size: clamp(1.35rem, 2.6vw, 2rem); line-height: 1.16; margin: 0 0 12px; letter-spacing: -0.01em; }
.slide-card__body { font-size: 0.94rem; line-height: 1.6; color: var(--text-dim); max-width: 56ch; margin: 0 0 16px; white-space: pre-wrap; }
.slide-card__image { max-width: 100%; max-height: 220px; border-radius: 8px; border: 1px solid var(--border); object-fit: cover; }

.stage-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.deck__nav-signals { display: flex; gap: 8px; }
.signal {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 11px; border-radius: 100px; border: 1px solid var(--border);
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em; color: var(--text-faint);
  background: var(--panel-raised); transition: all 0.12s ease;
}
.signal--back.is-firing { color: var(--accent-back); border-color: var(--accent-back); background: var(--accent-back-dim); }
.signal--next.is-firing { color: var(--accent-next); border-color: var(--accent-next); background: var(--accent-next-dim); }

.present-controls { display: flex; gap: 10px; }

/* ==========================================================================
   Slide manager
   ========================================================================== */
.manager-panel__head { display: flex; align-items: center; justify-content: space-between; }
.slide-count { font-size: 0.78rem; color: var(--text-dim); }

.slide-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 480px;
  overflow-y: auto;
}

.slide-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-raised);
  cursor: pointer;
  transition: border-color 0.12s ease;
}

.slide-item:hover { border-color: var(--text-faint); }
.slide-item[data-active="true"] { border-color: var(--accent-data); }

.slide-item__thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-faint);
}

.slide-item__thumb img { width: 100%; height: 100%; object-fit: cover; }

.slide-item__info { flex: 1; min-width: 0; }
.slide-item__title { font-size: 0.83rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slide-item__index { font-size: 0.7rem; color: var(--text-faint); font-family: var(--font-mono); }

.slide-item__actions { display: flex; gap: 3px; flex-shrink: 0; }

.icon-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--border); }
.icon-btn.danger:hover { color: var(--accent-danger); }

.storage-note {
  margin: 0;
  font-size: 0.74rem;
  color: var(--accent-back);
  padding: 8px 10px;
  border: 1px solid var(--accent-back);
  background: var(--accent-back-dim);
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Modal
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(5, 7, 10, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.modal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal__head h3 { margin: 0; font-family: var(--font-display); font-size: 1.05rem; }

.modal__close {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--panel-raised); color: var(--text-dim); font-size: 1.1rem; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.modal__close:hover { color: var(--text); }

.modal__form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: 0.78rem; color: var(--text-dim); font-weight: 500; }

.field input[type="text"],
.field textarea,
.field input[type="file"] {
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 11px;
  font-size: 0.88rem;
  font-family: inherit;
  resize: vertical;
}

.field input[type="text"]:focus,
.field textarea:focus { outline: 2px solid var(--accent-data); outline-offset: 1px; }

.image-preview { display: flex; align-items: center; gap: 10px; }
.image-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }

.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ==========================================================================
   Presentation mode
   ========================================================================== */
.app.is-presenting .manager-panel { display: none; }
.app.is-presenting .layout { grid-template-columns: 260px 1fr; }
.app.is-presenting .stage-panel { min-height: 70vh; }
.app.is-presenting .camera-panel { position: sticky; top: 16px; }

@media (max-width: 900px) {
  .app.is-presenting .layout { grid-template-columns: 1fr; }
  .app.is-presenting .camera-panel { position: static; order: 2; }
  .app.is-presenting .stage-panel { order: 1; }
}

/* ==========================================================================
   Footer
   ========================================================================== */
.footer { text-align: center; font-size: 0.76rem; color: var(--text-faint); padding-top: 4px; }
