/* 弈核围棋 · 星核银白主题（网页版）
   布局要点：整页 100dvh + safe-area；棋盘用 aspect-ratio 锁正方形并在容器里居中。 */

:root {
  --bg: #050608; --panel: #111317; --panel-2: #181b20; --board: #14161a;
  --ink: #eef1f5; --secondary: #8c929c; --line: #5c626c; --border: #24272e;
  --accent: #5eead4; --accent-ink: #04201c; --accent-soft: rgba(94, 234, 212, .14);
  --danger: #f87171; --stone-black: #0b0c0f; --stone-white: #f2f4f7;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --radius: 16px;
  --sat: env(safe-area-inset-top, 0px); --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}
:root[data-theme="day"] {
  --bg: #f2f2ef; --panel: #ffffff; --panel-2: #e9eae8; --board: #e2e4e6;
  --ink: #16171a; --secondary: #6b6e74; --line: #70757d; --border: #d6d8da;
  --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: rgba(15, 118, 110, .12);
  --danger: #c2410c; --shadow: 0 10px 30px rgba(20, 24, 30, .14);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  overflow: hidden; overscroll-behavior: none; -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: default; opacity: .4; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg.i { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

#app {
  height: 100vh; height: 100dvh;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
  display: flex; flex-direction: column;
}
.view { flex: 1; min-height: 0; min-width: 0; position: relative; }

/* ───────── 首页 ───────── */
#home { display: flex; overflow-y: auto; }
#stars { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.home-inner {
  position: relative; margin: auto; width: 100%; max-width: 440px;
  padding: 24px 20px; display: flex; flex-direction: column; gap: 12px;
}
.brand { text-align: center; padding: 8px 0 14px; }
.brand-mark { width: 68px; height: 68px; color: var(--ink); }
.brand h1 { margin: 10px 0 2px; font-size: 26px; font-weight: 600; letter-spacing: .14em; text-indent: .14em; }
.brand p { margin: 0; color: var(--secondary); font-size: 12px; letter-spacing: .2em; text-indent: .2em; }

.card {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 15px 16px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  border: 1px solid var(--border); backdrop-filter: blur(10px);
  transition: transform .12s ease, border-color .12s ease;
}
.card:active { transform: scale(.985); }
@media (hover: hover) { .card:hover { border-color: var(--line); } }
.card.primary { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); background: linear-gradient(135deg, var(--accent-soft), color-mix(in srgb, var(--panel) 86%, transparent) 70%); }
.card-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--panel-2); font-size: 18px; flex: none; }
.card.primary .card-icon, .card.resume .card-icon { background: var(--accent); color: var(--accent-ink); }
.card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.card-text strong { font-size: 16px; font-weight: 600; }
.card-text small { color: var(--secondary); font-size: 12.5px; }
.chev { color: var(--secondary); }
.modes { display: flex; flex-direction: column; gap: 10px; }

.join { display: flex; gap: 8px; margin-top: 2px; }
.join input {
  flex: 1; min-width: 0; height: 46px; padding: 0 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 86%, transparent); border: 1px solid var(--border);
  font-size: 16px; letter-spacing: .12em; font-variant-numeric: tabular-nums; -webkit-user-select: text; user-select: text;
}
.join input::placeholder { letter-spacing: 0; color: var(--secondary); }
.home-foot { display: flex; justify-content: center; gap: 22px; padding-top: 10px; }
.link { display: inline-flex; align-items: center; gap: 6px; color: var(--secondary); font-size: 13px; padding: 8px 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 12px; font-weight: 600;
  background: var(--panel-2); border: 1px solid var(--border); white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:active:not(:disabled) { transform: scale(.98); }

/* ───────── 对局页 ───────── */
#game {
  display: grid; gap: 8px; padding: 6px 12px 10px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "bar" "players" "board" "panel";
}
.bar { grid-area: bar; display: flex; align-items: center; gap: 2px; min-height: 44px; }
.bar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0 6px; line-height: 1.25; }
.bar-title strong { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bar-title span { font-size: 12px; color: var(--secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 17px; flex: none; }
.icon-btn:active { background: var(--panel-2); }
@media (hover: hover) { .icon-btn:hover { background: var(--panel); } }
.icon-btn.on { color: var(--accent); }

.players { grid-area: players; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.player {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; min-width: 0;
  border-radius: 14px; background: var(--panel); border: 1px solid var(--border);
}
.player.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.player .dot { width: 22px; height: 22px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(128, 136, 148, .5); }
.player .dot.black { background: radial-gradient(circle at 35% 30%, #6c7480, #111316 60%, #050607); }
.player .dot.white { background: radial-gradient(circle at 35% 30%, #fff, #e6eaef 60%, #b9c1cc); }
.player .who { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.player .who b { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .who small { color: var(--secondary); font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.presence { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.presence.on { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.board-wrap { grid-area: board; container-type: size; display: grid; place-items: center; min-width: 0; min-height: 0; }
.board {
  width: min(100cqw, 100cqh); aspect-ratio: 1 / 1; max-width: 100%; max-height: 100%;
  border-radius: clamp(10px, 2.4cqmin, 20px); background: var(--board);
  border: 1px solid var(--border); box-shadow: var(--shadow); overflow: hidden;
}
.board canvas { display: block; width: 100%; height: 100%; touch-action: manipulation; }

.panel { grid-area: panel; display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; }
.status { display: flex; align-items: center; gap: 8px; min-height: 24px; font-size: 13.5px; color: var(--secondary); }
.status b { color: var(--ink); font-weight: 600; }
.status .grow { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status .tag { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; font-variant-numeric: tabular-nums; }
.status.warn .grow { color: var(--danger); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.curve { position: relative; height: 40px; border-radius: 10px; background: var(--panel); border: 1px solid var(--border); overflow: hidden; }
.curve svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.curve .mid { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.curve .path { fill: none; stroke: var(--accent); stroke-width: 1.6; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.curve .area { fill: var(--accent-soft); stroke: none; }
.curve label { position: absolute; left: 8px; top: 3px; font-size: 10.5px; color: var(--secondary); }
.curve output { position: absolute; right: 8px; top: 3px; font-size: 10.5px; color: var(--ink); font-variant-numeric: tabular-nums; }

.actions { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; }
.action {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 54px; border-radius: 14px; background: var(--panel); border: 1px solid var(--border);
  font-size: 12px; color: var(--ink);
}
.action svg.i { width: 20px; height: 20px; }
.action.on { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); background: var(--accent-soft); }
.action.danger { color: var(--danger); }
.action:active:not(:disabled) { transform: scale(.96); }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }

.invite { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--border); }
.invite .code { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.invite .code span { font-size: 12.5px; color: var(--secondary); }
.invite .code b { font-size: 30px; letter-spacing: .16em; font-weight: 600; font-variant-numeric: tabular-nums; -webkit-user-select: text; user-select: text; }
.invite p { margin: 0; font-size: 12.5px; color: var(--secondary); }

.result { padding: 12px 14px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.result b { font-size: 17px; }
.result small { color: var(--secondary); font-variant-numeric: tabular-nums; }

/* 横屏、折叠屏展开、电脑：棋盘在左，信息与操作在右 */
@media (min-width: 760px) and (min-aspect-ratio: 6/5) {
  #game {
    padding: 8px 20px 16px; column-gap: 20px;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "bar bar" "board players" "board panel";
  }
  .players { grid-template-columns: 1fr; }
  .panel { overflow-y: auto; }
  .actions { grid-auto-flow: row; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .home-inner { max-width: 460px; }
}
/* 矮屏（手机横放）：压缩纵向占用 */
@media (max-height: 460px) {
  .action { min-height: 44px; flex-direction: row; gap: 6px; }
  .brand { padding: 0; }
  .brand-mark { width: 40px; height: 40px; }
}
@media (max-width: 350px) {
  #game { padding-left: 8px; padding-right: 8px; }
  .action { font-size: 11px; }
}

/* ───────── 弹层 ───────── */
.backdrop {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .5); animation: fade .16s ease;
}
.sheet {
  width: 100%; max-width: 520px; max-height: min(88dvh, 760px);
  display: flex; flex-direction: column;
  background: var(--bg); border: 1px solid var(--border); border-bottom: 0;
  border-radius: 22px 22px 0 0; box-shadow: var(--shadow);
  padding-bottom: var(--sab); animation: rise .2s ease;
}
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 10px 8px 20px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 17px; font-weight: 600; }
.sheet-body { overflow-y: auto; padding: 4px 20px 18px; display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }
.sheet-body > * { flex-shrink: 0; }
.sheet-foot { padding: 10px 20px 16px; display: flex; gap: 8px; }
.sheet-foot > * { flex: 1; }
@media (min-width: 620px) and (min-height: 520px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 22px; border-bottom: 1px solid var(--border); padding-bottom: 0; max-width: 460px; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

.group { display: flex; flex-direction: column; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--border); overflow: hidden; }
.group-title { font-size: 12.5px; color: var(--secondary); margin: 0 4px -6px; display: flex; align-items: center; gap: 6px; }
.group-note { font-size: 12px; color: var(--secondary); margin: -8px 4px 0; }
.field { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 52px; }
.field + .field { border-top: 1px solid var(--border); }
.field.col { flex-direction: column; align-items: stretch; gap: 8px; }
.field .label { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.field .label small { color: var(--secondary); font-size: 12px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--panel-2); }
.seg button { min-height: 36px; border-radius: 9px; font-size: 13.5px; color: var(--secondary); padding: 0 4px; }
.seg button.on { background: var(--bg); color: var(--ink); font-weight: 600; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); }
.switch { position: relative; width: 48px; height: 28px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: var(--secondary); transition: transform .15s, background .15s; }
.switch[aria-checked="true"] { background: var(--accent); border-color: transparent; }
.switch[aria-checked="true"]::after { transform: translateX(20px); background: var(--accent-ink); }
select.pick { height: 38px; border-radius: 10px; padding: 0 10px; background: var(--panel-2); border: 1px solid var(--border); }
.prose { font-size: 13.5px; color: var(--secondary); margin: 0; -webkit-user-select: text; user-select: text; }
.prose b { color: var(--ink); font-weight: 600; }
.copybox { width: 100%; height: 42px; border-radius: 10px; padding: 0 10px; background: var(--panel-2); border: 1px solid var(--border); font-size: 13px; -webkit-user-select: text; user-select: text; }

#toasts { position: fixed; left: 0; right: 0; top: calc(var(--sat) + 56px); z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 16px; }
.toast { max-width: 420px; padding: 9px 14px; border-radius: 12px; background: var(--ink); color: var(--bg); font-size: 13.5px; box-shadow: var(--shadow); animation: rise .18s ease; text-align: center; }
.toast.out { opacity: 0; transition: opacity .25s; }

#boot-fallback, .noscript { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: var(--bg); color: var(--ink); z-index: 99; padding: 24px; text-align: center; }
#boot-fallback button { min-height: 44px; padding: 0 18px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }

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