/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg:       #0d0f14;
  --surface:  #1a1d24;
  --surface2: #22262f;
  --border:   #2e3340;
  --text:     #e2e6f0;
  --muted:    #7a8199;
  --accent:   #4f8ef7;
  --accent2:  #7c6af7;
  --danger:   #e05c5c;
  --success:  #4caf7d;
  --gold:     #c9a84c;
  --bg-tile:  none;
}

/* ── Light / Parchment theme ─────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:       #f5ede0;
  --surface:  #fdf6ec;
  --surface2: #ede2cf;
  --border:   #c8ad8a;
  --text:     #2e1f0e;
  --muted:    #7a6040;
  --accent:   #8b3a0f;
  --accent2:  #5c3d8f;
  --danger:   #b91c1c;
  --success:  #2d6a3f;
  --gold:     #9a6a00;
}

[data-theme="light"]::before,
[data-theme="dark"]::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: var(--bg-tile);
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0.4;
  pointer-events: none;
  z-index: -1;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ────────────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.5rem;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}

.nav-subtitle {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--muted);
}

.nav-links {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}

.nav-link {
  padding: 0.35rem 0.85rem;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover { color: var(--text); background: var(--surface2); text-decoration: none; }
.nav-link.active { color: var(--accent); background: rgba(79,142,247,0.12); }

.lang-btn {
  margin-left: auto;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  transition: color 0.15s, border-color 0.15s;
}
.lang-btn:hover { color: var(--text); border-color: var(--accent); }

/* ── Main layout ───────────────────────────────────────────────────────────── */
.main-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ── Dashboard ─────────────────────────────────────────────────────────────── */
.dashboard-hero {
  text-align: center;
  padding: 2.5rem 0 2rem;
}
.dashboard-hero h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.dashboard-hero p { color: var(--muted); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  transition: border-color 0.15s, transform 0.1s;
}
.stat-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  text-decoration: none;
}
.stat-number { font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-label  { font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem; }

.quick-links { margin-top: 2rem; }
.quick-links h2 { font-size: 1rem; color: var(--muted); margin-bottom: 1rem; }

.link-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.quick-btn {
  padding: 0.6rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color 0.15s;
}
.quick-btn:hover { border-color: var(--accent); text-decoration: none; }

/* ── Grimoire / Bestiary ───────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.tab {
  padding: 0.6rem 1.25rem;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s;
  text-decoration: none;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.filter-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.search-box {
  flex: 1;
  min-width: 200px;
  padding: 0.5rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
}
.search-box:focus { outline: none; border-color: var(--accent); }

.filter-select {
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.88rem;
}
.filter-select:focus { outline: none; border-color: var(--accent); }

/* ── Entry list ────────────────────────────────────────────────────────────── */
.entry-list { display: flex; flex-direction: column; gap: 0.4rem; }

.entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.15s;
}
.entry:hover { border-color: var(--accent); }

.entry-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  cursor: pointer;
  user-select: none;
}

.entry-name {
  font-weight: 600;
  flex: 1;
  font-size: 0.95rem;
}

.entry-level {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.entry-action {
  font-size: 0.85rem;
  color: var(--gold);
  min-width: 2rem;
  text-align: right;
}

.traits {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0 1rem 0.6rem;
}

.trait {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
}

/* Trait colour coding */
.trait-uncommon  { background: #3d2800; color: #f0a030; border-color: #7a5200; }
.trait-rare      { background: #001e3d; color: #5eb0ff; border-color: #004a8c; }
.trait-unique    { background: #2a0055; color: #c084fc; border-color: #6800cc; }

.entry-body {
  display: none;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
}
.entry.open .entry-body { display: block; }

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.88rem;
  color: var(--muted);
}
.stat-row span b { color: var(--text); }

.description {
  position: relative;
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
}

.description.has-fr { cursor: help; }

.fr-badge {
  position: absolute;
  top: 0;
  right: 0;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--accent2);
  opacity: 0.55;
  pointer-events: none;
  letter-spacing: 0.04em;
}

.fr-overlay {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background: #1a1a2e;
  border: 1px solid var(--accent2);
  border-radius: 4px;
  padding: 0.5rem 0.6rem;
  z-index: 10;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.description.has-fr:hover .fr-overlay { display: block; }

.source-tag {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.5rem;
  font-style: italic;
}

/* ── Creature specifics ────────────────────────────────────────────────────── */
.creature-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.creature-stat {
  background: var(--surface2);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  text-align: center;
}
.creature-stat-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.creature-stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.attacks-block {
  font-size: 0.85rem;
  margin: 0.5rem 0;
  font-family: monospace;
  color: var(--text);
  white-space: pre-wrap;
}

/* ── Conditions grid ───────────────────────────────────────────────────────── */
.conditions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}
.condition-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}
.condition-name {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.condition-value-badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 0.4rem;
  font-size: 0.7rem;
  color: var(--gold);
  font-weight: 600;
}
.condition-desc {
  font-size: 0.87rem;
  line-height: 1.65;
  color: var(--text);
}

/* ── Empty state ───────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.empty-state p { margin-top: 0.5rem; font-size: 0.9rem; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .main-content { padding: 1rem; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .navbar { gap: 0.75rem; padding: 0 1rem; }
  .nav-subtitle { display: none; }
}

/* ── Chat ───────────────────────────────────────────────────────────────────── */
#chat-app { height: calc(100vh - 56px); display: flex; flex-direction: column; }

.chat-login {
  display: flex; align-items: center; justify-content: center;
  height: 100%; flex: 1;
}
.chat-login-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 2rem; display: flex; flex-direction: column;
  gap: 0.75rem; min-width: 280px; text-align: center;
}
.chat-login-box h2 { color: var(--accent); margin-bottom: 0.5rem; }
.chat-login-box input {
  padding: 0.5rem 0.85rem; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 0.95rem;
}
.chat-login-box button {
  padding: 0.55rem; background: var(--accent); border: none;
  border-radius: 8px; color: #fff; font-weight: 600; cursor: pointer;
}

.chat-main { display: flex; flex: 1; height: 100%; overflow: hidden; }
.hidden { display: none !important; }

/* Sidebar */
.chat-sidebar {
  width: 200px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); overflow-y: auto;
  padding: 0.75rem 0;
}
.chat-sidebar-section { padding: 0 0.75rem 0.75rem; border-bottom: 1px solid var(--border); margin-bottom: 0.5rem; }
.chat-sidebar-label { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 0.4rem; }
.chat-side-btn {
  display: block; width: 100%; text-align: left; padding: 0.4rem 0.6rem;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: var(--text); font-size: 0.82rem; cursor: pointer; margin-bottom: 0.25rem;
}
.chat-side-btn:hover { background: var(--surface2); border-color: var(--border); }
.chat-side-btn.danger { color: var(--danger); }
.online-user { font-size: 0.82rem; padding: 0.2rem 0; color: var(--muted); }
.online-user.me { color: var(--accent); }
.upcoming-item { font-size: 0.78rem; padding: 0.2rem 0; color: var(--text); }
.upcoming-date { color: var(--accent); font-weight: 600; }

/* Chat area */
.chat-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.chat-room-name { font-weight: 700; color: var(--accent); }
.chat-status { font-size: 0.78rem; color: var(--muted); }

.chat-messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }

.chat-msg { max-width: 75%; display: flex; flex-direction: column; }
.chat-msg.me { align-self: flex-end; align-items: flex-end; }
.msg-meta { font-size: 0.72rem; color: var(--muted); margin-bottom: 0.2rem; }
.msg-bubble {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.5rem 0.85rem; font-size: 0.9rem; line-height: 1.5; word-break: break-word;
}
.chat-msg.me .msg-bubble { background: rgba(79,142,247,0.15); border-color: rgba(79,142,247,0.3); }
.chat-img { max-width: 240px; border-radius: 8px; cursor: pointer; }
.chat-system { text-align: center; font-size: 0.78rem; color: var(--muted); padding: 0.25rem 0; }

/* Input bar */
.chat-input-bar {
  display: flex; gap: 0.5rem; padding: 0.75rem 1rem;
  background: var(--surface); border-top: 1px solid var(--border);
}
.chat-input {
  flex: 1; padding: 0.5rem 0.85rem; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 0.92rem;
}
.chat-input:focus { outline: none; border-color: var(--accent); }
.chat-send-btn {
  padding: 0.5rem 1rem; background: var(--accent); border: none;
  border-radius: 8px; color: #fff; font-weight: 600; cursor: pointer;
}
.chat-attach-btn {
  padding: 0.5rem; background: transparent; border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; font-size: 1rem;
}

/* Polls */
.poll-card { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; min-width: 220px; }
.poll-question { font-weight: 600; margin-bottom: 0.5rem; font-size: 0.9rem; }
.poll-opt-btn {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; padding: 0.35rem 0.6rem; margin-bottom: 0.3rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); cursor: pointer; font-size: 0.85rem;
}
.poll-opt-btn.voted { border-color: var(--accent); background: rgba(79,142,247,0.1); }
.poll-opt-count { font-weight: 700; color: var(--accent); }

/* Modals */
.chat-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.chat-modal-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  width: min(520px, 95vw); max-height: 80vh; display: flex; flex-direction: column;
}
.chat-modal-box.wide { width: min(700px, 95vw); }
.chat-modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); font-weight: 700;
}
.chat-modal-header button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1.1rem; }
.chat-modal-body { padding: 1rem; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 0.75rem; }
.chat-field {
  width: 100%; padding: 0.45rem 0.75rem; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 0.9rem;
}
.chat-field:focus { outline: none; border-color: var(--accent); }
.chat-modal-body button {
  padding: 0.45rem 1rem; background: var(--accent); border: none;
  border-radius: 6px; color: #fff; cursor: pointer; font-size: 0.88rem;
}
.btn-secondary { background: var(--surface2) !important; color: var(--text) !important; border: 1px solid var(--border) !important; }
.btn-danger-sm { background: var(--danger) !important; font-size: 0.78rem !important; padding: 0.2rem 0.5rem !important; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* Notes */
.notes-form { display: flex; flex-direction: column; gap: 0.5rem; }
.note-card { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; }
.note-meta { font-size: 0.72rem; color: var(--muted); }
.note-title { font-weight: 600; margin: 0.2rem 0; }
.note-body { font-size: 0.85rem; color: var(--text); white-space: pre-wrap; }

/* References */
.ref-card { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.ref-name { font-size: 0.88rem; }
.ref-actions { display: flex; gap: 0.4rem; }
.ref-actions button { padding: 0.25rem 0.6rem; font-size: 0.78rem; }

/* Calendar */
.cal-form { display: flex; flex-direction: column; gap: 0.5rem; }
.event-card { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; margin-bottom: 0.5rem; }
.event-date { font-size: 0.78rem; color: var(--accent); font-weight: 600; }
.event-title { font-weight: 600; }
.event-desc { font-size: 0.85rem; color: var(--muted); }
.event-author { font-size: 0.72rem; color: var(--muted); margin-top: 0.3rem; }

/* Roll tables */
.roll-table { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 0.5rem; overflow: hidden; }
.roll-table-header { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0.85rem; background: var(--surface2); cursor: pointer; font-size: 0.9rem; font-weight: 600; }
.roll-table-header:hover { background: var(--surface); }
.roll-btn { padding: 0.2rem 0.6rem; background: var(--accent2); border: none; border-radius: 4px; color: #fff; cursor: pointer; font-size: 0.78rem; }
.roll-table-body { padding: 0.5rem 0.85rem; }
.rt-entry { font-size: 0.82rem; padding: 0.2rem 0; border-bottom: 1px solid var(--border); }
.rt-range { color: var(--accent); font-weight: 600; margin-right: 0.5rem; }
.roll-result { padding: 0.4rem 0.85rem; font-size: 0.85rem; color: var(--gold); font-weight: 600; }

/* ── Dark theme tile — dimmed via pseudo-element ────────────────────────────── */
[data-theme="light"] body::before,

/* ── Light theme: navbar and surfaces need readable contrast ─────────────── */
[data-theme="light"] .navbar {
  background: rgba(253, 246, 236, 0.95);
  border-bottom-color: var(--border);
  backdrop-filter: blur(4px);
}
[data-theme="light"] .entry,
[data-theme="light"] .stat-card,
[data-theme="light"] .condition-card,
[data-theme="light"] .chat-sidebar,
[data-theme="light"] .chat-header,
[data-theme="light"] .chat-input-bar,
[data-theme="light"] .chat-modal-box {
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
[data-theme="light"] .trait {
  background: #e8d8c0;
  border-color: var(--border);
  color: var(--muted);
}
[data-theme="light"] .fr-overlay {
  background: #f0e4d0;
  border-color: var(--accent2);
}
[data-theme="light"] .search-box,
[data-theme="light"] .filter-select,
[data-theme="light"] .chat-input,
[data-theme="light"] .chat-field {
  background: #fdf6ec;
  color: var(--text);
  border-color: var(--border);
}
