/* ═══════════════════════════════════════════════════════════════
   吃子围棋 · 视觉方向「棋院夜灯」
   深墨为底，棋盘是唯一的暖光源；朱砂只用在“提子”这一件事上。
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* 墨 */
  --ink:        #12171c;
  --ink-2:      #1a2129;
  --ink-3:      #232d37;
  /* 宣纸 */
  --paper:      #e8e2d6;
  --paper-dim:  #98a3ab;
  --paper-faint:#69737b;
  /* 榧木（棋盘） */
  --kaya:       #d9a860;
  --kaya-2:     #b8803c;
  --kaya-3:     #8d5f28;
  /* 朱砂：只给“提子”用 */
  --cinnabar:   #c0392b;
  --cinnabar-lt:#e0685a;
  /* 青瓷：在线/成功 */
  --celadon:    #5f8c7a;

  --line:       rgba(232, 226, 214, 0.10);
  --line-soft:  rgba(232, 226, 214, 0.06);

  --font-display: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
             "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;

  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  background-image:
    radial-gradient(120% 80% at 50% -10%, rgba(217, 168, 96, 0.10), transparent 55%),
    radial-gradient(90% 60% at 50% 120%, rgba(95, 140, 122, 0.07), transparent 60%);
  background-attachment: fixed;
}

.screen[hidden] { display: none !important; }

/* ─────────────────────────────── 通用控件 ─────────────────────────────── */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--ink-3);
  color: var(--paper);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 18px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.08s ease, color 0.16s ease;
}
.btn:hover:not(:disabled) { background: #2b3742; border-color: rgba(232, 226, 214, 0.20); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }

.btn--primary {
  background: linear-gradient(180deg, var(--kaya), var(--kaya-2));
  border-color: rgba(0, 0, 0, 0.3);
  color: #241605;
  box-shadow: 0 8px 26px rgba(184, 128, 60, 0.28);
}
.btn--primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #e6b972, var(--kaya));
  border-color: rgba(0, 0, 0, 0.3);
}

.btn--ghost { background: transparent; }
.btn--ghost:hover:not(:disabled) { background: rgba(232, 226, 214, 0.07); }

.btn--danger { color: var(--cinnabar-lt); }
.btn--danger:hover:not(:disabled) { background: rgba(192, 57, 43, 0.14); border-color: rgba(192, 57, 43, 0.4); }

.btn--small { padding: 9px 14px; font-size: 14px; }

.linkbtn {
  appearance: none;
  background: none;
  border: 0;
  color: var(--paper-dim);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 6px 4px;
  border-radius: 6px;
  transition: color 0.15s ease;
}
.linkbtn:hover { color: var(--paper); }

:focus-visible {
  outline: 2px solid var(--kaya);
  outline-offset: 2px;
  border-radius: 6px;
}

.chip {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  flex: none;
  display: inline-block;
}
.chip--black {
  background: radial-gradient(circle at 34% 30%, #6c737b, #1b1f24 62%, #07090c);
  box-shadow: inset 0 -1px 2px rgba(0, 0, 0, 0.8);
}
.chip--white {
  background: radial-gradient(circle at 34% 30%, #ffffff, #e4ded1 60%, #bdb5a4);
  box-shadow: inset 0 -1px 2px rgba(0, 0, 0, 0.25);
}

/* 提子印记：本页的记忆点 —— 五枚棋谱凹痕，被提的子逐一点亮成朱砂 */
.pips { display: inline-flex; gap: 5px; align-items: center; }
.pip {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1px solid rgba(232, 226, 214, 0.20);
  background: radial-gradient(circle at 36% 30%, rgba(232, 226, 214, 0.08), rgba(0, 0, 0, 0.42));
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.65);
  transition: background 0.35s ease, box-shadow 0.35s ease, border-color 0.35s ease, transform 0.35s ease;
}
.pip.is-filled {
  background: radial-gradient(circle at 36% 30%, var(--cinnabar-lt), #9d2b1f 72%);
  border-color: rgba(224, 104, 90, 0.65);
  box-shadow: 0 0 9px rgba(192, 57, 43, 0.55), inset 0 1px 1px rgba(255, 255, 255, 0.28);
  transform: scale(1.08);
}

/* ─────────────────────────────── 大厅 ─────────────────────────────── */

.screen--lobby {
  position: relative;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 34px;
  padding: 48px 20px 40px;
  overflow: hidden;
}

#lobby-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.5;
  pointer-events: none;
}

.lobby-grid {
  position: relative;
  display: grid;
  gap: 34px;
  width: 100%;
  max-width: 980px;
  align-items: center;
}

.lobby-head { max-width: 34rem; }

.title-row { display: flex; align-items: flex-start; gap: 18px; }

.title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(40px, 8.5vw, 72px);
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1.05;
  color: var(--paper);
  text-shadow: 0 2px 30px rgba(217, 168, 96, 0.18);
}

.seal {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.22em;
  padding: 9px 6px;
  background: var(--cinnabar);
  color: #f7f1e6;
  border-radius: 3px;
  transform: rotate(2.5deg);
  box-shadow: 0 8px 26px rgba(192, 57, 43, 0.36);
  flex: none;
}

.lede {
  margin: 20px 0 0;
  font-size: 16px;
  line-height: 1.75;
  color: var(--paper-dim);
  max-width: 30rem;
}
.lede em { color: var(--cinnabar-lt); font-style: normal; font-weight: 600; }

.rules {
  margin: 22px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 9px;
  font-size: 14px;
  color: var(--paper-faint);
}
.rule-key {
  display: inline-block;
  min-width: 3.2em;
  margin-right: 10px;
  color: var(--paper-dim);
  font-family: var(--font-display);
  letter-spacing: 0.08em;
}

.card {
  background: linear-gradient(180deg, rgba(35, 45, 55, 0.92), rgba(26, 33, 41, 0.92));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  display: grid;
  gap: 14px;
}

.field { display: grid; gap: 7px; }
.field-label {
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--paper-faint);
  text-transform: uppercase;
}
.field input,
.field select,
.chat-form input {
  width: 100%;
  padding: 12px 13px;
  font-family: inherit;
  font-size: 16px;
  color: var(--paper);
  background: rgba(18, 23, 28, 0.75);
  border: 1px solid var(--line);
  border-radius: 9px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.field input:focus,
.field select:focus,
.chat-form input:focus {
  outline: none;
  border-color: rgba(217, 168, 96, 0.55);
  background: rgba(18, 23, 28, 0.95);
}
.field input::placeholder, .chat-form input::placeholder { color: #556069; }
.field select { appearance: none; cursor: pointer; }

.field--code input {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.32em;
  font-size: 18px;
}
.field--inline { grid-template-columns: 1fr auto; align-items: center; }

.join-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.join-row .btn { height: 47px; }

.or {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--paper-faint);
  font-size: 12px;
  letter-spacing: 0.1em;
}
.or::before, .or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line-soft);
}

.hint {
  margin: 0;
  min-height: 1.2em;
  font-size: 13.5px;
  color: var(--cinnabar-lt);
}

.lobby-rooms {
  position: relative;
  width: 100%;
  max-width: 980px;
}
.rooms-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 8px;
}
.rooms-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--paper-dim);
}
.rooms-count { font-family: var(--font-mono); font-size: 13px; letter-spacing: 0; color: var(--paper-faint); }
.room-list { display: grid; gap: 8px; margin-top: 12px; }
.rooms-empty { margin: 4px 0; font-size: 14px; color: var(--paper-faint); }

.room-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 11px 14px;
  background: rgba(26, 33, 41, 0.6);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.room-item:hover { border-color: rgba(217, 168, 96, 0.4); background: rgba(35, 45, 55, 0.75); }
.room-item .code {
  font-family: var(--font-mono);
  letter-spacing: 0.18em;
  color: var(--kaya);
  font-size: 15px;
}
.room-item .who { color: var(--paper-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-item .meta { color: var(--paper-faint); font-size: 12.5px; }

/* ─────────────────────────────── 对局 ─────────────────────────────── */

.screen--game {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(18, 23, 28, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.scoreboard { display: flex; gap: 10px; flex-wrap: wrap; }
.side-score {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--line-soft);
  background: rgba(26, 33, 41, 0.6);
  transition: border-color 0.25s ease, background 0.25s ease;
}
.side-score.is-turn {
  border-color: rgba(217, 168, 96, 0.55);
  background: rgba(217, 168, 96, 0.09);
}
.side-score.is-you .side-name { color: var(--paper); }
.side-name { font-size: 14px; color: var(--paper-dim); max-width: 8em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-count { font-family: var(--font-mono); font-size: 13px; color: var(--paper-faint); }

.room-tag { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--paper-faint); }
.room-tag b {
  font-family: var(--font-mono);
  font-size: 17px;
  letter-spacing: 0.24em;
  color: var(--kaya);
}

.table {
  flex: 1;
  display: grid;
  gap: 20px;
  padding: 20px 16px 32px;
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  align-items: start;
}

.board-wrap { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

#board {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  border-radius: 10px;
  box-shadow: 0 26px 60px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.4);
  touch-action: manipulation;
  cursor: pointer;
}
#board:focus-visible { outline: 2px solid var(--kaya); outline-offset: 3px; }
#board.is-locked { cursor: not-allowed; }

.turnbar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--paper-dim);
  padding: 0 4px;
}
.turn-dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: #3a444d;
  box-shadow: 0 0 0 3px rgba(232, 226, 214, 0.06);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.turn-dot.is-black { background: radial-gradient(circle at 34% 30%, #6c737b, #14171b); box-shadow: 0 0 0 3px rgba(232,226,214,.10); }
.turn-dot.is-white { background: radial-gradient(circle at 34% 30%, #fff, #cfc8b9); box-shadow: 0 0 0 3px rgba(232,226,214,.10); }
.turn-dot.is-mine  { box-shadow: 0 0 0 3px rgba(217, 168, 96, 0.45); }
.move-no { margin-left: auto; font-family: var(--font-mono); font-size: 12.5px; color: var(--paper-faint); }

.panel {
  display: grid;
  gap: 14px;
  background: rgba(26, 33, 41, 0.55);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.panel-block { display: grid; gap: 10px; }
.panel-block--actions { grid-template-columns: 1fr 1fr; }
.panel-block--actions .btn { padding: 11px 8px; font-size: 14px; }
.panel-block--chat { border-top: 1px solid var(--line-soft); padding-top: 14px; }

.seat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-size: 14px;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.seat.is-turn { border-color: rgba(217, 168, 96, 0.4); background: rgba(217, 168, 96, 0.07); }
.seat-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-mark { font-size: 11.5px; color: var(--paper-faint); letter-spacing: 0.08em; }
.seat-mark.is-online { color: var(--celadon); }
.seat-mark.is-offline { color: var(--cinnabar-lt); }
.seat-note { margin: 2px 0 0; font-size: 12.5px; color: var(--paper-faint); }

.chat-log {
  height: 190px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13.5px;
  padding-right: 4px;
  scrollbar-width: thin;
}
.chat-msg { line-height: 1.5; color: var(--paper-dim); overflow-wrap: anywhere; }
.chat-msg b { color: var(--paper); font-weight: 600; }
.chat-msg.is-black b { color: #b9c2c9; }
.chat-msg.is-white b { color: #f0eadf; }
.chat-msg.is-system { color: var(--paper-faint); font-size: 12.5px; font-style: normal; }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.chat-form input { font-size: 14px; padding: 10px 11px; }

/* 结果 */
.result {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(9, 12, 15, 0.72);
  backdrop-filter: blur(5px);
  z-index: 30;
  padding: 20px;
  animation: fade-in 0.25s ease;
}
.result[hidden] { display: none; }
.result-card {
  background: linear-gradient(180deg, rgba(35, 45, 55, 0.96), rgba(22, 28, 35, 0.98));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 30px 26px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 420px;
  width: 100%;
}
.result-kicker {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.28em;
  color: var(--paper-faint);
  text-transform: uppercase;
}
.result-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 40px;
  letter-spacing: 0.12em;
  color: var(--paper);
}
.result-detail { margin: 12px 0 0; font-size: 14px; color: var(--paper-dim); line-height: 1.7; }
.result-actions { display: flex; gap: 10px; justify-content: center; margin-top: 24px; flex-wrap: wrap; }
.result-votes { margin: 14px 0 0; font-size: 12.5px; color: var(--paper-faint); min-height: 1em; }

/* 悔棋确认 */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(9, 12, 15, 0.7);
  z-index: 40;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}
.modal-text { margin: 0 0 18px; font-size: 15px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }

/* 提示条 */
.toasts {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  z-index: 60;
  pointer-events: none;
  width: min(92vw, 420px);
}
.toast {
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  text-align: center;
  background: rgba(35, 45, 55, 0.96);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.22s ease;
}
.toast.is-error { border-color: rgba(192, 57, 43, 0.55); color: #f0c6c1; }
.toast.is-ok { border-color: rgba(95, 140, 122, 0.55); color: #cfe3da; }

.sound-toggle {
  position: fixed;
  right: 14px;
  bottom: 14px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(26, 33, 41, 0.9);
  color: var(--paper-dim);
  font-size: 16px;
  cursor: pointer;
  z-index: 20;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.sound-toggle:hover { color: var(--paper); border-color: rgba(217, 168, 96, 0.5); }
.sound-toggle[aria-pressed="false"] { color: #4d565e; text-decoration: line-through; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ─────────────────────────────── 桌面布局 ─────────────────────────────── */

@media (min-width: 860px) {
  .lobby-grid { grid-template-columns: 1.15fr 1fr; gap: 48px; }
  .table { grid-template-columns: minmax(0, 1fr) 320px; gap: 26px; padding: 26px 24px 40px; }
  .scoreboard { order: 2; }
  .chat-log { height: 240px; }
}

@media (max-width: 859px) {
  .topbar { padding: 9px 12px; gap: 10px; }
  .scoreboard { order: 3; width: 100%; }
  .side-score { flex: 1; justify-content: center; }
  .table { gap: 16px; padding: 14px 12px 28px; }
  .chat-log { height: 120px; }
}

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