/* ───────────── 设计变量 ───────────── */
:root {
  --paper: #F7F4EF;
  --surface: #FFFFFF;
  --surface-2: #F1EDE6;
  --ink: #1F1E1C;
  --ink-2: #55514B;
  --ink-3: #8C867D;
  --line: rgba(31, 30, 28, 0.10);
  --accent: #2F6F5E;
  --accent-soft: rgba(47, 111, 94, 0.10);
  --danger: #B4413C;
  --gold: #B8893C;
  --shadow-sm: 0 1px 2px rgba(31, 30, 28, .06), 0 2px 8px rgba(31, 30, 28, .05);
  --shadow-md: 0 4px 12px rgba(31, 30, 28, .08), 0 16px 40px rgba(31, 30, 28, .10);
  --radius: 14px;
  --radius-sm: 9px;
  --serif: "Songti SC", "SimSun", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17181B;
    --surface: #202225;
    --surface-2: #292B2F;
    --ink: #ECE8E2;
    --ink-2: #B4AFA7;
    --ink-3: #837E76;
    --line: rgba(236, 232, 226, 0.11);
    --accent: #6FBFA5;
    --accent-soft: rgba(111, 191, 165, 0.13);
    --danger: #E0817C;
    --gold: #D6A960;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.30), 0 2px 8px rgba(0,0,0,.24);
    --shadow-md: 0 4px 14px rgba(0,0,0,.40), 0 18px 44px rgba(0,0,0,.44);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: .01em; }
h2 { font-size: 15px; }
h3 { font-size: 17px; }
ul, ol, menu { margin: 0; padding: 0; list-style: none; }
button, input { font: inherit; color: inherit; }

.view { max-width: 980px; margin: 0 auto; padding: 20px 16px 40px; }
.view--center { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 26px; }
[hidden] { display: none !important; }
.muted { color: var(--ink-3); font-size: 13px; }
.hint { color: var(--ink-3); font-size: 12.5px; margin: 0; }
.error { color: var(--danger); font-size: 13px; margin: 0; }
.empty { color: var(--ink-3); font-size: 13px; text-align: center; padding: 18px 6px; margin: 0; }

/* ───────────── 品牌 ───────────── */
.brand { text-align: center; }
.brand__mark { display: inline-flex; align-items: center; }
.brand__mark .dot { width: 17px; height: 17px; border-radius: 50%; display: block; }
.brand__mark .dot--b { background: radial-gradient(circle at 32% 30%, #6E7176, #17181A 70%); }
.brand__mark .dot--w { background: radial-gradient(circle at 32% 30%, #fff, #CFC9BE 78%); margin-left: -6px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.10); }
.brand__mark--sm .dot { width: 13px; height: 13px; }
.brand__name { font-family: var(--serif); font-size: 44px; line-height: 1.1; margin-top: 6px; letter-spacing: .08em; }
.brand__sub { color: var(--ink-3); font-size: 13.5px; margin: 4px 0 0; letter-spacing: .16em; }

/* ───────────── 卡片 / 表单 ───────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}
.card--login { width: min(380px, 100%); padding: 22px; display: grid; gap: 14px; }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }

.field { display: grid; gap: 6px; }
.field__label { font-size: 12.5px; color: var(--ink-3); letter-spacing: .04em; }
input[type=email], input[type=text] {
  width: 100%; padding: 11px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2); outline: none;
  transition: border-color .16s, box-shadow .16s, background .16s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }

.btn {
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 16px; background: var(--surface-2); color: var(--ink);
  cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: background .16s, border-color .16s, opacity .16s, transform .08s;
}
.btn:hover { background: var(--line); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent); filter: brightness(1.07); }
@media (prefers-color-scheme: dark) { .btn--primary { color: #10201B; } }
.btn--ghost { background: transparent; border-color: var(--line); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--sm { padding: 6px 12px; font-size: 13px; }
.btn--block { width: 100%; }
.btn--danger { color: var(--danger); }

/* ───────────── 顶栏 ───────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 14px; margin-bottom: 16px; border-bottom: 1px solid var(--line);
}
.topbar__brand { display: flex; align-items: center; gap: 8px; font-family: var(--serif); font-size: 20px; letter-spacing: .1em; }
.topbar__right { display: flex; align-items: center; gap: 10px; }
.conn { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); transition: background .2s; }
.conn[data-status=online] { background: #4FAE7F; }
.conn[data-status=connecting] { background: var(--gold); animation: pulse 1.1s ease-in-out infinite; }
.conn[data-status=offline] { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }
.chip {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 5px 6px 5px 13px; font-size: 13.5px; box-shadow: var(--shadow-sm);
}
.chip:hover { background: var(--surface-2); }
.chip__points {
  background: var(--accent-soft); color: var(--accent); font-family: var(--mono);
  font-size: 12px; border-radius: 999px; padding: 2px 9px; font-weight: 600;
}

/* ───────────── 大厅栅格 ───────────── */
.lobby { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 760px) {
  .lobby { grid-template-columns: 1.15fr .85fr; align-items: start; }
  .card--wide { grid-column: 1 / -1; }
}

.list { display: grid; gap: 2px; }
.row {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 8px; border-radius: var(--radius-sm);
  transition: background .14s;
}
.row:hover { background: var(--surface-2); }
.avatar {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-size: 14px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent); position: relative;
}
.avatar[data-online="1"]::after {
  content: ''; position: absolute; right: -1px; bottom: -1px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #4FAE7F; border: 2px solid var(--surface);
}
.row__main { min-width: 0; flex: 1; }
.row__name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__meta { color: var(--ink-3); font-size: 12.5px; }
.row__actions { display: flex; gap: 6px; }

.requests { display: grid; gap: 8px; }
.requests:not(:empty) { margin-bottom: 10px; }
.req {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  background: var(--accent-soft); border-radius: var(--radius-sm); font-size: 13.5px;
}
.req .row__main { flex: 1; }

.rank { display: grid; gap: 1px; counter-reset: rank; }
.rank li { display: flex; align-items: center; gap: 11px; padding: 8px; border-radius: var(--radius-sm); }
.rank li.is-me { background: var(--accent-soft); }
.rank__no {
  width: 22px; text-align: center; font-family: var(--mono); font-size: 12.5px;
  color: var(--ink-3); flex: none;
}
.rank li:nth-child(-n+3) .rank__no { color: var(--gold); font-weight: 700; }
.rank__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank__pts { font-family: var(--mono); font-weight: 600; }
.rank__wl { color: var(--ink-3); font-size: 12px; font-family: var(--mono); }

.list--history .row { gap: 10px; }
.badge {
  font-size: 11.5px; padding: 2px 8px; border-radius: 999px; flex: none;
  background: var(--surface-2); color: var(--ink-2);
}
.badge--win { background: rgba(79, 174, 127, .16); color: #3D8F68; }
.badge--loss { background: rgba(180, 65, 60, .13); color: var(--danger); }
@media (prefers-color-scheme: dark) { .badge--win { color: #6FCB9C; } }

/* ───────────── 对局 ───────────── */
.view--game { max-width: 620px; }
.game { display: grid; gap: 12px; }
.player {
  display: flex; align-items: center; gap: 11px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow-sm);
  transition: border-color .2s, box-shadow .2s;
}
.player.is-turn { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.player__stone {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
}
.player__stone[data-color="1"] { background: radial-gradient(circle at 32% 30%, #6E7176, #17181A 70%); }
.player__stone[data-color="2"] { background: radial-gradient(circle at 32% 30%, #fff, #CFC9BE 78%); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.player__info { flex: 1; min-width: 0; }
.player__name { font-weight: 500; display: flex; align-items: center; gap: 7px; }
.player__sub { color: var(--ink-3); font-size: 12.5px; }
.clock {
  font-family: var(--mono); font-size: 20px; font-variant-numeric: tabular-nums;
  letter-spacing: .02em; padding: 2px 10px; border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.clock.is-running { background: var(--accent-soft); color: var(--accent); }
.clock.is-low { background: rgba(180, 65, 60, .14); color: var(--danger); animation: pulse 1s ease-in-out infinite; }
.offline-tag { font-size: 11px; color: var(--danger); background: rgba(180,65,60,.12); padding: 1px 7px; border-radius: 999px; }

.board-wrap { position: relative; width: 100%; aspect-ratio: 1; }
#board {
  width: 100%; height: 100%; display: block;
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  touch-action: manipulation;
}
.veil {
  position: absolute; inset: 0; border-radius: var(--radius);
  background: rgba(20, 18, 15, .28); backdrop-filter: blur(1.5px);
  display: grid; place-items: center; color: #fff; font-size: 14px;
}
.game__actions { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
/* 显式指定列位，任一按钮隐藏时提示文案仍居中 */
#btn-leave { grid-column: 1; justify-self: start; }
#turn-hint { grid-column: 2; }
#btn-resign { grid-column: 3; justify-self: end; }
.turn-hint { color: var(--ink-2); font-size: 13.5px; text-align: center; }

/* ───────────── 弹层 ───────────── */
.dlg {
  border: none; padding: 0; border-radius: var(--radius); max-width: min(400px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-md);
}
.dlg::backdrop { background: rgba(20, 18, 15, .42); backdrop-filter: blur(2px); }
.dlg[open] { animation: rise .18s cubic-bezier(.2,.8,.3,1); }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.dlg__body { padding: 20px; display: grid; gap: 13px; }
.dlg__body--center { text-align: center; justify-items: center; }
.dlg__actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 3px; }

.segmented { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: var(--radius-sm); }
.segmented button {
  flex: 1; border: none; background: transparent; border-radius: 6px;
  padding: 8px 4px; cursor: pointer; font-size: 13.5px; color: var(--ink-2);
  transition: background .16s, color .16s;
}
.segmented button[aria-checked=true] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm); }

.result__icon { font-size: 34px; line-height: 1; }
.result__delta { font-family: var(--mono); font-size: 15px; font-weight: 600; margin: 0; }
.stats { display: flex; gap: 8px; }
.stats div { flex: 1; text-align: center; background: var(--surface-2); border-radius: var(--radius-sm); padding: 9px 4px; }
.stats b { display: block; font-size: 18px; font-family: var(--mono); }
.stats span { font-size: 11.5px; color: var(--ink-3); }

/* ───────────── 轻提示 ───────────── */
.toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  display: grid; gap: 8px; z-index: 60; width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  background: var(--ink); color: var(--paper); padding: 9px 15px;
  border-radius: 999px; font-size: 13.5px; box-shadow: var(--shadow-md);
  animation: toast-in .2s cubic-bezier(.2,.8,.3,1);
}
.toast--error { background: var(--danger); color: #fff; }
.toast.is-out { animation: toast-out .25s forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
