/* The Skill Builder page. It sits on the site's own styles.css and uses its
   colours (the game's menu palette), so it only adds what the builder needs.
   This file lives in the game's repository, in Tools/SkillTreeSite/page/, and
   is copied into the site by Tools/SkillTreeSite/build.py: change it there.

   The site's `.panel p` rule sets every paragraph in a panel, so a paragraph
   of the builder's is styled as `.skills-page p.<class>` to have its say. */

.skills-page .page-shell--wide {
  width: min(1280px, calc(100% - 32px));
}

/* ---- The head of the page ------------------------------------------------ */

.builder-head {
  display: grid;
  grid-template-columns: minmax(120px, 200px) 1fr auto;
  gap: 20px 28px;
  align-items: center;
  padding: 8px 4px 24px;
}

.builder-head__home img {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 14px rgba(0, 0, 0, 0.7)) drop-shadow(0 0 16px rgba(255, 191, 72, 0.16));
}

.builder-head__text .hero__eyebrow {
  margin-bottom: 6px;
}

.builder-head__text h1 {
  margin: 0 0 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 3.4vw, 2.6rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--title);
  text-shadow: 0 0 18px rgba(255, 191, 72, 0.18);
}

.builder-head__text p:last-child {
  margin: 0;
  max-width: 62ch;
  color: var(--header-text);
  line-height: 1.6;
}

.builder-head__links {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.builder-head__back {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
}

/* ---- Buttons ------------------------------------------------------------- */

.btn {
  appearance: none;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--warm-glow);
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid rgba(246, 192, 66, 0.4);
  background: linear-gradient(180deg, rgba(94, 73, 38, 0.55), rgba(43, 34, 23, 0.85));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.btn:hover,
.btn:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(255, 191, 72, 0.85);
  box-shadow: 0 0 22px rgba(255, 139, 61, 0.25);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
  box-shadow: none;
}

.btn--primary {
  color: #0b0805;
  border-color: rgba(255, 191, 72, 0.85);
  background: linear-gradient(180deg, var(--warm-glow), var(--lower-glow));
  box-shadow: 0 0 18px rgba(255, 139, 61, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.btn--quiet {
  color: var(--muted);
  border-color: var(--panel-border-dim);
  background: transparent;
}

/* ---- The builder's bar and its tabs --------------------------------------- */

.builder {
  padding: 20px 20px 18px;
}

.builder__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  margin-bottom: 14px;
}

.builder__points {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 12px;
}

.builder__points-label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.builder__points-value {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.5rem;
  color: var(--title);
}

.builder__points.is-full .builder__points-value {
  color: var(--lower-glow);
}

.builder__level {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(246, 192, 66, 0.32);
  background: rgba(255, 191, 72, 0.08);
  color: var(--title);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.builder__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.builder__tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.tab {
  --tree-lit: rgb(230, 230, 230);
  appearance: none;
  font: inherit;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--panel-border-dim);
  border-bottom-width: 3px;
  background: var(--slot-fill);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.tab:hover,
.tab:focus-visible {
  color: var(--header-text);
  border-color: var(--panel-border);
}

.tab[aria-selected="true"] {
  color: var(--title);
  border-color: var(--panel-border);
  border-bottom-color: var(--tree-lit);
  background: var(--slot-inner);
}

.tab__points {
  min-width: 2.2em;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  color: var(--muted);
  font-size: 0.74rem;
  text-align: center;
}

.tab__points.has-points {
  color: var(--title);
}

/* ---- A tree ---------------------------------------------------------------
   The game lays a tree out on a grid (SkillTreeData.GridColumns x GridRows)
   and so does this: --pitch is one cell, and every size follows from it. Each
   tree has the colour its links wear in the game: dim when locked, brighter
   out of a learned skill, lit once the skill at the end is learned. */

.tree-frame {
  position: relative;
}

.tree-scroll {
  container-type: inline-size;
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--slot-border);
  background: rgba(0, 0, 0, 0.55);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.6);
}

.tree,
.tab {
  --tree-dim: rgb(51, 51, 51);
  --tree-frontier: rgb(115, 115, 115);
  --tree-lit: rgb(230, 230, 230);
  --tree-title: rgb(172, 172, 172);
}

[data-tree="combat"] {
  --tree-dim: rgb(56, 0, 0);
  --tree-frontier: rgb(125, 0, 0);
  --tree-lit: rgb(250, 0, 0);
  --tree-title: rgb(180, 89, 89);
}

[data-tree="white-magic"] {
  --tree-dim: rgb(84, 84, 84);
  --tree-frontier: rgb(190, 190, 190);
  --tree-lit: rgb(255, 255, 255);
  --tree-title: rgb(226, 226, 226);
}

[data-tree="black-magic"] {
  --tree-dim: rgb(60, 60, 60);
  --tree-frontier: rgb(135, 135, 135);
  --tree-lit: rgb(255, 255, 255);
  --tree-title: rgb(187, 187, 187);
}

.tree {
  --cols: 24;
  --rows: 12;
  --pitch: 40px;
  --pitch: clamp(34px, calc(100cqw / var(--cols)), 52px);
  position: relative;
  width: calc(var(--pitch) * var(--cols));
  height: calc(var(--pitch) * var(--rows));
  margin: 0 auto;
}

.skills-page p.tree__title {
  position: absolute;
  left: calc(var(--pitch) * 0.4);
  top: calc(var(--pitch) * 0.3);
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: calc(var(--pitch) * 0.56);
  line-height: 1.05;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tree-title);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.85);
  white-space: pre-line;
  pointer-events: none;
}

.tree__links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.link {
  stroke: var(--tree-dim);
  stroke-width: 0.1;
}

.link--frontier {
  stroke: var(--tree-frontier);
}

.link--lit {
  stroke: var(--tree-lit);
}

.link-shadow {
  stroke: rgba(0, 0, 0, 0.6);
  stroke-width: 0.1;
}

.node {
  appearance: none;
  position: absolute;
  left: calc(var(--pitch) * (var(--col) + 0.5));
  top: calc(var(--pitch) * (var(--row) + 0.5));
  width: calc(var(--pitch) * 0.78);
  height: calc(var(--pitch) * 0.78);
  transform: translate(-50%, -50%);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.node:focus-visible {
  outline: 2px solid var(--warm-glow);
  outline-offset: 5px;
}

/* A skill the player uses has a square icon; a passive's is a diamond. What
   is drawn behind an icon takes the icon's shape. */
.node__glow,
.node__select,
.node__rim {
  position: absolute;
  left: 50%;
  top: 50%;
  display: none;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.node--passive .node__select,
.node--passive .node__rim {
  transform: translate(-50%, -50%) rotate(45deg);
}

/* Available: a soft ember glow, the one thing that moves. */
.node__glow {
  width: 290%;
  height: 290%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 191, 72, 0.55), rgba(255, 191, 72, 0.18) 55%, transparent);
  animation: node-glow 1.6s ease-in-out infinite;
}

.node--passive .node__glow {
  width: 208%;
  height: 208%;
}

.node.is-available .node__glow {
  display: block;
}

@keyframes node-glow {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Selected: a solid plate in the selection gold, used for nothing else. */
.node__select {
  width: 125%;
  height: 125%;
  background: var(--title);
}

.node--passive .node__select {
  width: 90%;
  height: 90%;
}

.node.is-selected .node__select {
  display: block;
}

/* Learned: a rim in the tree's lit colour, so owned skills and lit links read as one. */
.node__rim {
  width: 112%;
  height: 112%;
  background: var(--tree-lit);
}

.node--passive .node__rim {
  width: 80%;
  height: 80%;
}

.node.is-learned .node__rim {
  display: block;
}

.icon {
  display: block;
  background-image: var(--icon-sheet);
  background-repeat: no-repeat;
}

/* Unlearned skills are dimmed, as the game dims them; a little less here,
   where the dark trees have no lit screen behind them. */
.node__icon {
  position: absolute;
  inset: 0;
  filter: brightness(0.62) drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.6));
}

.node:hover .node__icon {
  filter: brightness(0.85) drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.6));
}

.node.is-learned .node__icon {
  filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.6));
}

.node.is-learned:hover .node__icon {
  filter: brightness(1.15) drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.6));
}

/* The name over the skill under the pointer. */
.node-label {
  position: absolute;
  z-index: 4;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: rgba(10, 8, 6, 0.94);
  color: var(--header-text);
  font-size: 0.82rem;
  white-space: nowrap;
  pointer-events: none;
}

.node-label span {
  color: var(--title);
}

/* ---- A skill's details ---------------------------------------------------- */

.detail {
  position: absolute;
  z-index: 5;
  width: min(360px, calc(100% - 16px));
  padding: 16px 16px 14px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, var(--panel-fill-mini), var(--panel-fill));
  box-shadow: 0 18px 44px var(--shadow), 0 0 22px rgba(255, 191, 72, 0.08);
}

.detail__head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-right: 30px;
}

.detail__icon {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--slot-border);
  background: var(--slot-fill);
}

.detail__icon .icon {
  width: 100%;
  height: 100%;
}

.detail__name {
  margin: 0 0 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  color: var(--title);
}

.skills-page p.detail__kind {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.skills-page p.detail__kind b {
  margin-left: 10px;
  color: rgb(96, 164, 255);
  font-weight: 700;
}

.detail__close {
  appearance: none;
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--panel-border-dim);
  background: var(--slot-fill);
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.detail__close:hover,
.detail__close:focus-visible {
  color: var(--title);
  border-color: var(--panel-border);
}

.skills-page p.detail__text {
  margin: 14px 0 0;
  color: var(--body);
  line-height: 1.6;
  font-size: 0.95rem;
}

.skills-page p.detail__note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.skills-page p.detail__note b {
  color: var(--header-text);
}

.skills-page p.detail__note--locked {
  color: var(--lower-glow);
}

/* A clip is square, and takes its room before it has loaded, so the details
   are placed once and don't grow under the pointer. */
.detail__clip {
  display: block;
  width: 100%;
  max-width: 240px;
  height: auto;
  aspect-ratio: 1 / 1;
  margin: 14px auto 0;
  border-radius: 8px;
  border: 1px solid var(--slot-border);
  background: #000;
  image-rendering: pixelated;
}

.skills-page p.detail__cost {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--panel-border-dim);
  color: var(--muted);
  font-size: 0.9rem;
}

.skills-page p.detail__cost b {
  color: var(--title);
}

.skills-page p.detail__cost .is-short {
  color: rgb(232, 96, 80);
}

.detail__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

/* ---- Under the trees ------------------------------------------------------ */

.skills-page p.builder__hint,
.skills-page p.builder__noscript,
.skills-page p.saved__note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.skills-page p.summary__empty {
  color: var(--muted);
}

.summary__totals {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.summary__total {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-border-dim);
  background: var(--slot-fill);
  color: var(--body);
  font-size: 0.84rem;
}

.summary__total b {
  color: var(--positive);
}

.summary__total--points b {
  color: var(--title);
}

.summary__tree + .summary__tree {
  margin-top: 16px;
}

.summary__tree h3 {
  margin: 0 0 8px;
  font-size: 0.86rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--header-text);
}

.summary__tree h3 span {
  margin-left: 8px;
  color: var(--title);
}

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

.chip {
  appearance: none;
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border-radius: 8px;
  border: 1px solid var(--slot-border);
  background: var(--slot-fill);
  color: var(--body);
  font-size: 0.86rem;
  cursor: pointer;
}

.chip:hover,
.chip:focus-visible {
  border-color: var(--panel-border);
  color: var(--title);
}

.chip .icon {
  width: 28px;
  height: 28px;
}

.saved__form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.saved__form input {
  flex: 1 1 220px;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--panel-border-dim);
  background: var(--slot-fill);
  color: var(--header-text);
  font: inherit;
}

.saved__form input:focus-visible {
  outline: none;
  border-color: var(--warm-glow);
}

.saved__list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.saved__item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--slot-border);
  background: var(--slot-fill);
}

.saved__name {
  color: var(--header-text);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.saved__meta {
  margin-left: 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 400;
}

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

.saved__buttons .btn {
  padding: 7px 12px;
  font-size: 0.72rem;
}

.skill-list__trees {
  display: grid;
  gap: 8px;
}

.skill-list__tree {
  border-radius: 10px;
  border: 1px solid var(--slot-border);
  background: var(--slot-fill);
}

.skill-list__tree summary {
  padding: 12px 16px;
  color: var(--header-text);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.skill-list__tree summary span,
.skill-list__tree dt span {
  margin-left: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

.skill-list__tree dl {
  margin: 0;
  padding: 0 16px 14px;
}

.skill-list__tree dt {
  margin-top: 12px;
  color: var(--title);
  font-weight: 700;
}

.skill-list__tree dd {
  margin: 4px 0 0;
  color: var(--body);
  line-height: 1.6;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(560px, calc(100% - 32px));
  padding: 10px 18px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: rgba(10, 8, 6, 0.96);
  line-height: 1.45;
  overflow-wrap: anywhere;
  color: var(--header-text);
  font-size: 0.9rem;
  box-shadow: 0 12px 30px var(--shadow);
}

@media (prefers-reduced-motion: reduce) {
  .node__glow {
    animation: none;
  }

  .btn {
    transition: none;
  }
}

@media (max-width: 860px) {
  .builder-head {
    grid-template-columns: minmax(90px, 140px) 1fr;
  }

  .builder-head__links {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

@media (max-width: 720px) {
  .skills-page .page-shell--wide {
    width: min(100% - 20px, 1280px);
  }

  .builder {
    padding: 16px 12px 14px;
  }

  .builder__actions .btn {
    flex: 1 1 auto;
  }

  /* On a small screen the details come up from the bottom, clear of the tree. */
  .detail {
    position: fixed;
    left: 8px !important;
    right: 8px;
    top: auto !important;
    bottom: 8px;
    width: auto;
    max-height: 72vh;
    overflow-y: auto;
  }

  .toast {
    bottom: auto;
    top: 16px;
  }
}
