:root {
  color-scheme: dark;
  --bg: #010914;
  --bg-2: #061225;
  --panel: #071120;
  --panel-2: #0d1a30;
  --panel-3: #030b17;
  --dark-panel: #0b0f1a;
  --dark-panel-2: #0d1b33;
  --text: #f3f6ff;
  --text-on-dark: #ffffff;
  --muted: #a2b1be;
  --muted-on-dark: #a2b1be;
  --line: #1c3659;
  --line-soft: #12233d;
  --line-dark: #01050c;
  --accent: #2b7df7;
  --accent-2: #17d9ee;
  --focus: #17d9ee;
  --code-bg: #090d17;
  --code-text: #e8edf7;
  --danger: #8e342c;
  --glow: 0 0 20px rgba(43, 125, 247, 0.44);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% -20%, rgba(43, 125, 247, 0.22), transparent 38%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 8px),
    linear-gradient(180deg, #010914 0%, #030817 100%);
  color: var(--text);
  font-family: Calibri, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input,
a.download-link {
  border: 1px solid var(--line);
  border-radius: 4px;
}

button {
  background: linear-gradient(180deg, #2b7df7, #17d9ee);
  color: var(--text);
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 1px 0 rgba(0, 0, 0, 0.3);
}

button:hover,
a.download-link:hover {
  border-color: var(--accent);
  filter: brightness(1.03);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a.download-link:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  height: 88px;
  padding: 16px 22px;
  background:
    radial-gradient(circle at 18% -40%, rgba(43, 125, 247, 0.28), transparent 36%),
    linear-gradient(180deg, rgba(1, 9, 20, 0.96) 0%, rgba(1, 9, 20, 0.78) 100%);
  border-bottom: 2px solid var(--line);
  box-shadow: 0 10px 28px rgba(5, 3, 2, 0.36);
  color: var(--text-on-dark);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: #ffffff;
  font-family: Jost, Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 24px;
  line-height: 1.2;
  font-weight: 700;
  text-shadow: 0 0 24px rgba(43, 125, 247, 0.5);
}

h2 {
  font-size: 17px;
  line-height: 1.25;
}

.topbar p,
.viewer-header p,
.units-toolbar p,
.meta-row {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.topbar p {
  color: var(--muted-on-dark);
}

.viewer-header p,
.units-toolbar p {
  color: var(--muted-on-dark);
}

.tabs,
.view-switch {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab,
.view-mode {
  padding: 8px 12px;
  min-height: 36px;
  color: var(--text-on-dark);
  background: rgba(9, 19, 36, 0.86);
  border-color: var(--line);
}

.tab.active,
.view-mode.active {
  background: linear-gradient(180deg, #2b7df7, #17d9ee);
  border-color: transparent;
  color: #ffffff;
  box-shadow: var(--glow);
}

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  height: calc(100vh - 88px);
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 14px;
  border-right: 2px solid var(--line-dark);
  background: linear-gradient(180deg, #071120, #010914);
  color: var(--text-on-dark);
}

.search-block {
  display: grid;
  gap: 8px;
}

.search-block label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted-on-dark);
  text-transform: uppercase;
}

.search-block input,
.unit-filters input,
.unit-filters select {
  min-height: 38px;
  padding: 8px 10px;
  background: var(--panel-3);
  color: var(--text);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

.search-block button {
  min-height: 38px;
  padding: 8px 10px;
  color: var(--text);
  font-weight: 700;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 0 8px;
}

.file-list {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.file-item {
  display: block;
  width: 100%;
  padding: 9px 10px;
  text-align: left;
  background: #071120;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.file-item.active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.file-path {
  display: block;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.file-info {
  display: block;
  margin-top: 4px;
  color: var(--muted-on-dark);
  font-size: 12px;
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 20px;
  overflow: hidden;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 0;
  flex: 1;
  color: var(--muted);
  border: 1px dashed var(--line);
  background: rgba(21, 27, 43, 0.9);
}

.viewer,
.table-wrap {
  min-width: 0;
  min-height: 0;
  background: rgba(7, 17, 32, 0.96);
  border: 1px solid rgba(43, 125, 247, 0.32);
  border-radius: 6px;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.viewer {
  display: flex;
  flex: 1;
  flex-direction: column;
}

.viewer-header,
.units-toolbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(43, 125, 247, 0.28) 0%, rgba(7, 17, 32, 0.96) 72%);
}

.json-view {
  flex: 1;
  min-height: 0;
  padding: 14px 16px;
  overflow: auto;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 14px;
  line-height: 1.45;
  font-family: "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.tree {
  font-family: "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

.tree details {
  margin-left: 14px;
}

.tree summary {
  cursor: pointer;
}

.tree-key {
  color: #8ef4ff;
  font-weight: 700;
}

.tree-type {
  color: var(--muted);
}

.tree-string {
  color: #9cc7ff;
}

.tree-number,
.tree-boolean {
  color: var(--accent-2);
}

.tree-null {
  color: var(--muted);
}

.notice {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #071120;
  color: var(--text);
  border-radius: 4px;
}

.units-toolbar {
  background:
    linear-gradient(90deg, rgba(43, 125, 247, 0.28) 0%, rgba(7, 17, 32, 0.96) 66%, #010914 100%);
  border: 1px solid rgba(43, 125, 247, 0.32);
  border-radius: 6px 6px 0 0;
  border-bottom: 0;
  color: var(--text-on-dark);
  box-shadow: var(--shadow);
}

.units-toolbar h2 {
  color: #ffffff;
  font-family: Jost, Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 22px;
  text-shadow: 0 0 18px rgba(43, 125, 247, 0.42);
}

.units-toolbar p {
  color: var(--muted-on-dark);
}

#units-panel,
#spells-panel {
  grid-column: 1 / -1;
}

.unit-filters {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 12px;
  color: var(--text);
  text-decoration: none;
  background: linear-gradient(180deg, #2b7df7, #17d9ee);
  font-weight: 700;
}

.table-wrap {
  flex: 1;
  border-radius: 0 0 6px 6px;
  overflow: auto;
}

.units-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  min-height: 0;
  flex: 1;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1140px;
}

th,
td {
  padding: 10px 11px;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: linear-gradient(180deg, #0d1a30, #071120);
  color: #a2b1be;
  font-size: 12px;
  text-transform: uppercase;
  border-bottom: 2px solid var(--line);
  text-shadow: 0 1px 0 #05070c;
}

th[data-sort] {
  cursor: pointer;
  user-select: none;
}

th[data-sort]::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 6px;
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
  border-top: 4px solid currentColor;
  opacity: 0.3;
  vertical-align: middle;
}

th[data-sort].sorted {
  color: #8ef4ff;
}

th[data-sort].ascending::after {
  border-top: 0;
  border-bottom: 6px solid currentColor;
  opacity: 0.8;
}

th[data-sort].descending::after {
  border-top: 6px solid currentColor;
  opacity: 0.8;
}

th[data-sort]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

td {
  background: #071120;
  color: #e8edf7;
}

tbody tr:nth-child(even) td {
  background: #06101f;
}

tbody tr:hover td {
  background: #0d1a30;
}

tbody tr {
  cursor: pointer;
}

tbody tr.selected td {
  background: rgba(43, 125, 247, 0.16);
  border-bottom-color: var(--accent-2);
}

tbody tr.selected td:first-child {
  box-shadow: inset 4px 0 0 var(--accent-2);
}

tbody tr:focus-visible td {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.unit-name {
  color: #ffffff;
  font-weight: 700;
}

.unit-sub {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.unit-detail-header .unit-sub {
  display: inline;
  margin-left: 6px;
}

.json-link {
  min-height: 30px;
  padding: 5px 9px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.unit-detail {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(43, 125, 247, 0.14), transparent 120px),
    var(--panel);
  border: 1px solid rgba(43, 125, 247, 0.32);
  border-left: 0;
  border-radius: 0 0 6px 0;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.unit-detail-empty {
  display: grid;
  min-height: 180px;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 4px;
}

.unit-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--line-soft);
}

.unit-detail h3 {
  margin: 0;
  color: #ffffff;
  font-family: Calibri, Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 18px;
  line-height: 1.2;
}

.unit-detail h4 {
  margin: 0 0 8px;
  font-size: 12px;
  color: #8ef4ff;
  text-transform: uppercase;
}

.unit-detail p {
  color: var(--muted);
  line-height: 1.4;
}

.detail-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.detail-actions button {
  min-height: 32px;
  padding: 6px 9px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.detail-stat {
  padding: 9px;
  background: #030b17;
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.detail-stat span,
.muted {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.detail-stat strong {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
  color: var(--text);
}

.detail-section {
  margin-top: 16px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chips span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 8px;
  background: #030b17;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.detail-list {
  display: grid;
  gap: 8px;
}

.faction-badge,
.school-badge,
.mode-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid rgba(23, 217, 238, 0.22);
  border-radius: 999px;
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  text-transform: capitalize;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.school-badge,
.mode-badge {
  background: linear-gradient(180deg, rgba(43, 125, 247, 0.82), rgba(23, 217, 238, 0.36));
}

.mode-badge {
  border-color: rgba(162, 177, 190, 0.26);
  background: rgba(13, 26, 48, 0.9);
  color: var(--muted);
}

.faction-demon {
  background: linear-gradient(180deg, #b84631, #672019);
}

.faction-dungeon {
  background: linear-gradient(180deg, #69539c, #302249);
}

.faction-human {
  background: linear-gradient(180deg, #3d75a0, #1e405d);
}

.faction-nature {
  background: linear-gradient(180deg, #5f8f46, #2f4f28);
}

.faction-neutral {
  background: linear-gradient(180deg, #8a7656, #4d3f2d);
}

.faction-undead {
  background: linear-gradient(180deg, #6b6987, #303044);
}

.faction-unfrozen {
  background: linear-gradient(180deg, #5f9ea8, #285460);
}

.source-path {
  overflow-wrap: anywhere;
  font-family: "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.files-disabled .source-column,
.files-disabled .source-cell {
  display: none;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .topbar,
  .viewer-header,
  .units-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .file-list {
    max-height: 280px;
  }

  .unit-filters {
    justify-content: flex-start;
  }

  .units-content {
    grid-template-columns: 1fr;
    overflow: auto;
  }

  .table-wrap {
    min-height: 360px;
  }

  .unit-detail {
    border-left: 1px solid var(--line);
    border-top: 0;
    border-radius: 0 0 8px 8px;
  }
}
