:root {
  --club-primary: #1F2937;
  --club-on-primary: #FFFFFF;
  --club-on-accent: #FFFFFF;
  --club-pattern: #1F2937;
  --row-tint: #1F2937;
  --club-accent: #111827;
  --card-ink: #111827;
  --card-muted: #5B6170;
  --page-ink: #111827;
  --page-muted: #5B6170;
  --page-hi: #1F2937;
  --page-on-hi: #FFFFFF;
  --paper: #F5F2EC;
  --card: #FFFFFF;
  --line: rgba(17, 24, 39, 0.12);
  --radius: 14px;
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "Barlow", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

[data-tone="dark"] { color-scheme: dark; }

body {
  --ink: var(--page-ink);
  --dim: var(--page-muted);
  --hi: var(--page-hi);
  --on-hi: var(--page-on-hi);
  background: var(--paper);
  transition: background-color 0.25s ease, color 0.25s ease;
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button { font: inherit; }

main {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 16px 48px;
}

.foot {
  text-align: center;
  font-size: 12px;
  color: var(--dim);
  padding: 16px;
}

h1, h2 {
  font-family: var(--display);
  font-weight: 800;
  text-transform: uppercase;
  line-height: 0.95;
  margin: 0;
}

h1 { font-size: clamp(40px, 7vw, 68px); font-style: italic; }

.eyebrow {
  margin: 0 0 6px;
  font-family: var(--display);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 14px;
  color: var(--hi);
}

:root:not([data-club]) .eyebrow { color: #a55448; }

.hero { padding: 16px 0 28px; }

.back-link {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: inline-block;
  margin-bottom: 18px;
  font-family: var(--display);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 14px;
  color: var(--dim);
  text-decoration: none;
}

.back-link:hover { color: var(--hi); }

.hero-sub { color: var(--dim); font-size: 16px; margin: 14px 0 0; }

.league { margin-top: 18px; }

.league-name {
  font-size: 28px;
  margin-bottom: 14px;
}

.league-name small {
  font-family: var(--body);
  font-weight: 500;
  font-size: 14px;
  text-transform: none;
  color: var(--dim);
  margin-left: 6px;
}

.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.team-tile {
  width: 100%;
  font: inherit;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 108px;
  padding: 16px;
  background: var(--card);
  border: 0;
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.team-tile:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.08); }

.team-tile-text { display: flex; flex-direction: column; }

.team-tile-name {
  font-family: var(--display);
  font-weight: 800;
  font-size: 24px;
  text-transform: uppercase;
  line-height: 1;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.team-tile-meta { color: var(--dim); font-size: 14px; margin-top: 4px; }

.crest, .avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.crest-fallback, .avatar-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--display);
  font-weight: 800;
}

.crest .swap-img, .avatar .swap-img {
  position: relative;
  width: 100%;
  height: 100%;
  opacity: 0;
}

.crest .swap-img { object-fit: contain; }
.avatar .swap-img { object-fit: cover; object-position: top center; }

.has-img .swap-img { opacity: 1; }
.has-img > .crest-fallback, .has-img > .avatar-fallback { display: none; }

.crest-fallback {
  border-radius: 50%;
  background: var(--club-primary);
  color: var(--club-on-primary);
  border: 3px solid var(--club-accent);
  letter-spacing: 0.04em;
}

.crest.has-img .crest-fallback { display: none; }

.crest.has-img {
  background: var(--crest-bg, transparent);
  border-radius: var(--crest-radius, 0);
}

.crest.has-img .swap-img { transform: scale(var(--crest-scale, 1)); }

.crest-md { width: 52px; height: 52px; }
.crest-md .crest-fallback { font-size: 15px; }
.crest-lg { width: 88px; height: 88px; }
.crest-lg .crest-fallback { font-size: 24px; }
.crest-card { position: absolute; top: 12px; right: 12px; width: 40px; height: 40px; z-index: 2; }
.crest-card .crest-fallback { font-size: 12px; border-width: 2px; }

.avatar { border-radius: 50%; background: var(--club-accent); }

.avatar-fallback {
  color: var(--club-on-accent);
  background: var(--club-pattern);
}

.avatar-fallback span {
  background: var(--club-accent);
  color: var(--club-on-accent);
  border-radius: 999px;
  padding: 0 0.35em;
  line-height: 1.15;
}

.avatar-sm { width: 40px; height: 40px; }
.avatar-sm .avatar-fallback { font-size: 15px; }
.avatar-md { width: 56px; height: 56px; }
.avatar-md .avatar-fallback { font-size: 20px; }

.setup-head { display: flex; align-items: center; gap: 18px; margin-bottom: 24px; }

.setup-body {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
}

.setup-label { margin: 0 0 10px; font-weight: 600; }

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

.chip input { position: absolute; opacity: 0; pointer-events: none; }

.chip span {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid var(--club-accent);
  cursor: pointer;
  font-weight: 600;
  user-select: none;
}

.chip span b { opacity: 0.6; margin-left: 4px; }

.chip input:checked + span { background: var(--club-accent); color: var(--club-on-accent); }
.chip input:focus-visible + span { outline: 3px solid var(--hi); outline-offset: 2px; }

.setup-estimate { color: var(--dim); margin: 14px 0 0; font-size: 15px; }

.setup-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

.btn {
  appearance: none;
  border: 2px solid var(--club-accent);
  border-radius: 999px;
  padding: 11px 20px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: transform 0.1s ease, background 0.15s ease;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--hi); border-color: var(--hi); color: var(--on-hi); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--ink); border-color: currentColor; }
.btn-ghost:hover:not(:disabled) { background: color-mix(in srgb, currentColor 10%, transparent); }
.btn-tie { background: var(--club-accent); color: var(--club-on-accent); }

.roster {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  margin-top: 24px;
}

.roster-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--card);
  border-radius: 10px;
}

.roster-name { flex: 1; font-weight: 600; font-size: 15px; }

.roster-pos { font-family: var(--display); font-weight: 700; color: var(--dim); }

.battle-top { display: flex; justify-content: space-between; font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }

.battle-pct { color: var(--hi); }

.progress { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 8px 0 22px; }
.progress span { display: block; height: 100%; background: var(--hi); transition: width 0.25s ease; }

.battle-q { font-size: clamp(28px, 4.4vw, 40px); text-align: center; font-style: italic; margin-bottom: 16px; }

.arena { display: grid; grid-template-columns: 1fr auto 1fr; align-items: stretch; gap: 16px; max-width: 720px; margin: 0 auto; }

.vs {
  font-family: var(--display);
  font-weight: 800;
  font-style: italic;
  font-size: 28px;
  color: var(--club-on-accent);
  background: var(--club-accent);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  align-self: center;
}

.pick-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 0;
  border-radius: 18px;
  overflow: hidden;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

@media (hover: hover) { .pick-card:hover { transform: translateY(-4px); box-shadow: 0 0 0 3px var(--page-hi), 0 16px 32px rgba(0, 0, 0, 0.16); } }

.pick-card:focus-visible {
  transform: translateY(-4px);
  box-shadow: 0 0 0 3px var(--page-hi), 0 16px 32px rgba(0, 0, 0, 0.16);
  outline: none;
}

.pick-media {
  position: relative;
  display: block;
  aspect-ratio: 4 / 4.2;
  max-height: max(200px, calc(100vh - 470px));
  width: 100%;
  background: var(--club-accent);
}

.avatar-card {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
}

.avatar-card .avatar-fallback {
  font-size: clamp(64px, 12vw, 120px);
  font-style: italic;
}

.avatar-card .avatar-fallback span {
  padding: 0.05em 0.3em;
  border-radius: 18px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.15);
}

.pick-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 14px 16px 16px;
}

.pick-pos { font-family: var(--display); font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; font-size: 13px; color: var(--hi); }

.pick-name { font-family: var(--display); font-weight: 800; text-transform: uppercase; font-size: clamp(22px, 3.4vw, 32px); line-height: 1; margin: 2px 0 4px; }

.pick-meta { color: var(--dim); font-size: 14px; font-weight: 600; }

.pick-key {
  position: absolute;
  bottom: 14px;
  right: 14px;
  font-weight: 700;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 7px;
  font-size: 14px;
}

.battle-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 20px; }

.battle-kit { display: flex; justify-content: center; margin-top: 16px; }

.hint { text-align: center; color: var(--dim); font-size: 13px; margin-top: 14px; }

.rank-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.rank-row {
  --s: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: calc(8px + 10px * var(--s)) 16px;
  --t: 0;
  background: color-mix(in srgb, var(--row-tint) calc(var(--t) * 100%), var(--card));
  border-radius: calc(12px + 4px * var(--s));
}

.rank-num { width: 64px; flex-shrink: 0; text-align: center; font-family: var(--display); font-weight: 800; font-style: italic; font-size: calc(26px + 26px * var(--s)); line-height: 1; color: var(--hi); }
.rank-num small { font-size: 16px; margin-left: 1px; opacity: 0.8; }

.rank-text { display: flex; flex-direction: column; }
.rank-name { font-family: var(--display); font-weight: 800; text-transform: uppercase; font-size: calc(20px + 12px * var(--s)); line-height: 1.05; letter-spacing: 0.01em; }
.rank-meta { color: var(--dim); font-size: calc(13px + 3px * var(--s)); }

.rank-slot { width: 72px; flex-shrink: 0; display: flex; justify-content: center; }
.avatar-rank { width: calc(44px + 28px * var(--s)); height: calc(44px + 28px * var(--s)); }
.avatar-rank .avatar-fallback { font-size: calc(16px + 10px * var(--s)); }

@media (max-width: 640px) {
  .arena { grid-template-columns: 1fr 1fr; gap: 10px; }
  .vs { display: none; }
  .pick-key { display: none; }
  .pick-info { padding: 10px 12px 12px; }
  .crest-card { width: 30px; height: 30px; top: 8px; right: 8px; }
  .setup-head { gap: 12px; }
  .crest-lg { width: 64px; height: 64px; }
  .hint { display: none; }
}

body.modal-open { overflow: hidden; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 12, 24, 0.6);
}

.modal-card {
  width: 100%;
  max-width: 880px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--card);
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 0;
}

.modal-head h2 { font-size: 32px; font-style: italic; }

.modal-close {
  border: 0;
  background: none;
  font-size: 34px;
  line-height: 1;
  cursor: pointer;
  color: var(--ink);
  padding: 4px 8px;
}

.modal-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  padding: 18px 22px 24px;
}

.share-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  background: color-mix(in srgb, var(--club-accent) 8%, var(--card));
  border-radius: 14px;
  padding: 14px;
  transition: opacity 0.15s ease;
}

.share-preview.busy { opacity: 0.55; }

.share-preview canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 62vh;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

.share-loading { color: var(--dim); font-weight: 600; }

.share-controls .setup-label { margin: 0 0 8px; }
.share-controls .seg + .setup-label { margin-top: 18px; }

.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  background: var(--card);
  border-radius: 999px;
}

.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }

.seg-opt span {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  user-select: none;
}

.seg-opt input:checked + span { background: var(--club-accent); color: var(--club-on-accent); }
.seg-opt input:focus-visible + span { outline: 3px solid var(--hi); outline-offset: 1px; }

.share-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 24px; }
.share-buttons .btn { justify-content: center; }

.btn-social { color: #FFFFFF; border-color: transparent; }
.btn-ig { background: linear-gradient(45deg, #F58529, #DD2A7B 55%, #8134AF); }
.btn-x { background: #000000; border-color: rgba(255, 255, 255, 0.22); }
.btn-social:hover { filter: brightness(1.1); }

.share-note { color: var(--dim); font-size: 14px; margin: 14px 0 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  max-width: min(520px, calc(100vw - 32px));
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--card-ink);
  color: var(--card);
  font-weight: 600;
  font-size: 15px;
  text-align: center;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.credits {
  margin-top: 24px;
  font-size: 14px;
  color: var(--dim);
}

.credits summary {
  cursor: pointer;
  font-family: var(--display);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.credits ul { padding-left: 18px; margin: 10px 0 0; }
.credits li { margin-bottom: 4px; }
.credits a { color: var(--ink); }

@media (max-width: 720px) {
  .modal { padding: 0; align-items: flex-end; }
  .modal-card { max-height: 94vh; border-radius: 20px 20px 0 0; }
  .modal-body { grid-template-columns: 1fr; gap: 16px; }
  .share-preview canvas { max-height: 42vh; }
}

.setup-head { flex-wrap: wrap; }

.kit-picker {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.kit-label {
  font-family: var(--display);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 13px;
  color: var(--dim);
}

.kit-seg .seg-opt span { display: inline-flex; align-items: center; gap: 7px; }

.swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  box-shadow: 0 0 0 1.5px var(--line);
  flex-shrink: 0;
}

.roster-item { transition: opacity 0.2s ease, filter 0.2s ease; }

.roster-item.is-out {
  opacity: 0.35;
  filter: grayscale(1);
}

.roster-item.is-out .roster-name { text-decoration: line-through; text-decoration-color: var(--dim); }

@media (max-width: 720px) {
  .kit-picker { margin-left: 0; width: 100%; align-items: flex-start; }
}

.team-tile, .setup-body, .roster-item, .pick-card, .rank-row, .modal-card, .seg {
  --ink: var(--card-ink);
  --dim: var(--card-muted);
  --hi: var(--club-primary);
  --on-hi: var(--club-on-primary);
  color: var(--ink);
}

.team-tile-club {
  position: relative;
  overflow: hidden;
  background: var(--tile-bg);
  color: var(--tile-fg);
  isolation: isolate;
}

.team-tile-club::after {
  content: "";
  position: absolute;
  inset: 0 0 0 58%;
  z-index: -1;
  background: var(--tile-pattern);
  background-size: 100% 100%;
  opacity: 0.55;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 75%);
  mask-image: linear-gradient(90deg, transparent, #000 75%);
}

.team-tile-club .team-tile-name { color: var(--tile-fg); }
.team-tile-club .team-tile-meta { color: var(--tile-muted); }
.team-tile-club:hover { box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18); }
.results-actions { margin: 0 0 20px; }