:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1b2430;
  --muted: #5d6b7b;
  --border: #d9e0e8;
  --primary: #1f6feb;
  --primary-text: #ffffff;
  --danger: #c62828;
  --waiting: #b26a00;
  --sharing: #1f6feb;
  --connected: #1b873f;
  --ended: #6b7280;
  --notice-bg: #fff4d6;
  --notice-text: #5c4300;
  --stage-bg: #0b0f14;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --card: #19212b;
    --text: #e6ebf1;
    --muted: #93a1b1;
    --border: #2b3643;
    --primary: #4c8dff;
    --primary-text: #0b1220;
    --danger: #ef5350;
    --waiting: #f0a63a;
    --sharing: #6ea5ff;
    --connected: #4cc27a;
    --ended: #9aa5b1;
    --notice-bg: #3a2f10;
    --notice-text: #ffe29a;
    --stage-bg: #05080c;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main { max-width: 760px; margin: 0 auto; padding: 16px; }
main.wide { max-width: 1500px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
}

h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1rem; margin: 0; }
p { margin: 8px 0; }
.muted { color: var(--muted); font-size: 0.92rem; }

.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.row.between { justify-content: space-between; }
.row.tight { gap: 8px; }

button, .btn {
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: var(--primary-text);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.secondary { background: transparent; color: var(--primary); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger.secondary { background: transparent; color: var(--danger); }
button.small { padding: 5px 10px; font-size: 0.85rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, label:focus-within { outline: 3px solid var(--primary); outline-offset: 2px; }

input[type="text"], select {
  font: inherit;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 12px;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
}
.badge::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.badge.waiting { color: var(--waiting); }
.badge.sharing { color: var(--sharing); }
.badge.connected { color: var(--connected); }
.badge.ended { color: var(--ended); }

.chip { font-size: 0.8rem; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; }
.chip.on { color: var(--connected); border-color: var(--connected); }

.codebar { display: flex; align-items: baseline; gap: 10px; }
.code {
  font: 700 1.9rem/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.2em;
  user-select: all;
}
.code.dim { opacity: 0.4; text-decoration: line-through; }

.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 12px 0 4px; }
.settings label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
details summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }

.message { min-height: 1.5em; margin: 8px 0 0; }
.message.error { color: var(--danger); }

.notice {
  background: var(--notice-bg);
  color: var(--notice-text);
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 12px;
  font-size: 0.92rem;
}
.instruction {
  background: var(--primary);
  color: var(--primary-text);
  border-radius: 12px;
  padding: 12px 18px;
  margin-bottom: 16px;
  font-size: 1.15rem;
  font-weight: 600;
}
.instruction small { display: block; font-weight: 400; opacity: 0.85; font-size: 0.8rem; }

/* ---- barra de ferramentas ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.toolbar .group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--border); }

.mt { margin-top: 12px; }
.seg { position: relative; display: inline-flex; border: 1px solid var(--primary); border-radius: 8px; overflow: hidden; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: 0.92rem; color: var(--primary); }
.seg input:checked + label { background: var(--primary); color: var(--primary-text); }
.seg input:focus-visible + label { outline: 3px solid var(--primary); outline-offset: -3px; }

.tool.active { background: var(--primary); color: var(--primary-text); }
.swatches { display: inline-flex; gap: 6px; }
.swatch { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 3px solid transparent; }
.swatch[aria-pressed="true"] { border-color: var(--text); }
.swatch.red { background: #e53935; }
.swatch.yellow { background: #fdd835; }
.swatch.green { background: #43a047; }
.swatch.blue { background: #1e88e5; }

/* ---- área de trabalho: painéis de tela + chat ---- */
.workspace { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
.panels { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); align-items: start; }
.panel { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px; min-width: 0; }
.panel > header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; min-height: 30px; }

.stagebox {
  position: relative;
  background: var(--stage-bg);
  border-radius: 8px;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.stagebox.fill-width { align-items: flex-start; }
.stagebox.stale .stage { opacity: 0.45; }
.stagebox .placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 16px; color: #cbd5e1; }
.stage { position: relative; display: inline-block; line-height: 0; max-width: 100%; }
.stage .base { display: block; max-width: 100%; max-height: 72vh; width: auto; height: auto; }
.stage canvas.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.stage.draw canvas.overlay { pointer-events: auto; touch-action: none; cursor: crosshair; }
.stagebox.actual { overflow: auto; align-items: flex-start; justify-content: flex-start; max-height: 72vh; }
.stagebox.actual .stage .base { max-width: none; max-height: none; }
.stagebox:fullscreen { max-height: none; border-radius: 0; width: 100vw; height: 100vh; }
.stagebox:fullscreen .stage .base { max-height: 100vh; }

/* vídeo usado só para capturar a tela: fora da vista, sem aparecer em lugar nenhum */
.capture-only { position: fixed; right: 0; bottom: 0; width: 2px; height: 2px; opacity: 0.01; pointer-events: none; }

.guard { margin-top: 8px; }
.guard .notice { margin-top: 0; }
.guard button { margin-top: 8px; }

/* ---- chat ---- */
.chat { display: flex; flex-direction: column; height: min(72vh, 600px); margin: 0; padding: 12px; }
.chat h2 { margin-bottom: 8px; }
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.chat-empty { margin: auto; }
.msg { max-width: 88%; padding: 6px 10px; border-radius: 10px; word-break: break-word; overflow-wrap: anywhere; }
.msg .who { font-size: 0.7rem; opacity: 0.75; }
.msg.mine { align-self: flex-end; background: var(--primary); color: var(--primary-text); }
.msg.theirs { align-self: flex-start; background: var(--card); border: 1px solid var(--border); }
.msg.system { align-self: center; font-size: 0.8rem; color: var(--muted); }
.chat form { display: flex; gap: 8px; margin-top: 8px; }
.chat form input { flex: 1; min-width: 0; }

.code-input { width: 11ch; font: 700 1.6rem ui-monospace, Consolas, monospace; letter-spacing: 0.2em; text-align: center; }

.links { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }

@media (max-width: 1000px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .chat { height: 360px; }
}
@media (max-width: 480px) {
  .code { font-size: 1.5rem; }
  .toolbar .sep { display: none; }
}
