:root {
  --bg: #15161a;
  --panel: #1f2127;
  --panel-2: #272a32;
  --border: #353945;
  --text: #e6e6e6;
  --muted: #9aa0ab;
  --accent: #d9a441;
  --alliance: #3d6fd1;
  --horde: #c0392b;
  --tank: #5b8def;
  --healer: #3fb27f;
  --dps: #d35d5d;
  --ok: #3fb27f;
  --alliance-bg: linear-gradient(135deg, #1c2536, #1a2130);
  --alliance-border: #2f4570;
  --alliance-text: #8fb3f5;
  --horde-bg: linear-gradient(135deg, #2e1d1f, #271a1c);
  --horde-border: #6a3030;
  --horde-text: #ef8a7c;
  --warn: #e0a030;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select { font: inherit; }
button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 12px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: #1a1a1a; border-color: var(--accent); font-weight: 600; }
button.link { background: none; border: none; color: var(--accent); padding: 4px 0; }
input, select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 8px;
}
.muted { color: var(--muted); }
.error { color: var(--dps); }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 24px; padding: 10px 24px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 17px; margin: 0; color: var(--accent); }
#tabs { display: flex; gap: 4px; }
#tabs a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 6px; }
#tabs a.active { color: var(--text); background: var(--panel-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.lang-switch { display: inline-flex; gap: 2px; }
.lang-switch button { padding: 2px 8px; font-size: 12px; }
#logout { padding: 2px 10px; font-size: 12px; }
.lang-switch button.active { border-color: var(--accent); color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 20px 24px 60px; }

/* controls */
.controls { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.switch-row { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.faction-switch, .size-switch { display: flex; gap: 6px; }
.faction-switch button, .size-switch button { padding: 8px 22px; font-weight: 600; }
.faction-switch button.fac-alliance { border-color: var(--alliance-border); color: var(--alliance-text); }
.faction-switch button.fac-horde { border-color: var(--horde-border); color: var(--horde-text); }
.faction-switch button.active.fac-all { background: #4a4f5c; border-color: #7a8090; color: #fff; }
.faction-switch button.active.fac-alliance { background: var(--alliance); border-color: var(--alliance); color: #fff; }
.faction-switch button.active.fac-horde { background: var(--horde); border-color: var(--horde); color: #fff; }
.size-switch button.active { background: var(--accent); border-color: var(--accent); color: #1a1a1a; }
.player-select { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.player-select .label { color: var(--muted); }
.filter-bar { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
.notice { background: var(--panel); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 4px; }
.counts { font-weight: 600; }

/* cards */
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 16px; margin-bottom: 10px;
}
/* faction styling: subtle colour + emblem watermark + label */
.fcard { position: relative; overflow: hidden; }
.fcard > * { position: relative; }
.fcard::before {
  content: ""; position: absolute; right: 18px; top: 50%; width: 150px; height: 150px; max-height: 90%;
  transform: translateY(-50%); background: center / contain no-repeat; opacity: .09; pointer-events: none;
}
.fcard.fac-alliance { background: var(--alliance-bg); border-color: var(--alliance-border); }
.fcard.fac-horde { background: var(--horde-bg); border-color: var(--horde-border); }
.fcard.fac-alliance::before { background-image: url(/img/alliance.svg); }
.fcard.fac-horde::before { background-image: url(/img/horde.svg); }
.fcard.invalid { border-color: var(--warn); box-shadow: 0 0 0 1px var(--warn) inset; }
.fac-tag { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.fac-alliance .fac-tag, .fac-text-alliance { color: var(--alliance-text); }
.fac-horde .fac-tag, .fac-text-horde { color: var(--horde-text); }
.fblock { border-style: solid; border-width: 1px; border-radius: 6px; padding: 8px 12px; margin-top: 8px; }
.fblock::before { width: 90px; height: 90px; }
.notice.fcard { border-style: solid; border-width: 1px 1px 1px 3px; }
.section-title { font-size: 15px; margin: 18px 0 4px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.card h4 { margin: 8px 0 4px; font-size: 13px; }
.card-head { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; margin-bottom: 8px; }
.rank { font-size: 16px; font-weight: 700; color: var(--accent); }
.status.ok { color: var(--ok); font-weight: 600; }
.status.warn { color: var(--warn); font-weight: 600; }
.score { color: var(--muted); }
.score b { color: var(--text); font-weight: 500; }
.card-actions { display: flex; gap: 8px; margin-top: 10px; }

.opt-list { list-style: none; margin: 0; padding: 0; }
.opt-list li { padding: 3px 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.opt-list li.open-slot { color: var(--muted); font-style: italic; }
.pname { min-width: 90px; font-weight: 600; }
.badge, .role {
  display: inline-block; font-size: 11px; padding: 0 7px; border-radius: 10px; line-height: 18px;
}
.prio-primary { background: var(--accent); color: #1a1a1a; }
.prio-secondary { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.role {
  width: 22px; height: 22px; padding: 0; border-radius: 50%; line-height: 0;
  display: inline-flex; align-items: center; justify-content: center; cursor: help; vertical-align: middle;
}
.role svg { width: 14px; height: 14px; display: block; }
.role-tank { background: var(--tank); }
.role-healer { background: var(--healer); }
.role-dps { background: var(--dps); }

.layouts { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.layout { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 5px 0; border-bottom: 1px dashed var(--border); }
.layout:last-child { border-bottom: none; }

.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 16px; }
.raid-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }

/* option form */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.form-grid label select, .form-grid label input { color: var(--text); }
.spec-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 10px; }
.spec {
  display: block; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  background: var(--panel-2); cursor: pointer;
}
.spec.checked { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.spec-head { display: flex; gap: 8px; align-items: center; }
.spec p { margin: 6px 0 8px; color: var(--muted); font-size: 13px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 80px; gap: 8px; align-items: center; font-size: 12px; margin: 3px 0; }
.bar-label { color: var(--muted); }
.bar-label.right { text-align: left; }
.bar { position: relative; height: 8px; background: #3a3e4a; border-radius: 4px; overflow: hidden; }
.bar .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 4px; }
.bar.range { background: linear-gradient(90deg, #8a5a3a, #3a5a8a); overflow: visible; }
.bar.range .marker {
  position: absolute; top: -3px; width: 4px; height: 14px; margin-left: -2px;
  background: #fff; border-radius: 2px;
}

/* character portraits (public/portrait.js) */
.portrait { display: block; flex: none; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); }
.portrait-large { width: 220px; height: 330px; border-radius: 10px; }
.portrait-small { width: 64px; height: 96px; }
.portrait-empty { background: var(--panel-2) center / 55% no-repeat; }
.portrait-empty.fac-alliance { background-color: #1c2536; background-image: url(/img/alliance.svg); border-color: var(--alliance-border); }
.portrait-empty.fac-horde { background-color: #2e1d1f; background-image: url(/img/horde.svg); border-color: var(--horde-border); }
.portrait-open {
  display: flex; align-items: center; justify-content: center; font-size: 26px; color: var(--muted);
  background: transparent; border-style: dashed;
}
.fac-alliance img.portrait { border-color: var(--alliance-border); }
.fac-horde img.portrait { border-color: var(--horde-border); }

.form-layout { display: grid; grid-template-columns: 1fr 222px; gap: 16px 24px; align-items: start; }
.form-layout .form-portrait { grid-column: 2; grid-row: 1; position: sticky; top: 64px; }
.form-layout .form-main { grid-column: 1; grid-row: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
@media (max-width: 720px) {
  .form-layout { grid-template-columns: 1fr; }
  .form-layout .form-portrait, .form-layout .form-main { grid-column: 1; grid-row: auto; position: static; }
  .form-layout .form-portrait { justify-self: center; }
}

/* icon pickers (faction / gender / race / class) */
.pickers { display: flex; flex-wrap: wrap; gap: 12px 28px; }
.picker { border: none; margin: 0; padding: 0; min-width: 0; }
.picker-race, .picker-class { flex: 1 1 100%; }
.racials { flex: 1 1 100%; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px 10px; }
.racials h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: normal; }
.racial-groups { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 20px; }
.racial-group h5 { margin: 0 0 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.racial-group ul { list-style: none; margin: 0; padding: 0; }
.racial-group li { font-size: 13px; line-height: 1.35; margin: 3px 0; }
@media (max-width: 560px) { .racial-groups { grid-template-columns: 1fr; } }
.picker legend { padding: 0; margin-bottom: 6px; color: var(--muted); }
.picker-hint { margin: 0; font-size: 13px; min-height: 40px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  position: relative; width: 84px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 5px 4px 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2);
  cursor: pointer; text-align: center; user-select: none;
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.choice input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.choice-icon { width: 58px; height: 58px; border-radius: 6px; display: block; filter: saturate(.65) brightness(.85); transition: filter .12s; }
.choice-name { font-size: 11px; line-height: 1.25; color: var(--muted); }
@media (max-width: 480px) {
  .choice { width: 72px; }
  .choice-icon { width: 50px; height: 50px; }
}
.choice:hover { border-color: #5a6070; transform: translateY(-1px); }
.choice:hover .choice-icon { filter: none; }
.choice.selected, .choice:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset, 0 0 10px rgba(217, 164, 65, .25); }
.choice.selected .choice-icon, .choice:has(input:checked) .choice-icon { filter: none; }
.choice.selected .choice-name, .choice:has(input:checked) .choice-name { color: var(--text); font-weight: 600; }
.choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
/* faction tiles: crest on the faction colour */
.picker-faction .choice-icon { padding: 7px; object-fit: contain; }
.picker-faction .choice.fac-alliance .choice-icon { background: radial-gradient(#3a5a9c, #141c2c); }
.picker-faction .choice.fac-horde .choice-icon { background: radial-gradient(#9c3a32, #2a1414); }
.picker-faction .choice.fac-alliance.selected { border-color: var(--alliance); box-shadow: 0 0 0 1px var(--alliance) inset, 0 0 10px rgba(61, 111, 209, .35); }
.picker-faction .choice.fac-horde.selected { border-color: var(--horde); box-shadow: 0 0 0 1px var(--horde) inset, 0 0 10px rgba(192, 57, 43, .35); }

.party { display: flex; flex-wrap: wrap; gap: 10px; margin: 4px 0 10px; }
.party-member { margin: 0; width: 64px; text-align: center; font-size: 11px; color: var(--muted); }
.party-member figcaption { margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.party-member:not(.open) figcaption { color: var(--text); font-weight: 600; }

.with-portrait { display: flex; gap: 14px; align-items: flex-start; }
.with-portrait-body { flex: 1; min-width: 0; }

/* login */
.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 28px; width: 320px; display: flex; flex-direction: column; gap: 14px;
}
.login-box h1 { font-size: 18px; margin: 0 0 4px; color: var(--accent); }
.login-box label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.login-box .lang-switch { justify-content: center; }
