* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #f0f0f0;
  font-family: system-ui, "Segoe UI", sans-serif;
}

#out {
  display: block;
  width: 100vw;
  height: 100vh;
  background: #000;
  /* the canvas itself handles the mirror flip; CSS-flip would not be picked
     up by ctx.drawImage and would break MediaPipe */
}

/* ===== Toolbar ===== */
#toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #1f1f1f;
  border-bottom: 1px solid #2c2c2c;
  z-index: 8;
  user-select: none;
  display: flex;
  flex-direction: column;
}

.tb-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  flex-wrap: nowrap;
  border-bottom: 1px solid #2c2c2c;
}
.tb-row:last-child { border-bottom: 0; }

.tb-sep {
  width: 1px;
  align-self: stretch;
  background: rgba(180, 180, 180, 0.18);
  margin: 4px 4px;
}

.tb-btn {
  background: transparent;
  color: #f0f0f0;
  border: 1px solid transparent;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
.tb-btn:hover { background: rgba(120, 120, 120, 0.25); }
.tb-btn:active { background: rgba(120, 120, 120, 0.4); }
.tb-btn:disabled {
  color: #777;
  cursor: not-allowed;
  background: transparent;
}

/* Record button — red dot, plus a tinted background while a recording is
   in progress. The bullet character is part of the label text. */
#btn-record { color: #ff6b6b; }
#btn-record.recording {
  color: #fff;
  background: rgba(200, 60, 60, 0.55);
}
#btn-record.recording:hover {
  background: rgba(200, 60, 60, 0.75);
}

.tb-cb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 0 4px;
  cursor: pointer;
}
.tb-cb input[type="checkbox"] {
  accent-color: #4a90d9;
  cursor: pointer;
}

.tb-label {
  font-size: 13px;
  color: #ccc;
}

.tb-value {
  font-size: 13px;
  color: #ccc;
  min-width: 38px;
  text-align: right;
}

.tb-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 130px;
  height: 4px;
  background: #555;
  border-radius: 2px;
  outline: none;
}
.tb-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fafafa;
  cursor: pointer;
  border: 0;
}
.tb-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fafafa;
  cursor: pointer;
  border: 0;
}

.tb-combo {
  background: #2a2a2a;
  color: #f0f0f0;
  border: 1px solid #444;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 13px;
  font-family: inherit;
  min-width: 200px;
  max-width: 280px;
  cursor: pointer;
}

/* In fullscreen the toolbar hides and only re-appears when mouse is near
   the top edge. fullscreen.js toggles the .fullscreen class on body and
   .visible on the toolbar. */
body.fullscreen #toolbar {
  background: rgba(20, 20, 20, 0.85);
  border-bottom: 0;
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: opacity 180ms, transform 180ms;
}
body.fullscreen #toolbar.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ===== Success overlay (online-mode execution-check feedback) =====
   Single <img> created lazily by SuccessOverlay; pinned top-left. Sits above
   the central #anim-overlay (clock) but below the toolbar. drop-shadow gives
   a soft separation from the canvas. */
#success-anim {
  position: fixed;
  /* Tuck below the two-row toolbar (~100 px) — at top:24px the gif
     visually crops because the toolbar (z-index 8) sits on top of it.
     In fullscreen the toolbar hides itself, so override there. */
  top: 112px;
  left: 24px;
  /* Fixed-width with viewport-scaled fallback. height:auto preserves the
     gif's native aspect (398×362 source), so we never crop or stretch. */
  width: clamp(120px, 12vw, 180px);
  height: auto;
  display: none;
  z-index: 5;
  pointer-events: none;
  filter: drop-shadow(0 0 8px rgba(0, 0, 0, 0.4));
  overflow: visible;
}
#success-anim.active { display: block; }
/* In fullscreen the toolbar floats above the canvas and auto-hides, so the
   gif can sit at the actual top-left corner. */
body.fullscreen #success-anim { top: 24px; }

/* ===== Animation overlay (online-mode centred GIFs) =====
   Lives above the canvas but below the toolbar. Each AnimationTrack item
   gets one <img> in here; only the active one carries the .active class.
   filter: blur softens alpha edges around the gif's own transparency. */
#anim-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 4;
}
#anim-overlay img {
  display: none;
  max-width: 28vw;
  max-height: 55vh;
  filter: blur(0.6px) drop-shadow(0 0 6px rgba(0, 0, 0, 0.35));
}
#anim-overlay img.active {
  display: block;
}

/* ===== Status bar ===== */
#status-bar {
  position: fixed;
  bottom: 12px;
  left: 12px;
  background: rgba(0, 0, 0, 0.6);
  color: #ddd;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 5;
  max-width: 70vw;
}
#status-bar:empty { display: none; }

/* ===== Start overlay ===== */
#start-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
  z-index: 10;
  transition: opacity 200ms ease;
}
#start-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.card {
  background: #1a1a1a;
  padding: 32px 40px;
  border-radius: 10px;
  text-align: center;
  max-width: 720px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.card.hidden { display: none; }
.card h1 {
  margin: 0 0 8px;
  font-weight: 500;
  font-size: 24px;
}
.card-sub {
  margin: 0 0 24px;
  color: #bbb;
  font-size: 14px;
}
#status {
  margin: 0 0 24px;
  color: #bbb;
  font-size: 14px;
  min-height: 20px;
}
button#start-btn {
  font-size: 16px;
  padding: 10px 28px;
  background: #4a90d9;
  color: #fff;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  transition: background 100ms;
  font-family: inherit;
}
button#start-btn:hover { background: #5aa0e9; }
button#start-btn:disabled {
  background: #555;
  cursor: not-allowed;
}

.start-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.link-btn {
  background: transparent;
  border: 0;
  color: #8ab4e8;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
}
.link-btn:hover { text-decoration: underline; }

/* ===== Mode selection ===== */
.mode-row {
  display: flex;
  gap: 16px;
  margin-top: 8px;
}
.mode-btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  min-width: 240px;
  padding: 24px 18px;
  background: #232323;
  border: 2px solid #333;
  border-radius: 8px;
  color: #f0f0f0;
  cursor: pointer;
  font-family: inherit;
  transition: background 100ms, border-color 100ms, transform 100ms;
}
.mode-btn:hover {
  background: #2c2c2c;
  border-color: #4a90d9;
}
.mode-btn:active {
  transform: scale(0.99);
}
.mode-btn .mode-title {
  font-size: 18px;
  font-weight: 600;
}
.mode-btn .mode-sub {
  font-size: 13px;
  color: #8ab4e8;
}
.mode-btn .mode-hint {
  font-size: 12px;
  color: #999;
  margin-top: 6px;
  max-width: 230px;
  line-height: 1.4;
}

/* Disabled overlay-positioning controls (online mode) */
.tb-btn:disabled, .tb-cb input:disabled, .tb-slider:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.tb-cb input:disabled + * { color: #888; }
