:root {
  /* Escuro de brasa — levantado do quase-preto para o carvão quente, com o
     laranja mais saturado. Escuro continua sendo o padrão, mas legível. */
  --fundo: #211e1b;
  --fundo-2: #2a2622;
  --fundo-3: #35302a;
  --linha: #4a443b;
  --texto: #f4efe6;
  --texto-fraco: #b8ac99;
  --brasa: #ef8f52;
  --brasa-forte: #ffab72;
  --brasa-texto: #221610;
  --verde: #93d07c;
  --vermelho: #ef8171;
  --codigo-fundo: #171512;
  --aviso-fundo: #3a2a1c;
  --aviso-texto: #f0d0ae;
  --sombra: rgba(0, 0, 0, .5);

  --raio: 10px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-tema="claro"] {
  /* Papel quente. Mesma família de cor, sem estridência. */
  --fundo: #faf6ef;
  --fundo-2: #f2ebdf;
  --fundo-3: #e9e0d1;
  --linha: #d6c9b6;
  --texto: #2c2621;
  --texto-fraco: #7b6f5f;
  --brasa: #c96a2c;
  --brasa-forte: #ab531c;
  --brasa-texto: #fff6ee;
  --verde: #4a8b3a;
  --vermelho: #c04a3c;
  --codigo-fundo: #ece4d6;
  --aviso-fundo: #fbecd8;
  --aviso-texto: #7a4a17;
  --sombra: rgba(80, 60, 40, .22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--fundo);
  color: var(--texto);
  font-family: var(--sans);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

.oculto { display: none !important; }
.fraco { color: var(--texto-fraco); }
.erro { color: var(--vermelho); min-height: 1.2em; margin: .4rem 0 0; font-size: .85rem; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--raio);
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, opacity .15s;
}
button:disabled { opacity: .45; cursor: not-allowed; }

.primario {
  background: var(--brasa);
  color: var(--brasa-texto);
  font-weight: 600;
  padding: .6rem 1.1rem;
}
.primario:hover:not(:disabled) { background: var(--brasa-forte); }
.largo { width: 100%; }

.fantasma {
  background: transparent;
  color: var(--texto-fraco);
  border-color: var(--linha);
  padding: .35rem .7rem;
  font-size: .82rem;
}
.fantasma:hover:not(:disabled) { color: var(--texto); border-color: var(--brasa); }

.mini {
  background: transparent;
  border: 1px solid var(--linha);
  color: var(--texto-fraco);
  width: 1.5rem; height: 1.5rem;
  line-height: 1; padding: 0;
  font-size: .95rem;
}
.mini:hover { color: var(--brasa); border-color: var(--brasa); }

input, textarea, select {
  font: inherit;
  width: 100%;
  background: var(--fundo);
  color: var(--texto);
  border: 1px solid var(--linha);
  border-radius: var(--raio);
  padding: .5rem .65rem;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brasa);
}
textarea { resize: vertical; }
label { display: block; font-size: .8rem; color: var(--texto-fraco); margin-bottom: .7rem; }
label input, label textarea, label select { margin-top: .25rem; color: var(--texto); }

/* --------------------------------------------------------------- login */

.tela-login {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 1.5rem;
}
.cartao-login {
  width: min(380px, 100%);
  background: var(--fundo-2);
  border: 1px solid var(--linha);
  border-radius: 16px;
  padding: 2rem;
}
.cartao-login h1, .lateral-topo h1 {
  font-family: var(--serif);
  font-weight: 400;
  margin: 0;
  letter-spacing: .01em;
}
.cartao-login h1 { font-size: 1.9rem; }
.cartao-login h1 span, .lateral-topo h1 span { color: var(--brasa); }
.cartao-login .sub { color: var(--texto-fraco); margin: .2rem 0 1.6rem; font-size: .9rem; }
.cartao-login button { width: 100%; margin-top: .4rem; }

/* ---------------------------------------------------------------- jogo */

.tela-jogo {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 290px;
  height: 100dvh;
}

.lateral {
  background: var(--fundo-2);
  border-right: 1px solid var(--linha);
  display: flex;
  flex-direction: column;
  padding: 1rem .8rem;
  gap: .8rem;
  min-height: 0;
}
.lateral-topo { display: flex; align-items: center; justify-content: space-between; }
.lateral-topo h1 { font-size: 1.15rem; }
.lateral-rodape { margin-top: auto; padding-top: .6rem; display: flex; gap: .4rem; }
.lateral-rodape button { flex: 1; }

.status {
  display: flex; align-items: center; gap: .5rem;
  font-size: .78rem; color: var(--texto-fraco);
  padding: .4rem .55rem;
  background: var(--fundo-3);
  border-radius: var(--raio);
}
.status .bolinha {
  width: .55rem; height: .55rem; border-radius: 50%;
  background: var(--texto-fraco); flex: none;
}
.status.ok .bolinha { background: var(--verde); }
.status.ruim .bolinha { background: var(--vermelho); }

.lista-cenas { overflow-y: auto; display: flex; flex-direction: column; gap: .3rem; min-height: 0; flex: 1; }
.item-cena {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--texto);
  padding: .5rem .6rem;
  width: 100%;
  display: block;
}
.item-cena:hover { background: var(--fundo-3); }
.item-cena.ativa { background: var(--fundo-3); border-color: var(--brasa); }
.item-cena strong { display: block; font-weight: 500; font-size: .9rem; }
.item-cena small { color: var(--texto-fraco); font-size: .72rem; }

.palco { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.palco-topo {
  display: flex; align-items: center; gap: .8rem;
  padding: .8rem 1.2rem;
  border-bottom: 1px solid var(--linha);
}
.palco-titulo { flex: 1; min-width: 0; }
.palco-titulo h2 {
  font-family: var(--serif); font-weight: 400; font-size: 1.15rem;
  margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.palco-titulo p { margin: .1rem 0 0; font-size: .75rem; color: var(--texto-fraco); }
.palco-acoes { display: flex; gap: .4rem; flex: none; }

.fluxo {
  flex: 1;
  overflow-y: auto;
  padding: 1.6rem clamp(1rem, 6vw, 3.5rem);
  display: flex; flex-direction: column; gap: 1.5rem;
  scroll-behavior: smooth;
}
.vazio { margin: auto; text-align: center; color: var(--texto-fraco); max-width: 34ch; }
.vazio p { margin: 0 0 .6rem; }
.vazio button { margin-top: .8rem; }

.turno { max-width: 62ch; width: 100%; }
.turno.narrador {
  font-family: var(--serif);
  font-size: 1.06rem;
  line-height: 1.72;
  white-space: pre-wrap;
  align-self: flex-start;
}
.turno.narrador p { margin: 0 0 1em; }
.turno.narrador p:last-child { margin-bottom: 0; }

.turno.jogador {
  align-self: flex-end;
  background: var(--fundo-3);
  border-left: 2px solid var(--brasa);
  border-radius: 0 var(--raio) var(--raio) 0;
  padding: .6rem .85rem;
  white-space: pre-wrap;
  font-size: .95rem;
  color: var(--texto);
}
.turno .direcao {
  display: block;
  font-size: .72rem;
  color: var(--brasa);
  margin-bottom: .35rem;
  font-style: italic;
}
.turno.pensando::after {
  content: "";
  display: inline-block;
  width: .5rem; height: 1.05rem;
  background: var(--brasa);
  vertical-align: text-bottom;
  animation: piscar 1s steps(2) infinite;
}
@keyframes piscar { 50% { opacity: 0; } }

.entrada {
  border-top: 1px solid var(--linha);
  padding: .8rem clamp(1rem, 6vw, 3.5rem) 1rem;
  background: var(--fundo-2);
}
.entrada details { margin-bottom: .5rem; }
.entrada summary {
  cursor: pointer; font-size: .74rem; color: var(--brasa);
  list-style: none; width: max-content;
}
.entrada summary::-webkit-details-marker { display: none; }
.entrada summary::before { content: "▸ "; }
.entrada details[open] summary::before { content: "▾ "; }
.entrada details input { margin-top: .4rem; font-size: .85rem; }
.linha-entrada { display: flex; gap: .6rem; align-items: flex-end; }
.linha-entrada textarea { flex: 1; max-height: 40vh; }
.linha-entrada button { flex: none; }

/* --------------------------------------------------------------- ficha */

.ficha {
  background: var(--fundo-2);
  border-left: 1px solid var(--linha);
  display: flex; flex-direction: column;
  min-height: 0;
}
.ficha-topo {
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 1rem; border-bottom: 1px solid var(--linha);
}
.ficha-topo h3 { margin: 0; font-size: .82rem; text-transform: uppercase; letter-spacing: .08em; color: var(--texto-fraco); font-weight: 600; }
.ficha-corpo { overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 1.3rem; }
.ficha-vazia { display: none; padding: 1.2rem 1rem; font-size: .82rem; line-height: 1.5; }
.ficha.sem-cena .ficha-corpo { display: none; }
.ficha.sem-cena .ficha-vazia { display: block; }
.ficha-corpo h4 {
  margin: 0 0 .5rem; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .07em; color: var(--texto-fraco);
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
.mini-ajuda { font-size: .72rem; margin: -.3rem 0 .4rem; }

.npcs { display: flex; flex-direction: column; gap: .5rem; }
.npc {
  background: var(--fundo-3);
  border: 1px solid var(--linha);
  border-radius: var(--raio);
  padding: .55rem .65rem;
  font-size: .82rem;
}
.npc-topo { display: flex; align-items: baseline; justify-content: space-between; gap: .4rem; }
.npc-nome { font-weight: 600; }
.npc-humor { color: var(--brasa); font-size: .75rem; font-style: italic; }
.npc-linha { color: var(--texto-fraco); font-size: .75rem; margin-top: .15rem; }
.barra { height: 3px; background: var(--linha); border-radius: 2px; margin-top: .45rem; overflow: hidden; }
.barra i { display: block; height: 100%; background: var(--brasa); }
.npc-acoes { display: flex; gap: .35rem; margin-top: .45rem; flex-wrap: wrap; }
.npc.fora { opacity: .5; }
.npc.editando { border-color: var(--brasa); }
.npc.editando label { margin: .5rem 0 0; font-size: .72rem; }
.npc.editando input[type="range"] { padding: 0; accent-color: var(--brasa); }
.npc.editando b { color: var(--brasa); }

.fatos { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.fatos li {
  font-size: .8rem; color: var(--texto-fraco);
  padding-left: .8rem; position: relative; line-height: 1.45;
}
.fatos li::before { content: "·"; position: absolute; left: 0; color: var(--brasa); }
.perigo { border-top: 1px solid var(--linha); padding-top: .9rem; }
.perigo button:hover { color: var(--vermelho); border-color: var(--vermelho); }

/* ------------------------------------------------------------ dialogos */

dialog {
  background: var(--fundo-2);
  color: var(--texto);
  border: 1px solid var(--linha);
  border-radius: 14px;
  padding: 1.5rem;
  width: min(600px, calc(100vw - 2rem));
  max-height: 88dvh;
}
dialog::backdrop { background: rgba(20, 14, 8, .62); }
dialog h3 { margin: 0 0 .3rem; font-family: var(--serif); font-weight: 400; font-size: 1.3rem; }
dialog h4 { margin: 1.1rem 0 .5rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--texto-fraco); display: flex; gap: .5rem; align-items: center; }
dialog > form { max-height: 78dvh; overflow-y: auto; }
dialog .fraco { font-size: .8rem; margin: 0 0 1.2rem; }
dialog menu { display: flex; justify-content: flex-end; gap: .6rem; margin: 1.2rem 0 0; padding: 0; }
.dupla { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }

.npcs-form { display: flex; flex-direction: column; gap: .6rem; }
.npc-form {
  border: 1px solid var(--linha);
  border-radius: var(--raio);
  padding: .7rem;
  background: var(--fundo-3);
}
.npc-form .dupla { gap: .6rem; }
.npc-form label { margin-bottom: .5rem; }
.npc-form .remover { float: right; }

/* -------------------------------------------------------------- mobile */

.so-mobile { display: none; }

@media (max-width: 1100px) {
  .tela-jogo { grid-template-columns: 220px minmax(0, 1fr); }
  .ficha {
    position: fixed; inset: 0 0 0 auto; width: min(320px, 88vw);
    z-index: 20; transform: translateX(100%); transition: transform .2s;
    box-shadow: -18px 0 40px var(--sombra);
  }
  .ficha.aberta { transform: none; }
  .so-mobile { display: inline-block; }
}

@media (max-width: 760px) {
  .tela-jogo { grid-template-columns: minmax(0, 1fr); }
  .lateral {
    position: fixed; inset: 0 auto 0 0; width: min(280px, 86vw);
    z-index: 21; transform: translateX(-100%); transition: transform .2s;
    box-shadow: 18px 0 40px var(--sombra);
  }
  .lateral.aberta { transform: none; }
  .fluxo { padding: 1.2rem 1rem; }
  .entrada { padding: .7rem 1rem 1rem; }
  .turno.jogador, .turno.narrador { max-width: 100%; }
  .dupla { grid-template-columns: 1fr; }
}
