/* ── 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;
}

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;
}

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-links { list-style: none; display: flex; gap: 0.25rem; flex-wrap: wrap; }
.nav-links a {
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
}
.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;
}
.sse-status.connected    { color: var(--win); }
.sse-status.disconnected { color: var(--lose); }
.nav-logout { font-size: 1.1rem; color: var(--muted); cursor: pointer; padding: 0 0.25rem; line-height: 1; }
.nav-logout:hover { color: var(--text); }

/* ── 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: var(--surface2); }
tr.row-link { cursor: pointer; }
.data-table tr.highlight-row td,
.cwl-super tr.highlight-row td,
.cwl-matrix 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 { 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 { 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; }
[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; }

/* ── CWL two-column layout ─────────────────────────────────────────────────── */
.cwl-layout {
  display: grid;
  grid-template-columns: 450px 1fr;
  gap: 1rem;
  align-items: start;
}
.cwl-sidebar, .cwl-main { display: flex; flex-direction: column; gap: 1rem; }

/* ── 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 ───────────────────────────────────────────────────────────────────── */
.war-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1rem;
  text-align: center;
  margin-bottom: 1rem;
}
.war-side h2 { font-size: 1rem; }
.war-stars { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.war-center { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; }
.war-state-badge {
  background: var(--accent2);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}
.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.85rem; }
.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; }
.wmt-name.wmt-opp { text-align: right; }
.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; }

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

.tab-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  padding: 0.35rem 0.85rem;
  transition: color 0.15s, background 0.15s;
}
.tab-btn:hover  { color: var(--text); background: var(--surface2); }
.tab-btn.active { color: var(--accent); border-color: var(--accent2); background: var(--surface2); font-weight: 600; }

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

/* ── 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; }

/* ── 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; background: var(--surface); }
.cwl-matrix .sticky-col--th      { left: 0;    min-width: 38px; text-align: center; }
.cwl-matrix .sticky-col--name    { left: 38px; min-width: 130px; }
.cwl-matrix thead .sticky-col    { background: var(--surface2); z-index: 3; }
.cwl-matrix tbody tr:hover .sticky-col { background: var(--surface2); }

/* 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); }

/* Defence cell colours (fewer stars = better defence) */
.cwl-matrix .def-stars-0 { background: rgba(34,  197, 94,  0.20); }
.cwl-matrix .def-stars-1 { background: rgba(245, 158, 11,  0.12); }
.cwl-matrix .def-stars-2 { background: rgba(245, 158, 11,  0.22); }
.cwl-matrix .def-stars-3 { background: rgba(239, 68,  68,  0.18); }

/* Attack position-differential badge (▲N = attacked up, ▼N = attacked down) */
.pos-badge { font-size: 0.7rem; font-weight: 700; line-height: 1; }
.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; }


/* ── 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; }
