:root {
  --bg: #0d0f14;
  --panel: #161923;
  --panel-2: #1e2230;
  --border: #2b3042;
  --text: #dfe3ee;
  --muted: #7d8698;
  --accent: #c9a24b;
  --accent-dim: #9a7b36;
  --good: #4aa96c;
  --bad: #b4553f;
  --player: #3a5d8c;
  --narrator: #2c3444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: radial-gradient(1200px 600px at 50% -100px, #1a2030, var(--bg));
  color: var(--text);
  font-family: Georgia, 'Times New Roman', serif;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 15, 20, 0.8);
}

.brand {
  font-size: 20px;
  font-weight: bold;
  letter-spacing: 2px;
  color: var(--accent);
}

.campaign-badge {
  color: var(--muted);
  font-size: 13px;
  flex: 1;
}

nav {
  display: flex;
  gap: 8px;
}

button {
  font-family: inherit;
  background: var(--accent);
  color: #14100a;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: bold;
}

button:hover:not(:disabled) { filter: brightness(1.1); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

#chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 10px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.narrator {
  background: var(--narrator);
  align-self: flex-start;
  border: 1px solid var(--border);
}

.msg.player {
  background: var(--player);
  align-self: flex-end;
}

.msg.system {
  align-self: center;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  background: transparent;
}

.diary-btn {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  padding: 4px 10px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
}

/* Indicador de IA: 3 pontos pulsantes */
.msg.typing { min-height: 24px; }

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: dot-pulse 1.2s infinite ease-in-out;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* Sidebar / Memória */
.sidebar {
  width: 320px;
  border-left: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
}

.sidebar.hidden { display: none; }

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 4px;
  font-size: 13px;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
}

.tab-body h4 {
  margin: 8px 0 2px;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.hp-bar {
  height: 10px;
  border-radius: 5px;
  background: var(--panel-2);
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  background: linear-gradient(90deg, #7a3b2b, var(--bad));
}

.muted { color: var(--muted); font-size: 12px; }

.item-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.item-acts { display: flex; flex-direction: column; gap: 4px; }

.clue {
  border-left: 3px solid var(--accent-dim);
  padding: 6px 8px;
  background: var(--panel-2);
  border-radius: 0 6px 6px 0;
  font-size: 13px;
}

.diary-form {
  display: flex;
  gap: 6px;
}

.diary-form input {
  flex: 1;
  font-family: inherit;
}

/* Formulário de chat */
#form {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: rgba(13, 15, 20, 0.9);
}

#input {
  flex: 1;
  font-family: inherit;
  font-size: 15px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
}

#input:focus { outline: none; border-color: var(--accent-dim); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal.hidden { display: none; }

.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: 400px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-card h3 { margin-top: 0; color: var(--accent); }

.modal-card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

.modal-card select,
.modal-card input,
.modal-card textarea {
  font-family: inherit;
  font-size: 14px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}

.modal-card textarea { resize: vertical; }

.setup-card { width: 460px; }

.setup-row {
  display: flex;
  gap: 10px;
}

.setup-row label { flex: 1; }

.preview {
  border: 1px dashed var(--accent-dim);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

/* Rolagem */
.roll-card { width: 360px; text-align: center; }

.roll-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  color: var(--muted);
  text-align: left;
  margin-bottom: 14px;
}

.die-area { margin: 14px 0; }

.d20 {
  width: 90px;
  height: 90px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  color: var(--accent);
  border: 3px solid var(--accent);
  border-radius: 18px;
  transform: rotate(12deg) skewX(-6deg);
}

.roll-result {
  white-space: pre-line;
  padding: 10px;
  border-radius: 8px;
  font-weight: bold;
  margin-bottom: 8px;
}

.roll-result.success { background: rgba(74, 169, 108, 0.18); color: var(--good); }
.roll-result.fail { background: rgba(180, 85, 63, 0.18); color: var(--bad); }

@media (max-width: 760px) {
  .sidebar { position: fixed; right: 0; top: 0; bottom: 0; z-index: 40; }
  .msg { max-width: 90%; }
}