:root {
  --parede: #191613;
  --parede-2: #221d18;
  --madeira: #6b4526;
  --madeira-clara: #8a5c34;
  --madeira-escura: #3e2614;
  --lousa: #1f2622;
  --icone: #e8e2d4;
  --icone-fraco: rgba(232, 226, 212, .55);
  --aviso-fundo: rgba(20, 17, 14, .94);
  --painel: #241e19;
  --painel-2: #2e2620;
  --linha: #43382e;
  --texto: #efe7dc;
  --texto-fraco: #b3a595;
  --acento: #f4e27c;
  --acento-tinta: #1e1a15;
  --perigo: #e0676b;
  --ok: #8fd19a;
  --ui: system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 35%, var(--parede-2), var(--parede) 70%);
  color: var(--icone);
  font-family: system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#palco {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 10px 16px 16px;
  gap: 0;
}

/* Moldura de madeira em volta da lousa (tamanho definido pelo JS) */
#moldura {
  position: relative;
  padding: 14px;
  border-radius: 6px;
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,.08) 0 2px, transparent 2px 9px),
    linear-gradient(180deg, var(--madeira-clara), var(--madeira) 45%, var(--madeira-escura));
  box-shadow:
    0 18px 40px rgba(0,0,0,.55),
    inset 0 1px 0 rgba(255,255,255,.18),
    inset 0 -2px 0 rgba(0,0,0,.35);
  flex: none;
}

#lousa {
  position: relative;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(232, 226, 212, .25) transparent;
  background: var(--lousa);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.45), inset 0 0 30px rgba(0,0,0,.6);
  touch-action: none;
}

#mundo {
  position: absolute;
  left: 0;
  top: 0;
  width: 1920px;
  height: 1080px;
  transform-origin: 0 0;
}

#rolo { position: relative; width: 100%; overflow: hidden; }
#mundo canvas {
  position: absolute;
  left: 0;
  top: 0;
  width: 1920px;
  height: 100%;
}
/* No toque, o dedo rola a lousa (e a pinça amplia) quando a ferramenta não desenha nem arrasta */
#lousa.f-escrever, #lousa.f-leitura { touch-action: pan-y pinch-zoom; }

#textos {
  position: absolute;
  inset: 0;
}

/* Cursores por ferramenta */
#lousa.f-escrever { cursor: text; }
#lousa.f-desenhar { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28'%3E%3Cpath d='M4 24l3-8 13-13 5 5-13 13z' fill='%23f3f0e6' stroke='%23333' stroke-width='1'/%3E%3C/svg%3E") 3 25, crosshair; }
#lousa.f-apagar { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='20' cy='20' r='17' fill='none' stroke='%23f3f0e6' stroke-opacity='.7' stroke-dasharray='3 3'/%3E%3C/svg%3E") 20 20, cell; }
#lousa.f-mover { cursor: default; }
#lousa.f-mover .texto { cursor: move; user-select: none; }
#lousa:not(.f-escrever) .texto { pointer-events: auto; }

/* Texto escrito a giz */
.texto {
  position: absolute;
  white-space: pre;
  line-height: 1.15;
  min-height: 1.15em;
  min-width: .6em;
  padding: 2px 10px;
  outline: none;
  border-radius: 6px;
  caret-color: currentColor;
  filter: url(#giz);
  text-shadow: 0 0 3px color-mix(in srgb, currentColor 40%, transparent);
  transform-origin: center;
  font-kerning: normal;
  transition: opacity .35s ease, filter .35s ease;
}
.texto:focus {
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.10);
}
.texto.apagando {
  opacity: 0;
}

/* Calha do giz */
#calha {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: -2px;
  padding: 8px 14px 10px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(180deg, var(--madeira-escura), var(--madeira) 30%, var(--madeira-escura));
  box-shadow: 0 10px 22px rgba(0,0,0,.5), inset 0 2px 3px rgba(0,0,0,.45);
  flex: none;
}
#calha::-webkit-scrollbar { display: none; }

.grupo {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 10px;
  border-right: 1px solid rgba(0,0,0,.35);
  box-shadow: 1px 0 0 rgba(255,255,255,.06);
  flex: none;
}
.grupo:last-child { border-right: 0; box-shadow: none; padding-right: 0; }

#calha button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--icone-fraco);
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  flex: none;
}
#calha button:hover { color: var(--icone); background: rgba(255,255,255,.06); }
#calha button:focus-visible { outline: 2px solid rgba(255,255,255,.5); outline-offset: 1px; }
#calha button[aria-pressed="true"],
#calha button[aria-checked="true"] { color: var(--icone); background: rgba(0,0,0,.28); }
#calha button:disabled { opacity: .3; cursor: default; background: transparent; }

#calha svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#calha svg .feltro { fill: currentColor; stroke: none; opacity: .6; }
#calha svg .cheio { fill: currentColor; stroke: none; }

.aa {
  font-family: 'Caveat', cursive;
  font-weight: 500;
  font-size: 24px;
  line-height: 1;
}

/* Pedaços de giz */
#calha button.giz {
  width: 44px;
  height: 38px;
}
#calha button.giz span {
  display: block;
  width: 36px;
  height: 11px;
  border-radius: 3px 5px 5px 3px;
  background: var(--c);
  background-image: linear-gradient(180deg, rgba(255,255,255,.35), transparent 45%, rgba(0,0,0,.18));
  box-shadow: 0 2px 2px rgba(0,0,0,.45);
  transform: rotate(-4deg);
  transition: transform .15s ease;
}
#calha button.giz:nth-child(even) span { transform: rotate(3deg); width: 30px; }
#calha button.giz[aria-checked="true"] { background: transparent; }
#calha button.giz[aria-checked="true"] span {
  transform: translateY(-5px) rotate(-8deg);
  box-shadow: 0 6px 6px rgba(0,0,0,.45), 0 0 10px color-mix(in srgb, var(--c) 45%, transparent);
}

/* Partículas de poeira (tela inteira, por cima de tudo) */
#cv-vivo {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
}

#aviso {
  position: fixed;
  left: 50%;
  bottom: 104px;
  transform: translate(-50%, 8px);
  padding: 8px 16px;
  border-radius: 8px;
  background: var(--aviso-fundo);
  color: var(--icone);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  max-width: calc(100vw - 32px);
}
#aviso.visivel { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 600px) {
  #palco { padding: 16px 8px; }
  #moldura { padding: 8px; }
  #calha { gap: 6px 8px; padding: 6px 8px 8px; flex-wrap: wrap; justify-content: center; overflow: visible; }
  .grupo { padding-right: 6px; }
  #gizes { flex-basis: 100%; justify-content: center; border-right: 0; box-shadow: none; padding-right: 0; }
  #calha button { width: 34px; height: 34px; }
  #calha button.giz { width: 36px; }
  #calha button.giz span { width: 28px; }
}

/* ---------- barra superior ---------- */
#barra {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  padding-bottom: 10px;
  font: 14px var(--ui);
  flex: none;
}
#nome {
  font: 500 24px 'Caveat', 'Long Cang', cursive;
  color: var(--texto);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 8px;
  min-width: 0;
  width: min(320px, 60vw);
  height: 36px;
}
#nome:hover { border-color: var(--linha); }
#nome:focus { outline: none; border-color: var(--texto-fraco); background: rgba(0,0,0,.2); }
#nome:disabled { opacity: 1; border-color: transparent; }
.espaco { flex: 1 1 0; }
.btb, .btn {
  appearance: none;
  font: 500 13.5px var(--ui);
  color: var(--texto);
  background: var(--painel-2);
  border: 1px solid var(--linha);
  border-radius: 7px;
  padding: 7px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btb:hover, .btn:hover { background: #3a3028; }
.btb:focus-visible, .btn:focus-visible, .langs button:focus-visible { outline: 2px solid var(--acento); outline-offset: 2px; }
.btn.primario { background: var(--acento); color: var(--acento-tinta); border-color: var(--acento); }
.btn.primario:hover { background: #fbeb95; }
.btn.perigo { color: var(--perigo); border-color: color-mix(in srgb, var(--perigo) 45%, var(--linha)); }
.btn:disabled { opacity: .45; cursor: default; }
.status { display: inline-flex; align-items: center; gap: 6px; color: var(--texto-fraco); font-size: 13px; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--texto-fraco); }
.status[data-s="saved"] i { background: var(--ok); }
.status[data-s="saving"] i, .status[data-s="loading"] i { background: var(--acento); animation: pulso 1s ease-in-out infinite; }
.status[data-s="error"] i { background: var(--perigo); }
.status[data-s="readonly"] i { background: #9ed4f2; }
@keyframes pulso { 50% { opacity: .3; } }
#quem { color: var(--texto-fraco); font-size: 13px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.langs { display: inline-flex; gap: 2px; }
.langs button {
  appearance: none; border: 0; background: transparent; color: var(--texto-fraco);
  font: 600 12px var(--ui); padding: 5px 6px; border-radius: 5px; cursor: pointer;
}
.langs button.on { color: var(--acento-tinta); background: var(--acento); }
#faixa {
  width: 100%;
  margin: -4px 0 8px;
  padding: 6px 12px;
  border-radius: 7px;
  font: 13px var(--ui);
  color: var(--texto);
  background: rgba(158, 212, 242, .12);
  border: 1px solid rgba(158, 212, 242, .3);
  flex: none;
}

/* Somente leitura: esconde o que edita */
body.leitura .so-edicao { display: none !important; }
body.leitura #lousa { cursor: default; }
body.leitura #calha .grupo { border-right: 0; box-shadow: none; }
body.leitura #calha { justify-content: center; }

/* ---------- login ---------- */
body.bloqueado #palco { visibility: hidden; }
#login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 20;
  overflow-y: auto;
}
.login-cartao {
  width: min(480px, 100%);
  padding: 28px clamp(18px, 5vw, 36px) 22px;
  text-align: center;
  font: 15px/1.5 var(--ui);
  color: var(--texto);
  border-radius: 8px;
  border: 12px solid var(--madeira);
  background: radial-gradient(ellipse at 40% 30%, #2a322e, var(--lousa) 70%);
  box-shadow: 0 18px 40px rgba(0,0,0,.55), inset 0 0 30px rgba(0,0,0,.5);
}
.giz-titulo {
  font: 500 64px/1 'Caveat', 'Long Cang', cursive;
  color: var(--acento);
  margin: 0 0 10px;
  filter: url(#giz);
  transform: rotate(-2deg);
}
.login-cartao .sub { color: #d9d2c4; margin: 0 0 20px; }
.gbtn {
  appearance: none; display: inline-flex; align-items: center; gap: 10px;
  background: #fff; color: #1f1f1f; border: 0; border-radius: 6px;
  padding: 11px 18px; font: 500 15px var(--ui); cursor: pointer;
}
.gbtn svg { width: 20px; height: 20px; }
#login-msg { min-height: 1.5em; color: #f6b3b5; margin: 12px 0 4px; }
.login-cartao .langs { margin: 4px 0 10px; }
.legal { font-size: 12.5px; color: var(--texto-fraco); margin: 8px 0 6px; }
.legal a, .login-cartao .voltar { color: #cfe9f7; }
.login-cartao .voltar { font-size: 12.5px; }

/* ---------- diálogos ---------- */
dialog {
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--painel);
  color: var(--texto);
  border: 1px solid var(--linha);
  border-radius: 10px;
  padding: 20px 22px;
  font: 14px/1.5 var(--ui);
  box-shadow: 0 20px 50px rgba(0,0,0,.6);
}
dialog::backdrop { background: rgba(8, 6, 4, .6); }
dialog h3 { font: 500 30px/1.1 'Caveat', 'Long Cang', cursive; margin: 0 0 8px; color: var(--acento); }
dialog h4 { margin: 18px 0 6px; font-size: 14px; }
dialog section + section { border-top: 1px solid var(--linha); margin-top: 14px; }
.nota { color: var(--texto-fraco); font-size: 13px; margin: 4px 0 10px; }
.msg { min-height: 1.4em; font-size: 13px; color: var(--acento); margin: 6px 0; }
.linha { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.linha.inicio { justify-content: flex-start; align-items: flex-end; }
.linha.entre { justify-content: space-between; }
dialog input[type=text], dialog input[type=email], dialog input[type=search], dialog select {
  width: 100%;
  font: 14px var(--ui);
  color: var(--texto);
  background: var(--painel-2);
  border: 1px solid var(--linha);
  border-radius: 7px;
  padding: 8px 10px;
}
dialog input:focus, dialog select:focus { outline: 2px solid var(--acento); outline-offset: 0; }
.campo { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--texto-fraco); }
.campo.largo { flex: 1 1 220px; }
.lista, .pessoas { list-style: none; margin: 10px 0 0; padding: 0; }
.lista li { border: 1px solid var(--linha); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; background: var(--painel-2); }
.lista .topo { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.lista .nm { font-weight: 600; }
.lista .aberta { font-size: 11px; margin-left: 8px; padding: 1px 6px; border-radius: 4px; background: var(--acento); color: var(--acento-tinta); }
.lista .meta { color: var(--texto-fraco); font-size: 12.5px; }
.lista .confirmar { margin-top: 8px; font-size: 13px; }
.lista li.nota { border: 0; background: none; padding: 4px 0; }
.pessoas li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--linha); }
.pessoas li span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.pessoas select { width: auto; }
.pessoas button { background: none; border: 0; color: var(--perigo); cursor: pointer; font: 13px var(--ui); }
.confirmar-caixa { border: 1px solid color-mix(in srgb, var(--perigo) 50%, var(--linha)); border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.confirmar-caixa input { margin: 6px 0; }
.numeros { display: flex; flex-wrap: wrap; gap: 10px; }
.numeros div { background: var(--painel-2); border: 1px solid var(--linha); border-radius: 8px; padding: 8px 12px; }
.numeros b { display: block; font-size: 18px; }
.numeros span { color: var(--texto-fraco); font-size: 12px; }
.tabela { overflow-x: auto; margin-top: 12px; }
.tabela table { border-collapse: collapse; width: 100%; font-size: 13px; }
.tabela th, .tabela td { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--linha); vertical-align: top; }
.tabela th { color: var(--texto-fraco); font-weight: 600; font-size: 12px; }
.pilula { font-size: 11px; padding: 1px 6px; border-radius: 4px; border: 1px solid currentColor; }
.pilula.ok { color: var(--ok); }
.pilula.off { color: var(--perigo); }

/* aviso com botão opcional (Desfazer) */
#aviso { display: flex; align-items: center; gap: 12px; font-family: var(--ui); z-index: 30; }
#aviso button { appearance: none; border: 0; background: none; color: var(--acento); font: 600 14px var(--ui); cursor: pointer; padding: 0; }
#aviso.visivel { pointer-events: auto; }

@media (max-width: 600px) {
  #palco { padding: 8px 8px 12px; }
  #barra { gap: 6px; }
  #quem { display: none; }
  #nome { width: 100%; }
  .btb { padding: 6px 9px; font-size: 13px; }
}
:lang(zh) body, :lang(zh) .btb, :lang(zh) .btn, :lang(zh) dialog { font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", var(--ui); }

/* ---------- segundo cérebro ---------- */
.texto .lig { text-decoration: underline; text-decoration-style: wavy; text-decoration-thickness: 1px; text-underline-offset: 6px; cursor: pointer; }
.texto .tema { opacity: .9; cursor: pointer; font-style: italic; }
.texto:focus .lig, .texto:focus .tema { cursor: text; }
#mencoes { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 16px; font-size: 13px; color: var(--texto-fraco, #9aa6a0); border-bottom: 1px solid rgba(255,255,255,.08); flex: none; }
#mencoes button { appearance: none; border: 1px solid rgba(243,240,230,.25); background: rgba(243,240,230,.06); color: #f3f0e6; border-radius: 999px; padding: 2px 10px; font: 500 13px system-ui, sans-serif; cursor: pointer; }
#mencoes button:hover { border-color: #f4e27c; }
#constelacao { position: fixed; inset: 0; z-index: 40; background: #161b18; display: flex; flex-direction: column; }
#constelacao .cst-topo { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 10px 16px; color: #f3f0e6; border-bottom: 1px solid rgba(243,240,230,.12); font: 15px system-ui, sans-serif; }
#constelacao .cst-topo b { font: 500 26px 'Caveat', cursive; letter-spacing: .02em; }
#cst-busca { flex: 1 1 200px; max-width: 320px; background: rgba(243,240,230,.08); border: 1px solid rgba(243,240,230,.2); color: #f3f0e6; border-radius: 8px; padding: 6px 10px; font: 14px system-ui, sans-serif; }
.cst-legenda { display: flex; gap: 12px; align-items: center; font-size: 13px; color: #c9cfc9; margin-left: auto; }
.cst-legenda i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; border: 2px solid; }
.cst-legenda .l { border-color: #f3f0e6; } .cst-legenda .t { border-color: #f4e27c; background: rgba(244,226,124,.35); } .cst-legenda .f { border-color: #f5a9c6; border-style: dashed; }
#cst-canvas { flex: 1 1 auto; width: 100%; min-height: 0; display: block; cursor: grab; touch-action: none; }
#cst-msg { margin: 0; padding: 8px 16px 12px; color: #c9cfc9; font: 16px 'Caveat', cursive; text-align: center; }
@media (max-width: 760px) { .cst-legenda { display: none; } }
