:root {
  --bg: #0d0b09;
  --bg-2: #13100d;
  --panel: #191510;
  --panel-2: #211b14;
  --line: #3a2f22;
  --line-soft: #2a2219;
  --gold: #c8a35f;
  --gold-bright: #e9c983;
  --text: #ece4d4;
  --muted: #9d9180;
  --faint: #6f6556;
  --ok: #5fd38a;
  --next: #f2c14e;
  --open: #8a7a5c;
  --bad: #e0574f;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 600px at 50% -200px, rgba(200, 163, 95, 0.10), transparent 70%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .brand, .ring-label { font-family: Cinzel, Georgia, serif; letter-spacing: 0.02em; }
h1 { font-size: 26px; margin: 0; font-weight: 700; color: var(--gold-bright); }
h2 { font-size: 18px; margin: 0 0 12px; color: var(--gold); font-weight: 700; }
h3 { font-size: 15px; margin: 0 0 8px; color: var(--gold); }
a { color: var(--gold-bright); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.container { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: rgba(13, 11, 9, 0.88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line-soft);
}
.brand { text-decoration: none; display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--gold-bright); white-space: nowrap; }
.brand-mark {
  width: 22px; height: 22px; flex: none;
  background: var(--gold);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  box-shadow: inset 0 0 0 5px var(--bg);
}
.topbar-actions { display: flex; gap: 8px; align-items: center; min-width: 0; }
.topbar select { max-width: 46vw; }

/* ---------- Controls ---------- */
.btn {
  appearance: none; cursor: pointer;
  border: 1px solid var(--gold); color: var(--bg); background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  padding: 9px 16px; border-radius: 8px; font: 600 14px Inter, sans-serif;
  transition: filter .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: transparent; color: var(--gold-bright); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--gold); }
.btn-small { padding: 6px 10px; font-size: 13px; }
input, select, textarea {
  width: 100%;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; font: 14px Inter, sans-serif;
}
textarea { min-height: 90px; resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(200, 163, 95, 0.15); }
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 8px; align-items: stretch; }
.row > input { flex: 1; min-width: 0; }

/* ---------- Panels ---------- */
.panel {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 16px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.notice { border-left: 3px solid var(--next); background: rgba(242, 193, 78, 0.07); padding: 10px 12px; border-radius: 6px; font-size: 14px; margin: 12px 0; }
.notice.error { border-color: var(--bad); background: rgba(224, 87, 79, 0.08); }
.notice.ok { border-color: var(--ok); background: rgba(95, 211, 138, 0.07); }

/* ---------- Setup ---------- */
.setup { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.setup-head { grid-column: 1 / -1; }
.setup .panel + .panel { margin-top: 0; }
.step-no { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--gold); color: var(--gold-bright); font: 700 13px Cinzel, serif; margin-right: 8px; }
.done-badge { color: var(--ok); font-size: 13px; }
.bookmarklet {
  display: inline-block; padding: 7px 12px; border-radius: 8px;
  border: 1px dashed var(--gold); color: var(--gold-bright); text-decoration: none; font-weight: 600; font-size: 13px;
}
details summary { cursor: pointer; color: var(--gold-bright); font-size: 14px; }
details[open] summary { margin-bottom: 10px; }

/* ---------- Dashboard ---------- */
.hero { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; justify-content: space-between; margin-bottom: 16px; }
.hero-sub { color: var(--muted); margin-top: 2px; }
.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stage-bar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 16px; }
.stage-bar select { width: auto; min-width: 260px; max-width: 100%; }
.badge { display: inline-block; font-size: 12px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.auto { color: var(--ok); border-color: rgba(95, 211, 138, .4); }
.badge.suggest { color: var(--next); border-color: rgba(242, 193, 78, .4); }

.rings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.ring-card { display: flex; gap: 14px; align-items: center; padding: 14px; cursor: pointer; text-align: left; color: inherit; font: inherit; }
.ring-card:hover { border-color: var(--gold); }
.ring-card.active { border-color: var(--gold); box-shadow: var(--shadow), 0 0 0 1px var(--gold) inset; }
.ring { width: 64px; height: 64px; flex: none; }
.ring circle { fill: none; stroke-width: 7; }
.ring .track { stroke: var(--line-soft); }
.ring .bar { stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset .6s ease; }
.ring text { fill: var(--text); font: 700 15px Inter, sans-serif; text-anchor: middle; dominant-baseline: central; }
.ring-label { font-size: 14px; color: var(--gold-bright); font-weight: 700; }
.ring-detail { font-size: 12px; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.next-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.next-list li { display: grid; grid-template-columns: 22px 1fr; gap: 8px; align-items: start; font-size: 14px; }
.next-icon { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--bg); }
.next-icon.tree { background: var(--next); }
.next-icon.gem { background: #7fb4ff; }
.next-icon.gear { background: var(--gold); }
.next-icon.ms { background: var(--ok); }
.next-icon.bad { background: var(--bad); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tab { appearance: none; background: none; border: none; color: var(--muted); padding: 10px 14px; cursor: pointer; font: 600 14px Inter, sans-serif; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--gold-bright); border-bottom-color: var(--gold); }

/* Tree */
.tree-wrap { position: relative; height: min(68vh, 640px); border-radius: 8px; overflow: hidden; background: radial-gradient(circle at 50% 50%, #1a150f, #0b0907 75%); border: 1px solid var(--line-soft); }
.tree-wrap canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.tree-wrap canvas:active { cursor: grabbing; }
.tree-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; }
.tree-tools .btn { padding: 6px 10px; }
.tree-hint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: rgba(16, 13, 10, 0.92); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 13px; color: var(--muted); pointer-events: none; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; background: var(--c); }
.tooltip {
  position: absolute; z-index: 2; max-width: 300px; pointer-events: none;
  background: rgba(16, 13, 10, 0.96); border: 1px solid var(--gold); border-radius: 8px;
  padding: 10px 12px; font-size: 13px; box-shadow: var(--shadow);
}
.tooltip strong { color: var(--gold-bright); display: block; margin-bottom: 2px; }
.tt-status { font-size: 12px; margin-bottom: 6px; }
.st-owned { color: var(--ok); } .st-next { color: var(--next); } .st-missing { color: #c8b48a; } .st-extra { color: var(--bad); } .st-none { color: var(--faint); }

/* Skills */
.gem-groups { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.gem-group { padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); }
.gem-group.done { border-color: rgba(95, 211, 138, .45); }
.gem { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; padding: 3px 0; }
.gem.active { font-weight: 600; color: var(--gold-bright); }
.gem .state { font-size: 12px; white-space: nowrap; }
.state.ok { color: var(--ok); } .state.tier, .state.elsewhere, .state.close { color: var(--next); } .state.missing, .state.low { color: var(--bad); }

/* Gear */
.gear-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.gear-slot { padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); }
.gear-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; margin-bottom: 6px; }
.gear-head .slot { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.gear-head .pct { font-weight: 700; }
.item-name { font-weight: 600; }
.item-name.unique { color: #d9884a; }
.item-name.rare { color: #e9d36c; }
.item-have { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.mod { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 2px 0; border-top: 1px dashed var(--line-soft); }
.mod:first-of-type { border-top: none; }
.mod .must { color: var(--gold); font-size: 11px; margin-left: 4px; }
.bar { height: 5px; border-radius: 3px; background: var(--line-soft); overflow: hidden; margin: 4px 0 8px; }
.bar > i { display: block; height: 100%; background: var(--gold); }

/* Milestones */
.ms-list { display: grid; gap: 10px; }
.ms { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); }
.ms-check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--faint); display: grid; place-items: center; font-size: 12px; color: var(--bg); }
.ms.done .ms-check { background: var(--ok); border-color: var(--ok); }
.ms.part .ms-check { border-color: var(--next); }

/* Dialog & toast */
.dialog { width: min(560px, calc(100vw - 32px)); border: 1px solid var(--gold); border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 20px; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--gold); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 50; max-width: calc(100vw - 32px); }

.empty { text-align: center; padding: 40px 16px; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .rings { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .setup { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) {
  .ring-label { font-size: 13px; }
  .panel { padding: 14px; }
  .tree-wrap { height: 62vh; }
  .ring-card { padding: 10px; gap: 10px; }
  .ring { width: 52px; height: 52px; }
  h1 { font-size: 22px; }
  .brand { font-size: 16px; }
  #newPairBtn { padding: 8px 10px; }
  .stage-bar select { min-width: 0; width: 100%; }
}

/* History */
.linklike { appearance: none; background: none; border: none; padding: 0; color: var(--gold-bright); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.charts { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.chart-card { padding: 12px 12px 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); min-width: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chart-title { font: 700 14px Cinzel, serif; color: var(--gold); }
.chart-value { font-weight: 700; font-size: 18px; color: var(--text); }
.chart-delta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.chart-delta.up::before { content: '▲ '; color: var(--ok); }
.chart-delta.down::before { content: '▼ '; color: var(--bad); }
.chart-plot { position: relative; height: 128px; }
.chart-plot svg { display: block; overflow: visible; }
.chart-plot .grid { stroke: var(--line-soft); stroke-width: 1; }
.chart-plot .axis { fill: var(--faint); font: 11px Inter, sans-serif; }
.chart-plot .crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip { position: absolute; pointer-events: none; background: rgba(16, 13, 10, 0.96); border: 1px solid var(--gold); border-radius: 6px; padding: 4px 8px; font-size: 12px; white-space: nowrap; display: flex; gap: 8px; align-items: baseline; }
.chart-tip span { color: var(--muted); }
.chart-tip[hidden] { display: none; }
.snap-list { display: grid; gap: 10px; }
.snap { padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); }
.snap-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.snap-del { margin-left: auto; }
.snap-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 10px 0 8px; }
.snap-stats div { background: var(--panel); border: 1px solid var(--line-soft); border-radius: 6px; padding: 4px 8px; }
.snap-stats dt { font-size: 11px; color: var(--muted); }
.snap-stats dd { margin: 0; font-weight: 700; }
.snap-changes { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.snap-stats dt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Topbar (Party) */
.topbar .btn-ghost.active { border-color: var(--gold); color: var(--gold-bright); background: rgba(200, 163, 95, 0.08); }
.topbar select { width: auto; padding: 6px 10px; font-size: 13px; }
.account { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.account::before { content: '●'; color: var(--ok); margin-right: 6px; font-size: 10px; vertical-align: 1px; }

/* Join */
.join { max-width: 460px; margin: 6vh auto 0; }
.join h1 { margin-bottom: 4px; }
.join form { margin-top: 18px; }

/* Party */
.faint { color: var(--faint); }
.up { color: var(--ok); }
.down { color: var(--bad); }
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.board-row {
  width: 100%; text-align: left; cursor: pointer; color: inherit; font: inherit;
  display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; grid-template-areas: "rank who score" "rank minis minis" "rank updated updated";
  gap: 6px 12px; align-items: start;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2);
}
.board-row:hover { border-color: var(--gold); }
.board-row.mine { box-shadow: inset 3px 0 0 var(--gold); }
.rank { grid-area: rank; font: 700 20px Cinzel, serif; color: var(--gold); text-align: center; padding-top: 2px; }
.who { grid-area: who; display: grid; min-width: 0; }
.who > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score { grid-area: score; display: grid; justify-items: end; }
.score-value { font: 700 22px Inter, sans-serif; color: var(--gold-bright); line-height: 1.1; }
.minis { grid-area: minis; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.mini { display: grid; grid-template-columns: 1fr auto; gap: 2px 6px; font-size: 11px; color: var(--muted); }
.mini b { color: var(--text); font-weight: 600; }
.mini-bar { grid-column: 1 / -1; height: 4px; background: var(--line-soft); border-radius: 2px; overflow: hidden; }
.mini-bar i { display: block; height: 100%; background: var(--gold); border-radius: 2px; }
.updated { grid-area: updated; }
.invite { display: grid; gap: 6px; margin: 10px 0; }
.invite code { display: block; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-2); font: 13px ui-monospace, Menlo, monospace; overflow-wrap: anywhere; }
.invite-code { color: var(--gold-bright); font-weight: 700; letter-spacing: .06em; }
.players { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.notice.viewing { border-color: #7fb4ff; background: rgba(127, 180, 255, 0.07); margin-top: 0; }

@media (max-width: 560px) {
  .brand-text { display: none; }
  .account { font-size: 0; padding: 6px 10px; }
  .account::before { font-size: 12px; margin: 0; }
  .minis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar select { max-width: 38vw; }
}

/* Charaktere verwalten / löschen */
.btn.danger { color: var(--bad); border-color: rgba(224, 87, 79, 0.45); }
.btn.danger:hover { border-color: var(--bad); background: rgba(224, 87, 79, 0.08); }
.char-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; }
.char-list li { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); }
.char-actions { display: flex; gap: 6px; }
.remove-option { display: flex; gap: 14px; align-items: center; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--line-soft); }
.remove-option .hint { margin: 2px 0 0; }
.remove-option .btn { flex: none; }
@media (max-width: 480px) { .remove-option { flex-direction: column; align-items: stretch; } }
