:root {
  --bg: #1b1a17;
  --panel: #262420;
  --panel-2: #2f2c27;
  --line: #3b3731;
  --text: #f1ebdf;
  --muted: #a39b8c;
  --accent: #e0a44a;
  --accent-ink: #1b1a17;
  --good: #7fc28a;
  --bad: #e07a6a;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; }
#app { max-width: 980px; margin: 0 auto; padding: 12px 16px 40px; padding-top: max(12px, env(safe-area-inset-top)); }

.top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; min-height: 40px; }
.brand { font-weight: 700; font-size: 20px; letter-spacing: .3px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand img { width: 26px; height: 26px; }
.top .sp { flex: 1; }
.top .who { color: var(--muted); font-size: 14px; }
.link-btn { background: none; border: 0; color: var(--muted); padding: 6px 4px; cursor: pointer; font-size: 14px; }
.link-btn:hover { color: var(--text); }
.nav a { color: var(--muted); font-size: 14px; padding: 6px 4px; }
.nav a.on, .nav a:hover { color: var(--text); }

.btn { border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600; cursor: pointer; background: var(--panel-2); color: var(--text); transition: transform .06s, filter .15s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.danger { color: var(--bad); }

.card { background: var(--panel); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h2 { margin: 0 0 12px; font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.auth { max-width: 380px; margin: 8vh auto 0; }
.auth h1 { font-size: 28px; margin: 0 0 6px; }
.tabs { display: flex; gap: 6px; background: var(--panel); border-radius: 12px; padding: 4px; margin: 18px 0 14px; }
.tabs button { flex: 1; border: 0; background: none; color: var(--muted); padding: 10px; border-radius: 9px; cursor: pointer; font-weight: 600; }
.tabs button.on { background: var(--panel-2); color: var(--text); }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input { width: 100%; padding: 12px 14px; border-radius: 11px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px; }
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; margin: 4px 0 8px; }

.create { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.create .btn { padding: 16px; text-align: left; }
.create .btn b { display: block; font-size: 17px; }
.create .btn span { font-size: 13px; font-weight: 500; opacity: .75; }

.list { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; background: var(--panel-2); border-radius: 12px; padding: 12px 14px; color: var(--text); }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { font-size: 13px; color: var(--muted); }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--line); color: var(--muted); white-space: nowrap; }
.badge.go { background: var(--accent); color: var(--accent-ink); }
.empty { color: var(--muted); font-size: 14px; padding: 4px 2px; }

/* --- игра --- */
.game { display: flex; flex-direction: column; gap: 8px; }
.player { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel); border-radius: 12px; border: 2px solid transparent; }
.player.turn { border-color: var(--accent); }
.chip { width: 20px; height: 20px; border-radius: 50%; flex: none; }
.chip.w { background: #f7f1e3; box-shadow: inset 0 0 0 2px #b8a98a; }
.chip.b { background: #2a2522; box-shadow: inset 0 0 0 2px #000, 0 0 0 1px #555; }
.player .nm { font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .st { font-size: 13px; color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #555; display: inline-block; margin-left: 6px; vertical-align: middle; }
.dot.on { background: var(--good); }

.board-wrap { position: relative; }
svg.board { width: 100%; height: auto; display: block; border-radius: 10px; user-select: none; touch-action: manipulation; }
svg.board .hit { cursor: pointer; }
.actions { display: flex; gap: 10px; align-items: center; min-height: 48px; flex-wrap: wrap; }
.actions .msg { flex: 1; color: var(--muted); font-size: 14px; min-width: 150px; }
.actions .msg b { color: var(--text); }

.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(20,18,15,.55); border-radius: 10px; }
.overlay .box { background: var(--panel); border-radius: 16px; padding: 22px 24px; text-align: center; max-width: 90%; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.overlay .box h3 { margin: 0 0 6px; font-size: 24px; }
.overlay .box .btns { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

.share { display: flex; gap: 8px; margin-top: 10px; }
.share input { flex: 1; min-width: 0; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 14px; }

.log { font-size: 13px; color: var(--muted); max-height: 160px; overflow: auto; }
.log div { padding: 2px 0; }

/* --- статистика --- */
.vs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.vs { background: var(--panel-2); border-radius: 12px; padding: 14px; }
.vs .score { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.vs .score .n { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.vs .score .n.lead { color: var(--accent); }
.vs .names { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 2px; }
.vs .bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin: 8px 0; display: flex; }
.vs .bar i { display: block; height: 100%; background: var(--accent); }
.vs .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.pills { display: flex; gap: 4px; margin-top: 8px; }
.pills i { width: 16px; height: 16px; border-radius: 4px; font-style: normal; font-size: 10px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.pills i.w { background: var(--good); color: #10240f; }
.pills i.l { background: var(--bad); color: #2a0f0a; }
table.lb { width: 100%; border-collapse: collapse; font-size: 14px; }
table.lb th { text-align: right; color: var(--muted); font-weight: 500; padding: 6px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.lb td { text-align: right; padding: 8px 6px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.lb th:first-child, table.lb td:first-child { text-align: left; }
table.lb tr.me td { color: var(--accent); }
.scroll-x { overflow-x: auto; }

.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: #3a342c; color: var(--text); padding: 12px 18px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.4); font-size: 15px; z-index: 50; max-width: calc(100% - 32px); }

@media (max-width: 560px) {
  #app { padding-left: 10px; padding-right: 10px; }
  .player { padding: 6px 10px; }
  .card { padding: 14px; }
}

.nav { display: flex; gap: 10px; }
@media (max-width: 560px) {
  .brand { font-size: 18px; }
  .actions .msg { flex-basis: 100%; }
  .actions .btn { flex: 1; }
  svg.board { max-height: 64vh; width: auto; max-width: 100%; margin: 0 auto; }
}
