:root {
  --bg: #e8ebee;
  --panel: #f7f7f7;
  --panel-head: #1b1b1b;
  --panel-head-fg: #ffffff;
  --text: #1d2329;
  --muted: #6b7380;
  --line: #d9dde2;
  --zebra: #eceef0;
  --hover: #e2e6ea;
  --input-bg: #ffffff;
  --link: #2f6f9f;
  --ok: #2e9e44;
  --bad: #d93025;
  --info: #1a6fd1;
  --bar-track: #cfd3d9;
  --bar-fill: #8a96cf;
  --win-bg: #dff0d8;
  --loss-bg: #f8d7da;
  --shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

:root[data-theme='dark'] {
  --bg: #0e1115;
  --panel: #161a20;
  --panel-head: #090b0e;
  --panel-head-fg: #e8ecf1;
  --text: #d6dce4;
  --muted: #8a94a3;
  --line: #29303a;
  --zebra: #1b2028;
  --hover: #232a34;
  --input-bg: #0f1318;
  --link: #6fb3e8;
  --ok: #4cc766;
  --bad: #ff6b5f;
  --info: #5b9dff;
  --bar-track: #2a313b;
  --bar-fill: #6f7fd1;
  --win-bg: #1c3626;
  --loss-bg: #432127;
  --shadow: 0 1px 3px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 Roboto, system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
code { background: var(--zebra); padding: 1px 5px; border-radius: 4px; }

.ic { width: 16px; height: 16px; vertical-align: -3px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel-head); color: var(--panel-head-fg);
  position: sticky; top: 0; z-index: 20; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: .3px; }
.brand .ic { width: 22px; height: 22px; color: #e5484d; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  background: transparent; color: #aab3bf; border: 0; padding: 8px 14px; border-radius: 6px;
  cursor: pointer; font: inherit; font-weight: 500;
}
.tabs button:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.tabs button.active { color: #fff; background: rgba(255, 255, 255, .16); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.save-ind { font-size: 12px; color: #98a2b0; min-width: 110px; text-align: right; }
.save-ind.ok { color: #6fdc8c; }
.save-ind.err { color: #ff8a80; }
.save-ind.pending { color: #ffd479; }
.chip {
  background: rgba(255, 255, 255, .1); color: #fff; border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 999px; padding: 5px 12px; cursor: pointer; font: inherit; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { background: rgba(255, 255, 255, .18); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: #6b7380; }
.chip.on .dot { background: #4cc766; }
.chip.off .dot { background: #ff6b5f; }

.icon-btn {
  background: transparent; border: 0; color: inherit; cursor: pointer; padding: 6px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1;
}
.icon-btn:hover { background: var(--hover); }
.topbar .icon-btn:hover { background: rgba(255, 255, 255, .14); }
.icon-btn.lg .ic { width: 19px; height: 19px; }

/* ---------- banner / toast ---------- */
.banner { padding: 10px 16px; font-size: 13.5px; border-bottom: 1px solid var(--line); }
.banner.warn { background: #fff3cd; color: #5c4400; }
.banner.err { background: #f8d7da; color: #6b1d24; }
:root[data-theme='dark'] .banner.warn { background: #3a3012; color: #ffe08a; }
:root[data-theme='dark'] .banner.err { background: #43212a; color: #ffb4bd; }
.banner button { margin-left: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #22282f; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
  transition: opacity .2s, transform .2s; z-index: 100; max-width: 90vw; font-size: 13.5px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #8b1f27; }
.toast.ok { background: #1f6b35; }

/* ---------- panels ---------- */
main { max-width: 1500px; margin: 16px auto; padding: 0 12px 40px; }
.panel { background: var(--panel); border-radius: 6px; box-shadow: var(--shadow); overflow: hidden; }
.panel-head {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  background: var(--panel-head); color: var(--panel-head-fg); padding: 10px 16px;
}
.panel-head h2 { margin: 0; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.panel-head h2 small { font-size: 12px; font-weight: 400; color: #98a2b0; margin-left: 4px; }
.head-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.hbtn {
  background: transparent; color: #fff; border: 0; padding: 6px 10px; border-radius: 6px; cursor: pointer;
  font: inherit; font-weight: 700; display: inline-flex; gap: 6px; align-items: center;
}
.hbtn:hover { background: rgba(255, 255, 255, .14); }
.hbtn[disabled] { opacity: .5; cursor: not-allowed; }
.hbtn.spin .ic { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hselect { background: #2a2f36; color: #fff; border: 1px solid #3b424b; border-radius: 6px; padding: 6px 8px; font: inherit; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 0; color: #fff; padding: 7px 14px; border-radius: 4px; cursor: pointer; font: inherit; font-weight: 500;
}
.btn:hover { filter: brightness(1.1); }
.btn.sm { padding: 3px 10px; font-size: 12.5px; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .6; cursor: not-allowed; }
.btn.blue { background: #0d6efd; }
.btn.grey { background: #6c757d; }
.btn.green { background: #198754; }
.btn.red { background: #dc3545; }
.btn.yellow { background: #ffc107; color: #1d2329; }

input[type='text'], input[type='number'], input[type='password'], input[type='search'], select, textarea {
  background: var(--input-bg); color: var(--text); border: 1px solid var(--line); border-radius: 4px;
  padding: 6px 8px; font: inherit;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid #4c8dff; outline-offset: 1px;
}
textarea { width: 100%; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }

/* ---------- filters ---------- */
.filters { margin: 12px 16px; padding: 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.filters.collapsed { display: none; }
.frow { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.frow + .frow { margin-top: 10px; }
.filters input[type='number'] { width: 90px; }
.filters input[type='search'] { width: 190px; }
.chips { display: inline-flex; gap: 6px; }
.chip-btn {
  border: 1px solid var(--line); background: var(--input-bg); border-radius: 6px; width: 34px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text);
}
.chip-btn.on { outline: 2px solid #4c8dff; background: var(--hover); }

/* ---------- progress ---------- */
.progress { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--zebra); border-bottom: 1px solid var(--line); }
.pbar { flex: 1; height: 8px; background: var(--bar-track); border-radius: 99px; overflow: hidden; }
.pbar i { display: block; height: 100%; width: 0; background: #0d6efd; transition: width .3s; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; padding: 0 16px 14px; }
.table-wrap.narrow { max-width: 1100px; margin: 0 auto; }
table.grid { width: 100%; border-collapse: collapse; min-width: 1120px; }
.grid th {
  text-align: left; font-size: 11.5px; letter-spacing: .4px; text-transform: uppercase; color: var(--muted);
  padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none;
}
.grid th[data-sort] { cursor: pointer; }
.grid th[data-sort]:hover { color: var(--text); }
.grid th .arr { display: inline-block; width: 10px; margin-left: 4px; font-size: 9px; opacity: .35; }
.grid th.sorted .arr { opacity: 1; color: var(--text); }
.grid td { padding: 8px; border-bottom: 1px solid transparent; white-space: nowrap; vertical-align: middle; }
.grid tbody tr:nth-child(even) { background: var(--zebra); }
.grid tbody tr:hover { background: var(--hover); }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .ctr { text-align: center; }
.grid .strong { font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 30px !important; }

.res-win { color: var(--ok); }
.res-loss { color: var(--bad); }
.st.ok { color: var(--ok); font-weight: 500; }
.st.bad { color: var(--bad); }
.st.info { color: var(--info); }

.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: middle; background: #5d646d; }
.dot.online { background: #1fb53c; }
.dot.idle { background: #f0a020; }
.dot.offline { background: #5d646d; }

.life { width: 150px; }
.bar { height: 14px; background: var(--bar-track); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--bar-fill); border-radius: 99px; }

.c-notes { display: flex; align-items: center; gap: 8px; }
.note { width: 170px; border: 0; background: transparent; padding: 4px 2px; color: var(--text); border-radius: 0; }
.note::placeholder { color: var(--muted); opacity: .8; }
.note:focus { border-bottom: 1px solid #4c8dff; outline: none; }

/* notes colour glyphs: 0 none, 1 green play, 2 orange square, 3 black circle */
.cbtn { background: transparent; border: 0; padding: 4px; cursor: pointer; width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; }
.cbtn i, .chip-btn i { display: block; }
.cbtn[data-c='0'] i, .chip-btn[data-c='0'] i { width: 12px; height: 12px; border: 2px dashed var(--muted); border-radius: 50%; opacity: .7; }
.cbtn[data-c='1'] i, .chip-btn[data-c='1'] i { width: 0; height: 0; border-left: 12px solid #1fb53c; border-top: 7px solid transparent; border-bottom: 7px solid transparent; }
.cbtn[data-c='2'] i, .chip-btn[data-c='2'] i { width: 12px; height: 12px; background: #f59e0b; border-radius: 2px; }
.cbtn[data-c='3'] i, .chip-btn[data-c='3'] i { width: 13px; height: 13px; background: #111; border-radius: 50%; border: 1px solid #666; }
:root[data-theme='dark'] .cbtn[data-c='3'] i, :root[data-theme='dark'] .chip-btn[data-c='3'] i { background: #000; border-color: #9aa3ad; }
.cbtn[data-c='4'] i, .chip-btn[data-c='4'] i {
  width: 17px; height: 17px; background: #e5242f;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

.act { color: var(--link); }
.act:hover { background: var(--hover); text-decoration: none; }
.act.danger { color: var(--bad); }

/* ---------- attacks page ---------- */
table.grid.attacks { min-width: 820px; }
.attacks tbody tr.win { background: var(--win-bg); }
.attacks tbody tr.loss { background: var(--loss-bg); }
.attacks tbody tr:hover { filter: brightness(.96); }
:root[data-theme='dark'] .attacks tbody tr:hover { filter: brightness(1.15); }
.save-btn.saved { color: var(--ok); }
.save-btn.unsaved { color: var(--bad); }
.more-row { text-align: center; padding: 6px 0 18px; }

/* ---------- dialogs ---------- */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 18px 20px; width: min(520px, 94vw); box-shadow: 0 10px 40px rgba(0, 0, 0, .4);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h3 { margin: 0 0 8px; }
dialog label { display: block; margin: 10px 0 4px; font-weight: 500; }
dialog input[type='password'], dialog input[type='text'] { width: 100%; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.radios label { font-weight: 400; margin: 6px 0; }
.radios input { margin-right: 6px; }
#imp-file { margin: 6px 0; max-width: 100%; }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 28px 26px; box-shadow: var(--shadow); text-align: center;
}
.login-card h1 { margin: 6px 0 4px; font-size: 22px; }
.login-card label { display: block; text-align: left; margin: 16px 0 4px; font-weight: 500; }
.login-card input[type='password'] { width: 100%; padding: 10px; }
.login-card .btn { margin-top: 14px; padding: 10px; }
.login-logo { color: #e5484d; }
.login-err { color: var(--bad); min-height: 1.3em; margin: 8px 0 0; font-size: 13px; }

/* ---------------------------------------------------------------- chains */
.ch-body { padding: 0 0 16px; }
.ch-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 16px 0; }
.ch-bar .grow { flex: 1; }
.ch-bar label.chk { font-weight: 400; display: inline-flex; align-items: center; gap: 6px; }
.ch-info { margin: 10px 16px; color: var(--muted); font-size: 13.5px; }
.ch-info.err { color: var(--bad); }
.ch-setup { margin: 16px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.ch-setup pre { background: var(--zebra); padding: 10px; border-radius: 6px; overflow-x: auto; }
table.grid.chains { min-width: 900px; }
.chains tr.live { background: var(--win-bg) !important; }
.chains td.rep { white-space: nowrap; }
.chains td.rep .icon-btn { vertical-align: middle; }
.rbadge { display: inline-block; width: 20px; text-align: center; font-weight: 700; }
.rbadge.ok, .rbadge-text.ok { color: var(--ok); }
.rbadge.partial, .rbadge-text.partial { color: #c98a00; }
.rbadge.counts, .rbadge-text.counts { color: var(--muted); }
.rbadge-text { font-size: 11.5px; margin-left: 6px; }
.rbadge-text.ok { font-weight: 600; }
.rep-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; background: var(--panel-head); color: var(--panel-head-fg); padding: 10px 16px; margin-top: 12px; }
.rep-bar h3 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.rep-bar .head-actions { margin-left: auto; }
.rep-bar label.tog { font-size: 13px; display: inline-flex; align-items: center; gap: 6px; font-weight: 400; color: var(--panel-head-fg); }
.rep-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 18px; padding: 16px; text-align: center; }
.rep-stats .stat { font-size: 14px; }
.rep-note { margin: 0 16px 10px; padding: 8px 12px; border-radius: 6px; font-size: 13px; background: var(--zebra); border-left: 4px solid var(--muted); }
.rep-note.partial { border-left-color: #c98a00; }
.rep-note.complete { border-left-color: var(--ok); }
.chain-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; justify-content: center; }
.chain-chip { border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; font-size: 12.5px; background: var(--panel); }
.chain-chip.partial { border-color: #c98a00; }
.chain-chip.counts { border-style: dashed; }
.bonus-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; padding: 4px 16px 16px; }
.bonus { border: 1px solid var(--line); border-radius: 4px; padding: 8px 12px; text-align: center; background: var(--panel); min-width: 150px; display: flex; flex-direction: column; gap: 1px; }
.bonus b { font-size: 16px; font-weight: 500; }
.bonus small { color: var(--muted); font-size: 11px; }
.grid.players { min-width: 1100px; }
.grid.players th { white-space: normal; line-height: 1.2; vertical-align: bottom; }
.grid.players th .arr { margin-left: 2px; }
.grid td.na { color: var(--muted); }
.players tbody tr.me { background: var(--win-bg) !important; font-weight: 600; }
.ch-foot { padding: 0 16px; font-size: 12.5px; }
.prizes { margin-top: 18px; }
.prize-ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 16px 4px; font-size: 13px; }
.prize-ctl input { width: 70px; }
.prize-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; padding: 12px 16px 4px; }
.prize { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; background: var(--panel); }
.prize h4 { margin: 0 0 2px; font-size: 15px; }
.prize p { margin: 0 0 6px; font-size: 12.5px; }
.prize p.na { color: var(--muted); font-style: italic; }
.prize ol { list-style: none; margin: 6px 0 0; padding: 0; }
.prize li { display: flex; gap: 6px; align-items: baseline; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.prize li:last-child { border-bottom: 0; }
.prize li .rk { min-width: 22px; color: var(--muted); }
.prize li .val { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; padding-left: 10px; }
@media (max-width: 720px) {
  .rep-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); text-align: left; }
  .rep-bar { padding: 8px 12px; }
  .bonus { flex: 1 1 42%; min-width: 130px; }
}

@media (max-width: 720px) {
  .save-ind { display: none; }
  .brand span:last-child { display: none; }
  .panel-head h2 { font-size: 16px; }
}
