/* Layout: a settings list on the left, the save on the right (sticky panel).
   On phones the save follows the settings and a docked bar keeps Download in reach.
   Night elf theme, one deliberate night look: indigo-violet night, moonlight-silver text,
   moonwell teal as the only action colour, Elune violet for quiet highlights.
   Rarity colours only mean rarity. */
:root {
  /* Sampled from the hero painting */
  --bg: #0a0e26;          /* navy night */
  --surface: #121738;     /* settings list */
  --raised: #1d2356;      /* selected segment, hover */
  --ink: #e6e8f8;         /* moonlight */
  --muted: #9ea4cf;       /* misty lavender */
  --rule: #262d63;
  --accent: #4fe6dc;      /* moonwell */
  --accent-ink: #0a0e26;
  --violet: #8f7dff;      /* indigo roofs */
  --lantern: #f5b75c;     /* lantern light, small touches only */
  --ok: #4fe6dc;
  --warn: #f5b75c;

  --panel: #151b47;
  --panel-ink: #eceefb;
  --panel-muted: #a3a9d4;
  --panel-rule: #2c3470;

  --rc: #d9d7e8;
  --ru: #4ade5a;
  --rr: #5ea2ff;
  --re: #c084fc;
  --rp: #8b5cf6;          /* PvP is purple in the game too: deeper than Epic so the chips differ */
  --rl: #ff9a3c;

  --display: 'Cormorant', 'Cormorant Garamond', Georgia, serif;
  --font: 'Schibsted Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  color-scheme: dark;
}

.r-c { --r: var(--rc); }
.r-u { --r: var(--ru); }
.r-r { --r: var(--rr); }
.r-e { --r: var(--re); }
.r-l { --r: var(--rl); }
.r-p { --r: var(--rp); }

* { box-sizing: border-box; }

html { background: var(--bg); }
body {
  position: relative;
  margin: 0;
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  -webkit-font-smoothing: antialiased;
}

/* Elven tree city behind the top of the page. The painting's left side is empty mist,
   so the headline sits there; the city stays visible on the right, fading into the night. */
body::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 820px;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(180deg, #0a0e2666 0%, transparent 20%, transparent 55%, var(--bg) 92%),
    linear-gradient(90deg, #0a0e2699 0%, #0a0e2640 45%, transparent 60%),
    /* Anchored left and at least 1780px wide, so the empty mist (left 40%) sits under the text */
    url('images/hero-tree-city.jpg') left top / max(100%, 1780px) auto no-repeat,
    var(--bg);
}

.framed { position: relative; }

.wrap { max-width: 1080px; margin-inline: auto; }

h1, h2, p { margin: 0; }
code { font-family: var(--mono); font-size: 0.875em; }
b { font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Header */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: 20px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}
/* Crescent moon mark, drawn with a shadow */
.brand::before {
  content: '';
  width: 16px; height: 16px;
  border-radius: 50%;
  box-shadow: inset 5px -2px 0 0 #dcdaf2;
  transform: rotate(-20deg);
  filter: drop-shadow(0 0 6px #a98bff80);
}

/* Intro */
.intro { padding-block: 72px 88px; max-width: 600px; }
h1 {
  font-family: var(--display);
  font-size: clamp(3.25rem, 7vw + 1rem, 6rem);
  font-weight: 600;
  line-height: 0.9;
  letter-spacing: -0.015em;
  text-shadow: 0 0 48px #a98bff40;
}
.lede {
  margin-top: 26px;
  max-width: 50ch;
  color: var(--muted);
  font-size: 1.1875rem;
  line-height: 1.5;
  text-wrap: pretty;
  text-shadow: 0 1px 12px #0a0e26;
}

.cta { margin-top: 32px; }

/* Workbench: settings + save */
.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 360px);
  gap: 28px;
  align-items: start;
  padding-bottom: 72px;
}

.config-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
h2 { font-family: var(--display); font-size: 1.75rem; font-weight: 600; line-height: 1.1; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }

.group {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
}
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px 24px;
  align-items: center;
  padding: 18px 20px;
}
.row + .row { border-top: 1px solid var(--rule); }
.row-stack { grid-template-columns: minmax(0, 1fr); }
.row-label { display: block; font-size: 1.0625rem; font-weight: 600; }
.row-detail { margin-top: 2px; color: var(--muted); font-size: 0.9375rem; }

/* Switch */
.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 46px; height: 28px;
  margin: 0;
  border-radius: 14px;
  background: var(--rule);
  cursor: pointer;
  transition: background 0.15s;
}
.switch::before {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s, background 0.15s;
}
.switch:checked { background: var(--accent); box-shadow: 0 0 14px #5fe0d255; }
.switch:checked::before { background: var(--accent-ink); }
.switch:checked::before { transform: translateX(18px); }
.row[data-flag] { cursor: pointer; }

/* Rarity chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 12px;
  font: inherit;
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chip .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid var(--r);
  transition: background 0.15s;
}
.chip:hover { border-color: var(--r); }
.chip[aria-pressed="true"] {
  color: var(--r);
  border-color: var(--r);
  background: color-mix(in srgb, var(--r) 10%, var(--surface));
}
.chip[aria-pressed="true"] .dot { background: var(--r); }

/* Zone slider */
.zone-ctl { display: flex; flex-direction: column; gap: 10px; }
.zone-name { display: block; font-size: 1.125rem; font-weight: 700; letter-spacing: -0.01em; }
.zone-name small { display: block; font-size: 0.875rem; font-weight: 500; color: var(--muted); letter-spacing: 0; }
input[type="range"] {
  --p: 0%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) var(--p), var(--rule) var(--p));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--ink);
  border: 3px solid var(--accent);
  box-shadow: 0 0 12px #5fe0d280;
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--rule); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--ink);
  border: 3px solid var(--accent);
}
.ticks {
  display: flex;
  justify-content: space-between;
  padding-inline: 6px;
  margin-top: -6px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
.ticks span { width: 10px; text-align: center; white-space: nowrap; display: flex; justify-content: center; }
.ticks .on { color: var(--ink); font-weight: 600; }
/* Heroic steps after the zones */
.ticks .heroic { color: var(--violet); font-family: var(--display); font-weight: 700; }
.ticks .heroic.on { color: var(--lantern); }
@media (max-width: 520px) {
  .ticks { font-size: 0.6875rem; padding-inline: 4px; }
}

/* Difficulty segmented control */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  width: fit-content;
  max-width: 100%;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 10px;
}
.seg { position: relative; cursor: pointer; }
.seg input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.seg span {
  display: block;
  min-width: 44px;
  padding: 7px 14px;
  border-radius: 7px;
  text-align: center;
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.seg:hover span { color: var(--ink); }
.seg input:checked + span { background: var(--raised); color: var(--violet); box-shadow: inset 0 0 0 1px #a98bff66; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Buttons */
.ghost {
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
}
.ghost:hover { border-color: var(--muted); }
.ghost:disabled { color: var(--muted); opacity: 0.5; cursor: default; border-color: var(--rule); }

.download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 13px 20px;
  font: inherit;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  text-decoration: none;
  cursor: pointer;
  transition: filter 0.15s;
}
.download:hover { filter: brightness(1.08); box-shadow: 0 0 22px #5fe0d266; }
.download.disabled { background: var(--panel-rule); color: var(--panel-muted); cursor: not-allowed; filter: none; }
.download.small { padding: 10px 16px; font-size: 0.9375rem; }

/* The save */
.summary {
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 20px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
  /* A moonwell: teal light pooling at the top of the panel */
  background:
    radial-gradient(120% 55% at 50% 0%, #5fe0d22a, transparent 70%),
    var(--panel);
  color: var(--panel-ink);
  border: 1px solid var(--panel-rule);
  border-radius: 18px;
  box-shadow: inset 0 1px 0 #5fe0d240, 0 30px 70px -30px #5fe0d238;
}
.summary h2 { font-size: 1.5rem; color: var(--panel-ink); }
.filename {
  font-family: var(--mono);
  font-size: 1.0625rem;
  font-weight: 500;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.fn-dim { color: var(--panel-muted); }
.fn-seg { color: var(--panel-ink); }
.fn-seg.gear { color: var(--r); }

.unlocks { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--panel-rule); }
.unlocks li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px solid var(--panel-rule);
  font-size: 0.9375rem;
}
.unlocks .k { color: var(--panel-muted); }
.unlocks .v { text-align: right; font-weight: 600; }
.unlocks .rname { color: var(--r); }
.empty { color: var(--panel-muted); font-size: 0.9375rem; }

.state { font-size: 0.9375rem; }
.state:empty { display: none; }
.state.ready { color: var(--ok); }
.state.missing { color: var(--warn); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .download { flex: 1 1 auto; }
.summary .ghost { color: var(--panel-ink); border-color: var(--panel-rule); }
.summary .ghost:hover { border-color: var(--panel-muted); }
.version { width: 100%; color: var(--panel-muted); font-size: 0.8125rem; }

.howto { font-size: 0.9375rem; color: var(--panel-muted); border-top: 1px solid var(--panel-rule); padding-top: 14px; }
.howto summary { cursor: pointer; color: var(--panel-ink); font-weight: 600; }
.howto ol { margin: 10px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.howto b { color: var(--panel-ink); }

/* FAQ: short, at the bottom */
.faq { max-width: 680px; padding-bottom: 56px; }
.faq h2 { margin-bottom: 8px; }
.faq details { border-bottom: 1px solid var(--rule); }
.faq summary {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-block: 14px;
  list-style: none;
  cursor: pointer;
  font-weight: 600;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary:hover { color: var(--violet); }
.faq summary::after { content: '+'; color: var(--violet); transition: transform 0.15s; }
.faq details[open] summary::after { transform: rotate(45deg); }
.faq p { padding-bottom: 14px; color: var(--muted); }

/* Footer */
.foot { padding-block: 24px 40px; border-top: 1px solid var(--rule); color: var(--muted); font-size: 0.875rem; }
.foot p { max-width: 70ch; }

/* Phone dock */
.dock { display: none; }

@media (max-width: 860px) {
  .intro { padding-block: 24px 28px; }
  .workbench { grid-template-columns: minmax(0, 1fr); padding-bottom: 48px; }
  .summary { position: relative; top: 0; }
  /* Phones: show the city, darkened so the text stays readable */
  body::before {
    height: 720px;
    background:
      linear-gradient(180deg, #0a0e26b3 0%, #0a0e2699 50%, var(--bg) 100%),
      url('images/hero-tree-city.jpg') 72% top / auto 600px no-repeat,
      var(--bg);
  }
  .intro { padding-block: 40px 56px; }
  .row { padding: 16px; }
  .dock {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 20;
    padding: 10px max(16px, env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
    background: var(--panel);
    color: var(--panel-ink);
  }
  .dock-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 0.875rem; }
  .foot { padding-bottom: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
