/* ============================================================
   DM Tools — Dark Fantasy Theme
   ============================================================ */

/* --- CSS Variables / Design Tokens --- */
:root {
  --bg-darkest: #0d1117;
  --bg-card: #161b22;
  --bg-input: #21262d;
  --bg-hover: #292e36;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent: #d4a017;
  --accent-hover: #e6b422;
  --accent-dim: rgba(212, 160, 23, 0.15);
  --army1: #4a90d9;
  --army1-dim: rgba(74, 144, 217, 0.2);
  --army2: #d94a4a;
  --army2-dim: rgba(217, 74, 74, 0.2);
  --success: #3fb950;
  --error: #f85149;
  --warning: #d29922;
  --info: #58a6ff;
  --border: #30363d;
  --border-light: #3d444d;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Fira Code', 'Cascadia Code', 'JetBrains Mono', Consolas, monospace;
  --transition: 0.2s ease;
  --header-height: 52px;
  --sidebar-width: 280px;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-darkest);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
ul, ol { list-style: none; }
img { max-width: 100%; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-darkest); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ============================================================
   Layout
   ============================================================ */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* --- Header --- */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 16px; }
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-weight: 700;
  font-size: 16px;
}
.logo:hover { color: var(--accent-hover); }
.logo-icon { font-size: 20px; }
.header-campaign {
  color: var(--text-secondary);
  font-size: 13px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}
.header-campaign:empty { display: none; }
.header-nav { display: flex; gap: 4px; }
.header-nav a {
  padding: 6px 12px;
  color: var(--text-secondary);
  border-radius: var(--radius);
  font-size: 13px;
  transition: all var(--transition);
}
.header-nav a:hover, .header-nav a.active {
  color: var(--text-primary);
  background: var(--bg-input);
}
.header-right { display: flex; align-items: center; gap: 12px; }
.header-user { color: var(--text-secondary); font-size: 13px; }
.header-change-pw { color: var(--text-secondary); text-decoration: none; font-size: 14px; opacity: 0.6; transition: opacity 0.2s; }
.header-change-pw:hover { opacity: 1; }

/* --- Body --- */
#app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--transition);
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar.collapsed { width: 40px; }
.sidebar.collapsed .sidebar-content { display: none; }
.sidebar.hidden { width: 0; border-right: none; }
.sidebar.hidden .sidebar-toggle { display: none; }
.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 10px;
  cursor: pointer;
  font-size: 16px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-hover); }
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

/* --- Main Content --- */
.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
}

/* ============================================================
   Typography
   ============================================================ */
h1 { font-size: 24px; font-weight: 700; color: var(--text-primary); }
h2 { font-size: 20px; font-weight: 600; color: var(--text-primary); }
h3 { font-size: 16px; font-weight: 600; color: var(--text-primary); }
h4 { font-size: 14px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.mono { font-family: var(--font-mono); }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: var(--bg-darkest);
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-outline:hover:not(:disabled) { border-color: var(--text-secondary); background: var(--bg-input); }
.btn-danger {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
}
.btn-danger:hover:not(:disabled) { background: #e03b34; }
.btn-success {
  background: var(--success);
  color: var(--bg-darkest);
  border-color: var(--success);
}
.btn-success:hover:not(:disabled) { background: #4cc961; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-icon {
  padding: 6px;
  min-width: 32px;
  min-height: 32px;
}
.btn-group { display: flex; gap: 4px; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.btn-group .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }

/* ============================================================
   Forms / Inputs
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  transition: border-color var(--transition);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-input::placeholder { color: var(--text-muted); }
.form-textarea { resize: vertical; min-height: 60px; }
.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b949e'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
}
.form-select option { background: var(--bg-card); color: var(--text-primary); }
.form-inline { display: flex; gap: 8px; align-items: center; }
.form-inline .form-group { margin-bottom: 0; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-input-sm { padding: 4px 8px; font-size: 12px; }

/* Range / Slider */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.range-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); }

/* Checkbox / Toggle */
.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
}
.form-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* Number input (compact) */
.number-input {
  width: 64px;
  text-align: center;
  padding: 4px 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
}
.number-input:focus { outline: none; border-color: var(--accent); }

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color var(--transition);
}
.card:hover { border-color: var(--border-light); }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-body { font-size: 13px; color: var(--text-secondary); }
.card-footer {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.card-clickable { cursor: pointer; }
.card-clickable:hover { border-color: var(--accent); }

/* ============================================================
   Tabs
   ============================================================ */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 0;
}
.tab {
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ============================================================
   Tags / Badges
   ============================================================ */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 12px;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.tag-gold { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }
.tag-blue { background: var(--army1-dim); color: var(--army1); border-color: var(--army1); }
.tag-red { background: var(--army2-dim); color: var(--army2); border-color: var(--army2); }
.tag-green { background: rgba(63,185,80,0.15); color: var(--success); border-color: var(--success); }
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 10px;
  background: var(--accent);
  color: var(--bg-darkest);
}

/* ============================================================
   Health Bars
   ============================================================ */
.health-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.health-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.health-bar-fill.health-high { background: var(--success); }
.health-bar-fill.health-mid { background: var(--warning); }
.health-bar-fill.health-low { background: var(--error); }
.health-text {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

/* ============================================================
   Stat Blocks
   ============================================================ */
.stat-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 13px;
}
.stat-block-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}
.stat-block-meta {
  font-size: 12px;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 12px;
}
.stat-block-divider {
  border: none;
  border-top: 1px solid var(--accent);
  opacity: 0.3;
  margin: 10px 0;
}
.stat-block-row {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}
.stat-block-label {
  font-weight: 600;
  color: var(--text-primary);
  min-width: 30px;
}
.stat-block-value { color: var(--text-secondary); }
.stat-block-abilities {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  text-align: center;
  gap: 4px;
  margin: 10px 0;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.stat-block-ability-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
}
.stat-block-ability-score {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
}
.stat-block-ability-mod {
  font-size: 11px;
  color: var(--text-secondary);
}
.stat-block-section-title {
  font-weight: 700;
  font-style: italic;
  color: var(--accent);
  margin-top: 10px;
  margin-bottom: 4px;
  font-size: 13px;
}
.stat-block-trait {
  margin-bottom: 6px;
}
.stat-block-trait-name {
  font-weight: 700;
  font-style: italic;
}

/* ============================================================
   Modifier Chips
   ============================================================ */
.modifier-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  font-size: 11px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(212,160,23,0.3);
  border-radius: 12px;
}
.modifier-chip .chip-remove {
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  opacity: 0.7;
}
.modifier-chip .chip-remove:hover { opacity: 1; }

/* ============================================================
   Tooltips
   ============================================================ */
.tooltip {
  position: absolute;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  pointer-events: none;
  max-width: 240px;
}

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.modal-lg { max-width: 800px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Toast Notifications
   ============================================================ */
.toast-container {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: 600;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  color: #fff;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toast-in 0.3s ease;
  max-width: 360px;
}
.toast-success { background: #1a3a1a; border: 1px solid var(--success); color: var(--success); }
.toast-error { background: #3a1a1a; border: 1px solid var(--error); color: var(--error); }
.toast-info { background: #1a2a3a; border: 1px solid var(--info); color: var(--info); }
.toast-warning { background: #3a2a1a; border: 1px solid var(--warning); color: var(--warning); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   Loading / Empty States
   ============================================================ */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-secondary);
}
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}
.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.3;
}
.empty-state-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}
.empty-state-text {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  max-width: 360px;
}

/* ============================================================
   Login Page
   ============================================================ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: var(--bg-darkest);
}
.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 360px;
  text-align: center;
}
.login-logo {
  font-size: 36px;
  color: var(--accent);
  margin-bottom: 8px;
}
.login-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}
.login-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 28px;
}
.login-box .form-group { text-align: left; }
.login-box .btn { width: 100%; margin-top: 8px; }
.login-error {
  color: var(--error);
  font-size: 12px;
  margin-top: 8px;
}
.login-toggle {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-secondary);
}
.login-toggle a { color: var(--accent); cursor: pointer; }

/* ============================================================
   Dashboard
   ============================================================ */
.dashboard {
  padding: 24px;
  max-width: 1100px;
  margin: 0 auto;
}
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.campaign-card { cursor: pointer; }
.campaign-card:hover { border-color: var(--accent); }
.campaign-card .card-title { font-size: 16px; }
.campaign-card .card-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ============================================================
   Campaign View
   ============================================================ */
.campaign-view { padding: 24px; max-width: 1200px; margin: 0 auto; }
.campaign-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}
.campaign-header h1 { margin-bottom: 4px; }
.campaign-desc { color: var(--text-secondary); font-size: 13px; }
.campaign-sections { display: flex; flex-direction: column; gap: 24px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-header h3 { display: flex; align-items: center; gap: 8px; }
.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
  transition: border-color var(--transition);
  cursor: pointer;
}
.item-row:hover { border-color: var(--accent); }
.item-row-name { font-weight: 500; }
.item-row-meta { font-size: 12px; color: var(--text-secondary); }
.item-row-actions { display: flex; gap: 4px; }

/* ============================================================
   Army Builder
   ============================================================ */
.army-builder {
  display: flex;
  height: 100%;
}
.army-builder-search {
  width: 320px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
}
.army-builder-search-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.army-builder-search-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.army-builder-search-filters .form-select,
.army-builder-search-filters .form-input {
  width: auto;
  flex: 1;
  min-width: 80px;
  font-size: 12px;
  padding: 4px 8px;
}
.army-builder-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.creature-card {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: pointer;
  transition: all var(--transition);
}
.creature-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}
.creature-card-name { font-weight: 600; font-size: 13px; }
.creature-card-meta {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.army-builder-composition {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.army-builder-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.army-builder-units {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.army-builder-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.unit-entry {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
}
.unit-entry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.unit-entry-name { font-weight: 600; }
.unit-entry-stats {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}
.unit-entry-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.unit-modifiers {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.army-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding: 8px 0;
  margin-top: 16px;
}
.army-section-title:first-child { margin-top: 0; }

/* ============================================================
   Map Editor
   ============================================================ */
.map-editor {
  display: flex;
  height: 100%;
}
.map-editor-palette {
  width: 220px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.map-editor-palette-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.palette-items {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 4px;
  transition: all var(--transition);
  font-size: 13px;
}
.palette-item:hover { background: var(--bg-hover); }
.palette-item.selected { background: var(--accent-dim); border: 1px solid var(--accent); }
.palette-swatch {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.palette-info {
  padding: 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-secondary);
}
.map-editor-canvas {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.map-editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.map-editor-grid {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: #0a0e14;
}
.map-editor-grid canvas { display: block; }
.map-editor-info {
  width: 200px;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
}
.terrain-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 12px;
}
.terrain-legend-swatch {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

/* ============================================================
   Battle View
   ============================================================ */
.battle-view {
  display: flex;
  height: 100%;
}
.battle-view-sidebar {
  width: 280px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}
.battle-view-sidebar-right {
  border-right: none;
  border-left: 1px solid var(--border);
}
.battle-panel-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.battle-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.battle-view-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.battle-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  gap: 12px;
}
.battle-canvas-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: #0a0e14;
}
.battle-canvas-container canvas { display: block; }
.battle-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}
.round-counter {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}
.speed-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.speed-control input[type="range"] { width: 80px; }

/* Battle Log */
.battle-log-entry {
  padding: 6px 8px;
  font-size: 12px;
  border-bottom: 1px solid rgba(48,54,61,0.5);
  line-height: 1.4;
}
.battle-log-entry:hover { background: var(--bg-hover); }
.battle-log-round {
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
}
.battle-log-actor { font-weight: 600; }
.battle-log-army1 { color: var(--army1); }
.battle-log-army2 { color: var(--army2); }
.battle-log-damage { color: var(--error); font-weight: 600; }
.battle-log-heal { color: var(--success); font-weight: 600; }
.battle-log-death { color: var(--error); font-weight: 700; font-style: italic; }
.battle-log-filters {
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.battle-log-filter {
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.battle-log-filter.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

/* Unit list items in battle sidebar */
.unit-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 4px;
  transition: all var(--transition);
  font-size: 13px;
}
.unit-list-item:hover { background: var(--bg-hover); }
.unit-list-item.selected { background: var(--accent-dim); border: 1px solid rgba(212,160,23,0.3); }
.unit-list-item.eliminated { opacity: 0.4; text-decoration: line-through; }
.unit-token-preview {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  flex-shrink: 0;
}
.unit-token-preview.commander {
  border-radius: 4px;
  transform: rotate(45deg);
}
.unit-token-preview.commander span { transform: rotate(-45deg); }
.unit-list-info { flex: 1; min-width: 0; }
.unit-list-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.unit-list-hp {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

/* Draggable unit in setup */
.unit-draggable {
  cursor: grab;
  user-select: none;
}
.unit-draggable:active { cursor: grabbing; }
.unit-draggable.placed { opacity: 0.5; }
.unit-drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.8;
}

/* ============================================================
   Battle Results
   ============================================================ */
.results-view { padding: 24px; max-width: 900px; margin: 0 auto; }
.results-winner {
  text-align: center;
  padding: 32px;
  margin-bottom: 24px;
  border-radius: var(--radius-lg);
  border: 2px solid var(--accent);
  background: var(--accent-dim);
}
.results-winner-label {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.results-winner-name {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}
.results-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.results-army-card {
  border-radius: var(--radius);
  padding: 20px;
}
.results-army-card.army1 { background: var(--army1-dim); border: 1px solid var(--army1); }
.results-army-card.army2 { background: var(--army2-dim); border: 1px solid var(--army2); }
.results-army-name {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
}
.results-stat {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
}
.results-stat-label { color: var(--text-secondary); }
.results-stat-value { font-weight: 600; font-family: var(--font-mono); }
.results-casualties {
  margin-top: 24px;
}
.casualty-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.casualty-row:last-child { border-bottom: none; }
.results-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 32px;
}
.monte-carlo-section { margin-top: 24px; }
.monte-carlo-bar {
  display: flex;
  height: 32px;
  border-radius: var(--radius);
  overflow: hidden;
  margin: 12px 0;
}
.monte-carlo-bar-army1 { background: var(--army1); }
.monte-carlo-bar-army2 { background: var(--army2); }
.monte-carlo-bar-draw { background: var(--text-muted); }
.monte-carlo-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  text-align: center;
}
.monte-carlo-stat-value {
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-mono);
}
.monte-carlo-stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
}

/* ============================================================
   Collapsible Sections
   ============================================================ */
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  cursor: pointer;
  user-select: none;
}
.collapsible-header:hover { color: var(--accent); }
.collapsible-arrow {
  transition: transform var(--transition);
  font-size: 10px;
  color: var(--text-secondary);
}
.collapsible-header.open .collapsible-arrow { transform: rotate(90deg); }
.collapsible-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.collapsible-body.open {
  max-height: 2000px;
}

/* ============================================================
   Confirm Dialog
   ============================================================ */
.confirm-message {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.6;
}

/* ============================================================
   Search box
   ============================================================ */
.search-box {
  position: relative;
}
.search-box .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}
.search-box .form-input {
  padding-left: 32px;
}

/* ============================================================
   Dice / Roll Results
   ============================================================ */
.dice-result {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
}
.dice-roll {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}
.dice-roll.crit { border-color: var(--accent); color: var(--accent); }
.dice-roll.miss { border-color: var(--error); color: var(--error); }
.dice-total {
  font-weight: 700;
  padding-left: 4px;
  border-left: 1px solid var(--border);
  margin-left: 4px;
}

/* ============================================================
   Victory / Announcement Overlay
   ============================================================ */
.victory-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fade-in 0.5s ease;
}
.victory-text {
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 16px;
  text-shadow: 0 0 20px rgba(212,160,23,0.5);
}
.victory-sub {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ============================================================
   Grid / Canvas overlays
   ============================================================ */
.grid-tooltip {
  position: absolute;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 11px;
  z-index: 50;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.grid-zoom-controls {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 50;
}

/* ============================================================
   Custom Creature Form
   ============================================================ */
.attack-entry {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 8px;
}
.attack-entry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

/* ============================================================
   Utility Classes
   ============================================================ */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.p-8 { padding: 8px; }
.p-12 { padding: 12px; }
.p-16 { padding: 16px; }
.p-24 { padding: 24px; }
.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.text-center { text-align: center; }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.text-army1 { color: var(--army1); }
.text-army2 { color: var(--army2); }
.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 700; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-full { width: 100%; }
.overflow-auto { overflow: auto; }
.relative { position: relative; }
.cursor-pointer { cursor: pointer; }
.no-select { user-select: none; }

/* ============================================================
   Hub Page — Tools Menu
   ============================================================ */
.hub-page { max-width: 900px; margin: 0 auto; padding: 48px 24px; }
.hub-header { text-align: center; margin-bottom: 40px; }
.hub-header h1 { font-size: 2rem; color: var(--gold); margin-bottom: 8px; }

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  text-align: center;
}

.tool-card:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.tool-card-coming-soon {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

.tool-icon { font-size: 2.5rem; margin-bottom: 12px; }
.tool-name { font-size: 1.1rem; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.tool-desc { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; margin-bottom: 12px; }
.tool-badge {
  display: inline-block;
  background: var(--gold);
  color: var(--bg);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 10px;
}
.badge-muted { background: var(--border); color: var(--text-muted); }

/* ============================================================
   Request Account / Login Success
   ============================================================ */
.login-success {
  background: rgba(76, 175, 80, 0.15);
  border: 1px solid rgba(76, 175, 80, 0.4);
  color: #81c784;
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  line-height: 1.4;
}

/* ============================================================
   Admin Panel
   ============================================================ */
.admin-page { max-width: 800px; margin: 0 auto; padding: 32px 24px; }
.admin-page h1 { color: var(--gold); margin-bottom: 16px; }

.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}
.admin-tab { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.admin-tab.active { background: var(--gold); color: var(--bg); border-color: var(--gold); }

.admin-list { display: flex; flex-direction: column; gap: 8px; }

.admin-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.admin-item-resolved { opacity: 0.6; }
.admin-item-info { flex: 1; }
.admin-item-name { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.admin-item-meta { font-size: 0.8rem; color: var(--text-muted); }
.admin-item-message { font-size: 0.85rem; color: var(--text-muted); margin-top: 6px; font-style: italic; }
.admin-item-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; margin-left: 16px; }

.badge-success { background: rgba(76,175,80,0.2); color: #81c784; padding: 2px 8px; border-radius: 4px; font-size: 0.75rem; }
.badge-danger { background: rgba(244,67,54,0.2); color: #e57373; padding: 2px 8px; border-radius: 4px; font-size: 0.75rem; }

.admin-create-form { max-width: 400px; }
.admin-create-form h3 { margin-bottom: 16px; color: var(--text); }

/* ============================================================
   Responsive (1024px+)
   ============================================================ */
@media (max-width: 1024px) {
  .army-builder-search { width: 260px; }
  .battle-view-sidebar { width: 240px; }
  .map-editor-palette { width: 180px; }
  .map-editor-info { width: 160px; }
}
