/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #1e1e1e;
  --surface:   #252526;
  --surface2:  #2d2d2d;
  --accent:    #e8a838;
  --accent2:   #454545;
  --text:      #d4d4d4;
  --muted:     #888888;
  --win:       #22c55e;
  --lose:      #ef4444;
  --tie:       #f59e0b;
  --radius:    8px;
  --gap:       1rem;
}

html { overflow-x: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ────────────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--accent2);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand { font-size: 1.1rem; font-weight: 700; color: var(--accent); white-space: nowrap; }

/* nav-collapse is transparent on desktop — children act as direct flex items */
.nav-collapse { display: contents; }

.nav-links { list-style: none; display: flex; gap: 0.25rem; }
.nav-links a {
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  white-space: nowrap;
}
.nav-links a:hover { background: var(--accent2); text-decoration: none; }
.nav-links a.active { background: var(--accent); color: #000; font-weight: 600; }

.nav-search-wrap {
  position: relative;
  margin-left: auto;
}
.nav-search {
  background: var(--surface2);
  border: 1px solid var(--accent2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.3rem 0.65rem;
  font-size: 0.85rem;
  width: 180px;
}
.nav-search:focus { outline: none; border-color: var(--accent); }
.nav-search::placeholder { color: var(--muted); }

.nav-search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  z-index: 200;
  display: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.nav-search-dropdown.open { display: block; }
.nav-search-dropdown li {
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
}
.nav-search-dropdown li:hover,
.nav-search-dropdown li.active { background: var(--accent2); }
.nav-search-dropdown .dd-former { color: var(--muted); font-size: 0.75rem; }

.sse-status {
  font-size: 1.2rem;
  color: var(--muted);
  cursor: default;
  transition: color 0.3s;
  flex-shrink: 0;
}
.sse-status.connected    { color: var(--win); }
.sse-status.disconnected { color: var(--lose); }

.nav-refresh {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
  font-size: 1.2rem;
  flex-shrink: 0;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-refresh:hover:not(:disabled) { color: var(--accent); }
.nav-refresh:disabled { cursor: default; opacity: 0.7; }
.nav-refresh-icon { display: inline-block; transition: transform 0.2s; }
.nav-refresh.is-refreshing .nav-refresh-icon {
  animation: nav-refresh-spin 0.9s linear infinite;
  color: var(--accent);
}
@keyframes nav-refresh-spin { to { transform: rotate(360deg); } }
.nav-logout {
  font-size: 1.1rem;
  color: var(--muted);
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
  flex-shrink: 0;
  background: none;
  border: none;
  font-family: inherit;
}
.nav-logout:hover { color: var(--text); }
.nav-logout-form { display: inline-flex; margin: 0; padding: 0; }

.nav-user {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0 0.4rem;
  flex-shrink: 0;
  white-space: nowrap;
}
.nav-user-badge {
  background: var(--accent);
  color: #000;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  letter-spacing: 0.05em;
}
.nav-admin-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 1.05rem;
  padding: 0 0.15rem;
  flex-shrink: 0;
}
.nav-admin-link:hover { color: var(--accent); }

/* Hamburger button — hidden on desktop */
.nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.3rem;
  flex-shrink: 0;
}
.nav-hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.22s ease, opacity 0.22s ease;
  transform-origin: center;
}
/* X animation when open */
.nav-hamburger--open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger--open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.nav-hamburger--open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Navbar — mobile (≤ 960px) ─────────────────────────────────────────────── */
@media (max-width: 960px) {
  .navbar {
    flex-wrap: wrap;
    gap: 0;
    padding: 0.6rem 1rem;
    column-gap: 0.75rem;
  }

  /* Brand stays left, remaining static items go right, hamburger far right */
  .nav-brand    { margin-right: auto; }
  .nav-hamburger { display: flex; }

  /* Collapse: hidden by default, revealed as a full-width dropdown below brand row */
  .nav-collapse {
    display: none;
    flex-direction: column;
    width: 100%;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--accent2);
    gap: 0.25rem;
  }
  .nav-collapse.nav-open { display: flex; }

  /* Links stack vertically */
  .nav-links {
    flex-direction: column;
    gap: 0.1rem;
  }
  .nav-links a {
    padding: 0.6rem 0.75rem;
    font-size: 0.95rem;
    display: block;
  }

  /* Search goes full-width below links */
  .nav-search-wrap { width: 100%; margin: 0.35rem 0 0.25rem; }
  .nav-search { width: 100%; box-sizing: border-box; }
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
main.main--wide { max-width: 1600px; }
main.main--fluid { max-width: none; }

.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.clan-meta { color: var(--muted); margin-top: 0.25rem; }
.clan-description { margin-top: 0.5rem; max-width: 60ch; }
.muted { color: var(--muted); }
.center { text-align: center; margin-top: 2rem; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--accent2);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: 0.75rem; color: var(--accent); }
.card.full-width { grid-column: 1 / -1; }

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

/* ── Tables ────────────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.data-table th, .data-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--accent2);
}
.data-table th {
  background: var(--surface2);
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background-image: linear-gradient(rgba(255,255,255,0.06), rgba(255,255,255,0.06)); }
[data-no-row-link] tr:hover td { background-image: none; }
tr.row-link { cursor: pointer; }
.data-table tr.highlight-row td,
.cwl-super tr.highlight-row td,
.cwl-matrix tr.highlight-row td,
.users-table tr.highlight-row td,
.audit-table tr.highlight-row td { font-weight: 600; box-shadow: inset 0 1px 0 var(--accent), inset 0 -1px 0 var(--accent); }
.data-table tr.highlight-row td:first-child,
.cwl-super tr.highlight-row td:first-child,
.cwl-matrix tr.highlight-row td:first-child,
.users-table tr.highlight-row td:first-child,
.audit-table tr.highlight-row td:first-child { box-shadow: inset 3px 0 0 var(--accent), inset 0 1px 0 var(--accent), inset 0 -1px 0 var(--accent); }
.data-table tr.highlight-row td:last-child,
.cwl-super tr.highlight-row td:last-child,
.cwl-matrix tr.highlight-row td:last-child,
.users-table tr.highlight-row td:last-child,
.audit-table tr.highlight-row td:last-child { box-shadow: inset -1px 0 0 var(--accent), inset 0 1px 0 var(--accent), inset 0 -1px 0 var(--accent); }

/* ── Town Hall level colours ────────────────────────────────────────────────── */
[data-th] { font-weight: 600; }
td[data-th] { text-align: center; }
[data-th="1"],[data-th="2"],[data-th="3"],[data-th="4"],
[data-th="5"],[data-th="6"],[data-th="7"],[data-th="8"] { color: #b8956a; background: #b8956a26; }
[data-th="9"]  { color: #9d8ec9; background: #9d8ec926; }
[data-th="10"] { color: #e05c4b; background: #e05c4b26; }
[data-th="11"] { color: #b366e0; background: #b366e026; }
[data-th="12"] { color: #d4ac0d; background: #d4ac0d26; }
[data-th="13"] { color: #5ab4ee; background: #5ab4ee26; }
[data-th="14"] { color: #4cba7a; background: #4cba7a26; }
[data-th="15"] { color: #8b5cf6; background: #8b5cf626; }
[data-th="16"] { color: #e07030; background: #e0703026; }
[data-th="17"] { color: #3a7fc1; background: #3a7fc126; }
[data-th="18"] { color: #22d3ee; background: #22d3ee26; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent); }
th.sort-asc::after  { content: ' ↑'; color: var(--accent); }
th.sort-desc::after { content: ' ↓'; color: var(--accent); }

/* ── War stat bar ──────────────────────────────────────────────────────────── */
.war-stat-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

/* Star cell coloring */
.stars-cell-3 { color: var(--win); font-weight: 600; }
.stars-cell-2 { color: var(--tie); font-weight: 500; }
.stars-cell-1 { color: #f97316; }
.stars-cell-0 { color: var(--lose); }
.stat-value--warn { color: var(--lose) !important; }
.star-pct--high  { color: var(--win); }
.star-pct--mid   { color: #e5a700; }
.star-pct--low   { color: var(--lose); }

/* War attacks table: our-side | th | attack (with direction arrow) | th | opp-side */
.war-attacks-table td.wa-name { font-weight: 500; }
.war-attacks-table td.wa-name--ours { text-align: right; }
.war-attacks-table th.wa-hdr-ours   { text-align: right; }
.war-attacks-table th.wa-hdr-attack { text-align: center; }
.war-attacks-table .wa-attack-inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}
.war-attacks-table .wa-attack--ours   .wa-details { justify-self: end;   grid-column: 1; }
.war-attacks-table .wa-attack--ours   .wa-arrow   { grid-column: 2; }
.war-attacks-table .wa-attack--theirs .wa-arrow   { grid-column: 2; }
.war-attacks-table .wa-attack--theirs .wa-details { justify-self: start; grid-column: 3; }
.war-attacks-table .wa-details { display: inline-flex; align-items: center; gap: 0.35rem; }
.war-attacks-table .wa-dest    { font-size: 0.85rem; opacity: 0.85; }
.war-attacks-table .wa-arrow   { font-size: 1.1rem; color: var(--muted); font-weight: 700; }
.war-attacks-table .wa-arrow--right { color: var(--accent); }
.war-attacks-table .wa-arrow--left  { color: var(--lose); }
.war-attacks-table td.wa-order {
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: center;
}
.war-attacks-table .wa-slot-time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
}
/* Fixed-width slots so every element lines up vertically across rows */
.war-attacks-table .wa-slot {
  display: inline-block;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}
.war-attacks-table .wa-slot-time  { min-width: 2.6rem; }
.war-attacks-table .wa-slot-stars { min-width: 2.4rem; }
.war-attacks-table .wa-slot-dest  { min-width: 2.4rem; }
.war-attacks-table .wa-slot-pos   { min-width: 2rem; }
.war-attacks-table .wa-details    { gap: 0.15rem; }

/* ── CWL title row (h1 + round cards inline) ────────────────────────────────── */
.cwl-title-row {
  display: flex;
  align-items: flex-start;
  gap: 1.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.cwl-title-row .page-header { flex-shrink: 0; }
.cwl-title-row .cwl-round-cards { flex: 1; min-width: 0; align-self: flex-end; }

/* ── CWL two-column layout ─────────────────────────────────────────────────── */
.cwl-top-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}
.cwl-main {  flex-direction: column; gap: 1rem; }

/* ── CWL per-round cards (replaces Our Rounds table) ────────────────────────── */
.cwl-round-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: flex-start;
  align-content: flex-start;
}

.cwl-round-card {
  background: var(--surface);
  border: 1px solid var(--accent2);
  border-top: 3px solid var(--accent2);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  min-width: 130px;
  flex: 1 1 130px;
  max-width: 220px;
}
.cwl-round-card--win  { border-top-color: var(--win); }
.cwl-round-card--lose { border-top-color: var(--lose); }
.cwl-round-card--tie  { border-top-color: var(--tie); }
.cwl-round-card--unknown { border-top-color: var(--muted); }

.cwl-round-card-num {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
.cwl-round-card-opp {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.3rem;
}
.cwl-round-card-score {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.4rem;
  white-space: nowrap;
}
.cwl-round-card-result {
  display: inline-block;
  padding: 0.12rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
}
.cwl-round-card--win  .cwl-round-card-result { background: var(--win);  color: #000; }
.cwl-round-card--lose .cwl-round-card-result { background: var(--lose); color: #fff; }
.cwl-round-card--tie  .cwl-round-card-result { background: var(--tie);  color: #000; }
.cwl-round-card--unknown .cwl-round-card-result { background: var(--accent2); color: var(--text); }

/* ── Result pill (global) ──────────────────────────────────────────────────── */
.result-pill {
  display: inline-block;
  padding: 0.08rem 0.35rem;
  border-radius: 3px;
  font-size: 0.66rem;
  font-weight: 700;
  vertical-align: middle;
}
.result-pill--win     { background: var(--win);   color: #000; }
.result-pill--lose    { background: var(--lose);  color: #fff; }
.result-pill--tie     { background: var(--tie);   color: #000; }
.result-pill--unknown { background: var(--muted); color: var(--bg); }

/* ── War summary card ──────────────────────────────────────────────────────── */
.war-summary-top {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.15rem 0 0.7rem;
  margin-bottom: 0.7rem;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.war-summary-top--live   { color: var(--win); }
.war-summary-top--prep   { color: var(--accent); }
.war-summary-top--result { padding-bottom: 0.6rem; font-size: 1rem; }
.war-summary-top--back   { padding-bottom: 0.6rem; font-size: 0.9rem; font-weight: 500; }
.war-summary-back-link   { color: var(--accent); }
.war-summary-back-link:hover { text-decoration: underline; }
.war-summary-timer       { font-variant-numeric: tabular-nums; }
.war-summary-timer-icon  { font-size: 1rem; }
.war-summary-timer-label { color: var(--muted); font-weight: 400; font-size: 0.9rem; }

.war-summary-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.6rem;
}
.war-summary-side {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  text-align: right;
}
.war-summary-side--right { justify-content: flex-start; text-align: left; }
.war-summary-name { font-size: 0.92rem; font-weight: 600; }
.war-summary-score { font-size: 1.2rem; font-weight: 700; color: var(--accent); }
.war-summary-dest { font-size: 0.8rem; }
.war-summary-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  text-align: center;
}
.war-summary-sub {
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.war-summary-countdown { font-size: 0.75rem; }
.war-lead-pill {
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 700;
  min-width: 3rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  border: 1px solid transparent;
}
.lead-pill--ahead  { background: rgba(34, 197, 94, 0.15);  color: var(--win);   border-color: rgba(34, 197, 94, 0.35); }
.lead-pill--behind { background: rgba(239, 68, 68, 0.15);  color: var(--lose);  border-color: rgba(239, 68, 68, 0.35); }
.lead-pill--tie    { background: var(--accent2);           color: var(--muted); }

.war-summary-bars {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.15rem 0 0.75rem;
}
.war-bar-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}
.war-bar-half {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}
.war-bar-half--ours,
.war-bar-half--opp  { align-items: center; }

/* Name + total-star label sits on top of each side's star strip (stacked) */
.war-side-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  line-height: 1.15;
  white-space: nowrap;
}

/* Star strip — one star per possible star, wraps if huge team size */
.war-star-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  line-height: 1;
  font-size: 1rem;
  letter-spacing: -0.04em;
  width: 100%;
}
.war-bar-half--ours .war-star-strip,
.war-bar-half--opp  .war-star-strip { justify-content: center; }
.war-star {
  display: inline-block;
  line-height: 1;
  transition: color 0.4s ease;
}
.war-star--on  { color: var(--accent); }
.war-star--off { color: var(--accent); opacity: 0.25; }

/* Center column between the two star strips — lead pill, state, dest%, attacks */
.war-bar-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0 0.4rem;
  white-space: nowrap;
  line-height: 1.2;
}
.war-bar-center .war-summary-sub { margin-bottom: 0.15rem; }
.war-bar-dest {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.war-bar-dest .war-dest-num { color: var(--text); }
.war-bar-dest .war-dest-sep { color: var(--muted); opacity: 0.5; }
.war-bar-atks {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
}
.war-atk-count {
  font-size: 0.72rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.war-atk-count--muted { color: var(--muted); font-weight: 500; }
.war-atk-count--warn  { color: var(--lose); }
.war-atk-icon {
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1;
  opacity: 0.75;
}
.war-state-badge {
  background: var(--accent2);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
/* ── Slopegraph (Chart tab in war page) ────────────────────────────────── */
.chart-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
  padding-bottom: 0.75rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.chart-filter {
  display: inline-flex;
  gap: 0.15rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--accent2);
  border-radius: 999px;
  padding: 2px;
}
.chart-filter-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.chart-filter-btn:hover { color: var(--text); }
.chart-filter-btn.active {
  background: var(--accent);
  color: #000;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  align-items: center;
  font-size: 0.75rem;
  color: var(--muted);
}
.slopegraph[data-filter="ours"]   .slope-line--theirs { display: none; }
.slopegraph[data-filter="theirs"] .slope-line--ours   { display: none; }
.chart-legend-item { display: inline-flex; align-items: center; gap: 0.35rem; }
.chart-legend-sep  { opacity: 0.4; }
.chart-swatch {
  display: inline-block;
  width: 14px;
  height: 3px;
  border-radius: 2px;
}

.slopegraph {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 45%) minmax(0, 1fr);
  gap: 0;
  align-items: start;
  position: relative;
}
.slope-col {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.slope-row {
  height: var(--row-h, 46px);
  min-height: var(--row-h, 46px);
  max-height: var(--row-h, 46px);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.05rem;
  padding: 0 0.5rem;
  font-size: 0.82rem;
  border-radius: 4px;
  line-height: 1.15;
}
.slope-row:hover { background: rgba(255,255,255,0.04); }
.slope-row-top {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}
.slope-col--ours .slope-row     { align-items: flex-end; text-align: right; }
.slope-col--opp  .slope-row     { align-items: flex-start; text-align: left; }
.slope-col--ours .slope-row-top { justify-content: flex-end; }
.slope-col--opp  .slope-row-top { justify-content: flex-start; }
.slope-def-hold {
  font-size: 0.85rem;
  line-height: 1;
  letter-spacing: -0.04em;
}
.slope-name { font-weight: 500; max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slope-th   {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  min-width: 1.3rem;
  text-align: center;
}
.slope-pos  { color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; min-width: 1.8rem; }
.slope-lines {
  width: 100%;
  display: block;
  overflow: visible;
  align-self: stretch;
}
.slope-line { transition: opacity 0.15s ease; }
.slope-line:hover { opacity: 1 !important; stroke-width: 3; }

.war-score { font-size: 1.4rem; font-weight: 700; color: var(--accent); display: flex; gap: 0.5rem; align-items: center; }
.vs { color: var(--muted); font-size: 1rem; }
.war-opponent { color: var(--muted); font-size: 0.9rem; }
.war-team-size { color: var(--muted); font-size: 0.8rem; }
.war-result { margin-bottom: 0.5rem; }

.result-badge, .result--win, .result--lose, .result--tie {
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 700;
}
.result--win    { background: var(--win);  color: #000; }
.result--lose   { background: var(--lose); color: #fff; }
.result--tie    { background: var(--tie);  color: #000; }
.result--unknown { background: var(--muted); color: #fff; }
.war-result--win  .result-badge { background: var(--win);  color: #000; }
.war-result--lose .result-badge { background: var(--lose); color: #fff; }
.war-result--tie  .result-badge { background: var(--tie);  color: #000; }

/* ── War Map ───────────────────────────────────────────────────────────────── */
.war-map {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 2px;
}

.war-map-hdr {
  padding: 0.5rem 0.75rem;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--accent);
  background: var(--surface2);
  border-radius: 4px;
  margin-bottom: 2px;
}
.war-map-hdr--opp { text-align: center; }
.war-map-hdr { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.1rem; }
.war-map-hdr-name { font-weight: 600; font-size: 0.85rem; color: var(--accent); }
.war-map-hdr-stats { font-size: 0.72rem; font-weight: 400; color: var(--muted); }

/* Base card */
.wbase {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.55rem;
  border-radius: 4px;
  background: var(--surface2);
  min-height: 50px;
  border-left: 3px solid transparent;
  transition: background 0.15s;
}
.wbase--opp {
  flex-direction: row-reverse;
  border-left: none;
  border-right: 3px solid transparent;
}

/* Status colour stripes */
.wbase--3star { border-color: var(--win)  !important; background: rgba(34, 197, 94,  0.10); }
.wbase--2star { border-color: var(--tie)  !important; background: rgba(245,158, 11,  0.10); }
.wbase--1star { border-color: #f97316     !important; background: rgba(249,115, 22,  0.07); }
.wbase--0star { border-color: var(--lose) !important; background: rgba(239, 68, 68,  0.08); }
.wbase--no-atk { border-color: var(--accent2) !important; }

.war-map-row-pos {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  min-width: 28px;
  text-align: center;
}
.wbase-body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
  min-width: 0;
}
.wbase--ours .wbase-body { align-items: flex-end; }
.wbase--opp .wbase-body { align-items: flex-start; }

.wbase-top {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.wbase-bottom {
  display: flex;
  align-items: center;
}

.wbase-th {
  background: var(--accent);
  color: #000;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.08rem 0.28rem;
  border-radius: 3px;
  white-space: nowrap;
  flex-shrink: 0;
}
/* TH-level colours for the war map badge — solid fills using the global TH palette */
.wbase-th[data-th="1"],.wbase-th[data-th="2"],.wbase-th[data-th="3"],
.wbase-th[data-th="4"],.wbase-th[data-th="5"],.wbase-th[data-th="6"],
.wbase-th[data-th="7"],.wbase-th[data-th="8"] { background: #b8956a; color: #000; }
.wbase-th[data-th="9"]  { background: #9d8ec9; color: #fff; }
.wbase-th[data-th="10"] { background: #e05c4b; color: #fff; }
.wbase-th[data-th="11"] { background: #b366e0; color: #fff; }
.wbase-th[data-th="12"] { background: #d4ac0d; color: #000; }
.wbase-th[data-th="13"] { background: #5ab4ee; color: #000; }
.wbase-th[data-th="14"] { background: #4cba7a; color: #000; }
.wbase-th[data-th="15"] { background: #8b5cf6; color: #fff; }
.wbase-th[data-th="16"] { background: #e07030; color: #fff; }
.wbase-th[data-th="17"] { background: #3a7fc1; color: #fff; }
.wbase-th[data-th="18"] { background: #22d3ee; color: #000; }
.wbase-name {
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Attack slot dots (one per attack available) */
.wbase-slots { display: flex; gap: 3px; align-items: center; }
.atk-slot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.atk-slot--empty { border: 1.5px solid var(--muted); }
.atk-slot--3 { background: var(--win); }
.atk-slot--2 { background: var(--tie); }
.atk-slot--1 { background: #f97316; }
.atk-slot--0 { background: var(--lose); }

.wbase-stars  { font-size: 1rem; color: var(--accent); letter-spacing: -0.04em; }
.wbase-stars-dim { opacity: 0.25; }
.wbase-def-stars { color: var(--lose); }
.wbase-count  { font-size: 0.8rem; color: var(--muted); }
.wbase-untouched { font-size: 0.8rem; color: var(--muted); font-style: italic; }

/* "def" label on our bases */
.wbase-def {
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

/* ── War Map Table ─────────────────────────────────────────────────────────── */
.war-map-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.war-map-table th,
.war-map-table td {
  padding: 0.12rem 0.35rem;
  border-bottom: 1px solid var(--accent2);
  vertical-align: middle;
  line-height: 1.2;
}

/* Clan header row */
.wmt-clan-hdr {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--accent2);
}
.wmt-clan-hdr--ours { text-align: left; }
.wmt-clan-hdr--opp  { text-align: right; }
.wmt-clan-name { font-weight: 600; font-size: 1rem; color: var(--accent); display: block; }
.wmt-clan-stats { font-size: 0.82rem; color: var(--muted); }
.wmt-pos-hdr { width: 32px; }

/* Column label row */
.wmt-col-labels th {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 0.1rem;
  padding-bottom: 0.1rem;
  border-bottom: 2px solid var(--accent2);
}

/* Cell types */
.wmt-th   { width: 44px; text-align: center; white-space: nowrap; padding: 0; }
.wmt-th .wbase-th {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 2rem;
  border-radius: 0;
  padding: 0;
}
.wmt-name { font-weight: 500; min-width: 70px; text-align: center; }
.wmt-name.wmt-opp { text-align: center; }
.wmt-def-hold { margin-top: 0.1rem; line-height: 1; letter-spacing: -0.04em; }
.war-map-table .wmt-def-hold .wbase-stars,
.war-map-table .wmt-def-hold .wbase-stars-dim { font-size: 0.95rem; }
.wmt-atk  { text-align: center; white-space: nowrap; min-width: 52px; }
.wmt-pos  { width: 32px; text-align: center; color: var(--muted); font-size: 0.82rem; font-weight: 600; white-space: nowrap; }

/* Left-edge stripe on TH cell */
.wmt-th.wmt-our[data-status="3star"]  { border-left: 3px solid var(--win); }
.wmt-th.wmt-our[data-status="2star"]  { border-left: 3px solid var(--tie); }
.wmt-th.wmt-our[data-status="1star"]  { border-left: 3px solid #f97316; }
.wmt-th.wmt-our[data-status="0star"]  { border-left: 3px solid var(--lose); }
.wmt-th.wmt-our[data-status="no-atk"] { border-left: 3px solid var(--accent2); }

/* Right-edge stripe on TH cell */
.wmt-th.wmt-opp[data-status="3star"]  { border-right: 3px solid var(--win); }
.wmt-th.wmt-opp[data-status="2star"]  { border-right: 3px solid var(--tie); }
.wmt-th.wmt-opp[data-status="1star"]  { border-right: 3px solid #f97316; }
.wmt-th.wmt-opp[data-status="0star"]  { border-right: 3px solid var(--lose); }
.wmt-th.wmt-opp[data-status="no-atk"] { border-right: 3px solid var(--accent2); }

/* Larger stars scoped to the war map table */
.war-map-table .wbase-stars,
.war-map-table .wbase-stars-dim,
.war-map-table .wbase-def-stars { font-size: 1.3rem; }

/* Attack cell content */
.wmt-dest { font-size: 0.8rem; color: var(--muted); margin-left: 0.2rem; }
.wmt-atk-empty { color: var(--muted); opacity: 0.35; }

/* Defense row */
.wmt-def-row td {
  padding-top: 0.08rem;
  padding-bottom: 0.18rem;
  border-bottom: 2px solid var(--accent2);
}
.wmt-defs { font-size: 0.88rem; color: var(--muted); }
.wmt-defs--ours { text-align: left; }
.wmt-defs--opp  { text-align: right; }
.wmt-defs-label { font-weight: 600; margin-right: 0.25rem; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; }
.wmt-def-gap { width: 36px; }

/* ── Stat lists ────────────────────────────────────────────────────────────── */
.stat-list { list-style: none; display: flex; flex-direction: column; gap: 0.4rem; }
.stat-list li { display: flex; justify-content: space-between; align-items: center; }
.stat-value { font-weight: 600; color: var(--accent); }

/* ── Badges ─────────────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 0.1rem 0.4rem; border-radius: 4px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; vertical-align: middle; margin-left: 0.3rem; }
.badge--live { background: var(--win); color: #000; }
.badge--warn { background: var(--tie); color: #000; }

.role-badge { display: inline-block; padding: 0.1rem 0.45rem; border-radius: 4px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.03em; }
.role-badge--leader   { background: var(--accent); color: #000; }
.role-badge--coLeader { background: var(--surface2); color: var(--accent); border: 1px solid var(--accent); }

/* ── Raid stats grid ─────────────────────────────────────────────────────────── */
.raid-stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-bottom: 0.25rem; }
.raid-stat { background: var(--surface2); border-radius: var(--radius); padding: 0.5rem 0.75rem; display: flex; flex-direction: column; }
.raid-stat-value { font-size: 1.1rem; font-weight: 700; color: var(--accent); }
.raid-stat-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* ── Member detail ─────────────────────────────────────────────────────────── */
.member-header { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 1rem; }
.member-stats { display: flex; gap: 1rem; flex-wrap: wrap; }
.stat-box { background: var(--surface2); padding: 0.5rem 1rem; border-radius: var(--radius); text-align: center; }
.stat-box .stat-label { display: block; font-size: 0.75rem; color: var(--muted); }
.stat-box .stat-value { display: block; font-size: 1.2rem; font-weight: 700; color: var(--accent); }
.stat-box-row { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; }

.member-note { display: flex; flex-direction: column; gap: 0.35rem; flex: 1; min-width: 200px; align-self: stretch; }
.member-note__header { display: flex; align-items: baseline; justify-content: space-between; }
.member-note__label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.member-note__status { font-size: 0.75rem; color: var(--muted); }
.member-note__textarea { background: var(--surface2); border: 1px solid var(--accent2); color: var(--text); border-radius: var(--radius); padding: 0.6rem 0.75rem; font-size: 0.875rem; font-family: inherit; resize: vertical; flex: 1; min-height: 60px; width: 100%; line-height: 1.5; }
.member-note__textarea:focus { outline: none; border-color: var(--accent); }
.member-note__textarea::placeholder { color: var(--muted); }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--gap); }

.troop-grid { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
.troop-card {
  background: var(--surface2);
  border: 1px solid var(--accent2);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  display: flex;
  gap: 0.4rem;
  align-items: center;
}
.troop-card.maxed { border-color: var(--accent); }
.troop-card.maxed .troop-level { color: var(--accent); }
.troop-name { font-weight: 500; }
.troop-level { color: var(--muted); font-size: 0.8rem; }
.troop-grid--small .troop-card { font-size: 0.78rem; }
.sub-heading { font-size: 0.85rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 0.75rem 0 0.4rem; }

/* ── Misc ──────────────────────────────────────────────────────────────────── */
.count-badge {
  background: var(--accent2);
  color: var(--text);
  font-size: 0.75rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  vertical-align: middle;
  margin-left: 0.3rem;
}
.badge { background: var(--accent2); padding: 0.15rem 0.5rem; border-radius: 4px; font-size: 0.8rem; }
.badge--left { background: var(--lose); color: #fff; margin-left: 0.5rem; }

.search-input {
  background: var(--surface2);
  border: 1px solid var(--accent2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  margin-top: 0.5rem;
  width: 240px;
}
.search-input:focus { outline: none; border-color: var(--accent); }

.season-select {
  background: var(--surface2);
  border: 1px solid var(--accent2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

canvas { display: block; }

/* ── Collapsible card (details/summary) ─────────────────────────────────────── */
details.card > summary {
  cursor: pointer;
  list-style: none;
  display: block;
}
details.card > summary::-webkit-details-marker { display: none; }
.summary-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0;
}
details.card[open] .summary-header-row { margin-bottom: 0.75rem; }
.collapse-chevron { font-size: 0.75em; color: var(--muted); transition: transform 0.2s; flex-shrink: 0; }
details.card[open] .collapse-chevron { transform: rotate(180deg); }

/* ── Participation badges ────────────────────────────────────────────────────── */
.part-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  font-size: 0.72rem;
  font-weight: 700;
}
.part-badge--full    { background: var(--win);  color: #000; }
.part-badge--partial { background: var(--tie);  color: #000; }
.part-badge--missed  { background: var(--lose); color: #fff; }
.part-badge--yes     { background: var(--win);  color: #000; }
.part-badge--no      { background: var(--lose); color: #fff; }

/* ── Stat summary strip (above tables) ──────────────────────────────────────── */
.stat-summary { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1rem; }
.stat-summary-item {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 0.35rem 0.85rem;
  text-align: center;
  min-width: 90px;
}
.ss-label { display: block; font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.ss-value { display: block; font-size: 1.05rem; font-weight: 700; color: var(--accent); }
.ss-value--warn { color: var(--lose) !important; }

.summary-left { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.4rem; min-width: 0; }
.card-meta-inline { font-size: 0.78rem; font-weight: 400; color: var(--muted); }
.card-meta-warn { color: var(--lose); font-weight: 600; }

/* ── Page-header utilities ──────────────────────────────────────────────────── */
.page-header-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

/* ── Tabs ───────────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--accent2);
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 0.55rem 1.25rem;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
  font-family: inherit;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Folder-style tabs that sit on top of a card and merge with it */
.tab-bar--card {
  gap: 0.15rem;
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
  align-items: flex-end;
}
.tab-bar--card .tab-btn {
  padding: 0.5rem 1.1rem;
  background: var(--surface2);
  border: 1px solid var(--accent2);
  border-radius: var(--radius) var(--radius) 0 0;
  margin-bottom: -1px;
  color: var(--muted);
  font-weight: 500;
}
.tab-bar--card .tab-btn:hover { color: var(--text); }
.tab-bar--card .tab-btn.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  border-bottom: 1px solid var(--surface);
  position: relative;
  z-index: 2;
}
/* Cards immediately after a card-tab-bar lose their top-left rounding so tabs blend in */
.tab-bar--card + .card,
.tab-bar--card ~ .tab-panel > .card,
.tab-bar--card ~ .tab-panel > section.card {
  border-top-left-radius: 0;
  margin-top: 0;
}

/* Sub tabs that attach directly to a table below them */
.tab-bar--table {
  gap: 0.15rem;
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: 1px solid var(--accent2);
  align-items: flex-end;
}
.tab-bar--table .tab-btn {
  padding: 0.4rem 0.9rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius) var(--radius) 0 0;
  margin-bottom: -1px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
}
.tab-bar--table .tab-btn:hover { color: var(--text); }
.tab-bar--table .tab-btn.active {
  background: var(--surface2);
  border-color: var(--accent2);
  border-bottom-color: var(--surface2);
  color: var(--accent);
  font-weight: 600;
}
/* Table wraps / tables that follow a table-tab-bar sit flush */
.tab-bar--table + .tab-panel,
.tab-bar--table + .table-wrap,
.tab-bar--table ~ .tab-panel > .table-wrap {
  margin-top: 0;
}
.tab-bar--table + .tab-panel .data-table,
.tab-bar--table + .table-wrap .data-table,
.tab-bar--table ~ .tab-panel .data-table {
  margin-top: 0;
}

/* ── CWL clan matrix panels ─────────────────────────────────────────────────── */
.clan-panel          { display: none; }
.clan-panel.active   { display: block; }
.tab-bar--clans .tab-btn { font-size: 0.82rem; padding: 0.3rem 0.65rem; }

/* ── CWL Super Table ────────────────────────────────────────────────────────── */
.cwl-super-wrap { overflow-x: auto; }

.cwl-super {
  border-collapse: collapse;
  font-size: 0.82rem;
  white-space: nowrap;
}

.cwl-super th, .cwl-super td {
  padding: 0.32rem 0.55rem;
  border: 1px solid var(--accent2);
  text-align: center;
  vertical-align: middle;
}

.cwl-super th {
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  line-height: 1.4;
}

.cwl-super tbody tr:hover td { background: var(--surface2); }
.cwl-super tbody tr:hover .sp-sticky { background: var(--surface2); }

.sp-sticky { position: sticky; z-index: 2; background: var(--surface); }
.sp-sticky--name { left: 0; min-width: 130px; text-align: left; }
.sp-sticky--th   { left: 130px; min-width: 38px; }
.cwl-super thead .sp-sticky { background: var(--surface2); z-index: 3; }

.cwl-super .sp-war-hdr { padding: 0.4rem 0.55rem; }

/* Attack result cells */
.cwl-super .sp-atk-3    { background: rgba(34,  197, 94,  0.18); }
.cwl-super .sp-atk-2    { background: rgba(245, 158, 11,  0.22); }
.cwl-super .sp-atk-1    { background: rgba(239, 68,  68,  0.15); }
.cwl-super .sp-atk-0    { background: rgba(239, 68,  68,  0.25); }
.cwl-super .sp-atk-miss { background: rgba(239, 68,  68,  0.10); color: var(--muted); }
.cwl-super .sp-none     { color: var(--accent2); }

/* Ineligible rows */
.cwl-super .row-ineligible td:not(.sp-sticky) { opacity: 0.4; }

/* Total column */
.cwl-super .sp-total { font-weight: 600; min-width: 60px; }

/* ── CWL Matrix ─────────────────────────────────────────────────────────────── */
.cwl-matrix-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
}

.cwl-matrix {
  border-collapse: collapse;
  font-size: 0.78rem;
  white-space: nowrap;
}

.cwl-matrix th,
.cwl-matrix td {
  padding: 0.28rem 0.45rem;
  border: 1px solid var(--accent2);
  vertical-align: middle;
}

.cwl-matrix th {
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  text-align: center;
}

/* Sticky left columns */
.cwl-matrix .sticky-col          { position: sticky; z-index: 2; }
.cwl-matrix .sticky-col--th      { left: 0;    min-width: 38px; text-align: center; }
.cwl-matrix .sticky-col--name    { left: 38px; min-width: 130px; background: var(--surface); }
.cwl-matrix thead .sticky-col    { background: var(--surface2); z-index: 3; }
.cwl-matrix tbody tr:hover .sticky-col--name { background: var(--surface2); }
[data-no-row-link] .cwl-matrix tbody tr:hover .sticky-col--name { background: var(--surface); }

/* War section divider */
.cwl-matrix .war-section-start   { border-left: 2px solid var(--muted) !important; }

/* War round header */
.cwl-matrix .cwl-mhdr {
  text-align: center;
  padding: 0.45rem 0.6rem;
  line-height: 1.5;
}
.cwl-matrix .war-result--win     { background: rgba(34,  197, 94,  0.10); }
.cwl-matrix .war-result--lose    { background: rgba(239, 68,  68,  0.10); }
.cwl-matrix .war-result--tie     { background: rgba(245, 158, 11,  0.10); }
.cwl-matrix .war-result--unknown { background: var(--surface2); }

/* result-pill styles are defined globally above */

/* Attack cell colours */
.cwl-matrix .atk-stars-3 { background: rgba(34,  197, 94,  0.18); }
.cwl-matrix .atk-stars-2 { background: rgba(245, 158, 11,  0.18); }
.cwl-matrix .atk-stars-1 { background: rgba(239, 68,  68,  0.14); }
.cwl-matrix .atk-stars-0 { background: rgba(239, 68,  68,  0.28); }

/* Attack position-differential badge (▲N = attacked up, ▼N = attacked down) */
.pos-badge { font-size: 0.7rem; font-weight: 700; line-height: 1; display: inline-block; min-width: 1.6em; text-align: left; }
.pos-up    { color: var(--win); }
.pos-dn    { color: var(--lose); }
.pos-eq    { color: var(--muted); }
/* .cwl-matrix .pos-badge { margin-left: 0.25rem; } */
.wbase-atk-group,
.wbase-def-group { display: inline-flex; align-items: center; gap: 0.15rem; }

/* Ineligible members — dim war cells but keep name readable */
.cwl-matrix .row-ineligible td:not(.sticky-col) { opacity: 0.4; }

.cwl-matrix .center         { text-align: center; }
.cwl-matrix .cwl-stars      { letter-spacing: -0.05em; }
.cwl-matrix .cwl-pct        { margin-left: 0.2rem; }

/* ── War Map — matrix-style overrides ──────────────────────────────────────── */
/* All rules use .war-map-table.cwl-matrix so they only apply to the war map
   and live here next to the base .cwl-matrix rules they extend or override.   */

.war-map-table.cwl-matrix { font-size: 0.85rem; }
.war-map-table.cwl-matrix .sticky-col--th   { min-width: 44px; }
.war-map-table.cwl-matrix .sticky-col--name { left: 44px; min-width: 90px; }
.war-map-table.cwl-matrix .wbase-stars,
.war-map-table.cwl-matrix .wbase-stars-dim,
.war-map-table.cwl-matrix .wbase-def-stars  { font-size: 1.05rem; }

/* Rowspan cells (TH + name on both sides) span player + def rows */
.war-map-table.cwl-matrix td[rowspan="2"] { border-bottom: 2px solid var(--accent2); vertical-align: middle; }

/* Attack cell colours: 3★ green · 2★ yellow · 1★ orange · 0★ red */
.war-map-table.cwl-matrix .atk-stars-3 { background: rgba(34,  197, 94,  0.15); }
.war-map-table.cwl-matrix .atk-stars-2 { background: rgba(245, 158, 11,  0.15); }
.war-map-table.cwl-matrix .atk-stars-1 { background: rgba(249, 115, 22,  0.15); }
.war-map-table.cwl-matrix .atk-stars-0 { background: rgba(239, 68,  68,  0.15); }


/* ── CWL Wars view matchup header ──────────────────────────────────────────── */
.wars-matchup-hdr {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--accent2);
}
.wars-clan-side {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.wars-clan-side--ours { justify-content: flex-end; text-align: right; }
.wars-clan-side--opp  { justify-content: flex-start; text-align: left; }
.wars-clan-name { font-size: 0.9rem; }
.wars-score { font-size: 1.2rem; font-weight: 700; color: var(--accent); }
.wars-middle {
  text-align: center;
  min-width: 70px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

/* ── CWL Round wars list ────────────────────────────────────────────────────── */
.cwl-round-wars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; align-items: start; }

.cwl-war-block { padding-right: 1rem; border-right: 1px solid var(--accent2); }
.cwl-war-block:last-child { padding-right: 0; border-right: none; }
.cwl-war-block--ours .cwl-war-block-hdr { border-left: 3px solid var(--accent); padding-left: 0.5rem; }

.cwl-war-block-hdr {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
  padding: 0.3rem 0;
}
.cwl-war-block-name { font-size: 0.82rem; flex: 1; }
.cwl-war-block-name--left { text-align: right; }
.cwl-war-block-name--right { text-align: left; }
.cwl-war-block-state { min-width: 52px; text-align: center; display: flex; flex-direction: column; align-items: center; }

.cwl-war-compact td { padding: 0.18rem 0.45rem; font-size: 0.82rem; }

/* ── CWL Prep War card ──────────────────────────────────────────────────────── */
.prep-war-header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.75rem; }

.prep-clan-hdr {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  padding: 0.4rem 0.75rem;
  background: var(--surface2);
}
.prep-clan-hdr--ours { text-align: left; border-left: 3px solid var(--accent); }
.prep-clan-hdr--opp  { text-align: left; }

.prep-divider { width: 12px; background: var(--bg); border-left: 2px solid var(--accent2); border-right: 2px solid var(--accent2); padding: 0; }
.prep-divider-right { border-right: 2px solid var(--accent2); }

/* ── Plan tab ─────────────────────────────────────────────────────────────── */
.plan-dots { display: flex; gap: 0.25rem; align-items: center; }
.plan-dot {
  display: inline-block;
  width: 0.7rem; height: 0.7rem;
  border-radius: 50%;
  flex-shrink: 0;
}
.plan-dot--full    { background: var(--win, #22c55e); }
.plan-dot--partial { background: #f59e0b; }
.plan-dot--miss    { background: var(--lose, #ef4444); }
.plan-dot--none    { background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.18); }
.plan-pos--up   { color: var(--win, #22c55e); font-weight: 600; }
.plan-pos--down { color: var(--lose, #ef4444); font-weight: 600; }

/* ── War page sidebar layout ────────────────────────────────────────────────── */
.cwl-layout { display: grid; grid-template-columns: 400px 1fr; gap: 1rem; align-items: start; }
.cwl-sidebar { display: flex; flex-direction: column; gap: 1rem; }
.cwl-sidebar .card { overflow: hidden; }

/* Scroll wrapper for wide tables that live outside .card */
.table-wrap { overflow-x: auto; }

/* ── Responsive ────────────────────────────────────────────────────────────── */

/* Narrow window / tablet (≤ 960px) */
@media (max-width: 960px) {
  /* CWL top section stacks */
  .cwl-top-row    { grid-template-columns: 1fr; }
  .cwl-title-row  { flex-direction: column; }
  /* CWL round wars: 4 → 2 per row */
  .cwl-round-wars { grid-template-columns: repeat(2, 1fr); }
  /* War sidebar stacks below main content */
  .cwl-layout     { grid-template-columns: 1fr; }
  /* Cards may contain wide tables — let them scroll rather than overflow */
  .card { overflow-x: auto; }
  /* War summary stats: wrap on narrow screens */
  .war-summary-stats { gap: 1rem; }
}

/* Phone / very narrow window (≤ 640px) */
@media (max-width: 640px) {
  main { padding: 0.75rem; }
  main.main--fluid { padding: 0.75rem; }

  .page-header h1 { font-size: 1.35rem; }

  /* Cards tighten on phone */
  .card { padding: 0.85rem; }

  /* Bare data-tables (outside cards) and table-wrap scroll on their own */
  .data-table { display: block; overflow-x: auto; }

  /* CWL: one war block per row */
  .cwl-round-wars { grid-template-columns: 1fr; }

  /* War summary: shrink score on narrow screens */
  .war-summary-score { font-size: 1rem; }

  /* Member detail: stack header sections vertically */
  .member-header { flex-direction: column; }
  .member-note   { min-width: 0; width: 100%; }
  .member-stats  { flex-wrap: wrap; width: 100%; }

  /* Inputs fill available width on small screens */
  .search-input  { width: 100%; }
  .season-select { width: 100%; }

  /* Stat summary strip: smaller pills */
  .stat-summary-item { min-width: 70px; padding: 0.3rem 0.55rem; }
  .ss-label { font-size: 0.62rem; }
  .ss-value  { font-size: 0.95rem; }

  /* Dashboard grid: single column */
  .dashboard-grid { grid-template-columns: 1fr; }
}
