:root {
  --bg: #1b1520;
  --panel: #261d2c;
  --line: #3b2e44;
  --text: #f3e9dc;
  --muted: #a99bb0;
  --accent: #e9a35b;
  --ok: #7bc47f;
  --warn: #e57373;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
#app { display: flex; flex-direction: column; height: 100%; }

header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { font-weight: 700; color: var(--accent); }
.status { margin-left: auto; font-size: 12px; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }

main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 12px 16px; min-height: 0; }
/* O palco tem sempre a proporção do canvas, para o chat ficar colado no canto da cena. */
.stage { position: relative; width: min(100%, calc((100vh - 70px) * 16 / 9)); aspect-ratio: 16 / 9; }
canvas {
  display: block; width: 100%; height: 100%;
  border: 2px solid var(--line); border-radius: 6px; background: #000; cursor: pointer;
}
.hint {
  position: absolute; bottom: 10px; right: 12px; font-size: 11px; color: var(--text);
  background: rgba(27, 21, 32, .6); padding: 3px 8px; border-radius: 4px; pointer-events: none;
}

/* Chat pequeno flutuando no canto inferior esquerdo da cena */
.chat {
  position: absolute; left: 10px; bottom: 10px; width: min(300px, calc(100% - 20px)); height: min(240px, 60%);
  display: flex; flex-direction: column;
  background: rgba(27, 21, 32, .82); border: 1px solid var(--line); border-radius: 6px; backdrop-filter: blur(3px);
}
.chat.min { height: auto; }
.chat.min #log, .chat.min #chat-form { display: none; }
.chat-head { padding: 5px 8px; border-bottom: 1px solid var(--line); font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.chat-toggle { font: inherit; color: var(--muted); background: none; border: 0; cursor: pointer; padding: 0 4px; font-size: 14px; line-height: 1; }
#log { list-style: none; margin: 0; padding: 6px 8px; flex: 1; overflow-y: auto; font-size: 12px; line-height: 1.4; }
#log li { margin-bottom: 6px; overflow-wrap: anywhere; }
#log .who { font-weight: 700; }
#log .store { color: var(--muted); font-size: 11px; }
#log .sys { color: var(--muted); font-style: italic; font-size: 12px; }
#chat-form { display: flex; gap: 4px; padding: 6px; border-top: 1px solid var(--line); }
#chat-form input { flex: 1; min-width: 0; padding: 5px 7px; font-size: 12px; }
#chat-form .btn { padding: 5px 8px; font-size: 12px; }

input, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 4px; padding: 8px; width: 100%;
}
.btn { font: inherit; color: var(--text); background: var(--line); border: 0; border-radius: 4px; padding: 8px 12px; cursor: pointer; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn.primary { background: var(--accent); color: #2a1a10; font-weight: 700; width: 100%; margin-top: 8px; }

.modal { position: fixed; inset: 0; background: rgba(10, 6, 14, .82); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.card { width: 100%; max-width: 380px; background: var(--panel); border: 2px solid var(--line); border-radius: 8px; padding: 20px; }
.card h1 { margin: 0 0 6px; color: var(--accent); font-size: 22px; }
.card label { display: block; margin: 12px 0 4px; font-size: 12px; color: var(--muted); }
.card label > input, .card label > select, .card label > div { margin-top: 4px; }
.muted { color: var(--muted); font-size: 13px; }
.dev { border: 1px dashed var(--accent); border-radius: 4px; padding: 0 10px 10px; margin: 10px 0; }
.colors { display: flex; gap: 6px; }
.colors button { width: 28px; height: 28px; border-radius: 4px; border: 2px solid transparent; cursor: pointer; }
.colors button.sel { border-color: var(--text); }
.card { max-height: calc(100dvh - 32px); overflow-y: auto; }
.tabs { display: flex; gap: 4px; margin-top: 12px; }
.tabs button { flex: 1; font: inherit; color: var(--muted); background: none; border: 0; border-bottom: 2px solid var(--line); padding: 6px; cursor: pointer; }
.tabs button.sel { color: var(--accent); border-color: var(--accent); }
.error { color: var(--warn); font-size: 12px; margin: 8px 0 0; }
.private-note { font-size: 12px; color: var(--muted); background: var(--bg); border-radius: 4px; padding: 8px; line-height: 1.5; }
.private-note b { color: var(--ok); }
textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 8px; width: 100%; resize: vertical; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chips button { font: inherit; font-size: 11px; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px 9px; cursor: pointer; }
.chips button.sel { color: #2a1a10; background: var(--accent); border-color: var(--accent); }
.card label.check { display: flex; gap: 8px; align-items: flex-start; color: var(--text); line-height: 1.4; }
.card label.check input { width: auto; margin-top: 2px; }
.btn.link { background: none; padding: 0; color: var(--accent); text-decoration: underline; font-size: 12px; }
#pf-skip { display: block; margin: 10px auto 0; }
.hello { font-size: 13px; margin: 12px 0 0; }
#log .private { border-left: 2px solid var(--ok); padding-left: 6px; }
#log .npc .who::after { content: " AI"; font-size: 9px; color: #2a1a10; background: var(--ok); border-radius: 3px; padding: 0 3px; margin-left: 4px; vertical-align: middle; }
.looks { display: flex; gap: 6px; }
.looks button { flex: 1; font: inherit; color: var(--text); background: var(--bg); border: 2px solid var(--line); border-radius: 4px; padding: 6px; cursor: pointer; }
.looks button.sel { border-color: var(--accent); color: var(--accent); }
#watch select { margin: 8px 0; }

@media (max-width: 760px) {
  #app { height: 100dvh; }
  main { flex-direction: column; justify-content: flex-start; align-items: stretch; padding: 8px; }
  .stage { width: 100%; flex: 1; min-height: 0; aspect-ratio: auto; display: flex; flex-direction: column; }
  canvas { flex: none; height: auto; aspect-ratio: 16 / 9; }
  /* no celular a cena é baixa demais: o chat vai para baixo dela e ocupa o resto da tela */
  .chat { position: static; width: 100%; height: auto; flex: 1; min-height: 0; margin-top: 8px; }
  .chat.min { flex: none; }
  .hint { display: none; }
}
