:root {
  --bg: #0b1220;
  --bg-elevated: #111827;
  --panel: #151e2e;
  --panel-hover: #1c273a;
  --border: #2a364a;
  --border-soft: #1a2435;
  --text: #e8eef7;
  --muted: #8b9bb3;
  --accent: #38bdf8;
  --cta: #22c55e;
  --cta-hover: #16a34a;
  --cta-text: #052e16;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --focus: #38bdf8;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 28px rgba(2, 6, 23, 0.4);
  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --header-h: 56px;
  --workbench-h: auto;
  --ease: 160ms ease;
  --slot-a: #38bdf8;
  --slot-b: #4ade80;
  --slot-c: #fbbf24;
  --slot-d: #c4b5fd;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  font-family: var(--sans);
  background:
    radial-gradient(1000px 480px at 8% -8%, rgba(56, 189, 248, 0.07), transparent 55%),
    radial-gradient(800px 420px at 92% 0%, rgba(34, 197, 94, 0.05), transparent 50%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}
button, a, summary, [role="button"], tr.clickable, .slot-card { cursor: pointer; }
button, input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.7rem;
  transition: border-color var(--ease), background var(--ease), box-shadow var(--ease);
}
button:hover, select:hover { border-color: #475569; background: var(--panel-hover); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
input::placeholder, textarea::placeholder { color: #64748b; }
.mono { font-family: var(--mono); font-size: 0.78rem; }
.text-ok { color: var(--ok); font-weight: 600; }
.play-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.play-badge.can {
  color: var(--cta-text);
  background: var(--ok);
  border-color: #166534;
}
.play-badge.cannot {
  color: #fecaca;
  background: #3f1d1d;
  border-color: #7f1d1d;
}
.play-badge.warn {
  color: #422006;
  background: var(--warn);
  border-color: #a16207;
}
tr.row-cannot-play td:first-child { box-shadow: inset 3px 0 0 var(--err); }
tr.row-can-play td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
.copyable {
  cursor: copy;
  border-radius: 3px;
  padding: 0 0.15em;
  transition: color var(--ease), background var(--ease);
}
.copyable:hover {
  color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
}
.copyable:active {
  background: rgba(56, 189, 248, 0.22);
}
.hint { color: var(--muted); font-size: 0.75rem; line-height: 1.45; }
.btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-weight: 560; font-size: 0.82rem; line-height: 1.2;
}
.btn-primary {
  background: var(--cta); color: var(--cta-text); border-color: transparent; font-weight: 650;
}
.btn-primary:hover { background: var(--cta-hover); color: #fff; border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-danger { border-color: #7f1d1d; color: #fecaca; background: #291314; }
.btn-danger:hover { border-color: #b91c1c; background: #3f1719; }
.btn-sm { padding: 0.28rem 0.5rem; font-size: 0.74rem; }
.icon { width: 1rem; height: 1rem; flex-shrink: 0; }

/* Header — single compact row; long endpoints live in the connections popover */
.app-header {
  position: sticky; top: 0; z-index: 40;
  min-height: var(--header-h);
  height: auto;
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(11, 18, 32, 0.94);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 0.65rem; min-width: 0; flex-shrink: 0; }
.brand-mark {
  width: 1.85rem; height: 1.85rem; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #0ea5e9, #22c55e);
  color: #052e16;
}
.brand h1 { margin: 0; font-size: 0.98rem; font-weight: 700; letter-spacing: -0.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 0.68rem; }
.header-meta {
  display: flex; align-items: center; gap: 0.55rem;
  margin-inline-start: auto; min-width: 0; flex: 1 1 auto;
  justify-content: flex-end;
}
.chips { display: flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; }
.chips-status { flex: 0 1 auto; min-width: 0; justify-content: flex-end; }
.header-actions {
  display: flex; align-items: center; gap: 0.35rem; flex-shrink: 0;
}
.chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.7rem; color: var(--muted);
  border: 1px solid var(--border); background: rgba(21, 30, 46, 0.8);
  padding: 0.18rem 0.5rem; border-radius: 999px;
  max-width: 100%;
}
.chip-env strong { color: var(--accent); }
.chip strong { color: var(--text); font-weight: 600; }
.chip .dot { width: 0.4rem; height: 0.4rem; border-radius: 50%; background: var(--ok); }
.chip .dot.warn { background: var(--warn); }
.chip .dot.err { background: var(--err); }

.env-details {
  position: relative;
}
.env-details > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.env-details > summary::-webkit-details-marker { display: none; }
.env-details > summary::marker { content: ""; }
.chip-conn {
  gap: 0.35rem;
  transition: border-color var(--ease), background var(--ease), color var(--ease);
}
.chip-conn:hover,
.env-details[open] > .chip-conn {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  background: rgba(56, 189, 248, 0.12);
  color: var(--text);
}
.env-popover {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 50;
  width: min(28rem, calc(100vw - 2rem));
  display: grid;
  gap: 0.35rem;
  padding: 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(17, 24, 39, 0.98);
  box-shadow: var(--shadow);
  animation: env-pop 140ms ease;
}
@keyframes env-pop {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.env-row {
  display: grid;
  grid-template-columns: 3.2rem minmax(0, 1fr);
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  margin: 0;
  padding: 0.4rem 0.5rem;
  text-align: start;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: rgba(11, 18, 32, 0.55);
  cursor: copy;
}
.env-row:hover {
  border-color: var(--border);
  background: var(--panel-hover);
}
.env-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.env-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 0.72rem;
}

.feed-toggle[aria-expanded="true"] {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
  color: var(--text);
}

/* Permanent left navigation */
.app-shell {
  --side-nav-w: 11.5rem;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  min-height: calc(100vh - var(--header-h));
}
.side-nav {
  flex: 0 0 var(--side-nav-w);
  width: var(--side-nav-w);
  position: sticky;
  top: var(--header-h);
  align-self: flex-start;
  height: calc(100vh - var(--header-h));
  overflow: auto;
  padding: 0.85rem 0.55rem;
  border-inline-end: 1px solid var(--border-soft);
  background: rgba(17, 24, 39, 0.96);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  z-index: 20;
}
.side-nav-label {
  margin: 0.55rem 0.55rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.side-nav-label:first-child { margin-top: 0.15rem; }
.side-nav-item {
  display: block;
  width: 100%;
  text-align: start;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.48rem 0.65rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.84rem;
}
.side-nav-item:hover {
  background: var(--panel-hover);
  color: var(--text);
}
.side-nav-item.active {
  background: rgba(56, 189, 248, 0.14);
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent);
}
.app-content {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--header-h));
}

/* Workbench */
.workbench {
  position: sticky; top: var(--header-h); z-index: 25;
  flex: 0 0 auto;
  padding: 0.65rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(17, 24, 39, 0.94);
  backdrop-filter: blur(10px);
}
.workbench-head {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  margin-bottom: 0.55rem;
}
.workbench-toggle {
  display: inline-flex; align-items: center; gap: 0.4rem;
  margin: 0; padding: 0.28rem 0.55rem 0.28rem 0.4rem;
  border: 1px solid var(--border); background: rgba(21, 30, 46, 0.85); color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease);
}
.workbench-toggle:hover {
  background: var(--panel-hover);
  border-color: #475569;
}
.workbench-toggle:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.workbench-title {
  margin: 0; font-size: 0.82rem; font-weight: 650;
}
.workbench-toggle .chevron {
  flex-shrink: 0;
  color: var(--muted);
  transition: transform var(--ease);
}
.workbench.is-collapsed .workbench-toggle {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  background: rgba(56, 189, 248, 0.08);
}
.workbench-actions {
  margin-inline-start: auto;
  display: flex; gap: 0.35rem; flex-wrap: wrap;
}
.workbench-body {
  overflow-x: auto;
  overflow-y: hidden;
  transition: opacity var(--ease);
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
}
.workbench.is-collapsed {
  padding-bottom: 0.55rem;
}
.workbench.is-collapsed .workbench-head {
  margin-bottom: 0;
}
.workbench.is-collapsed .workbench-body,
.workbench.is-collapsed .workbench-hint,
.workbench.is-collapsed .workbench-actions {
  display: none;
}
.workbench.is-collapsed .workbench-toggle .chevron {
  transform: rotate(-90deg);
}
.workbench.is-collapsed .context-bar {
  margin-top: 0.45rem;
}
.slots {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.55rem;
  align-items: stretch;
  width: max-content;
  min-width: 100%;
  padding-bottom: 0.15rem;
}
.slots .slot-card,
.slots .slot-add-card {
  flex: 0 0 220px;
  width: 220px;
  min-width: 220px;
}
@media (max-width: 720px) {
  .app-header {
    flex-wrap: wrap;
    align-items: flex-start;
    padding: 0.65rem 0.85rem;
  }
  .header-meta {
    width: 100%;
    margin-inline-start: 0;
    justify-content: space-between;
  }
  .env-popover { right: auto; left: 0; }
}
.slot-add-card {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  min-height: 7.5rem;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
}
.slot-add-card:hover {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(56, 189, 248, 0.05);
}
.slot-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 0.65rem 0.7rem;
  box-shadow: none;
  transition: border-color var(--ease), box-shadow var(--ease), transform var(--ease);
  position: relative;
  overflow: hidden;
}
.slot-card::before {
  content: "";
  position: absolute; inset: 0 auto 0 0; width: 4px;
  background: var(--slot-color, var(--accent));
}
.slot-card:hover { border-color: #475569; }
.slot-card.active {
  border-color: color-mix(in srgb, var(--slot-color) 65%, #475569);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--slot-color) 35%, transparent), var(--shadow);
}
.slot-card.collapsed .slot-body { display: none; }
.slot-top {
  display: flex; align-items: center; gap: 0.45rem; margin-bottom: 0.4rem;
}
.slot-badge {
  min-width: 1.45rem; height: 1.45rem; padding: 0 0.28rem; border-radius: 7px;
  display: grid; place-items: center;
  font-family: var(--mono); font-weight: 700; font-size: 0.72rem;
  background: color-mix(in srgb, var(--slot-color) 22%, transparent);
  color: var(--slot-color);
}
.slot-role {
  flex: 1; min-width: 0;
  border: none; background: transparent; padding: 0;
  font-weight: 600; font-size: 0.82rem;
}
.slot-role:focus { outline: none; box-shadow: none; background: rgba(255,255,255,0.04); border-radius: 4px; }
.tok {
  font-size: 0.65rem; font-weight: 650; letter-spacing: 0.02em;
  padding: 0.12rem 0.4rem; border-radius: 999px;
  border: 1px solid var(--border);
}
.tok.ok { color: var(--ok); border-color: #166534; background: #10261a; }
.tok.missing { color: var(--muted); }
.tok.bad { color: var(--err); border-color: #7f1d1d; background: #291314; }
.slot-meta { display: grid; gap: 0.2rem; font-size: 0.74rem; color: var(--muted); margin-bottom: 0.45rem; }
.slot-meta strong { color: var(--text); font-weight: 600; }
.slot-actions { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.slot-token-reveal {
  margin-top: 0.45rem;
  width: 100%;
  font-family: var(--mono);
  font-size: 0.65rem;
  min-height: 2.4rem;
  resize: vertical;
}

.context-bar {
  display: flex; gap: 0.55rem; flex-wrap: wrap; align-items: center;
  margin-top: 0.65rem;
  padding: 0.45rem 0.55rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: rgba(11, 18, 32, 0.45);
  font-size: 0.78rem;
}
.workbench.is-collapsed .context-bar {
  cursor: pointer;
}
.workbench.is-collapsed .context-bar:hover {
  border-color: #475569;
  background: rgba(11, 18, 32, 0.7);
}
.context-bar .pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.5rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel);
}
.context-bar .pill .swatch {
  width: 0.55rem; height: 0.55rem; border-radius: 50%;
  background: var(--slot-color, var(--accent));
}

/* Layout — page content + optional inline result feed */
.layout {
  --col-clans-list: min(420px, 42vw);
  --col-feed: 360px;
  --resizer-w: 6px;
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  width: 100%;
  flex: 1 1 0;
  min-height: 0;
  height: auto;
}
.layout-main {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.page {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.page[hidden] { display: none !important; }

/* Clans list | detail — always side-by-side on usable screens */
.clans-split {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  width: 100%;
  height: 100%;
  min-height: 0;
}
.page-tools {
  overflow: auto;
}
.page-tools .panel-tools {
  max-width: none;
  width: 100%;
  max-height: none;
  height: auto;
  min-height: 100%;
}
.col-resizer {
  position: relative;
  z-index: 6;
  flex: 0 0 var(--resizer-w);
  width: var(--resizer-w);
  cursor: col-resize;
  background: var(--border);
  transition: background var(--ease);
  touch-action: none;
  user-select: none;
  align-self: stretch;
}
.col-resizer::after {
  content: "";
  position: absolute;
  inset: 0 -4px;
}
.col-resizer:hover,
.col-resizer:focus-visible,
.col-resizer.dragging {
  background: var(--accent);
  outline: none;
}
.layout.resizing {
  cursor: col-resize;
  user-select: none;
}
.layout.resizing .panel { pointer-events: none; }

.panel {
  padding: 0.9rem 1rem 1.4rem;
  border-inline-end: none;
  overflow: auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.panel-clans-list {
  flex: 0 0 var(--col-clans-list);
  width: var(--col-clans-list);
  max-width: 55%;
  max-height: none;
  height: 100%;
  border-inline-end: none;
}
.panel-clans-detail {
  flex: 1 1 0;
  width: auto;
  min-width: 200px;
  max-height: none;
  height: 100%;
  background: rgba(11, 18, 32, 0.35);
  border-inline-start: 1px solid var(--border-soft);
}
.clan-detail-pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.detail-empty {
  flex: 1;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 0.35rem;
  padding: 2rem 1rem;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.35);
}
.detail-empty strong {
  color: var(--text);
  font-size: 0.95rem;
}
.detail-empty .hint { margin: 0; }
.clans-table-wrap {
  flex: 1;
  min-height: 0;
  max-height: none;
}
.panel-feed .result-feed {
  flex: 1;
  min-height: 12rem;
  max-height: none;
}

/* Only stack clans on very small phones */
@media (max-width: 640px) {
  .layout {
    flex-direction: column;
    height: auto;
    min-height: 0;
  }
  .layout-main {
    flex: 1 1 auto;
  }
  .clans-split {
    flex-direction: column;
    height: auto;
    min-height: 0;
  }
  .clans-split .col-resizer { display: none; }
  .panel-clans-list {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    max-height: min(40vh, 20rem);
    border-bottom: 1px solid var(--border-soft);
  }
  .panel-clans-detail {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 50vh;
    border-inline-start: none;
  }
  .feed-panel {
    flex: 0 0 auto !important;
    width: 100% !important;
    max-width: none !important;
    height: min(40vh, 22rem);
    border-inline-start: none !important;
    border-top: 1px solid var(--border);
  }
  .feed-resizer { display: none !important; }
}

.panel-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 0.75rem; margin-bottom: 0.75rem; flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 0.95rem; font-weight: 700; }
.toolbar { display: flex; gap: 0.4rem; margin-bottom: 0.7rem; flex-wrap: wrap; align-items: center; }
.table-wrap {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow: auto;
  background: var(--panel);
}
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
th, td {
  text-align: start; padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border-soft); vertical-align: middle;
}
th { color: var(--muted); font-weight: 600; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background: rgba(255,255,255,0.02); }
tbody tr.selected { background: rgba(56, 189, 248, 0.08); }
tbody tr:last-child td { border-bottom: none; }
.empty { color: var(--muted); text-align: center; padding: 1.2rem; }
.loading-state {
  display: flex; align-items: center; gap: 0.55rem; justify-content: center;
  padding: 1.2rem; color: var(--muted);
}
.spinner {
  width: 1rem; height: 1rem; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Result feed — inline column that reflows the main area */
.feed-panel {
  flex: 0 0 var(--col-feed);
  width: var(--col-feed);
  max-width: 48%;
  min-width: 240px;
  min-height: 0;
  height: 100%;
  border-inline-start: 1px solid var(--border);
  background: rgba(11, 18, 32, 0.98);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.feed-panel[hidden],
.feed-resizer[hidden] {
  display: none !important;
}
.feed-panel .panel-feed {
  flex: 1;
  max-height: none;
  height: 100%;
  min-height: 0;
}
.feed-head-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.detail-card {
  margin-top: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 0.85rem;
  flex: 1;
}
.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}
.detail-head h3 { margin: 0; font-size: 0.9rem; }
.war-board {
  margin-top: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  padding: 0.75rem;
}
.war-board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.55rem;
}
.war-score {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.war-score .score-us { color: var(--ok); }
.war-score .score-them { color: var(--err); }
.war-score .score-sep { color: var(--muted); margin: 0 0.25rem; }
.war-rounds tr.round-open td { background: rgba(56, 189, 248, 0.06); }
.war-rounds tr.round-claimed td { background: transparent; }
.war-rounds tr.round-mine td {
  background: rgba(52, 211, 153, 0.14);
  box-shadow: inset 3px 0 0 var(--ok);
}
.war-rounds tr.round-mine.round-open td {
  background: rgba(52, 211, 153, 0.2);
}
.war-viewer-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 0.55rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid rgba(52, 211, 153, 0.35);
  border-radius: var(--radius-sm);
  background: rgba(52, 211, 153, 0.08);
}
.chip-you {
  background: rgba(52, 211, 153, 0.25);
  color: var(--ok);
  font-weight: 600;
}
.chip-ok {
  background: rgba(52, 211, 153, 0.18);
  color: var(--ok);
}
.chip-pending {
  background: rgba(251, 191, 36, 0.18);
  color: var(--warn);
}
.claim-modal {
  max-width: min(720px, 94vw);
  width: min(720px, 94vw);
  max-height: min(88vh, 900px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}
.claim-modal::backdrop {
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(5px);
}
.claim-modal-shell {
  display: flex;
  flex-direction: column;
  max-height: min(88vh, 900px);
}
.claim-modal-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.claim-modal-top h3 {
  margin: 0 0 0.2rem;
  font-size: 1.05rem;
}
.claim-modal-top-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.claim-modal-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.claim-modal-x:hover {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.45);
  color: var(--err);
}
.claim-modal-body {
  padding: 0.85rem 1rem 1.1rem;
  overflow: auto;
  flex: 1;
  min-height: 12rem;
}
.review-modal {
  max-width: min(640px, 94vw);
  width: min(640px, 94vw);
}
.review-modal .quiz-question {
  font-size: 1.05rem;
  margin-top: 0.35rem;
}
.review-modal .quiz-choices {
  margin-top: 0.85rem;
}
.claim-game {
  margin-bottom: 0.85rem;
}
.claim-game:last-child { margin-bottom: 0; }
.claim-game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.45rem;
}
.claim-rows {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.claim-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  flex-wrap: wrap;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
}
.claim-row.is-open {
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.06);
}
.claim-row.is-done {
  opacity: 0.72;
  background: rgba(52, 211, 153, 0.05);
}
.claim-row-main {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}
.claim-prize { color: var(--muted); }
.claim-row-actions { display: flex; align-items: center; gap: 0.35rem; }
.war-raw {
  margin-top: 0.65rem;
  font-size: 0.8rem;
}
.war-raw summary {
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}
.war-raw pre {
  margin-top: 0.4rem;
  max-height: 220px;
  overflow: auto;
}

.war-play-panel {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
}
.quiz-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
  margin-bottom: 0.65rem;
}
.quiz-question {
  font-size: 1rem; font-weight: 600; line-height: 1.45;
  margin-bottom: 0.75rem;
}
.quiz-choices { display: grid; gap: 0.4rem; }
.quiz-choice {
  display: flex; align-items: flex-start; gap: 0.55rem;
  text-align: start; width: 100%;
  padding: 0.65rem 0.75rem;
  white-space: normal;
}
.quiz-choice .choice-letter {
  font-family: var(--mono); font-weight: 700; color: var(--muted);
  min-width: 2.2rem;
}
.quiz-choice.is-correct {
  border-color: var(--ok);
  box-shadow: inset 0 0 0 1px rgba(74, 222, 128, 0.35);
}
.quiz-choice.is-correct .choice-letter { color: var(--ok); }
.war-round-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}
.quiz-choice-readonly {
  cursor: default;
  pointer-events: none;
}
.quiz-choice.is-mine {
  box-shadow: inset 2px 0 0 #38bdf8;
}
.quiz-choice.is-opp {
  box-shadow: inset -2px 0 0 #fbbf24;
}
.quiz-choice.is-mine.is-opp {
  box-shadow: inset 2px 0 0 #38bdf8, inset -2px 0 0 #fbbf24;
}
.quiz-choice.is-correct.is-mine {
  box-shadow: inset 0 0 0 1px rgba(74, 222, 128, 0.35), inset 2px 0 0 #38bdf8;
}
.quiz-choice.is-correct.is-opp {
  box-shadow: inset 0 0 0 1px rgba(74, 222, 128, 0.35), inset -2px 0 0 #fbbf24;
}
.quiz-choice.is-correct.is-mine.is-opp {
  box-shadow: inset 0 0 0 1px rgba(74, 222, 128, 0.35), inset 2px 0 0 #38bdf8, inset -2px 0 0 #fbbf24;
}
.quiz-review-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}
.chip-bad {
  color: #fecaca;
  border-color: #7f1d1d;
  background: #291314;
}
.quiz-done { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: baseline; margin-bottom: 0.5rem; }
.quiz-done.ok strong { color: var(--ok); }
.quiz-done.err strong { color: var(--err); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.2rem 0.7rem; font-size: 0.78rem; margin-bottom: 0.7rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.5rem 0; }

.tabs {
  display: flex; gap: 0.25rem; margin-bottom: 0.85rem; flex-wrap: wrap;
  border-bottom: 1px solid var(--border-soft); padding-bottom: 0.45rem;
}
.tabs button {
  border: none; background: transparent; color: var(--muted);
  padding: 0.4rem 0.65rem; border-radius: 8px; font-weight: 600; font-size: 0.8rem;
}
.tabs button:hover { background: var(--panel-hover); color: var(--text); }
.tabs button.active { background: var(--panel); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }

.form-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: rgba(21, 30, 46, 0.55);
  padding: 0.75rem 0.85rem;
  margin-bottom: 0.7rem;
}
.form-card h3 {
  margin: 0 0 0.55rem; font-size: 0.84rem; font-weight: 650;
  display: flex; align-items: center; gap: 0.4rem;
}
.form-grid {
  display: grid;
  grid-template-columns: minmax(90px, 140px) 1fr;
  gap: 0.4rem 0.55rem; align-items: center; margin-bottom: 0.55rem;
}
.form-grid label { color: var(--muted); font-size: 0.75rem; }
select.member-pick {
  width: 100%;
  min-width: 0;
  font-family: var(--mono);
  font-size: 0.78rem;
}
.clan-combo {
  position: relative;
  min-width: 0;
  width: 100%;
}
.clan-combo-input {
  width: 100%;
  font-family: var(--mono);
  font-size: 0.78rem;
}
.clan-combo-meta {
  margin-top: 0.2rem;
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.3;
  min-height: 0.9rem;
}
.clan-combo-meta .known { color: var(--accent); }
.clan-combo-meta .custom { color: #fbbf24; }
.clan-combo-meta .fallback { color: var(--muted); }
.clan-combo-menu {
  position: absolute;
  z-index: 40;
  left: 0; right: 0; top: 2.05rem;
  margin: 0; padding: 0.25rem;
  list-style: none;
  max-height: 14rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #0f172a;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
.clan-combo-menu[hidden] { display: none; }
.clan-combo-menu li {
  display: flex; flex-direction: column; gap: 0.05rem;
  padding: 0.35rem 0.45rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--text);
}
.clan-combo-menu li:hover,
.clan-combo-menu li.is-active {
  background: rgba(56, 189, 248, 0.12);
}
.clan-combo-menu li .sub {
  color: var(--muted);
  font-size: 0.66rem;
  font-family: var(--sans);
}
.clan-combo-menu li.clan-combo-action {
  border-top: 1px solid var(--border-soft);
  margin-top: 0.15rem;
  color: #fbbf24;
}
.clan-combo-menu .empty {
  padding: 0.45rem;
  color: var(--muted);
  font-size: 0.72rem;
  cursor: default;
}
.picker-hint strong { color: var(--text); font-weight: 650; }
.picker-hint .in-our { color: var(--cta); }
.actor-pick {
  position: relative;
  display: inline-flex;
  vertical-align: middle;
  margin-inline-start: 0.15rem;
}
.actor-tag,
.actor-pick-btn {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-family: var(--mono); font-size: 0.7rem;
  padding: 0.15rem 0.45rem; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--slot-color) 45%, var(--border));
  background: color-mix(in srgb, var(--slot-color) 12%, transparent);
  color: var(--slot-color);
  cursor: pointer;
  line-height: 1.2;
}
.actor-pick-btn:hover {
  border-color: color-mix(in srgb, var(--slot-color) 70%, var(--border));
  background: color-mix(in srgb, var(--slot-color) 20%, transparent);
}
.actor-pick-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.actor-pick-caret {
  font-size: 0.65rem;
  opacity: 0.8;
}
.actor-pick-menu {
  position: absolute;
  z-index: 50;
  top: calc(100% + 0.25rem);
  left: 0;
  min-width: 16rem;
  max-width: min(22rem, 90vw);
  max-height: 16rem;
  overflow: auto;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #0f172a;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
.actor-pick-menu[hidden] { display: none; }
.actor-pick-menu li {
  display: flex; flex-direction: column; gap: 0.05rem;
  padding: 0.35rem 0.45rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--text);
}
.actor-pick-menu li:hover,
.actor-pick-menu li.is-active {
  background: rgba(56, 189, 248, 0.12);
}
.actor-pick-menu li .sub {
  color: var(--muted);
  font-size: 0.66rem;
  font-family: var(--sans);
}
.actor-pick-menu .actor-pick-head {
  cursor: default;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.66rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.4rem 0.45rem 0.2rem;
}
.actor-pick-menu .actor-pick-head:hover {
  background: transparent;
}
.actor-pick-menu .empty {
  cursor: default;
  color: var(--muted);
  font-size: 0.72rem;
}
.callout {
  display: flex; gap: 0.55rem; align-items: flex-start;
  font-size: 0.78rem; line-height: 1.45; margin-bottom: 0.75rem;
  padding: 0.6rem 0.7rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.5);
}
.callout.ok { border-color: #166534; background: #0f1f17; }
.callout.warn { border-color: #854d0e; background: #1f1a0c; }

.result-feed {
  display: flex; flex-direction: column; gap: 0.55rem;
  overflow: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: #0a101b;
  padding: 0.55rem;
}
.feed-item {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.65rem;
  border-inline-start: 3px solid var(--slot-color, var(--accent));
  background: rgba(21, 30, 46, 0.55);
}
.feed-item .meta {
  display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center;
  font-size: 0.72rem; color: var(--muted); margin-bottom: 0.45rem;
}
.feed-item .meta .who {
  color: var(--text); font-weight: 650;
}
.feed-item .meta .path {
  font-family: var(--mono); font-size: 0.68rem;
  color: var(--accent);
}
.feed-block {
  margin-top: 0.35rem;
}
.feed-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  margin-bottom: 0.2rem;
}
.feed-block-label {
  font-size: 0.65rem; font-weight: 650; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--muted);
}
.feed-item .meta-actions {
  margin-inline-start: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}
.btn-icon-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.45rem;
  height: 1.45rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex: 0 0 auto;
  line-height: 0;
}
.btn-icon-copy:hover {
  color: var(--text);
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.04);
}
.btn-icon-copy:active {
  color: var(--accent);
  transform: translateY(0.5px);
}
.btn-icon-copy svg {
  display: block;
}
.feed-item pre {
  margin: 0; white-space: pre-wrap; word-break: break-word;
  font-family: var(--mono); font-size: 0.68rem; max-height: 10rem; overflow: auto;
  background: rgba(0,0,0,0.25); border-radius: 6px; padding: 0.4rem 0.45rem;
  border: 1px solid var(--border-soft);
}
.feed-item.ok .meta .status { color: var(--ok); }
.feed-item.err .meta .status { color: var(--err); }
.feed-item .err-msg {
  margin: 0.25rem 0 0; font-size: 0.75rem; color: var(--err); line-height: 1.35;
}

.log {
  font-family: var(--mono); font-size: 0.72rem;
  background: #0a101b; border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 0.55rem; min-height: 10rem; max-height: 28rem; overflow: auto;
}
.log .e { padding: 0.35rem 0.4rem; border-bottom: 1px solid var(--border-soft); }
.log .lvl-error { color: var(--err); }
.log .lvl-warn { color: var(--warn); }

/* War skeleton */
.war-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}
@media (max-width: 720px) { .war-grid { grid-template-columns: 1fr; } }
.war-lane {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem;
  background: var(--panel);
}
.war-lane h3 { margin: 0 0 0.5rem; font-size: 0.85rem; }
.timeline {
  margin-top: 0.75rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem;
  min-height: 8rem;
  color: var(--muted); font-size: 0.78rem;
}
.timeline .ev {
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
}
.timeline .ev:last-child { border-bottom: none; }

.toast-host {
  position: fixed !important;
  top: auto !important;
  left: auto !important;
  right: 1rem !important;
  bottom: 1rem !important;
  inset: auto 1rem 1rem auto !important;
  z-index: 9999 !important;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 0.4rem;
  max-width: min(320px, 88vw);
  width: max-content;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  background: rgba(21, 30, 46, 0.96);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--text);
  animation: toast-in 160ms ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.toast.ok { border-color: #166534; background: rgba(15, 31, 23, 0.96); }
.toast.warn { border-color: #854d0e; background: rgba(31, 26, 12, 0.96); }
.toast.err { border-color: #7f1d1d; background: rgba(40, 16, 16, 0.96); }

.clan-type {
  display: inline-flex; align-items: center;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.55);
  color: var(--muted);
  white-space: nowrap;
}
.clan-type-public {
  border-color: #166534;
  background: rgba(22, 101, 52, 0.18);
  color: #86efac;
}
.clan-type-private {
  border-color: #854d0e;
  background: rgba(133, 77, 14, 0.2);
  color: #fcd34d;
}

/* Role badges + compact member rows */
.role-badge {
  display: inline-flex; align-items: center;
  font-size: 0.62rem; font-weight: 650; letter-spacing: 0.02em;
  padding: 0.08rem 0.35rem; border-radius: 4px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.6);
  color: var(--muted);
  vertical-align: middle;
}
.role-badge.owner { color: #fbbf24; border-color: #854d0e; background: #1f1a0c; }
.role-badge.admin { color: #38bdf8; border-color: #075985; background: #0c1a24; }
.role-badge.member { color: #94a3b8; border-color: #334155; }

.members-wrap {
  /* show all members — scroll the clans panel, not an inner box */
  max-height: none;
  overflow: visible;
}
.members-table {
  width: max-content;
  max-width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  table-layout: auto;
}
.members-table th,
.members-table td {
  padding: 0.3rem 0.45rem;
  white-space: nowrap;
  vertical-align: middle;
  width: 1%;
}
.members-table th:first-child,
.members-table td:first-child {
  width: 1%;
  padding-inline-end: 0.55rem;
}
.members-table th:last-child,
.members-table td:last-child {
  width: auto;
}
.member-id-cell {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}
.member-actions {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.25rem;
  max-width: none;
}
.member-actions .btn {
  white-space: nowrap;
  font-size: 0.68rem;
  padding: 0.22rem 0.45rem;
  line-height: 1.2;
}

.ready-cell { min-width: 5.5rem; }
.ready-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  user-select: none;
}
.ready-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.ready-track {
  position: relative;
  width: 2.1rem;
  height: 1.15rem;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: background var(--ease), border-color var(--ease);
  flex-shrink: 0;
}
.ready-knob {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
  transition: transform var(--ease);
}
.ready-toggle.is-ready .ready-track {
  background: var(--ok);
  border-color: #166534;
}
.ready-toggle.is-not-ready .ready-track {
  background: var(--err);
  border-color: #7f1d1d;
}
.ready-toggle.is-ready .ready-knob {
  transform: translateX(0.9rem);
}
.ready-toggle.is-not-ready .ready-knob {
  transform: translateX(0);
}
.ready-label {
  font-size: 0.68rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.ready-toggle.is-ready .ready-label { color: var(--ok); }
.ready-toggle.is-not-ready .ready-label { color: var(--err); }
.ready-toggle:has(input:disabled) {
  opacity: 0.55;
  cursor: not-allowed;
}
.ready-toggle:has(input:focus-visible) .ready-track {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.detail-card .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.detail-card .row-actions .btn {
  font-size: 0.72rem;
  padding: 0.28rem 0.5rem;
}
.detail-card .kv {
  grid-template-columns: auto 1fr auto 1fr;
  gap: 0.15rem 0.55rem;
}

/* Shared dialog shell (claim / donate / review) */
.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 0;
  max-width: min(440px, 92vw);
  box-shadow: var(--shadow);
}
.modal::backdrop {
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
}
.modal form { padding: 1.1rem 1.15rem 1rem; margin: 0; }
.modal h3 { margin: 0 0 0.55rem; font-size: 1rem; }
.modal p { margin: 0 0 0.65rem; font-size: 0.82rem; line-height: 1.45; color: var(--muted); }
.modal label { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 0.35rem; }
.modal input { width: 100%; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Login gate (operator password) */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-wrap { width: min(100%, 24rem); }
.login-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1.35rem 1.4rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.login-eyebrow {
  font-size: 0.65rem;
  font-weight: 650;
  letter-spacing: 0.2em;
  color: var(--muted);
}
.login-title {
  margin: 0.15rem 0 0;
  font-size: 1.15rem;
  font-weight: 650;
}
.login-sub {
  margin: 0.35rem 0 0.75rem;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--muted);
}
.login-label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
.login-input { width: 100%; }
.login-error {
  margin-top: 0.35rem;
  font-size: 0.82rem;
  color: var(--err);
}
.login-submit {
  margin-top: 0.85rem;
  width: 100%;
  justify-content: center;
  padding: 0.55rem 0.8rem;
}
