:root {
  --bg: #11161d;
  --bg-elev: #181f29;
  --bg-card: #1e2633;
  --bg-hover: #273244;
  --border: #313e52;
  --text: #edf2f7;
  --text-muted: #9fb0c7;
  --accent: #eab354;
  --accent-dim: rgba(234, 179, 84, 0.15);
  --link: #74b9ff;
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --lr: #4ade80;
  --hr: #60a5fa;
  --mr: #f59e0b;
  --icon-bg: #252f3f;
  --radius: 10px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

html[data-theme="light"] {
  --bg: #f3f6fa;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f0f4f9;
  --border: #d5dde7;
  --text: #1c2430;
  --text-muted: #5a687a;
  --accent: #b45309;
  --accent-dim: rgba(180, 83, 9, 0.10);
  --link: #0969da;
  --good: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --lr: #15803d;
  --hr: #1d4ed8;
  --mr: #b45309;
  --icon-bg: #263142;
  --shadow: 0 3px 12px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 15px; line-height: 1.6;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 13px; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.topbar-left { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 9px;
  background: var(--icon-bg); border: 1px solid var(--border);
}
.brand-title { display: block; font-weight: 800; letter-spacing: 0.04em; font-size: 15.5px; color: var(--accent); line-height: 1.15; }
.brand-sub { display: block; font-size: 11.5px; color: var(--text-muted); }

.search-wrap { position: relative; flex: 1; max-width: 600px; }
#global-search {
  width: 100%; padding: 9px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-size: 14px; outline: none; transition: border-color 0.15s;
}
#global-search:focus { border-color: var(--accent); }

.search-dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  max-height: 440px; overflow-y: auto;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45); z-index: 100;
}
.search-dropdown.hidden { display: none; }
.search-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.search-item:hover, .search-item.active { background: var(--bg-hover); }
.search-item-type {
  font-size: 11px; text-transform: uppercase; font-family: var(--mono);
  padding: 2px 8px; border-radius: 6px; background: var(--accent-dim); color: var(--accent);
}
.search-item-sub { font-size: 12.5px; color: var(--text-muted); }

.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-shrink: 0; }
.rank-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.rank-switch button {
  background: var(--bg); color: var(--text-muted); border: none; border-right: 1px solid var(--border);
  padding: 6px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.rank-switch button:last-child { border-right: none; }
.rank-switch button.active { background: var(--accent); color: #000; }

.icon-btn, .btn {
  background: var(--bg-card); color: var(--text); border: 1px solid var(--border);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover, .btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 700; }
.btn-primary:hover { opacity: 0.92; background: var(--accent); }
.mobile-only { display: none; }

/* Layout */
.layout { display: flex; min-height: calc(100vh - 59px); }
.sidebar {
  width: 245px; flex-shrink: 0; background: var(--bg-elev); border-right: 1px solid var(--border);
  padding: 14px 12px; overflow-y: auto;
}
.nav-group {
  margin: 16px 10px 6px; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted);
}
.nav-list a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 8px; color: var(--text);
  font-size: 13.5px; margin-bottom: 3px; transition: background 0.12s;
}
.nav-list a:hover { background: var(--bg-hover); text-decoration: none; }
.nav-list a.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.nav-list a.nav-highlight { border-left: 3px solid var(--accent); padding-left: 8px; font-weight: 600; }
.nav-ico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 6px; background: var(--icon-bg); flex-shrink: 0;
}
.nav-ico img { width: 16px; height: 16px; object-fit: contain; }

.main-content { flex: 1; padding: 26px 34px 64px; min-width: 0; max-width: 1320px; }

/* Icons & Visual Badges */
.icon-badge {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; background: var(--icon-bg); border: 1px solid rgba(255, 255, 255, 0.08);
  vertical-align: middle; flex-shrink: 0;
}
.icon-badge img { object-fit: contain; display: block; }
.icon-monster { border-radius: 10px; background: rgba(17, 22, 29, 0.85); }
.inline-icon { vertical-align: text-bottom; display: inline-block; }
.row-with-icon { display: inline-flex; align-items: center; gap: 10px; }

/* Typography & Hero */
h1 { margin: 0 0 10px; font-size: 26px; font-weight: 800; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; line-height: 1.25; }
h2 { margin: 28px 0 12px; font-size: 18px; font-weight: 700; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
h3 { margin: 18px 0 8px; font-size: 15px; color: var(--accent); }
.muted { color: var(--text-muted); }
.lead { margin: 0 0 20px; color: var(--text-muted); font-size: 15px; max-width: 78ch; }
.back-link { display: inline-block; margin-bottom: 14px; font-size: 13.5px; }

.hero-banner {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
  padding: 24px 26px; margin-bottom: 24px; box-shadow: var(--shadow);
}
.hero-banner h1 { font-size: 28px; margin-bottom: 8px; }
.hero-banner p { margin: 0; color: var(--text-muted); max-width: 72ch; }

/* Grids & Cards */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.card-link {
  display: block; color: inherit; text-decoration: none;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}
.card-link:hover { transform: translateY(-2px); border-color: var(--accent); background: var(--bg-hover); text-decoration: none; }
.card-title { font-weight: 700; font-size: 15.5px; margin-bottom: 4px; }

.stat-row { display: flex; flex-wrap: wrap; gap: 14px; margin: 14px 0 22px; }
.stat-box {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 16px; min-width: 130px;
}
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-val { font-size: 16px; font-weight: 700; font-family: var(--mono); margin-top: 2px; }

/* Monster Visual Grid */
.monster-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.monster-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; color: inherit; text-decoration: none; box-shadow: var(--shadow);
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}
.monster-card:hover { transform: translateY(-2px); border-color: var(--accent); background: var(--bg-hover); text-decoration: none; }
.monster-card-info { min-width: 0; flex: 1; }
.monster-card-name { font-weight: 700; font-size: 15.5px; color: var(--text); }
.monster-card-sub { font-size: 12.5px; color: var(--text-muted); margin-bottom: 4px; }
.monster-card-weak { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; }

/* Badges & Tags */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: 11.5px; font-family: var(--mono); font-weight: 600;
  border: 1px solid var(--border); background: var(--bg-elev);
}
.badge-LR { color: var(--lr); border-color: var(--lr); }
.badge-HR { color: var(--hr); border-color: var(--hr); }
.badge-MR { color: var(--mr); border-color: var(--mr); }
.badge-warn { color: var(--warn); border-color: var(--warn); background: rgba(251, 191, 36, 0.10); }
.badge-good { color: var(--good); border-color: var(--good); background: rgba(74, 222, 128, 0.08); }
.badge-bad { color: var(--bad); border-color: var(--bad); }

.elem-Fire { color: #f87171; }
.elem-Water { color: #60a5fa; }
.elem-Thunder { color: #facc15; }
.elem-Ice { color: #67e8f9; }
.elem-Dragon { color: #c084fc; }
.elem-Poison { color: #a855f7; }
.elem-Sleep { color: #818cf8; }
.elem-Paralysis { color: #fbbf24; }
.elem-Blast { color: #fb923c; }
.elem-Stun { color: #fde047; }

/* Controls & Tabs */
.controls {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 18px; padding: 12px 14px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
}
.controls input, .controls select {
  padding: 8px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 13.5px;
}
.tabs, .detail-tabs {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0;
  padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.tab-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text-muted); cursor: pointer; font-size: 13px; font-weight: 600;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.tab-btn:hover { border-color: var(--accent); color: var(--text); }
.tab-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 20px; background: var(--bg-card); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th {
  background: var(--bg-elev); color: var(--text-muted); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.05em; position: sticky; top: 0;
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }
.num { font-family: var(--mono); text-align: right; white-space: nowrap; }
.center { text-align: center; }

.hz-high { color: var(--good); font-weight: 700; }
.hz-mid { color: var(--warn); }
.hz-low { color: var(--text-muted); }

/* Sharpness bar */
.sharpness-wrap { display: flex; flex-direction: column; gap: 4px; min-width: 145px; }
.sharpness-bar { display: flex; height: 10px; width: 145px; background: #000; border: 1px solid var(--border); border-radius: 3px; overflow: hidden; }
.sh-red { background: #dc2626; }
.sh-orange { background: #ea580c; }
.sh-yellow { background: #eab308; }
.sh-green { background: #22c55e; }
.sh-blue { background: #3b82f6; }
.sh-white { background: #f8fafc; }
.sh-purple { background: #a855f7; }

/* Finder chips */
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 11px; border-radius: 999px; background: var(--accent-dim);
  border: 1px solid var(--accent); font-size: 13px; font-weight: 600;
}
.chip button { background: none; border: none; color: var(--text); cursor: pointer; font-weight: 700; padding: 0 2px; font-size: 15px; }

.callout {
  padding: 14px 16px; border-radius: var(--radius); border-left: 4px solid var(--accent);
  background: var(--accent-dim); margin: 14px 0 18px;
}
.loading { padding: 40px; color: var(--text-muted); font-family: var(--mono); }
.pager { display: flex; gap: 10px; align-items: center; margin: 12px 0; font-size: 13px; }

@media (max-width: 860px) {
  .mobile-only { display: inline-block; }
  .sidebar {
    position: fixed; top: 59px; left: 0; bottom: 0; z-index: 45;
    transform: translateX(-100%); transition: transform 0.18s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .brand-sub { display: none; }
  .main-content { padding: 18px 16px 48px; }
}
