/* 配色：蓝/橙互补，大面积压灰，只有选中与落点用高纯度橙 */
:root {
  --bg: #2b3038;
  --card: #353b45;
  --card-2: #3f4651;
  --text: #e9e3d8;
  --muted: #a39d92;
  --line: #4a515c;
  --board: #cfc3ae;
  --board-edge: #b8ab94;
  --accent: #ff9a3c;
  --accent-soft: rgba(255, 154, 60, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
h1 { margin: 0; font-size: 20px; letter-spacing: .08em; font-weight: 600; }
h2 { margin: 0 0 12px; font-size: 18px; font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

/* 按钮 */
button {
  font: inherit; color: var(--text);
  background: var(--card-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 14px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
button:hover:not(:disabled) { background: #4a525e; border-color: #5b6470; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #2b1d10; border-color: transparent; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #ffab5e; }
button.ghost { background: transparent; }
button.small { padding: 5px 10px; font-size: 13px; }

/* 设置面板 */
.setup { max-width: 560px; margin: 0 auto; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.presets button.active,
button[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.seats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin: 12px 0; }
.seat-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; background: var(--card-2); }
.seat-name { min-width: 3em; }
.seat-row select {
  flex: 1; font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px;
}
.summary { margin: 4px 0 12px; font-size: 14px; color: var(--text); min-height: 1.5em; }
button.wide { width: 100%; padding: 11px; font-size: 16px; }
.rules { margin-top: 16px; color: var(--muted); font-size: 13px; }
.rules summary { cursor: pointer; color: var(--text); }
.rules ul { padding-left: 1.2em; margin: 8px 0 0; }
.rules li { margin: 4px 0; }

.dot {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  vertical-align: -1px; margin-right: 6px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.3);
}

/* 对局布局 */
.game { display: flex; gap: 20px; align-items: flex-start; justify-content: center; }
.board-wrap {
  flex: 1 1 auto; min-width: 0; display: flex; justify-content: center;
  background: var(--board);
  border: 6px solid var(--board-edge);
  border-radius: 18px;
  padding: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35), inset 0 0 40px rgba(60,70,90,.15);
}
#board {
  display: block; user-select: none;
  width: 100%; height: auto;
  /* 撑满剩余宽度，但不高过视口 */
  max-width: calc((100vh - 150px) * 0.873);
  touch-action: manipulation;   /* 去掉双击缩放的等待，点击立刻响应 */
}
.side { flex: 0 0 300px; }

/* 棋盘元素 */
.hole { stroke: rgba(0,0,0,.22); stroke-width: 1; transition: fill .2s; }
.hole.legal-hole { stroke: var(--accent); stroke-width: 2; }
.piece { stroke: rgba(0,0,0,.4); stroke-width: 1.5; }
.piece-g.own { cursor: pointer; }
.piece-g.own:hover .piece { filter: brightness(1.12); }
.shine { fill: #fff; opacity: .32; pointer-events: none; }
.moving { filter: drop-shadow(0 4px 4px rgba(0,0,0,.35)); }
.legal-dot { fill: var(--accent); cursor: pointer; stroke: rgba(0,0,0,.25); }
.legal-dot:hover { r: 10; }
.selected-ring { fill: none; stroke: var(--accent); stroke-width: 4; pointer-events: none; transform-box: fill-box; transform-origin: center; animation: ring 1.1s ease-in-out infinite alternate; }
.selected-ring.shake { animation: shake .35s; }
.selected-halo { fill: var(--accent-soft); pointer-events: none; }
.piece-g.picked .piece { stroke: #2b1d10; stroke-width: 2; filter: brightness(1.15); }
@keyframes ring { from { transform: scale(1); } to { transform: scale(1.12); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@media (prefers-reduced-motion: reduce) { .selected-ring, .hint-ring { animation: none; } }
.target-ring { fill: none; stroke-width: 1.5; stroke-dasharray: 3 4; opacity: .55; pointer-events: none; }
.last-path { fill: none; stroke-width: 3; opacity: .45; stroke-linejoin: round; pointer-events: none; }
.last-from { fill: none; stroke-width: 2; stroke-dasharray: 3 3; opacity: .8; pointer-events: none; }
.hint-path { fill: none; stroke: var(--accent); stroke-width: 3; stroke-dasharray: 6 5; pointer-events: none; }
.hint-ring { fill: none; stroke: var(--accent); stroke-width: 3; pointer-events: none; animation: pulse 1s infinite alternate; }
.hint-dot { fill: var(--accent); pointer-events: none; }
@keyframes pulse { from { opacity: .4; } to { opacity: 1; } }

/* 侧栏 */
.notice { margin-top: 6px; color: var(--accent); font-size: 14px; }
.status { font-size: 15px; padding: 10px 12px; border-radius: 9px; background: var(--card-2); margin-bottom: 12px; min-height: 2.6em; }
.players { display: flex; flex-direction: column; gap: 6px; }
.player-row {
  display: grid; grid-template-columns: auto 1fr 70px 40px; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 9px; border: 1px solid transparent;
}
.player-row.current { border-color: var(--accent-soft); background: rgba(255,154,60,.08); }
.pname { display: flex; flex-direction: column; line-height: 1.25; font-size: 14px; }
.pname small { color: var(--muted); font-size: 11px; }
.bar { height: 6px; background: rgba(0,0,0,.35); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; transition: width .3s; }
.count { font-variant-numeric: tabular-nums; font-size: 13px; text-align: right; color: var(--muted); }
.counter { margin: 12px 0; font-size: 14px; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tip { margin: 12px 0 0; }

/* 结束弹层 */
.overlay {
  position: fixed; inset: 0; background: rgba(20, 24, 30, .7);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10;
}
.modal { width: min(420px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.ranking { list-style: none; padding: 0; margin: 8px 0 16px; }
.ranking li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.ranking .rank { width: 1.4em; color: var(--muted); font-variant-numeric: tabular-nums; }
.ranking .muted { margin-left: auto; }

@media (max-width: 760px) {
  main { padding: 10px 6px 32px; }
  header { padding: 10px 12px; }
  .game { flex-direction: column; gap: 12px; }
  .side { flex: none; width: 100%; }
  .seats { grid-template-columns: 1fr; }
  /* 手机上让棋盘尽量撑满屏宽，棋子才够大 */
  .board-wrap { border-width: 3px; border-radius: 12px; padding: 2px; }
  #board { max-width: none; }
  .actions button { padding: 10px 14px; }
  .quick-row { flex-direction: column; align-items: stretch; }
}

/* 本地 / 联机标签 */
.tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 16px; background: var(--card-2); border-radius: 11px; }
.tabs button { flex: 1; background: transparent; border-color: transparent; }
.tabs button.active { background: var(--card); border-color: var(--line); color: var(--text); font-weight: 600; }
.tabs button:not(.active) { color: var(--muted); }

/* 联机面板 */
h3 { margin: 18px 0 8px; font-size: 15px; font-weight: 600; }
.field { display: flex; align-items: center; gap: 10px; }
.field span { min-width: 3em; }
input {
  font: inherit; color: var(--text); background: var(--card-2);
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; min-width: 0;
}
input:focus { outline: none; border-color: var(--accent); }
.field input { flex: 1; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: .2em; font-variant-numeric: tabular-nums; }
.error { color: #e8836e; font-size: 13px; min-height: 1.2em; margin: 8px 0 0; word-break: break-all; }
.room-code { font-size: 26px; letter-spacing: .25em; color: var(--accent); font-variant-numeric: tabular-nums; margin-left: 6px; }
.room-seats { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; margin-left: 4px; }
.online-info { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.online-info b { color: var(--text); letter-spacing: .12em; }
.warn { color: #e8836e; }

/* 页头 */
.head-actions { display: flex; gap: 8px; }

/* 首页：继续上一局、快速开局、规则选择 */
.resume {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; margin-bottom: 14px; border-radius: 10px;
  background: rgba(255,154,60,.08); border: 1px solid var(--accent-soft); font-size: 14px;
}
.quick { display: flex; flex-direction: column; gap: 10px; }
.quick-row { display: flex; gap: 10px; align-items: stretch; }
.quick-row .quick-btn { flex: 1; }
.quick-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px 16px; text-align: left; }
.quick-btn b { font-size: 16px; font-weight: 600; }
.quick-btn small { font-size: 13px; opacity: .75; font-weight: 400; }
.quick-level { display: flex; flex-direction: column; justify-content: center; gap: 4px; font-size: 12px; color: var(--muted); }
select {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px;
}
.custom { margin-top: 16px; }
.custom summary, .rules summary { cursor: pointer; color: var(--text); padding: 4px 0; }
.custom[open] summary { margin-bottom: 8px; }
.rules-pick { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.rules-label { font-size: 14px; }
.rules-pick p { flex-basis: 100%; margin: 0; }
.seg { display: inline-flex; padding: 3px; gap: 3px; background: var(--card-2); border-radius: 10px; }
.seg button { background: transparent; border-color: transparent; padding: 5px 14px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--card); border-color: var(--accent); color: var(--text); font-weight: 600; box-shadow: none; }
.foot { margin: 16px 0 0; font-size: 13px; color: var(--muted); }
.foot a, button.link { color: var(--muted); text-decoration: underline; }
button.link { background: none; border: 0; padding: 0; font-size: 13px; }
button.link:hover:not(:disabled) { background: none; color: var(--text); }

/* 结算原因、确认框、反馈表单 */
.why { margin: 0 0 4px; }
#dialog { z-index: 20; }
#dialog-text { margin: 0 0 14px; }
#dialog-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
textarea {
  font: inherit; color: var(--text); background: var(--card-2); resize: vertical;
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; width: 100%;
}
textarea:focus { outline: none; border-color: var(--accent); }
#dialog-form .error { margin: 0; }

/* 统计同意条 */
.consent {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 30; max-width: 640px; margin: 0 auto;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-radius: 12px; font-size: 13px;
  background: var(--card); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0,0,0,.45);
}

/* 先手选择 */
.first-row { margin: 8px 0 4px; font-size: 14px; }
.first-row span { min-width: 6em; }
.first-row select { flex: 0 1 240px; }
/* 回合倒计时 */
.clock { font-variant-numeric: tabular-nums; color: var(--muted); margin-left: 6px; }
.clock.urgent { color: #e8836e; font-weight: 600; }
