:root {
  --bg: #0d1014;
  --surface: #15191f;
  --surface-2: #1d222a;
  --line: #303741;
  --line-soft: #252b33;
  --text: #f5f2e9;
  --muted: #98a2af;
  --gold: #f2bf52;
  --cyan: #56bac8;
  --green: #5ec487;
  --red: #e06d72;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--bg);
  font-family: Bahnschrift, "Aptos Display", "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { letter-spacing: 0; }
.hidden { display: none !important; }

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: 0 max(22px, calc((100vw - 1240px) / 2));
  border-bottom: 1px solid var(--line-soft);
  background: rgba(13,16,20,.94);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 11px; color: var(--text); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid #7d6636; border-radius: 7px; color: var(--gold); background: #211d14; font-weight: 900; }
.brand > span:last-child { display: grid; line-height: 1.05; }
.brand strong { font-size: 16px; text-transform: uppercase; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.appbar nav { display: flex; gap: 4px; margin-left: auto; }
.nav-link { padding: 9px 12px; border-radius: 6px; color: var(--muted); font-size: 12px; font-weight: 700; text-decoration: none; }
.nav-link:hover, .nav-link.active { color: var(--text); background: var(--surface-2); }
.language-switcher { display: inline-flex; flex: 0 0 auto; gap: 2px; margin-left: 12px; padding: 3px; border: 1px solid var(--line); border-radius: 6px; background: #11151a; }
.language-switcher button { min-width: 32px; height: 28px; padding: 0 7px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; font: 800 10px/1 ui-monospace, Consolas, monospace; cursor: pointer; }
.language-switcher button:hover { color: var(--text); }
.language-switcher button.is-active { color: #17130b; background: var(--gold); }

.counter-shell { width: min(1240px, calc(100vw - 36px)); margin: 0 auto; padding: 34px 0 64px; }
.page-intro { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding: 0 2px 26px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 7px; color: var(--gold); font-size: 10px; font-weight: 900; text-transform: uppercase; }
h1, h2, p { margin: 0; }
h1 { font-size: 46px; line-height: 1; letter-spacing: 0; }
h2 { font-size: 18px; }
.page-intro p:last-child, .team-builder-head p, .roster-toolbar p, .results-head p:last-child { margin-top: 7px; color: var(--muted); font-size: 12px; }
.database-stat { padding: 8px 10px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); font: 11px/1 ui-monospace, Consolas, monospace; white-space: nowrap; }

.team-builder { padding: 26px 0 28px; border-bottom: 1px solid var(--line); }
.team-builder-head, .roster-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 16px; }
.team-builder-head > div, .roster-toolbar > div { display: flex; align-items: center; gap: 12px; }
.section-index { color: var(--cyan); font: 800 11px/1 ui-monospace, Consolas, monospace; }
.text-button { padding: 6px 0; border: 0; color: var(--muted); background: transparent; font-size: 11px; cursor: pointer; }
.text-button:hover { color: var(--text); }
.selected-layout { display: grid; grid-template-columns: minmax(480px, 1fr) 210px 170px; align-items: end; gap: 16px; margin-top: 18px; }
.selected-team { display: grid; grid-template-columns: repeat(5, minmax(76px, 1fr)); gap: 8px; }
.team-slot { position: relative; display: grid; justify-items: center; gap: 5px; min-width: 0; height: 116px; padding: 10px 5px 7px; border: 1px solid var(--line); border-radius: 7px; color: var(--text); background: var(--surface); cursor: pointer; }
.team-slot img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gold); }
.team-slot strong { width: 100%; overflow: hidden; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.team-slot:hover { border-color: var(--red); }
.team-slot.is-empty { place-content: center; border-style: dashed; color: #59616c; cursor: default; }
.team-slot.is-empty > span { font: 800 20px/1 ui-monospace, Consolas, monospace; }
.team-slot.is-empty small { font-size: 9px; text-transform: uppercase; }
.slot-number { position: absolute; top: 5px; left: 7px; color: var(--muted); font: 9px/1 ui-monospace, Consolas, monospace; }
.power-field { display: grid; gap: 7px; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.power-field input, .hero-search input { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 6px; outline: none; color: var(--text); background: #11151a; }
.power-field input { padding: 0 12px; font: 700 14px/1 ui-monospace, Consolas, monospace; }
.power-field input:focus, .hero-search input:focus { border-color: var(--cyan); }
.primary-action { height: 44px; border: 1px solid #d6a846; border-radius: 6px; color: #17130b; background: var(--gold); font-weight: 900; cursor: pointer; }
.primary-action:hover:not(:disabled) { background: #ffd06a; }
.primary-action:disabled { opacity: .38; cursor: not-allowed; }
.builder-status { min-height: 16px; margin-top: 9px; color: var(--muted); font-size: 11px; }

.roster { padding-top: 28px; }
.hero-search { display: grid; gap: 6px; width: min(320px, 45vw); color: var(--muted); font-size: 10px; text-transform: uppercase; }
.hero-search input { padding: 0 38px 0 12px; }
.hero-grid { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 8px; margin-top: 18px; }
.hero-tile { position: relative; display: grid; justify-items: center; gap: 5px; min-width: 0; height: 118px; padding: 9px 5px 7px; border: 1px solid var(--line-soft); border-radius: 7px; color: var(--text); background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s, transform .15s; }
.hero-tile:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--cyan); background: var(--surface-2); }
.hero-tile.is-selected { border-color: var(--gold); background: #211d14; }
.hero-tile:disabled { opacity: .35; cursor: not-allowed; }
.hero-tile img { width: 66px; height: 66px; border-radius: 50%; object-fit: cover; }
.hero-tile strong, .hero-tile small { width: 100%; overflow: hidden; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.hero-tile strong { font-size: 10px; }
.hero-tile small { color: var(--muted); font-size: 8px; }
.hero-position { position: absolute; top: 5px; left: 6px; color: #66707c; font: 8px/1 ui-monospace, Consolas, monospace; }
.roster-empty { padding: 60px 0; color: var(--muted); text-align: center; }

.results-dialog { width: min(1080px, calc(100vw - 32px)); max-height: calc(100vh - 42px); padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: var(--surface); box-shadow: 0 30px 90px rgba(0,0,0,.7); }
.results-dialog::backdrop { background: rgba(5,7,9,.78); backdrop-filter: blur(5px); }
.results-capture { width: 100%; min-width: 0; overflow: hidden; border-radius: 7px; background: var(--surface); }
.results-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: start; justify-content: space-between; gap: 16px; padding: 20px 22px; border-bottom: 1px solid var(--line); background: var(--surface); }
.results-action-stack { display: grid; flex: 0 0 auto; justify-items: end; gap: 7px; }
.results-actions { display: flex; align-items: center; gap: 8px; }
.results-icon-button, .close-button { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: transparent; cursor: pointer; }
.results-icon-button:hover, .close-button:hover { color: var(--text); border-color: var(--muted); }
.results-icon-button.is-copied { color: var(--green); border-color: var(--green); }
.results-icon-button:disabled { opacity: .45; cursor: wait; }
.close-button { font-size: 24px; }
.copy-results-status { min-height: 14px; color: var(--green); font: 10px/1.35 ui-monospace, Consolas, monospace; text-align: right; white-space: nowrap; }
.copy-results-status:empty { visibility: hidden; }
.copy-results-status.is-error { color: var(--red); }
.counter-results { display: grid; gap: 1px; background: var(--line-soft); }
.counter-row { display: grid; grid-template-columns: 42px minmax(340px, 1.05fr) minmax(360px, .95fr); align-items: center; gap: 20px; min-height: 116px; padding: 14px 20px; background: var(--surface); }
.counter-rank { color: var(--gold); font: 900 16px/1 ui-monospace, Consolas, monospace; }
.result-team { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.result-avatar { display: grid; justify-items: center; gap: 4px; min-width: 0; }
.result-avatar img { width: 58px; height: 58px; border-radius: 50%; object-fit: cover; border: 2px solid var(--line); }
.result-avatar small { width: 100%; overflow: hidden; color: var(--muted); font-size: 10px; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.result-metrics { align-self: stretch; display: grid; grid-template-columns: repeat(4, 1fr); align-items: center; gap: 10px; margin: 0; padding-left: 20px; border-left: 1px solid var(--line); }
.result-metrics div { min-width: 0; }
.result-metrics dt { min-height: 18px; color: var(--muted); font-size: 12px; line-height: 1.25; text-transform: uppercase; }
.result-metrics dd { margin: 4px 0 0; font: 800 14px/1 ui-monospace, Consolas, monospace; }
.result-metrics dd.positive { color: var(--red); }
.result-metrics dd.negative { color: var(--green); }
.no-results { padding: 80px 20px; background: var(--surface); text-align: center; }
.no-results p { margin-top: 7px; color: var(--muted); font-size: 12px; }
.metrics-legend { max-width: 860px; margin-top: 10px !important; color: var(--muted); font-size: 12px !important; line-height: 1.5; }
.metrics-legend b { color: var(--text); font-family: ui-monospace, Consolas, monospace; }
.results-defense { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.results-defense > span { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.results-defense-team { display: flex; gap: 6px; }
.results-defense-avatar { position: relative; display: inline-flex; }
.results-defense-avatar img { display: block; width: 44px; height: 44px; border: 2px solid var(--gold); border-radius: 50%; object-fit: cover; }
.results-defense-avatar small { display: none; position: absolute; left: 50%; bottom: calc(100% + 6px); z-index: 3; transform: translateX(-50%); padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; color: var(--text); background: var(--surface-2); font-size: 10px; white-space: nowrap; }
.results-defense-avatar:hover small { display: block; }

@media (max-width: 1000px) {
  .selected-layout { grid-template-columns: 1fr 1fr; }
  .selected-team { grid-column: 1 / -1; }
  .hero-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .counter-row { grid-template-columns: 32px 1fr; }
  .result-metrics { grid-column: 2; padding: 14px 0 0; border-top: 1px solid var(--line); border-left: 0; }
}
@media (max-width: 700px) {
  .appbar { padding-inline: 14px; }
  .brand small { display: none; }
  .nav-link { padding-inline: 8px; }
  .language-switcher { margin-left: 6px; }
  .language-switcher button { min-width: 28px; padding-inline: 5px; }
  .counter-shell { width: min(100% - 24px, 1240px); padding-top: 24px; }
  h1 { font-size: 30px; }
  .page-intro { align-items: start; flex-direction: column; }
  .database-stat { white-space: normal; }
  .team-builder-head, .roster-toolbar { align-items: start; }
  .selected-team { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .team-slot { height: 102px; padding-inline: 3px; }
  .team-slot img { width: 50px; height: 50px; }
  .selected-layout { grid-template-columns: 1fr; }
  .hero-search { width: 46vw; }
  .hero-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .counter-row { grid-template-columns: 1fr; }
  .counter-rank { display: none; }
  .result-team, .result-metrics { grid-column: 1; }
}
@media (max-width: 430px) {
  .appbar nav .nav-link:first-child { display: none; }
  .brand > span:last-child { display: none; }
  .hero-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hero-search { width: 50vw; }
  .result-metrics { grid-template-columns: repeat(2, 1fr); row-gap: 14px; }
  .results-defense { align-items: start; flex-direction: column; }
  .results-defense-avatar img { width: 40px; height: 40px; }
}
