/* =========================================================
   TriNex Magic Items
   1. Theme variables
   2. Base / shared controls
   3. Header
   4. Layout / filters
   5. Catalog cards
   6. Print page
   7. Responsive
   8. Print
   ========================================================= */

:root {
  --bg: #0b0d12;
  --panel: #12151c;
  --panel-2: #161b25;
  --muted: #98a2b3;
  --text: #e8eef7;
  --border: #202637;
  --chip: #1d2433;
  --link: #a5b4fc;
  --brand: #8b5cf6;
  --brand-2: #22d3ee;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --gold: #f7c948;
  --maxw: 1180px;
  --pad: 16px;
  --magic-rgb: 139, 92, 246;
  --magic-2-rgb: 34, 211, 238;
  --headerH: 0px;
}

[data-theme="light"] {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --muted: #475569;
  --text: #0f172a;
  --border: #e2e8f0;
  --chip: #f1f5f9;
  --link: #4f46e5;
  --brand: #7c3aed;
  --brand-2: #0284c7;
  --magic-rgb: 79, 70, 229;
  --magic-2-rgb: 14, 165, 233;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  padding: 0;
  scroll-behavior: smooth;
}

body {
  position: relative;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.58 system-ui, -apple-system, Segoe UI, Roboto, Inter, "Noto Sans", Arial, sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -3;
  pointer-events: none;
  background:
    radial-gradient(920px 650px at 8% 8%, rgba(var(--magic-rgb), .18), transparent 62%),
    radial-gradient(820px 540px at 94% 18%, rgba(var(--magic-2-rgb), .12), transparent 60%),
    radial-gradient(700px 560px at 48% 100%, rgba(247, 201, 72, .055), transparent 66%),
    linear-gradient(180deg, rgba(255, 255, 255, .018), transparent 44%);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  opacity: .18;
  background-image:
    linear-gradient(rgba(165, 180, 252, .08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(165, 180, 252, .08) 1px, transparent 1px);
  background-size: 68px 68px;
  mask-image: radial-gradient(circle at 48% 12%, #000 0%, transparent 76%);
}

a {
  color: var(--link);
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding-left: var(--pad);
  padding-right: var(--pad);
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

.btn {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .025);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 11px;
  cursor: pointer;
  text-decoration: none;
  font-size: 13px;
  line-height: 1.2;
  transition: border-color .18s ease, background .18s ease, transform .18s ease, box-shadow .18s ease;
}

.btn::after {
  content: "";
  position: absolute;
  inset: -2px auto -2px -50%;
  z-index: -1;
  width: 44%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .16), transparent);
  transform: skewX(-18deg);
  opacity: 0;
  transition: transform .55s ease, opacity .22s ease;
}

.btn:hover {
  border-color: var(--link);
  background: rgba(165, 180, 252, .08);
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .16);
}

.btn:hover::after {
  opacity: 1;
  transform: translateX(330%) skewX(-18deg);
}

.btn:active {
  transform: translateY(0);
}

.btn.primary {
  border-color: rgba(165, 180, 252, .38);
  background: linear-gradient(135deg, rgba(var(--magic-rgb), .30), rgba(var(--magic-2-rgb), .15));
}

.magic-items-header {
  position: relative;
  top: auto;
  z-index: 120;
  border-bottom: 1px solid rgba(165, 180, 252, .18);
  background:
    radial-gradient(circle at 18% 0%, rgba(var(--magic-rgb), .20), transparent 34%),
    radial-gradient(circle at 80% 0%, rgba(var(--magic-2-rgb), .10), transparent 30%),
    linear-gradient(180deg, color-mix(in srgb, var(--bg) 98%, transparent), color-mix(in srgb, var(--bg) 94%, transparent));
  backdrop-filter: blur(13px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .28);
}

.header-top {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  align-items: start;
  gap: 18px;
  padding-top: 14px;
  padding-bottom: 8px;
}

.header-title-block {
  min-width: 0;
}

.crumbs {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.crumbs a {
  color: var(--muted);
}

.crumbs a:hover {
  color: var(--link);
}

.page-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-title-row::before {
  content: "";
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 11px;
  background: url("/gallery/tnx-logo-ts1760711022.png") center / cover no-repeat, url("/gallery/tnx-logo.WebP") center / cover no-repeat;
  box-shadow:
    0 0 18px rgba(var(--magic-rgb), .22),
    0 8px 18px rgba(0, 0, 0, .18);
}

.page-title-row h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.05;
  letter-spacing: .2px;
}

.page-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
  max-width: 760px;
}

.header-links {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: 760px;
}

.header-links-main,
.header-links-back {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
}

.header-links-back {
  padding-top: 0;
}

.header-links .btn {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .025);
  font-size: 13px;
  box-shadow: none;
}

.header-panel {
  padding-top: 9px;
  padding-bottom: 12px;
  border-top: 1px solid rgba(165, 180, 252, .10);
}

.catalog-toolbar {
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr) auto auto;
  align-items: center;
  gap: 8px;
}

.search-wrap {
  position: relative;
  min-width: 0;
}

.search-wrap::before {
  content: "⌕";
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 18px;
  pointer-events: none;
  z-index: 1;
}

.search-wrap input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: radial-gradient(circle at top left, rgba(165, 180, 252, .06), transparent 46%), var(--panel);
  color: var(--text);
  padding: 9px 42px 9px 42px;
  font-size: 14px;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

.search-wrap input:focus {
  border-color: var(--link);
  box-shadow: 0 0 0 3px rgba(165, 180, 252, .13);
}

.clear-search {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  min-width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
}

.clear-search:hover {
  transform: translateY(-50%);
}

.counter-pill,
.copy-status,
.active-filters {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(165, 180, 252, .06);
  color: var(--muted);
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.selected-count.has-selection {
  color: var(--link);
  border-color: rgba(165, 180, 252, .38);
  background: rgba(165, 180, 252, .10);
}

.actions-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 9px;
}

.magic-item-favorites-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding: 9px 10px;
  border: 1px solid rgba(165, 180, 252, .16);
  border-radius: 14px;
  background:
    radial-gradient(circle at top left, rgba(165, 180, 252, .09), transparent 62%),
    rgba(255, 255, 255, .025);
}

.magic-item-favorites-panel select {
  min-height: 36px;
  max-width: min(280px, 100%);
  padding: 7px 10px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  font: inherit;
  font-size: 13px;
}

.magic-item-favorites-panel .btn {
  min-height: 36px;
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
}

.magic-item-favorites-panel .btn:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.magic-item-favorites-status {
  color: var(--muted);
  font-size: 12px;
}

body.header-compact {
  --headerH: 112px;
}

body.header-compact .magic-items-header {
  position: sticky;
  top: 0;
  z-index: 120;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .24);
}

body.header-compact .header-top {
  display: none;
}

body.header-compact .header-panel {
  padding-top: 8px;
  padding-bottom: 8px;
  border-top: none;
}

body.header-compact .magic-item-favorites-panel,
body.header-compact #typeNav {
  display: none !important;
}

body.header-compact .actions-row {
  margin-top: 8px;
}

#magicItemsCompactHeaderToggle {
  border-color: rgba(165, 180, 252, .28);
}

body.header-compact #magicItemsCompactHeaderToggle {
  color: var(--link);
  border-color: var(--link);
  background: rgba(165, 180, 252, .10);
}

body.magic-item-favorites-disabled .magic-item-favorites-panel,
body.magic-item-favorites-disabled .magic-item-favorite-btn {
  display: none !important;
}

.copy-status {
  display: none;
  justify-content: center;
}

.copy-status:not(:empty) {
  display: inline-flex;
}

.magic-items-layout {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px var(--pad) 64px;
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
  gap: 16px;
}

body.filters-collapsed .magic-items-layout {
  grid-template-columns: minmax(0, 1fr);
}

body.filters-collapsed .filters-panel {
  display: none;
}

body.tool-mode .magic-items-layout {
  grid-template-columns: minmax(0, 1fr);
}

body.tool-mode .filters-panel {
  display: none;
}

.filters-panel {
  position: sticky;
  top: calc(var(--headerH) + 16px);
  align-self: start;
  max-height: calc(100vh - var(--headerH) - 32px);
  overflow: auto;
  border: 1px solid rgba(165, 180, 252, .16);
  background: linear-gradient(180deg, rgba(255, 255, 255, .035), transparent 24%), color-mix(in srgb, var(--panel) 94%, transparent);
  border-radius: 18px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 18px 70px rgba(0, 0, 0, .14);
  backdrop-filter: blur(10px);
  overscroll-behavior: contain;
}

.filters-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.filters-heading h2 {
  margin: 0 0 3px;
  font-size: 18px;
  line-height: 1.15;
}

.filters-close {
  display: none;
  width: 34px;
  min-width: 34px;
  padding: 0;
}

.filters-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 10px;
}

.filter summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 12px;
  font-weight: 750;
  font-size: 14px;
  line-height: 1.3;
}

.filter summary::-webkit-details-marker {
  display: none;
}

.filter[open] summary {
  border-bottom: 1px solid var(--border);
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--chip);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
  transition: border-color .16s ease, background .16s ease;
}

.filter-pill:hover {
  border-color: var(--link);
  background: rgba(165, 180, 252, .08);
}

.filter-pill input {
  margin: 0;
  accent-color: var(--brand);
}

.filter-pill input:checked + span {
  color: var(--link);
  font-weight: 700;
}

.catalog-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hero-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 24px;
  background:
    radial-gradient(circle at 18% 18%, rgba(var(--magic-rgb), .16), transparent 36%),
    radial-gradient(circle at 76% 14%, rgba(var(--magic-2-rgb), .10), transparent 34%),
    linear-gradient(135deg, color-mix(in srgb, var(--panel) 90%, #000), var(--panel));
  box-shadow: 0 24px 74px rgba(0, 0, 0, .20);
  padding: 20px;
}

.mode-tabs {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
  border: 1px solid rgba(165, 180, 252, .16);
  border-radius: 999px;
  background: rgba(255, 255, 255, .025);
  padding: 5px;
}

.mode-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.mode-tab:hover {
  color: var(--text);
  background: rgba(165, 180, 252, .08);
}

.mode-tab.active {
  color: var(--text);
  border-color: rgba(165, 180, 252, .42);
  background: linear-gradient(135deg, rgba(var(--magic-rgb), .22), rgba(var(--magic-2-rgb), .12));
}

.mode-tab-link {
  border-color: rgba(245, 158, 11, .26);
  color: color-mix(in srgb, var(--gold) 80%, var(--text));
}

body.magic-item-tools-locked [data-gm-tool-tab] {
  display: none;
}

body:not(.magic-item-tools-locked) .gm-tools-locked-tab {
  display: none;
}

.mode-panel[hidden] {
  display: none !important;
}

.generator-panel {
  border: 1px solid rgba(165, 180, 252, .16);
  background:
    radial-gradient(circle at top left, rgba(var(--magic-rgb), .10), transparent 42%),
    color-mix(in srgb, var(--panel) 94%, transparent);
  border-radius: 22px;
  padding: 16px;
  box-shadow: 0 18px 52px rgba(0, 0, 0, .14);
}

.generator-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.generator-head h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.generator-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.generator-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.generator-controls label {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.generator-controls select,
.generator-controls input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

.generator-controls select:focus,
.generator-controls input:focus {
  border-color: var(--link);
  box-shadow: 0 0 0 3px rgba(165, 180, 252, .13);
}

.generator-result:empty {
  display: none;
}

.generator-result {
  display: grid;
  gap: 12px;
}

.gm-tools-lock-panel {
  border-style: dashed;
  border-color: rgba(247, 201, 72, .32);
  background:
    radial-gradient(circle at top left, rgba(247, 201, 72, .10), transparent 38%),
    color-mix(in srgb, var(--panel) 94%, transparent);
}

.gm-tools-lock-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.shop-summary,
.loot-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.summary-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, .025);
  padding: 12px;
}

.summary-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.summary-value {
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
}

.compact-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, .018);
}

.compact-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

.compact-table th,
.compact-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.compact-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  background: rgba(255, 255, 255, .025);
}

.compact-table tr:last-child td {
  border-bottom: 0;
}

.rank-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  border: 1px solid color-mix(in srgb, var(--rank-color) 55%, var(--border));
  border-radius: 999px;
  background: color-mix(in srgb, var(--rank-color) 14%, transparent);
  color: var(--text);
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
}

.hero-card::before {
  content: "";
  position: absolute;
  inset: -1px;
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, .08), transparent),
    repeating-linear-gradient(135deg, transparent 0 18px, rgba(165, 180, 252, .035) 18px 19px);
  opacity: .55;
  pointer-events: none;
}

.hero-card > * {
  position: relative;
  z-index: 1;
}

.kicker {
  color: var(--brand-2);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
  margin: 0 0 8px;
}

.hero-title {
  font-size: 34px;
  line-height: 1.12;
  margin: 0 0 10px;
}

.hero-lead {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  max-width: 900px;
}

.hero-pills,
.type-nav,
.footer-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hero-pills {
  margin-top: 14px;
}

.hero-pill,
.type-nav-link,
.chip,
.mini-chip {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .035);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}

.type-nav {
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(165, 180, 252, .16);
  border-radius: 18px;
  background:
    radial-gradient(circle at top left, rgba(34, 211, 238, .08), transparent 42%),
    rgba(255, 255, 255, .022);
}

.type-nav:empty {
  display: none;
}

.type-nav-title {
  color: var(--muted);
  font-size: 12px;
  margin-right: 4px;
}

.type-nav-link {
  color: var(--text);
  text-decoration: none;
}

.type-nav-link:hover {
  border-color: var(--link);
  color: var(--link);
}

.catalog-panel {
  border: 1px solid rgba(165, 180, 252, .16);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  border-radius: 22px;
  padding: 16px;
  box-shadow: 0 18px 52px rgba(0, 0, 0, .14);
}

.results-head,
.item-section-head,
.rank-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.results-head {
  margin-bottom: 12px;
}

.results-head h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.section-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 18px;
  padding: 22px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, .02);
}

.item-section {
  scroll-margin-top: calc(var(--headerH) + 18px);
  margin: 18px 0 28px;
}

.item-section:first-child {
  margin-top: 0;
}

.item-section-head {
  padding: 10px 12px;
  border: 1px solid rgba(165, 180, 252, .14);
  border-radius: 16px;
  background:
    radial-gradient(circle at top left, rgba(var(--magic-rgb), .10), transparent 44%),
    rgba(255, 255, 255, .025);
  margin-bottom: 12px;
}

.item-section-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.section-count,
.rank-count {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.rank-block {
  margin: 14px 0 18px;
}

.rank-heading {
  align-items: center;
  margin-bottom: 10px;
}

.rank-heading h3 {
  margin: 0;
  font-size: 16px;
}

.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
}

.magic-item-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .040), rgba(255, 255, 255, .012)),
    var(--panel);
  border-radius: 18px;
  padding: 14px;
  color: var(--text);
  min-width: 0;
  box-shadow: 0 12px 36px rgba(0, 0, 0, .10);
  transition: border-color .18s ease, transform .18s ease, box-shadow .18s ease, background .18s ease;
  --rank-color: #9ca3af;
  scroll-margin-top: calc(var(--headerH) + 18px);
}

.magic-item-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, var(--rank-color), var(--rank-color-2, color-mix(in srgb, var(--rank-color) 62%, transparent)));
  box-shadow: 0 0 22px color-mix(in srgb, var(--rank-color) 42%, transparent);
}

.rank-0 { --rank-color: #9ca3af; }
.rank-1 { --rank-color: #22c55e; }
.rank-2 { --rank-color: #38bdf8; }
.rank-3 { --rank-color: #facc15; }
.rank-4 { --rank-color: #f97316; }
.rank-5 { --rank-color: #e11d48; --rank-color-2: #a855f7; }

.magic-item-card:hover {
  border-color: rgba(165, 180, 252, .42);
  transform: translateY(-2px);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .18);
}

.magic-item-card.selected {
  border-color: rgba(34, 211, 238, .60);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .18), 0 0 0 1px rgba(34, 211, 238, .18) inset;
}

.magic-item-card.linked-highlight {
  border-color: var(--rank-color);
  box-shadow: 0 20px 52px rgba(0, 0, 0, .22), 0 0 0 2px color-mix(in srgb, var(--rank-color) 42%, transparent) inset;
}

.item-card-top {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.item-media {
  width: 78px;
  min-width: 78px;
}

.item-thumb,
.item-media img {
  width: 78px;
  height: 78px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background:
    radial-gradient(circle at 34% 26%, rgba(var(--magic-2-rgb), .20), transparent 45%),
    var(--chip);
  display: grid;
  place-items: center;
  object-fit: cover;
  color: var(--text);
  font-size: 30px;
}

.item-title-block {
  min-width: 0;
}

.item-kicker {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  margin-bottom: 4px;
}

.item-title {
  margin: 0;
  font-size: 19px;
  line-height: 1.2;
}

.item-meta-line {
  color: var(--muted);
  font-size: 12px;
  margin-top: 5px;
}

.economy-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.price-tag,
.weight-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, .035);
  color: var(--text);
  padding: 5px 9px;
  font-size: 12px;
  white-space: nowrap;
}

.price-tag {
  color: var(--gold);
  border-color: rgba(247, 201, 72, .28);
  background: rgba(247, 201, 72, .06);
}

.meta-chips,
.tag-row,
.item-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.meta-chips {
  margin-top: 11px;
}

.mini-chip {
  color: var(--text);
  font-size: 12px;
  padding: 5px 8px;
}

.mini-chip.accent {
  color: var(--link);
  border-color: rgba(165, 180, 252, .38);
  background: rgba(165, 180, 252, .08);
}

.item-text {
  margin-top: 11px;
  color: color-mix(in srgb, var(--text) 92%, var(--muted));
  font-size: 14px;
  line-height: 1.48;
}

.text-block {
  margin: 0 0 6px;
}

.text-block:last-child {
  margin-bottom: 0;
}

.text-heading {
  display: inline-flex;
  color: var(--link);
  font-weight: 850;
  margin-bottom: 3px;
}

.tag-row {
  margin-top: 12px;
}

.magic-item-gm-panel {
  margin-top: 8px;
}

.magic-item-gm-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.magic-item-gm-panel-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.magic-item-gm-label {
  color: var(--gold);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.magic-item-gm-toggle {
  min-height: 32px;
  flex: 0 0 auto;
  padding: 6px 10px;
}

.magic-item-gm-action {
  border-color: rgba(247, 201, 72, .30);
  background: rgba(247, 201, 72, .055);
  color: var(--gold);
  font-size: 12px;
  box-shadow: none;
}

.magic-item-gm-action:hover,
.magic-item-gm-action:focus-visible {
  border-color: rgba(247, 201, 72, .56);
  background: rgba(247, 201, 72, .10);
  color: var(--gold);
}

.magic-item-gm-content {
  margin-top: 10px;
}

.magic-item-gm-message {
  border: 1px solid rgba(165, 180, 252, .18);
  border-radius: 12px;
  background: rgba(255, 255, 255, .035);
  color: var(--muted);
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.4;
}

.magic-item-gm-message.is-error {
  border-color: rgba(251, 113, 133, .34);
  background: rgba(251, 113, 133, .08);
  color: color-mix(in srgb, var(--danger) 76%, var(--text));
}

.magic-item-gm-card {
  display: grid;
  gap: 10px;
}

.magic-item-gm-head {
  border-bottom: 1px solid rgba(247, 201, 72, .18);
  padding-bottom: 8px;
}

.magic-item-gm-eyebrow {
  color: var(--gold);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.magic-item-gm-head h2,
.magic-item-gm-section h3,
.magic-item-gm-field h4 {
  margin: 0;
}

.magic-item-gm-head h2 {
  font-size: 18px;
  line-height: 1.2;
}

.magic-item-gm-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.magic-item-gm-section {
  display: grid;
  gap: 8px;
  border: 1px solid rgba(165, 180, 252, .14);
  border-radius: 12px;
  background: rgba(11, 13, 18, .18);
  padding: 10px;
}

.magic-item-gm-section h3 {
  color: var(--link);
  font-size: 14px;
  line-height: 1.25;
}

.magic-item-gm-field {
  display: grid;
  gap: 4px;
}

.magic-item-gm-field h4 {
  color: var(--text);
  font-size: 12px;
  line-height: 1.25;
}

.magic-item-gm-field p,
.magic-item-gm-kv dd {
  margin: 0;
  color: color-mix(in srgb, var(--text) 88%, var(--muted));
  font-size: 12px;
  line-height: 1.42;
}

.magic-item-gm-field p + p {
  margin-top: 6px;
}

.magic-item-gm-list {
  margin: 0;
  padding-left: 18px;
  color: color-mix(in srgb, var(--text) 88%, var(--muted));
  font-size: 12px;
  line-height: 1.42;
}

.magic-item-gm-dl {
  display: grid;
  gap: 6px;
  margin: 0;
}

.magic-item-gm-kv {
  display: grid;
  gap: 2px;
}

.magic-item-gm-kv dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.chip {
  color: var(--text);
  font-size: 12px;
  padding: 5px 8px;
}

.item-actions {
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 11px;
  border-top: 1px solid rgba(165, 180, 252, .12);
}

.magic-item-favorite-btn {
  display: inline-grid;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  place-items: center;
  padding: 0;
  color: var(--muted);
  border: 1px solid rgba(165, 180, 252, .22);
  border-radius: 999px;
  background: rgba(11, 13, 18, .26);
  font: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.magic-item-favorite-btn:hover,
.magic-item-favorite-btn:focus-visible {
  color: var(--gold);
  border-color: rgba(247, 201, 72, .52);
  outline: none;
}

.magic-item-favorite-btn.is-favorite {
  color: var(--gold);
  border-color: rgba(247, 201, 72, .65);
  background: rgba(247, 201, 72, .10);
  box-shadow: 0 0 18px rgba(247, 201, 72, .14);
}

[data-theme="light"] .magic-item-favorite-btn {
  color: #64748b;
  border-color: rgba(148, 163, 184, .42);
  background: rgba(255, 255, 255, .82);
  box-shadow: 0 8px 18px rgba(15, 23, 42, .06);
}

[data-theme="light"] .magic-item-favorite-btn:hover,
[data-theme="light"] .magic-item-favorite-btn:focus-visible {
  color: #b7791f;
  border-color: rgba(217, 119, 6, .48);
  background: rgba(255, 251, 235, .95);
}

[data-theme="light"] .magic-item-favorite-btn.is-favorite {
  color: #b7791f;
  border-color: rgba(217, 119, 6, .58);
  background: rgba(254, 243, 199, .86);
  box-shadow: 0 10px 22px rgba(217, 119, 6, .14);
}

.copy-item-btn,
.copy-link-btn {
  min-height: 32px;
  padding: 6px 10px;
}

.select-print {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, .025);
  color: var(--muted);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
  user-select: none;
}

.select-print input {
  margin: 0;
  accent-color: var(--brand-2);
}

.select-print input:checked + span {
  color: var(--link);
  font-weight: 750;
}

.footer-actions {
  margin-top: 4px;
}

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 8px 0;
}

.float-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 300;
  min-width: 104px;
  height: 52px;
  padding: 0 14px;
  border: 2px solid rgba(165, 180, 252, .34);
  border-radius: 999px;
  background:
    radial-gradient(circle at top left, rgba(165, 180, 252, .32), transparent 46%),
    linear-gradient(180deg, rgba(29, 36, 51, .98), rgba(18, 21, 28, .98));
  color: var(--text);
  font-weight: 750;
  box-shadow: 0 16px 38px rgba(0, 0, 0, .42), 0 0 0 1px rgba(165, 180, 252, .08) inset;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease, border-color .18s ease;
}

.float-top.visible {
  opacity: .98;
  pointer-events: auto;
  transform: translateY(0);
}

.float-top:hover {
  border-color: var(--link);
  transform: translateY(-3px);
}

[data-theme="light"] .float-top {
  border-color: rgba(79, 70, 229, .24);
  background:
    radial-gradient(circle at top left, rgba(79, 70, 229, .16), transparent 46%),
    linear-gradient(180deg, rgba(255, 255, 255, .98), rgba(241, 245, 249, .98));
  color: var(--text);
  box-shadow: 0 16px 34px rgba(15, 23, 42, .16), 0 0 0 1px rgba(79, 70, 229, .08) inset;
}

[data-theme="light"] .float-top:hover {
  border-color: var(--link);
}

.print-page .magic-items-header {
  position: sticky;
}

.print-page main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px var(--pad) 64px;
}

.print-summary {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  padding: 14px 16px;
  margin-bottom: 16px;
}

.print-summary h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.print-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 14px;
}

.print-page .magic-item-card {
  break-inside: avoid;
  page-break-inside: avoid;
}

[data-theme="light"] .magic-items-header {
  background:
    radial-gradient(circle at 18% 0%, rgba(var(--magic-rgb), .11), transparent 34%),
    radial-gradient(circle at 80% 0%, rgba(var(--magic-2-rgb), .10), transparent 30%),
    linear-gradient(180deg, rgba(247, 248, 251, .98), rgba(247, 248, 251, .94));
  box-shadow: 0 12px 26px rgba(15, 23, 42, .08);
}

[data-theme="light"] body::before {
  background:
    radial-gradient(920px 650px at 8% 8%, rgba(var(--magic-rgb), .09), transparent 62%),
    radial-gradient(820px 540px at 94% 18%, rgba(var(--magic-2-rgb), .08), transparent 60%),
    radial-gradient(700px 560px at 48% 100%, rgba(247, 201, 72, .09), transparent 66%),
    linear-gradient(180deg, rgba(15, 23, 42, .012), transparent 44%);
}

[data-theme="light"] .btn {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #334155;
  box-shadow: 0 1px 0 rgba(15, 23, 42, .04);
}

[data-theme="light"] .header-links .btn {
  background: rgba(255, 255, 255, .58);
  border-color: rgba(203, 213, 225, .86);
  box-shadow: none;
}

[data-theme="light"] .header-links .btn:hover {
  background: rgba(238, 242, 255, .84);
  border-color: #818cf8;
  box-shadow: 0 8px 18px rgba(79, 70, 229, .12);
}

[data-theme="light"] .btn:hover {
  background: #eef2ff;
  border-color: #818cf8;
  color: #312e81;
  box-shadow: 0 8px 18px rgba(79, 70, 229, .14);
}

[data-theme="light"] body.header-compact .magic-items-header,
[data-theme="light"].header-compact .magic-items-header {
  box-shadow: 0 8px 22px rgba(15, 23, 42, .10);
}

[data-theme="light"] #magicItemsCompactHeaderToggle {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #334155;
}

[data-theme="light"].header-compact #magicItemsCompactHeaderToggle,
[data-theme="light"] body.header-compact #magicItemsCompactHeaderToggle {
  background: #eef2ff;
  border-color: #818cf8;
  color: #312e81;
}

[data-theme="light"] .hero-card,
[data-theme="light"] .catalog-panel,
[data-theme="light"] .generator-panel,
[data-theme="light"] .filters-panel,
[data-theme="light"] .magic-item-card,
[data-theme="light"] .print-summary {
  box-shadow: 0 18px 44px rgba(15, 23, 42, .08);
}

@media (max-width: 980px) {
  :root {
    --headerH: 0px;
  }

  .magic-items-header {
    position: relative;
  }

  .header-top {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .header-links {
    align-items: flex-start;
    max-width: none;
  }

  .header-links-main,
  .header-links-back {
    justify-content: flex-start;
  }

  .catalog-toolbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .catalog-toolbar .btn,
  .counter-pill,
  .copy-status {
    width: 100%;
    justify-content: center;
  }

  .actions-row .btn {
    flex: 1 1 180px;
  }

  .mode-tabs {
    width: 100%;
  }

  .mode-tab {
    flex: 1 1 0;
  }

  .generator-head {
    flex-direction: column;
  }

  .generator-actions,
  .generator-actions .btn {
    width: 100%;
  }

  .magic-items-layout,
  body.filters-collapsed .magic-items-layout {
    grid-template-columns: 1fr;
  }

  .filters-panel {
    display: none;
  }

  .filters-panel.open {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 500;
    width: 100%;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    padding: 18px 16px 80px;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .72);
  }

  .filters-close {
    display: inline-flex;
  }

  body.filters-open {
    overflow: hidden;
  }

  body.filters-open .filters-overlay {
    position: fixed;
    inset: 0;
    z-index: 490;
    background: rgba(0, 0, 0, .50);
  }

  .hero-title {
    font-size: 30px;
  }
}

@media (max-width: 680px) {
  :root {
    --pad: 14px;
  }

  body {
    font-size: 15px;
  }

  .page-title-row h1 {
    font-size: 24px;
  }

  .header-links .btn,
  .footer-actions .btn {
    width: 100%;
  }

  .hero-card,
  .catalog-panel,
  .generator-panel {
    border-radius: 20px;
    padding: 15px;
  }

  .hero-title {
    font-size: 27px;
  }

  .results-head,
  .item-section-head {
    flex-direction: column;
  }

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

  .item-card-top {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .item-media {
    width: 64px;
    min-width: 64px;
  }

  .item-thumb,
  .item-media img {
    width: 64px;
    height: 64px;
    border-radius: 14px;
    font-size: 26px;
  }

  .economy-stack {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
  }

  .item-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .magic-item-gm-panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .magic-item-gm-toggle {
    width: 100%;
    justify-content: center;
  }

  .copy-item-btn,
  .copy-link-btn,
  .select-print {
    width: 100%;
    justify-content: center;
  }

  .float-top {
    right: 14px;
    bottom: 14px;
    height: 46px;
    min-width: 92px;
  }

  body.header-compact {
    --headerH: 96px;
  }

  body.header-compact #selectVisibleBtn,
  body.header-compact #clearSelectionBtn,
  body.header-compact #printSelectedBtn,
  body.header-compact .copy-status {
    display: none !important;
  }

  body.header-compact .actions-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  body.header-compact #magicItemsCompactHeaderToggle {
    width: 100%;
    justify-content: center;
  }
}

@media print {
  @page {
    size: A4;
    margin: 10mm;
  }

  * {
    box-shadow: none !important;
    text-shadow: none !important;
    animation: none !important;
    transition: none !important;
  }

  body {
    background: #fff !important;
    color: #000 !important;
    font-size: 10.5px;
  }

  body::before,
  body::after,
  .magic-items-header,
  .filters-panel,
  .filters-overlay,
  .hero-card,
  .type-nav,
  .footer-actions,
  .foot,
  .float-top,
  .item-actions,
  .no-print {
    display: none !important;
  }

  .print-page .magic-items-header {
    display: none !important;
  }

  .magic-items-layout,
  .print-page main {
    display: block;
    max-width: none;
    padding: 0;
    margin: 0;
    color: #000;
  }

  .catalog-panel,
  .print-summary {
    border: 0;
    background: #fff !important;
    padding: 0;
  }

  .results-head,
  .item-section-head,
  .rank-heading {
    display: none;
  }

  .item-section,
  .rank-block {
    margin: 0;
  }

  .items-grid,
  .print-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6mm;
  }

  .magic-item-card {
    border: 1px solid #777 !important;
    background: #fff !important;
    color: #000 !important;
    border-radius: 8px !important;
    padding: 10px !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .magic-item-card::before {
    display: none;
  }

  .item-card-top {
    grid-template-columns: 52px minmax(0, 1fr) auto;
    gap: 8px;
  }

  .item-media {
    width: 52px;
    min-width: 52px;
  }

  .item-thumb,
  .item-media img {
    width: 52px;
    height: 52px;
    border-radius: 8px;
    border-color: #777;
    background: #fff !important;
    color: #000;
    font-size: 22px;
  }

  .item-title {
    font-size: 14px;
    color: #000;
  }

  .item-kicker,
  .item-meta-line,
  .section-note,
  .muted {
    color: #333 !important;
  }

  .price-tag,
  .weight-tag,
  .mini-chip,
  .chip {
    border-color: #777 !important;
    background: #fff !important;
    color: #000 !important;
  }

  .item-text {
    color: #000 !important;
    font-size: 10.5px;
    line-height: 1.32;
  }

  .text-heading {
    color: #000 !important;
  }
}
