:root {
  --bg-deep: #0f0e17;
  --bg-base: #1a1a2e;
  --bg-panel: #16213e;
  --bg-elevated: #1e2a4a;
  --bg-hover: #243154;
  --bg-active: #2a3a63;
  --accent: #c9a84c;
  --accent-dim: #8a6f2e;
  --accent-glow: rgba(201, 168, 76, 0.15);
  --text-primary: #e8e0d0;
  --text-secondary: #9a8f7e;
  --text-muted: #5a5248;
  --border: #2a3154;
  --border-light: #3a4170;
  --danger: #c0392b;
  --danger-dim: #7a2820;
  --success: #27ae60;
  --mechanic-bg: rgba(100, 60, 180, 0.3);
  --mechanic-border: #8060cc;
  --mechanic-text: #c0a0ff;
  --panel-header: 36px;
  --scrollbar-size: 6px;
  --radius: 6px;
  --radius-sm: 3px;
  --font-main: 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'Cascadia Code', 'Consolas', monospace;
  --font-serif: 'Georgia', 'Times New Roman', serif;
}

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

html, body, #root {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: var(--scrollbar-size); height: var(--scrollbar-size); }
::-webkit-scrollbar-track { background: var(--bg-deep); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-elevated);
  color: var(--text-primary); font-size: 13px; cursor: pointer;
  transition: all 0.15s ease; white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-light); }
.btn:active { background: var(--bg-active); }
.btn.btn-accent {
  background: var(--accent-dim); border-color: var(--accent);
  color: var(--bg-deep); font-weight: 600;
}
.btn.btn-accent:hover { background: var(--accent); }
.btn.btn-ghost { background: transparent; border-color: transparent; }
.btn.btn-ghost:hover { background: var(--bg-hover); border-color: var(--border); }
.btn.btn-danger { border-color: var(--danger-dim); }
.btn.btn-danger:hover { background: var(--danger-dim); border-color: var(--danger); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.btn-icon { padding: 5px 8px; }
.btn.btn-sm { padding: 3px 8px; font-size: 12px; }

/* Standalone variants used throughout components */
.btn-sm {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-elevated);
  color: var(--text-primary); font-size: 12px; cursor: pointer;
  transition: all 0.15s ease; white-space: nowrap;
}
.btn-sm:hover { border-color: var(--border-light); background: var(--bg-hover); }
.btn-sm:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm.btn-danger { color: var(--danger); border-color: var(--danger-dim); }
.btn-sm.btn-danger:hover { background: var(--danger-dim); }

/* Inputs */
input, textarea, select {
  background: var(--bg-deep); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: var(--radius-sm);
  padding: 6px 10px; font-size: 13px; font-family: var(--font-main);
  outline: none; transition: border-color 0.15s;
  width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent-dim); }
input::placeholder, textarea::placeholder { color: var(--text-muted); }
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--bg-panel); }

/* Form groups */
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-group label { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }
.form-row { display: flex; gap: 8px; }
.form-row .form-group { flex: 1; margin-bottom: 0; }

/* Panel shells (used by dock layout) */
.panel-shell {
  display: flex; flex-direction: column;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  height: 100%;
}
.panel-header {
  display: flex; align-items: center; gap: 8px;
  height: var(--panel-header); min-height: var(--panel-header);
  padding: 0 10px; background: var(--bg-elevated);
  border-bottom: 1px solid var(--border); user-select: none;
}
.panel-title {
  flex: 1; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-secondary);
}
.panel-body {
  flex: 1; overflow: hidden; position: relative;
}
.panel-body.scrollable {
  overflow-y: auto;
}

/* Tabs */
.tab-bar {
  display: flex; border-bottom: 1px solid var(--border);
  background: var(--bg-deep); overflow-x: auto;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-item {
  padding: 8px 14px; font-size: 12px; cursor: pointer;
  white-space: nowrap; border-bottom: 2px solid transparent;
  color: var(--text-secondary); transition: all 0.15s;
}
.tab-item:hover { color: var(--text-primary); background: var(--bg-hover); }
.tab-item.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Modals */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg-panel); border: 1px solid var(--border-light);
  border-radius: var(--radius); padding: 24px;
  min-width: 360px; max-width: 90vw; max-height: 85vh;
  overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-title {
  font-size: 16px; font-weight: 600; color: var(--accent);
  margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* Context menu */
.context-menu {
  position: fixed; background: var(--bg-elevated);
  border: 1px solid var(--border-light); border-radius: var(--radius);
  padding: 4px 0; min-width: 160px; z-index: 2000;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.context-item {
  padding: 7px 14px; font-size: 13px; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
.context-item:hover { background: var(--bg-hover); }
.context-item.danger { color: var(--danger); }
.context-separator { height: 1px; background: var(--border); margin: 4px 0; }

/* Chip/badge */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 12px; font-size: 11px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text-secondary);
}
.chip.accent { background: var(--accent-glow); border-color: var(--accent-dim); color: var(--accent); }

/* Drag handle */
.drag-handle { cursor: grab; opacity: 0.5; }
.drag-handle:hover { opacity: 1; }
.drag-handle:active { cursor: grabbing; }

/* Divider */
.divider { height: 1px; background: var(--border); margin: 12px 0; }

/* Toast notification */
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 3000;
}
.toast {
  padding: 10px 16px; border-radius: var(--radius);
  background: var(--bg-elevated); border: 1px solid var(--border-light);
  font-size: 13px; animation: slideIn 0.2s ease;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Inline mechanic nodes (in editor) */
.mechanic-inline {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--mechanic-bg); border: 1px solid var(--mechanic-border);
  color: var(--mechanic-text); border-radius: var(--radius-sm);
  padding: 1px 6px; font-size: 12px; cursor: pointer;
  user-select: none; white-space: nowrap;
  vertical-align: middle;
}
.mechanic-inline:hover { background: rgba(100, 60, 180, 0.5); }
.mechanic-inline .result { font-weight: 700; margin-left: 4px; color: var(--accent); }

/* Clock inline node — gold tint */
.clock-inline {
  background: rgba(201, 168, 76, 0.1);
  border-color: rgba(201, 168, 76, 0.4);
  color: var(--accent);
}
.clock-inline:hover { background: rgba(201, 168, 76, 0.22); }

/* Reference inline node — teal tint */
.ref-inline {
  background: rgba(76, 168, 224, 0.1);
  border-color: rgba(76, 168, 224, 0.35);
  color: #7ec8ef;
}
.ref-inline:hover { background: rgba(76, 168, 224, 0.22); }

/* Entity wiki-link inline node — warm amber */
.entity-link-inline {
  display: inline;
  background: rgba(224, 160, 82, 0.12);
  border: 1px solid rgba(224, 160, 82, 0.4);
  border-radius: 3px;
  color: #e0a052;
  padding: 0 4px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92em;
  user-select: none;
}
.entity-link-inline:hover { background: rgba(224, 160, 82, 0.25); }
  background: rgba(76, 175, 114, 0.1);
  border-color: rgba(76, 175, 114, 0.35);
  color: #7ecfa0;
}
.progress-inline:hover { background: rgba(76, 175, 114, 0.22); }

/* Dice result display */
.dice-result {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; border-radius: 6px;
  font-weight: 700; font-size: 16px; transition: all 0.2s;
}
.dice-result.special-eye { color: #e74c3c; text-shadow: 0 0 8px rgba(231,76,60,0.5); }
.dice-result.special-gandalf { color: #f39c12; text-shadow: 0 0 8px rgba(243,156,18,0.5); }

/* Overlay for floating panels */
.floating-panel {
  position: fixed; background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  z-index: 500; overflow: hidden;
  display: flex; flex-direction: column;
  min-width: 300px; min-height: 200px;
}
.floating-panel .panel-header { cursor: move; }

/* Tooltip */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--bg-elevated); border: 1px solid var(--border-light);
  color: var(--text-primary); font-size: 11px; white-space: nowrap;
  padding: 4px 8px; border-radius: var(--radius-sm); pointer-events: none;
  opacity: 0; transition: opacity 0.15s; z-index: 100;
}
[data-tooltip]:hover::after { opacity: 1; }

/* Tiptap editor */
.tiptap-editor {
  height: 100%; overflow-y: auto;
  padding: 24px 32px;
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.8;
  color: var(--text-primary);
}
.tiptap-editor:focus-within { outline: none; }
.tiptap-editor .ProseMirror { min-height: 100%; outline: none; }
.tiptap-editor .ProseMirror h1 { font-size: 1.8em; color: var(--accent); margin: 1.2em 0 0.4em; border-bottom: 1px solid var(--border); padding-bottom: 0.2em; }
.tiptap-editor .ProseMirror h2 { font-size: 1.4em; color: var(--accent-dim); margin: 1em 0 0.3em; }
.tiptap-editor .ProseMirror h3 { font-size: 1.15em; color: var(--text-secondary); margin: 0.8em 0 0.2em; }
.tiptap-editor .ProseMirror p { margin-bottom: 0.8em; }
.tiptap-editor .ProseMirror strong { color: #f0e8d0; }
.tiptap-editor .ProseMirror em { color: #b8d4f0; font-style: italic; }
.tiptap-editor .ProseMirror ul, .tiptap-editor .ProseMirror ol { padding-left: 1.5em; margin-bottom: 0.8em; }
.tiptap-editor .ProseMirror blockquote {
  border-left: 3px solid var(--accent-dim); padding-left: 1em;
  color: var(--text-secondary); margin: 1em 0; font-style: italic;
}
.tiptap-editor .ProseMirror hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }
.tiptap-editor .ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder); color: var(--text-muted); pointer-events: none; float: left; height: 0;
}

/* Scrivener sidebar */
.scriv-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; cursor: pointer; border-radius: var(--radius-sm);
  transition: background 0.1s; user-select: none;
}
.scriv-item:hover { background: var(--bg-hover); }
.scriv-item.active { background: var(--bg-active); color: var(--accent); }
.scriv-item.dragging { opacity: 0.5; }
.scriv-item.drag-over { border-top: 2px solid var(--accent); }

/* Map canvas */
.map-layer-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; background: var(--bg-deep);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 4px;
}
.map-layer-item .layer-name { flex: 1; font-size: 12px; }

/* ── Checkbox & label alignment fix ─────────────────────────────────────────── */
input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0;
  flex-shrink: 0;
  vertical-align: middle;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Any flex row containing a checkbox auto-aligns */
label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

/* Floating panel ─────────────────────────────────────────────────────────────── */
.floating-panel {
  position: absolute;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  z-index: 500;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Toolbar active-state buttons ──────────────────────────────────────────────── */
.toolbar-btn-active {
  background: var(--bg-active) !important;
  border-color: var(--accent-dim) !important;
  color: var(--accent) !important;
}
