/* ===== Curse of Strahd — paleta =====
   fundo:      #100b10 (preto-arroxeado, noite de Baróvia)
   painel:     #1b1219
   sangue:     #7a1621 / claro #b3313f
   âmbar vela: #d4a154
   pergaminho: #e8dcc8
   névoa:      #8a8090
   sussurro:   #7d6ba0
*/

:root {
  --bg: #100b10;
  --panel: #1b1219;
  --panel-2: #241722;
  --blood: #7a1621;
  --blood-bright: #b3313f;
  --amber: #d4a154;
  --parchment: #e8dcc8;
  --mist: #8a8090;
  --whisper: #7d6ba0;
  --border: #3a2531;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 50% -10%, #2a1020 0%, transparent 55%),
    linear-gradient(180deg, #150d15 0%, var(--bg) 40%);
  color: var(--parchment);
  font-family: 'Crimson Pro', Georgia, serif;
  font-size: 17px;
  line-height: 1.45;
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
  z-index: 2;
}

/* ===== cabeçalho ===== */
.masthead {
  text-align: center;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(122, 22, 33, 0.12), transparent);
}

.masthead .logo {
  display: block;
  margin: 0 auto;
  max-width: min(420px, 80%);
  height: auto;
  filter: drop-shadow(0 0 18px rgba(179, 49, 63, 0.35));
}

.status {
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--mist);
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.status .candle { filter: grayscale(1); transition: filter 0.5s; }
.status.on .candle { filter: none; text-shadow: 0 0 10px var(--amber); }
.status.on #status-text { color: var(--amber); }

/* ===== chat ===== */
main#chat {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 80px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--blood);
  border-radius: 6px;
  padding: 10px 14px;
  animation: rise 0.35s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.msg .meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.msg .avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--blood);
  box-shadow: 0 0 8px rgba(122, 22, 33, 0.5);
  background: #000;
}

.msg .avatar.placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cinzel', serif;
  color: var(--amber);
  font-size: 0.9rem;
}

.msg .author {
  font-family: 'Cinzel', serif;
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--amber);
  letter-spacing: 0.04em;
}

.msg .time {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--mist);
  opacity: 0.7;
}

.msg .body { overflow-wrap: break-word; }
.msg .body img { max-width: 100%; }

/* mensagens seguidas do mesmo autor: compacta */
.msg.follow { border-left-color: var(--border); }
.msg.follow .meta { display: none; }

/* ===== emote ===== */
.msg.emote {
  background: transparent;
  border: none;
  text-align: center;
  font-family: 'IM Fell English', serif;
  font-style: italic;
  color: var(--amber);
}

/* ===== whisper ===== */
.msg.whisper {
  border-left-color: var(--whisper);
  background: linear-gradient(180deg, rgba(125, 107, 160, 0.08), transparent);
}
.msg.whisper .author { color: var(--whisper); }
.msg.whisper .body { font-style: italic; color: #c9bfdd; }
.msg.whisper .body::before { content: '🤫 '; font-style: normal; opacity: 0.7; }

/* ===== narração do mestre (desc) ===== */
.msg.desc {
  background: var(--panel-2);
  border: 1px solid var(--blood);
  border-left-width: 3px;
  font-family: 'IM Fell English', serif;
  font-size: 1.05rem;
  color: #efe4cf;
  text-align: center;
  padding: 16px 20px;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.5);
}

/* ===== rolagens ===== */
.msg.roll, .msg.template { border-left-color: var(--amber); }

.body .inlinerollresult {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 4px;
  background: #2c2030;
  border: 1px solid var(--amber);
  color: var(--amber);
  font-weight: 600;
  font-family: 'Cinzel', serif;
  cursor: help;
}

.body .inlinerollresult.fullcrit {
  border-color: #f0c75e;
  color: #ffd97a;
  background: rgba(240, 199, 94, 0.12);
  text-shadow: 0 0 8px rgba(255, 217, 122, 0.6);
}

.body .inlinerollresult.fullfail {
  border-color: #5c1a20;
  color: #a05055;
  background: #241114;
}

/* ===== card de rolagem (renderer custom) ===== */
.roll-card {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 4px 0;
}

.roll-formula {
  font-family: monospace;
  font-size: 0.85rem;
  color: var(--mist);
  white-space: nowrap;
}

.roll-dice {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.die {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 50px;
  padding: 6px 10px 4px;
  background: linear-gradient(160deg, #2c2030, #1d1420);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 2px 4px rgba(0, 0, 0, 0.4);
}

.die .die-val {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1.38rem;
  color: var(--parchment);
  line-height: 1.1;
}

.die .die-type {
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  color: var(--mist);
  text-transform: uppercase;
}

/* dado descartado (kh/kl — vantagem/desvantagem): esmaecido e riscado */
.die.dropped {
  opacity: 0.4;
  filter: grayscale(0.6);
}
.die.dropped .die-val {
  text-decoration: line-through;
  text-decoration-color: var(--blood-bright);
}
/* descartado nunca "brilha" como crit/falha */
.die.dropped.crit { box-shadow: none; border-color: var(--border); }
.die.dropped.crit .die-val { color: var(--parchment); text-shadow: none; }

/* máximo do dado (crítico): dourado */
.die.crit {
  border-color: #f0c75e;
  box-shadow: 0 0 12px rgba(240, 199, 94, 0.5), inset 0 0 8px rgba(240, 199, 94, 0.2);
}
.die.crit .die-val {
  color: #ffd97a;
  text-shadow: 0 0 8px rgba(255, 217, 122, 0.7);
}

/* mínimo do dado (falha crítica): vermelho opaco */
.die.fail {
  border-color: #5c1a20;
  background: linear-gradient(160deg, #33191d, #241114);
}
.die.fail .die-val { color: #a05055; }

/* ===== efeitos ao vivo ===== */

/* pulso dourado: dado no máximo "acende" como vela */
@keyframes glow-pulse {
  0% { box-shadow: 0 0 0 rgba(240, 199, 94, 0); }
  35% { box-shadow: 0 0 30px rgba(240, 199, 94, 0.95), inset 0 0 14px rgba(240, 199, 94, 0.45); }
  100% { box-shadow: 0 0 12px rgba(240, 199, 94, 0.5), inset 0 0 8px rgba(240, 199, 94, 0.2); }
}
.die.crit.pulse { animation: glow-pulse 1.1s ease-out; }

/* brasas subindo (nat 20) */
.ember {
  position: absolute;
  bottom: 15%;
  left: var(--x);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffe9b0, #f0c75e 55%, transparent 75%);
  pointer-events: none;
  opacity: 0;
  animation: ember-rise var(--dur) ease-out var(--delay) forwards;
}
@keyframes ember-rise {
  0% { opacity: 0; transform: translate(0, 0) scale(1); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), -75px) scale(0.35); }
}

/* carimbo CRÍTICO! (nat 20) */
.crit-stamp {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1.6rem;
  letter-spacing: 0.18em;
  color: #ffd97a;
  text-shadow: 0 0 18px rgba(255, 217, 122, 0.8), 0 2px 3px #000;
  border: 2px solid rgba(240, 199, 94, 0.8);
  border-radius: 5px;
  padding: 3px 18px;
  background: rgba(16, 11, 16, 0.55);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) rotate(-7deg) scale(3);
  animation:
    stamp-in 0.45s cubic-bezier(0.2, 1.5, 0.4, 1) 0.15s forwards,
    stamp-out 1.4s ease 2.4s forwards;
}
@keyframes stamp-in {
  to { opacity: 1; transform: translate(-50%, -50%) rotate(-7deg) scale(1); }
}
@keyframes stamp-out {
  to { opacity: 0; }
}

/* névoa vermelha + vela apagada (nat 1 no d20) */
.mist-overlay {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  overflow: hidden;
  pointer-events: none;
}
.mist-overlay::before {
  content: '';
  position: absolute;
  inset: -60% -30%;
  background:
    radial-gradient(ellipse at 30% 60%, rgba(122, 22, 33, 0.4), transparent 55%),
    radial-gradient(ellipse at 70% 40%, rgba(58, 20, 30, 0.5), transparent 60%);
  filter: blur(6px);
  animation: mist-drift 3s ease-in-out forwards;
}
@keyframes mist-drift {
  0% { transform: translateX(-35%); opacity: 0; }
  25% { opacity: 1; }
  100% { transform: translateX(35%); opacity: 0; }
}
.die.fail.snuff { animation: snuff 1.4s ease-out; }
@keyframes snuff {
  0% { filter: brightness(2); }
  100% { filter: brightness(1); }
}

.roll-total {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 4px;
  white-space: nowrap;
}
.roll-total .roll-eq { color: var(--mist); font-size: 1rem; }
.roll-total .roll-num {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1.7rem;
  color: var(--amber);
  text-shadow: 0 0 14px rgba(212, 161, 84, 0.45);
}

/* fallback: rolagem que o parser não entendeu (HTML cru do Roll20) */
.body .formula {
  display: block;
  font-size: 0.8rem;
  color: var(--mist);
  font-family: monospace;
}
.body .formula.formattedformula .dicegrouping { display: inline; }
.body .diceroll { display: inline-block; }
.body .diceroll .backing { display: none; }
.body .diceroll .didroll {
  display: inline-block;
  color: var(--parchment);
  font-weight: 600;
  padding: 0 4px;
}
.body .rolled {
  display: inline-block;
  font-family: 'Cinzel', serif;
  font-size: 1.5rem;
  color: var(--amber);
  text-shadow: 0 0 12px rgba(212, 161, 84, 0.4);
}

/* ===== roll templates de ficha (tabelas do Roll20) ===== */
.body .sheet-rolltemplate table,
.body table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--parchment);
}
.body td, .body th {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}
.body .sheet-rolltemplate .sheet-rt-title,
.body caption {
  font-family: 'Cinzel', serif;
  color: var(--amber);
  background: rgba(122, 22, 33, 0.25);
  padding: 4px;
}
.body a { color: var(--blood-bright); }

/* ===== botão limpar ===== */
#clear-btn {
  position: fixed;
  top: 78px;
  right: 16px;
  z-index: 3;
  background: transparent;
  color: var(--mist);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-family: 'Cinzel', serif;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
#clear-btn:hover {
  color: var(--parchment);
  border-color: var(--blood-bright);
  background: rgba(122, 22, 33, 0.25);
}

/* ===== botão de scroll ===== */
#scroll-down {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  background: var(--blood);
  color: var(--parchment);
  border: 1px solid var(--blood-bright);
  border-radius: 20px;
  padding: 8px 18px;
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}
#scroll-down:hover { background: var(--blood-bright); }

/* barra de rolagem temática */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--blood); border-radius: 5px; }
