:root {
  --bg: #0e0f12;
  --panel: #16181d;
  --panel-2: #1f2229;
  --line: #2a2e37;
  --text: #eceef2;
  --muted: #8b919e;
  --accent: #e5383b;
  --accent-deep: #8f1d1f;
  --accent-soft: rgba(229, 56, 59, .14);
  --ct: #4c9aff;
  --ct-soft: rgba(76, 154, 255, .13);
  --t: #f2a541;
  --t-soft: rgba(242, 165, 65, .13);
  --live: #3ccf7a;
  --down: #6b7280;
  --radius: 16px;
  --shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
:root[data-scheme="light"] {
  --bg: #f2f3f6;
  --panel: #ffffff;
  --panel-2: #eff0f4;
  --line: #e1e3e9;
  --text: #15171c;
  --muted: #6b7280;
  --shadow: 0 6px 18px rgba(20, 24, 40, .08);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
body.locked { overflow: hidden; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico.flip { transform: rotate(180deg); width: 16px; height: 16px; opacity: .45; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); }

.ring-top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.crest {
  width: 42px; height: 42px; border-radius: 13px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), var(--accent-deep));
  color: #fff;
  box-shadow: 0 4px 14px rgba(229, 56, 59, .35);
}
.crest .ico { width: 28px; height: 28px; stroke-width: 1.6; }
.ring-title { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.ring-title b { font-size: 16px; letter-spacing: .2px; }
.ring-title span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
  background: var(--panel-2); color: var(--text);
  transition: transform .1s;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn.danger { color: var(--accent); }
.icon-btn.spinning .ico { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { padding: 16px; }
.view[hidden] { display: none; }

.tally { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.tally-cell {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 4px;
}
.tally-cell .ico { color: var(--accent); }
.tally-cell b { font-size: 20px; font-variant-numeric: tabular-nums; }
.tally-cell span { font-size: 12px; color: var(--muted); }

.bout {
  width: 100%; text-align: left;
  display: flex; flex-direction: column; gap: 9px;
  padding: 14px; margin-bottom: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .12s;
}
.bout:active { transform: scale(.985); }
.bout.is-down { opacity: .72; }
.bout-head { display: flex; align-items: center; gap: 10px; }
.bout-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.bout-count { font-weight: 700; font-variant-numeric: tabular-nums; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--down); flex: none; }
.is-live .pulse { background: var(--live); animation: beat 2s infinite; }
@keyframes beat {
  0% { box-shadow: 0 0 0 0 rgba(60, 207, 122, .55); }
  70% { box-shadow: 0 0 0 8px rgba(60, 207, 122, 0); }
  100% { box-shadow: 0 0 0 0 rgba(60, 207, 122, 0); }
}
.bout-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.bout-meta .ico { width: 16px; height: 16px; }
.mini-score { margin-left: auto; padding: 2px 9px; border-radius: 8px; background: var(--panel-2); color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.mini-score .ct { color: var(--ct); }
.mini-score .t { color: var(--t); }
.meter { height: 6px; border-radius: 6px; background: var(--panel-2); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--accent), #ff7a59); transition: width .4s; }

.bout-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.bout-top-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bout-top-text b { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bout-top-text span { font-size: 12px; }
.state-tag { padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted); }
.state-tag.is-live { background: rgba(60, 207, 122, .15); color: var(--live); }

.address-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 8px 14px; margin-bottom: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.address-row code { flex: 1; font-size: 15px; overflow: hidden; text-overflow: ellipsis; }
.chip-btn { padding: 9px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 13px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.stat {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px;
  padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.stat .ico { grid-row: span 2; align-self: center; color: var(--accent); width: 22px; height: 22px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }

.scoreboard {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 16px; margin-bottom: 12px;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: linear-gradient(90deg, var(--ct-soft), transparent 45%, transparent 55%, var(--t-soft)), var(--panel);
}
.side { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.side b { font-size: 34px; line-height: 1; font-variant-numeric: tabular-nums; }
.side-ct { color: var(--ct); }
.side-t { color: var(--t); }
.side .ico { width: 24px; height: 24px; }
.versus { font-size: 26px; color: var(--muted); font-weight: 700; }

.corner { margin-bottom: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.corner-head { display: flex; align-items: center; gap: 8px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.corner-head b { flex: 1; }
.corner-count { min-width: 26px; text-align: center; padding: 2px 8px; border-radius: 10px; background: var(--panel-2); font-weight: 700; font-size: 13px; }
.corner-ct .corner-head { color: var(--ct); background: var(--ct-soft); }
.corner-t .corner-head { color: var(--t); background: var(--t-soft); }
.corner-spec .corner-head, .corner-none .corner-head { color: var(--muted); }
.roster { list-style: none; margin: 0; padding: 0; counter-reset: place; }
.fighter { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); counter-increment: place; }
.fighter:first-child { border-top: 0; }
.fighter::before { content: counter(place); width: 18px; color: var(--muted); font-size: 12px; text-align: right; flex: none; }
.corner-spec .fighter::before { content: ""; width: 0; }
.fighter.is-fallen .fighter-name { opacity: .5; }
.fighter-name { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; }
.fighter-name > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fighter-figures { display: flex; align-items: center; gap: 10px; font-size: 13px; font-variant-numeric: tabular-nums; flex: none; }
.kd b { font-size: 15px; }
.tag { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; background: var(--panel-2); color: var(--muted); flex: none; }
.tag .ico { width: 14px; height: 14px; }
.tag-dead { color: var(--accent); background: var(--accent-soft); }
.ping-good { color: var(--live); }
.ping-fair { color: var(--t); }
.ping-poor { color: var(--accent); }
.roster-empty { margin: 0; padding: 12px 14px; }
.bout-foot { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; padding: 6px 0 4px; }
.bout-foot .ico { width: 14px; height: 14px; }

.note {
  display: flex; align-items: center; gap: 10px;
  padding: 18px; border-radius: var(--radius);
  background: var(--panel); border: 1px dashed var(--line); color: var(--muted);
}
.loading { padding: 40px 0; text-align: center; color: var(--muted); }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.section-head h2 { margin: 0; font-size: 20px; }
.hint { font-size: 13px; color: var(--muted); margin: 10px 2px; word-break: break-word; }
.hint code { color: var(--text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 14px; border-radius: 12px;
  background: var(--panel-2); font-weight: 600;
  transition: transform .1s, opacity .1s;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .5; }
.btn .ico { width: 18px; height: 18px; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-danger { background: var(--accent-soft); color: var(--accent); }

.forge-list, .chat-list { display: flex; flex-direction: column; gap: 8px; }
.forge-row, .chat-row {
  width: 100%; text-align: left;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.chat-row > .ico { color: var(--accent); }
.forge-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.forge-text b, .forge-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.forge-text span { font-size: 13px; }
.forge-flags { display: flex; align-items: center; gap: 6px; }
.chat-form { display: flex; gap: 8px; margin-bottom: 14px; }
.chat-form input { flex: 1; }

input {
  width: 100%; padding: 11px 12px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: inherit;
  outline: none;
}
input:focus { border-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.field > span { font-size: 12px; color: var(--muted); }
.field-pair { display: grid; grid-template-columns: 1fr 96px; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin: -2px 0 10px; }
.check input { width: auto; }
.divider { display: flex; align-items: center; gap: 10px; margin: 6px 0 12px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.editor h3 { margin: 0 0 14px; font-size: 18px; }
.editor-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.editor-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.editor-tools .btn-danger { grid-column: span 2; }
.key-block { margin-top: 16px; padding: 12px; border-radius: 14px; background: var(--panel-2); }
.key-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.key-head b { flex: 1; }
.key-head > .ico { color: var(--accent); }
.key-block pre { margin: 0; padding: 10px; border-radius: 10px; background: var(--bg); font-size: 12px; white-space: pre-wrap; word-break: break-all; }

.sheet {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, .55);
  display: flex; align-items: flex-end;
  animation: fade .15s ease-out;
}
.sheet[hidden] { display: none; }
.sheet-body {
  width: 100%; max-height: 92vh; overflow-y: auto;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  background: var(--panel); border-radius: 22px 22px 0 0;
  animation: rise .2s ease-out;
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: .4; } }

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.dock[hidden] { display: none; }
.dock-btn { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; border-radius: 12px; color: var(--muted); font-size: 11px; font-weight: 600; }
.dock-btn.active { color: var(--accent); background: var(--accent-soft); }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
}
.toast.is-bad { background: var(--accent); color: #fff; }
.toast[hidden] { display: none; }
.fatal { padding: 60px 20px; text-align: center; color: var(--muted); }
.fatal .ico { width: 42px; height: 42px; color: var(--accent); margin-bottom: 12px; }

.dock-btn { position: relative; }
.dock-badge {
  position: absolute; top: 2px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff;
  font-size: 11px; font-style: normal; font-weight: 700; line-height: 18px; text-align: center;
}
.chat-row.is-knock { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.chat-row.is-knock > .ico { color: var(--t); }
.icon-btn.accept { color: var(--live); }
