:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #15181d;
  --muted: #6b7280;
  --line: #e3e5e9;
  --accent: #2f7d4f;
  --accent-text: #ffffff;
  --good: #2f7d4f;
  --warn: #b7791f;
  --bad: #c0392b;
  --staff-bubble: #e4f1e9;
  --player-bubble: #eef0f3;
  --tab-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --card: #191d23;
    --text: #e8eaed;
    --muted: #9aa1ab;
    --line: #2a3039;
    --accent: #4caf78;
    --accent-text: #0b0e11;
    --good: #5cc28a;
    --warn: #e0a84a;
    --bad: #ef6b5d;
    --staff-bubble: #1f3a2b;
    --player-bubble: #242a33;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { overflow-x: clip; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 14px; text-align: center; }
.login-logo { width: 72px; height: 72px; border-radius: 16px; margin: 0 auto; }
label { display: grid; gap: 6px; text-align: left; font-size: 13px; color: var(--muted); }

/* Shell */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.top-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.top-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 17px; }
main { padding: 4px 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px); max-width: 720px; margin: 0 auto; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs button {
  position: relative; height: var(--tab-h); border: 0; background: none;
  display: grid; justify-items: center; align-content: center; gap: 2px;
  font-size: 11px; color: var(--muted);
}
.tabs svg { width: 24px; height: 24px; }
.tabs button.on { color: var(--accent); }
.tabs .badge { position: absolute; top: 6px; left: calc(50% + 6px); }
.icon-btn { position: relative; border: 0; background: none; padding: 6px; color: var(--muted); }
.icon-btn .badge { position: absolute; top: 0; right: -2px; }

.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--bad); color: #fff; font-size: 11px; font-weight: 600;
  display: inline-grid; place-items: center;
}
.pill { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--line); color: var(--muted); white-space: nowrap; }
.pill.live { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.pill.stale { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.down { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.banner { padding: 8px 16px; font-size: 13px; background: color-mix(in srgb, var(--warn) 16%, var(--bg)); color: var(--text); border-bottom: 1px solid var(--line); }

/* Pieces */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.stack { display: grid; gap: 10px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.stat { text-align: center; padding: 12px 6px; }
.stat b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.row > * { min-width: 0; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.list > * { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.list > *:last-child { border-bottom: 0; }
.list button.item { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; }
.empty { padding: 18px; text-align: center; color: var(--muted); }
.ev { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 10px; align-items: baseline; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.anticheat, .dot.combatlog, .dot.pvp { background: var(--bad); }
.dot.tickets { background: var(--accent); }
.dot.restarts { background: var(--warn); }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 8px; background: var(--line); color: var(--muted); }
.tag.open { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.tag.claimed { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.tag.queued { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.tag.done { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.tag.failed { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.unread { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); display: inline-block; margin-right: 6px; }

.seg { display: grid; grid-auto-flow: column; gap: 4px; padding: 4px; background: var(--line); border-radius: 10px; margin: 12px 0; }
.seg button { border: 0; padding: 7px 4px; white-space: nowrap; border-radius: 7px; background: none; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; }

/* Forms */
input, select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg);
}
textarea { min-height: 90px; resize: vertical; }
.btn { border: 1px solid var(--line); background: var(--card); padding: 11px 14px; border-radius: 10px; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btns .btn { flex: 1; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.chip { flex: none; max-width: 240px; border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 6px 12px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.switch { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.switch input { width: auto; }

/* Ticket thread */
.back { border: 0; background: none; color: var(--accent); padding: 12px 0 4px; font-weight: 600; }
.thread { display: grid; gap: 8px; margin: 12px 0; }
.msg { max-width: 86%; padding: 9px 12px; border-radius: 14px; background: var(--player-bubble); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.staff { justify-self: end; background: var(--staff-bubble); }
.msg.pending { opacity: .65; border: 1px dashed var(--muted); }
.msg .meta { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px); z-index: 10;
  max-width: 480px; margin: 0 auto; padding: 12px 14px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}

/* Chips, leaderboards, logs */
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.rank { display: inline-block; min-width: 1.6em; }
.logline { font: 12px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.tbl th, .tbl td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--muted); font-weight: 600; }

/* Staff chat */
.thread.chat { max-height: calc(100dvh - 260px); overflow-y: auto; padding: 4px 0; }
.chatbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.chatbar textarea { min-height: 44px; }

/* Polish: tappable rows, avatars, menu icons */
.list button.item, .list button.item.row { cursor: pointer; transition: background .12s; }
.list button.item:active, .card.activity:active, .item-card:active { background: color-mix(in srgb, var(--text) 6%, var(--card)); }
.list button.item.row { display: flex; }
.who { justify-content: flex-start; gap: 10px; }
.av { flex: none; width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 12px; font-weight: 700; letter-spacing: .02em;
  background: color-mix(in srgb, var(--accent) 16%, var(--card)); color: var(--accent); }
.av.big { width: 44px; height: 44px; font-size: 16px; }
.list button.item.menu { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.mi { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 14%, var(--card)); color: var(--accent); }
.mi svg { width: 20px; height: 20px; }
.mt { display: grid; gap: 1px; min-width: 0; }
.chev { font-size: 18px; }
.card.activity, .item-card { display: block; width: 100%; text-align: left; cursor: pointer; }
.spark { display: block; width: 100%; height: 44px; margin: 8px 0 4px; }
.hl { color: var(--text); }
.pubrow { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.btn.slim { padding: 6px 12px; font-size: 13px; text-decoration: none; display: inline-block; flex: none; }
a.btn { color: inherit; text-decoration: none; text-align: center; }
a.btn.primary { color: var(--accent-text); }
.btns.nowrap { flex-wrap: nowrap; flex: none; }
.btns.nowrap .btn { flex: none; }
.bigdot { flex: none; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); }
.bigdot.on { background: var(--good); box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 25%, transparent); }
.badgeimg { height: 20px; width: auto; align-self: flex-start; }
.codebox { display: block; padding: 10px 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line);
  font: 12px/1.5 ui-monospace, Consolas, monospace; overflow-wrap: anywhere; }

/* Charts */
:root { --chart: #2f7d4f; }
@media (prefers-color-scheme: dark) { :root { --chart: #3f9a66; } }
.chartcard { margin-top: 10px; }
.chart { position: relative; margin-top: 6px; touch-action: pan-y; }
.chart svg { display: block; }
.cgrid { stroke: var(--line); stroke-width: 1; }
.ctxt { fill: var(--muted); font-size: 11px; }
.cline { fill: none; stroke: var(--chart); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.cbar { fill: var(--chart); }
.cross { stroke: var(--muted); stroke-width: 1; }
.tip { position: absolute; top: 0; padding: 4px 8px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); font-size: 12px; white-space: nowrap; pointer-events: none; }
.tip b { font-size: 14px; }
.hempty { fill: none; stroke: var(--line); stroke-width: 1; }
.hlegend { display: flex; align-items: center; gap: 3px; margin: 2px 0 6px; }
.hlegend span:not(.hsw) { margin-left: 4px; }
.hsw { width: 14px; height: 10px; border-radius: 2px; background: var(--chart); }

/* Map */
.mapwrap { position: relative; }
.map { width: 100%; aspect-ratio: 4 / 3; background: var(--card); border: 1px solid var(--line); border-radius: 14px; touch-action: none; display: block; }
.map .grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.map .gridtxt { fill: var(--muted); }
.map text { fill: var(--text); paint-order: stroke; stroke: var(--card); stroke-width: 3px; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.map .house { fill: color-mix(in srgb, var(--muted) 18%, transparent); stroke: var(--muted); stroke-width: 1; vector-effect: non-scaling-stroke; }
.map .warp rect { fill: var(--muted); }
.map .evt circle { fill: color-mix(in srgb, var(--warn) 15%, transparent); stroke: var(--warn); stroke-width: 1.5; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.map .tpin circle { fill: var(--bad); }
.map .pdot .dot { fill: var(--chart); stroke: var(--card); stroke-width: 2; vector-effect: non-scaling-stroke; }
.map .pdot.staff .dot { fill: var(--card); stroke: var(--chart); stroke-width: 3; }
.map .hit { fill: transparent; }
.map [data-mapu], .map [data-mapt] { cursor: pointer; }
.mapbtns { display: flex; gap: 6px; justify-content: flex-end; margin-top: 8px; }
.mapbtns .btn { padding: 6px 12px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { display: inline-block; width: 10px; height: 10px; }
.lg.dot { border-radius: 50%; background: var(--chart); }
.lg.ring { border-radius: 50%; border: 2px solid var(--chart); }
.lg.diamond { background: var(--muted); transform: rotate(45deg) scale(.8); }
.lg.house { background: color-mix(in srgb, var(--muted) 25%, transparent); border: 1px solid var(--muted); }
.lg.tpin { border-radius: 50%; background: var(--bad); }
.lg.evt { border-radius: 50%; border: 1.5px dashed var(--warn); }

/* Performance page */
details.item { padding: 12px 14px; }
details.item summary { list-style: none; cursor: pointer; }
details.item summary::-webkit-details-marker { display: none; }
details.item[open] summary { margin-bottom: 6px; }
details.item ul { margin: 4px 0; padding-left: 18px; }
pre.evidence { font: 11px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 220px; overflow-y: auto; margin: 6px 0 0; }
.map .hot { fill: var(--bad); }
.lg.hot { background: var(--bad); opacity: .45; }
