:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --line: #dcdad3;
  --accent: #2456c9;
  --accent-text: #ffffff;
  --ok-bg: #e5f4ea;
  --ok-text: #1b5e34;
  --err-bg: #fbe7e6;
  --err-text: #9b1c1c;
  --info-bg: #e8eefb;
  --info-text: #1f3f8a;
  --cell: #f1efe9;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316;
    --card: #1c1d22;
    --text: #ececef;
    --muted: #9a9aa3;
    --line: #2f3038;
    --accent: #6f9bff;
    --accent-text: #0d1424;
    --ok-bg: #173323;
    --ok-text: #9be3b4;
    --err-bg: #3a1a1a;
    --err-text: #ffb4ad;
    --info-bg: #1b2744;
    --info-text: #b8ccff;
    --cell: #25262d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  max-width: 820px;
  padding: 16px;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small-text { font-size: 0.85rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.brand { font-weight: 700; font-size: 1.2rem; color: var(--text); text-decoration: none; }
.brand .muted { font-weight: 400; font-size: 0.9rem; }
.conn { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.conn::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.conn[data-state="on"]::before { background: #22a55a; }
.conn[data-state="off"]::before { background: #d97706; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }

button {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
  border-radius: 8px; padding: 8px 14px; min-height: 40px;
}
button.ghost { background: transparent; color: var(--accent); }
button.small { min-height: 30px; padding: 2px 10px; font-size: 0.85rem; }
button:disabled { opacity: 0.55; cursor: default; }

input {
  font: inherit; width: 100%; padding: 8px 10px; min-height: 40px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text);
}

.wallet-row { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; justify-content: space-between; }
.wallet-id, .wallet-bal { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.label { color: var(--muted); font-size: 0.85rem; }
.addr { overflow-wrap: anywhere; }

.keybox { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.keybox summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.note { font-size: 0.9rem; color: var(--muted); margin: 0 0 8px; }
.keyrow { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.keyrow input { flex: 1 1 220px; width: auto; }
.wif { overflow-wrap: anywhere; padding: 6px 8px; background: var(--cell); border-radius: 6px; flex: 1 1 220px; }

.msg { margin: 10px 0 0; padding: 8px 10px; border-radius: 8px; font-size: 0.9rem; overflow-wrap: anywhere; }
.msg[data-kind="error"] { background: var(--err-bg); color: var(--err-text); }
.msg[data-kind="ok"] { background: var(--ok-bg); color: var(--ok-text); }
.msg[data-kind="info"] { background: var(--info-bg); color: var(--info-text); }

.hud { display: flex; gap: 8px 20px; flex-wrap: wrap; margin-bottom: 8px; font-size: 0.95rem; }
.board { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; border: 1px solid var(--line); border-radius: 8px; background: var(--cell); touch-action: manipulation; }
.towers { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 12px 0; }
.towers button { text-align: left; background: transparent; color: var(--text); border-color: var(--line); display: block; line-height: 1.3; }
.towers button[aria-checked="true"] { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: -2px; }
.towers .sw { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.towers small { display: block; color: var(--muted); font-weight: 400; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.banner { text-align: center; font-weight: 700; padding: 10px; border-radius: 8px; margin: 12px 0 0; background: var(--info-bg); color: var(--info-text); }

.lb { margin: 0 0 12px; padding-left: 1.6em; }
.lb li { padding: 4px 0; }
.lb li.me { font-weight: 700; }
.lb .score { float: right; font-variant-numeric: tabular-nums; }
.lb .prize { color: var(--ok-text); font-size: 0.85rem; margin-left: 8px; }

.games { list-style: none; margin: 0; padding: 0; }
.games li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.games li:first-child { border-top: 0; }

footer { margin-top: 8px; overflow-wrap: anywhere; }
