:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --line: #dcdad3;
  --accent: #2456c9;
  --accent-text: #ffffff;
  --x: #c2410c;
  --o: #2456c9;
  --ok-bg: #e5f4ea;
  --ok-text: #1b5e34;
  --err-bg: #fbe7e6;
  --err-text: #9b1c1c;
  --info-bg: #e8eefb;
  --info-text: #1f3f8a;
  --cell: #f1efe9;
  --cell-hover: #e6e3da;
  --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;
    --x: #fb923c;
    --o: #7fa7ff;
    --ok-bg: #173323;
    --ok-text: #9be3b4;
    --err-bg: #3a1a1a;
    --err-text: #ffb4ad;
    --info-bg: #1b2744;
    --info-text: #b8ccff;
    --cell: #25262d;
    --cell-hover: #2f3039;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  max-width: 720px;
  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, a.btn.ghost { background: transparent; color: var(--accent); }
a.btn {
  display: inline-flex; align-items: center; font-weight: 600; text-decoration: none;
  border: 1px solid var(--accent); border-radius: 8px; padding: 8px 14px; min-height: 40px;
}
button.small { min-height: 30px; padding: 2px 10px; font-size: 0.85rem; }
button:disabled { opacity: 0.55; cursor: progress; }

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);
}
label { display: block; font-size: 0.9rem; }
label input { margin-top: 4px; }

.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; }
#balance { font-size: 1.1rem; }

.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); }
.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; }

.fields { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; margin-bottom: 12px; }
@media (max-width: 520px) { .fields { grid-template-columns: 1fr; } }

.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); }

.games { list-style: none; margin: 0; padding: 0; }
.games li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.games li:first-child { border-top: 0; }
.games .info { min-width: 0; flex: 1 1 200px; }
.games .info a { font-weight: 600; }
.games .sub { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.games .btns { display: flex; gap: 8px; }

.pill { display: inline-block; font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; background: var(--cell); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.pill.you { background: var(--info-bg); color: var(--info-text); }

.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: min(100%, 360px); margin: 12px auto; }
.cell {
  aspect-ratio: 1; min-height: 0; padding: 0; border-radius: 10px;
  border: 1px solid var(--line); background: var(--cell); color: var(--text);
  font-size: clamp(2rem, 12vw, 3.4rem); font-weight: 800; line-height: 1;
}
.cell.playable:hover, .cell.playable:focus-visible { background: var(--cell-hover); }
.cell:disabled { opacity: 1; cursor: default; }
.cell.playable { cursor: pointer; }
.cell.pending { opacity: 0.5; }
.cell.win { outline: 3px solid var(--accent); outline-offset: -3px; }
.mark.x, .cell.x { color: var(--x); }
.mark.o, .cell.o { color: var(--o); }
.mark { font-weight: 800; }

.g-status { text-align: center; font-weight: 600; margin: 4px 0; }
.g-meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 12px 0; font-size: 0.9rem; }
.g-meta dt { color: var(--muted); }
.g-meta dd { margin: 0; overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.banner { text-align: center; font-weight: 700; padding: 10px; border-radius: 8px; margin-bottom: 8px; background: var(--info-bg); color: var(--info-text); }
.banner[data-kind="win"] { background: var(--ok-bg); color: var(--ok-text); }
.banner[data-kind="loss"] { background: var(--err-bg); color: var(--err-text); }

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