:root {
  --bg: #120e0c;
  --panel: #241812;
  --panel-2: #2d1d16;
  --line: #6d4c2e;
  --gold: #e4c27a;
  --gold-dim: #8c7044;
  --text: #f4ead8;
  --muted: #b5a28c;
  --known: #d7a441;
  --locked: #5c4636;
  --cell: 48px;
  --gap-x: 18px;
  --gap-y: 28px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: #000;
  background-image:
    repeating-radial-gradient(circle at 50% 0, rgba(180, 51, 26, 0.05) 0 2px, transparent 2px 28px),
    linear-gradient(#000 0%, #050303 14%, #0c0706 55%, #000);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.4 "Segoe UI", Tahoma, sans-serif;
}

button, input { font: inherit; color: inherit; }

.page {
  max-width: 1560px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

.chrome {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.class-name {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: 0.04em;
  color: var(--gold);
  margin-right: 4px;
}

.classes { display: flex; gap: 6px; flex-wrap: wrap; }

.class-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 3px;
  background: #1a100d;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.class-btn.selected {
  border-color: #ffe7a8;
  box-shadow: 0 0 0 2px #ffd56a;
  background: #3a2618;
}

.class-btn:disabled {
  opacity: 0.38;
  filter: grayscale(1);
  cursor: not-allowed;
}

.class-btn img {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  object-fit: cover;
  display: block;
}

.fallback {
  width: 32px;
  height: 32px;
  border-radius: 4px;
}

.fallback {
  display: grid;
  place-items: center;
  background: #3a241c;
  color: var(--gold);
  font-weight: 650;
}

.level {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.level input[type="range"] { width: 120px; accent-color: var(--gold); }
.level input[type="number"] {
  width: 52px;
  background: #1a100d;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 6px;
}

.points { color: var(--gold); min-width: 9em; }

.reset, .search input {
  background: #1a100d;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
}

.search { margin-left: auto; }
.search input { cursor: text; width: 180px; }

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 248px;
  gap: 12px;
  align-items: stretch;
}

.trees {
  display: grid;
  grid-template-columns: repeat(4, minmax(250px, 1fr));
  gap: 12px;
  align-items: start;
  min-width: 0;
  overflow-x: auto;
}

.tree {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 0 14px;
  min-width: 0;
  overflow: hidden;
}

.tree.primary {
  border-color: #ffe7a8;
  box-shadow: 0 0 0 2px #ffd56a, 0 0 18px rgba(255, 204, 80, 0.45);
}
.tree.locked { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35); }

.spec-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin: 0;
  padding: 0 0 6px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.spec-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 38px;
  padding: 8px 36px;
  background: linear-gradient(180deg, #a78458 0%, #6e5132 100%);
  color: #2a1c10;
  font-size: 16px;
  font-weight: 700;
}

.spec-card.selected .spec-banner {
  background: linear-gradient(180deg, #e6c48a 0%, #b07d3e 100%);
}

.spec-banner .spent {
  position: absolute;
  right: 12px;
  font-variant-numeric: tabular-nums;
}

.spec-crest {
  width: 56px;
  height: 56px;
  margin: 12px auto 8px;
  border-radius: 6px;
  border: 2px solid #6d4c2e;
  object-fit: cover;
  background: #140e0c;
}

img.spec-crest { display: block; }

.spec-card.selected .spec-crest { border-color: #ffd56a; }

.spec-blurb {
  margin: 8px 14px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
}

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  background: #3a2618;
  color: var(--gold);
  font-size: 11px;
  font-weight: 550;
  vertical-align: 1px;
}

.lock-note {
  margin: 4px 14px 8px;
  color: var(--muted);
  font-size: 12px;
}

.tree-reset {
  display: block;
  width: calc(100% - 16px);
  margin: 12px auto 0;
  padding: 6px 10px;
  background: #1a100d;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}

.tree-reset:disabled {
  opacity: 0.4;
  cursor: default;
}

.tree-reset:not(:disabled):hover {
  border-color: var(--gold-dim);
  color: var(--gold);
}

.grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--rows), var(--cell));
  column-gap: var(--gap-x);
  row-gap: var(--gap-y);
  justify-content: center;
  margin: 8px auto 0;
}

.links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.cell {
  grid-column: var(--c);
  grid-row: var(--r);
  position: relative;
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border: 2px solid #4a3428;
  border-radius: 4px;
  background: #140e0c;
  cursor: pointer;
}

.cell img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 2px; }

.cell.known { border-color: var(--known); }
.cell.maxed { border-color: #f0d48a; box-shadow: 0 0 0 1px #f0d48a; }
.cell.locked { filter: grayscale(0.85) brightness(0.7); cursor: default; }
.cell.dim { opacity: 0.22; }
.cell.hit { box-shadow: 0 0 0 2px #fff3c4; }

.rank {
  position: absolute;
  right: -2px;
  bottom: -2px;
  padding: 0 3px;
  background: #0c0908;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 10px;
  line-height: 1.3;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.cell.known .rank { color: var(--gold); border-color: var(--known); }

.glyphs {
  height: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 10px 12px;
}

.glyphs h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.glyph-kind {
  margin: 10px 0 4px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 650;
}

.glyph-kind:first-of-type { margin-top: 0; }

.glyph-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 4px;
  padding: 4px;
  text-align: left;
  background: #1a100d;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.glyph-slot:hover { border-color: var(--gold-dim); }

.glyph-slot img,
.socket {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 4px;
}

.socket {
  background:
    radial-gradient(circle at 50% 45%, #3a2a22 0 7px, transparent 8px),
    linear-gradient(#241812, #120e0c);
  border: 1px solid #4a3428;
}

.glyph-slot-name {
  min-width: 0;
  font-weight: 650;
  line-height: 1.2;
}

.glyph-slot.empty .glyph-slot-name {
  color: var(--muted);
  font-weight: 400;
}

.books {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.book {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px 14px;
  min-width: 0;
}

.spell-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 16px;
  align-items: start;
}
.spell > span { flex: 1; min-width: 0; }
.book h2 { margin: 0 0 8px; font-size: 16px; }
.book h3 {
  margin: 12px 0 6px;
  font-size: 13px;
  font-weight: 650;
  color: var(--gold);
}

.cat-board {
  display: grid;
  grid-template-columns: repeat(var(--cats, 5), minmax(0, 1fr));
  gap: 8px 18px;
  align-items: start;
}

.cat { grid-column: var(--cat); }
.cat h3 { margin: 0 0 4px; }
.cat .spell-grid { grid-template-columns: 1fr; }
.cat .spell { padding: 4px 6px; margin-bottom: 2px; }

.spell {
  display: flex;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 6px;
  margin: 0 0 4px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

@media (hover: hover) and (pointer: fine) {
  .spell:hover { background: var(--panel-2); border-color: var(--line); }
}
.spell img, .spell .fallback { width: 36px; height: 36px; flex: 0 0 36px; border-radius: 4px; }
.spell-name { font-weight: 650; }
.spell-meta { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.empty { color: var(--muted); margin: 8px 0; }

.picker {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: rgba(0, 0, 0, 0.62);
}

.picker[hidden] { display: none; }

.picker-card {
  width: min(760px, 100%);
  max-height: min(640px, calc(100vh - 48px));
  display: flex;
  flex-direction: column;
  background: #1a1a1a;
  border: 1px solid #3a3a3a;
  border-radius: 4px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}

.picker-tools,
.picker-head,
.picker-foot { flex: 0 0 auto; }

.picker-tools { padding: 12px 12px 8px; }

.picker-tools input {
  display: block;
  width: 100%;
  height: 34px;
  padding: 6px 10px;
  background: #111;
  border: 1px solid #4a4a4a;
  border-radius: 3px;
  color: #eee;
}

.picker-table {
  overflow: auto;
  flex: 1;
  min-height: 180px;
}

.picker-head,
.pick-row {
  display: grid;
  grid-template-columns: minmax(180px, 0.9fr) minmax(0, 1.4fr);
  gap: 12px;
  align-items: center;
}

.picker-head {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 6px 12px;
  background: #242424;
  color: #ddd;
  font-size: 13px;
  font-weight: 650;
}

.picker-sort {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 650;
  text-align: left;
  cursor: pointer;
}

.pick-row {
  width: 100%;
  padding: 6px 12px;
  border: 0;
  border-bottom: 1px solid #2a2a2a;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.pick-row:hover,
.pick-row.selected { background: #2c2c2c; }

.pick-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: #f0d070;
  font-weight: 650;
}

.pick-name img,
.pick-name .fallback,
.pick-name .socket {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 3px;
}

.pick-desc {
  color: #c8c8c8;
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.picker-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid #333;
  color: #aaa;
  font-size: 13px;
}

.picker-close {
  background: transparent;
  border: 0;
  color: #ddd;
  cursor: pointer;
  padding: 4px 2px;
}

.picker-close:hover { color: var(--gold); }

.tip {
  position: fixed;
  z-index: 40;
  width: min(360px, calc(100vw - 24px));
  padding: 10px 12px;
  background: #1a120e;
  border: 1px solid var(--gold-dim);
  border-radius: 6px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.tip h3 { margin: 0 0 4px; font-size: 15px; color: var(--gold); }
.tip .sub { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.tip .meta { margin: 0; padding: 0; list-style: none; color: #f0d7a4; font-size: 12px; }
.tip .desc { margin: 8px 0 0; white-space: pre-wrap; }
.tip .next { margin-top: 8px; color: var(--muted); white-space: pre-wrap; }
.tip .why { margin: 8px 0 0; color: #e7a2a2; font-size: 12px; }

@media (max-width: 1100px) {
  .stage { grid-template-columns: 1fr; }
  .trees { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search { margin-left: 0; }
  .cat-board { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cat { grid-column: auto; }
}

@media (max-width: 720px) {
  body { background-attachment: scroll; }
  .page { padding: 10px 10px 32px; }
  .chrome { gap: 10px; padding: 10px; }
  .class-name { width: 100%; margin-right: 0; }
  .classes { width: 100%; }
  .level { width: 100%; }
  .level input[type="range"] { flex: 1; width: auto; min-width: 0; }
  .level input[type="number"],
  .search input { font-size: 16px; }
  .points { min-width: 0; width: 100%; }
  .reset { flex: 1; }
  .search { width: 100%; }
  .search input { width: 100%; }
  .trees { grid-template-columns: 1fr; }
  .spell-grid { grid-template-columns: 1fr; }
  .cat-board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cat { grid-column: auto; }
  .picker { padding: 12px 8px; }
  .picker-head, .pick-row { grid-template-columns: 1fr; }
  .picker-head span { display: none; }
  .grid { max-width: 100%; }
  .cell {
    -webkit-touch-callout: none;
    user-select: none;
  }
  .cell, .class-btn, .spec-card, .spell, .reset, .tree-reset, .glyph-slot, .pick-row {
    touch-action: pan-y;
    -webkit-tap-highlight-color: transparent;
  }
  .rank {
    min-width: 28px;
    padding: 1px 4px;
    font-size: 11px;
    text-align: center;
  }
}
