:root {
  --bg: #14110e;
  --bg-2: #1b1713;
  --panel: #211c17;
  --panel-2: #262019;
  --line: #3a3129;
  --text: #eae0d0;
  --text-2: #b9a992;
  --muted: #8a7a66;
  --gold: #d9a441;
  --gold-2: #f0c46a;
  --red: #b23a2b;
  --black: #5b6a76;
  --teal: #2f9e8f;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 700px at 18% -10%, #2a2118 0%, transparent 60%),
    radial-gradient(900px 600px at 92% 8%, #241c15 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------------- 顶栏 ---------------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(20, 17, 14, .82);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.logo {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(160deg, #f0d9a7, #c9a05a);
  color: #6b3a12;
  font-family: "KaiTi", "STKaiti", serif;
  font-size: 21px;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), 0 4px 12px rgba(0, 0, 0, .35);
}

.brand-name {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: .3px;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
  padding-left: 10px;
  border-left: 1px solid var(--line);
  white-space: nowrap;
}

.status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .04);
}

.dot.red { background: #d4483a; box-shadow: 0 0 10px rgba(212, 72, 58, .55); }
.dot.black { background: #7f929f; box-shadow: 0 0 10px rgba(127, 146, 159, .5); }

.check-flag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  color: #ffd9d2;
  background: rgba(196, 56, 40, .18);
  border: 1px solid rgba(196, 56, 40, .5);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

.tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #2a231c, #221c16);
  color: var(--text-2);
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 9px;
  cursor: pointer;
  transition: .16s ease;
  font-family: inherit;
  white-space: nowrap;
}

.btn:hover { color: var(--gold-2); border-color: rgba(217, 164, 65, .5); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .38; cursor: not-allowed; }

.select {
  appearance: none;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #2a231c, #221c16);
  color: var(--text-2);
  font-size: 13px;
  font-family: inherit;
  padding: 7px 28px 7px 12px;
  border-radius: 9px;
  max-width: 220px;
  cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--gold-2) 50%),
    linear-gradient(135deg, var(--gold-2) 50%, transparent 50%),
    linear-gradient(180deg, #2a231c, #221c16);
  background-position:
    calc(100% - 15px) 52%,
    calc(100% - 10px) 52%,
    0 0;
  background-size: 5px 5px, 5px 5px, 100% 100%;
  background-repeat: no-repeat;
  transition: .16s ease;
}

.select:hover { color: var(--gold-2); border-color: rgba(217, 164, 65, .5); }
.select option { background: #221c16; color: var(--text-2); }

.btn-icon {
  width: 32px;
  padding: 7px 0;
  text-align: center;
  font-size: 16px;
  line-height: 1;
}

.keyhint {
  flex-basis: 100%;
  order: 9;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
  margin: 0;
  padding: 3px 0 0;
  border-top: 1px dashed rgba(58, 49, 41, .8);
  font-size: 12px;
  color: var(--muted);
}

.keyhint-title {
  color: var(--gold-2);
  letter-spacing: .4px;
}

.keyhint kbd {
  display: inline-block;
  min-width: 18px;
  margin-right: 4px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(38, 32, 25, .9);
  color: var(--text-2);
  font-family: inherit;
  font-size: 11px;
  text-align: center;
}

.switch {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-2);
  cursor: pointer;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, .015);
  user-select: none;
}

.switch input { accent-color: var(--gold); }

/* ---------------- 布局 ---------------- */

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 392px;
  gap: 18px;
  padding: 18px 22px 24px;
  align-items: start;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
}

.stage-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.stage {
  position: relative;
  align-self: center;
  /* 让整块棋盘在视口内完整可见：高度 = 视口高 - 顶栏/记录条/留白 */
  width: min(100%, calc((100vh - 205px) * 0.904));
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow), 0 0 0 1px rgba(217, 164, 65, .16);
  background: #efd3a4;
  line-height: 0;
}

#board {
  display: block;
  width: 100%;
  height: auto;
  cursor: pointer;
  touch-action: manipulation;
  border-radius: var(--radius);
}

/* 键盘焦点交给棋盘后才收方向键：给个淡金描边，别用默认 outline */
#board:focus { outline: none; }

#board:focus-visible {
  outline: 2px solid rgba(217, 164, 65, .55);
  outline-offset: 6px;
}

/* ---------------- 走棋记录 ---------------- */

.movebar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(33, 28, 23, .65);
}

.mv-label {
  font-size: 11.5px;
  letter-spacing: .12em;
  color: var(--muted);
  white-space: nowrap;
}

.move-list {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.mv-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 4px 9px;
  border-radius: 7px;
  background: rgba(255, 255, 255, .03);
  white-space: nowrap;
}

.mv-no { color: var(--muted); font-variant-numeric: tabular-nums; }
.mv-red { color: #e88b7d; min-width: 62px; }
.mv-black { color: #a9bfcd; min-width: 62px; }

/* ---------------- 侧栏 ---------------- */

.side {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), #1c1712);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: sticky;
  top: 78px;
}

.tabs {
  display: flex;
  padding: 8px 8px 0;
  gap: 4px;
  border-bottom: 1px solid var(--line);
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  padding: 9px 14px 10px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  position: relative;
  transition: color .16s;
}

.tab:hover { color: var(--text-2); }

.tab.active { color: var(--gold-2); }

.tab.active::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--gold);
}

.panel {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.panel.active { display: flex; }

/* ---------------- 对话 ---------------- */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
}

.msg {
  max-width: 100%;
  animation: rise .22s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
}

.kind {
  font-size: 10.5px;
  letter-spacing: .04em;
  padding: 2px 7px;
  border-radius: 5px;
  border: 1px solid transparent;
}

.kind.obs { color: #a9bfcd; background: rgba(91, 106, 118, .14); border-color: rgba(91, 106, 118, .32); }
.kind.fact { color: #8fc7a8; background: rgba(60, 140, 96, .13); border-color: rgba(60, 140, 96, .32); }
.kind.interp { color: #e0b877; background: rgba(217, 164, 65, .12); border-color: rgba(217, 164, 65, .3); }

.msg-src {
  font-size: 10.5px;
  color: var(--muted);
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(255, 255, 255, .03);
}

.msg-body {
  font-size: 14px;
  line-height: 1.72;
  color: var(--text);
  background: rgba(255, 255, 255, .032);
  border: 1px solid rgba(255, 255, 255, .045);
  border-left: 2px solid rgba(217, 164, 65, .45);
  border-radius: 4px 10px 10px 4px;
  padding: 10px 13px;
  word-break: break-word;
}

.msg-body p { margin: 0 0 6px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body strong { color: var(--gold-2); font-weight: 650; }

.msg-body.typing::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 3px;
  vertical-align: -2px;
  background: var(--gold);
  animation: blink .85s steps(2) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.hintline {
  padding: 10px 16px 14px;
  font-size: 11.5px;
  color: var(--muted);
  border-top: 1px solid rgba(255, 255, 255, .04);
}

/* ---------------- 事件流 ---------------- */

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  font-size: 11.5px;
  letter-spacing: .1em;
  color: var(--muted);
  border-bottom: 1px solid rgba(255, 255, 255, .045);
}

.events {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  scrollbar-width: thin;
}

.ev {
  padding: 6px 8px;
  border-radius: 7px;
  margin-bottom: 4px;
  background: rgba(255, 255, 255, .018);
  border-left: 2px solid transparent;
}

.ev-head {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.ev-type {
  font-size: 9.5px;
  letter-spacing: .02em;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .06);
  color: var(--text-2);
  white-space: nowrap;
}

.ev-type.custom { background: rgba(217, 164, 65, .16); color: var(--gold-2); }
.ev-type.text { background: rgba(47, 158, 143, .14); color: #79cfc2; }
.ev-type.run { background: rgba(91, 106, 118, .16); color: #9fb2c0; }
.ev-type.state { background: rgba(178, 58, 43, .14); color: #e08a7d; }

.ev-name {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ev-json {
  margin: 5px 0 0;
  color: #9d8f7b;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.55;
  font-size: 10.5px;
}

.ev-body {
  margin-top: 4px;
  color: #a9bfcd;
  line-height: 1.5;
  word-break: break-word;
}

/* ---------------- 局面 ---------------- */

.eval-box { padding: 16px; }

.eval-total {
  font-size: 20px;
  font-weight: 650;
  color: var(--gold-2);
  letter-spacing: .02em;
  margin-bottom: 14px;
}

.eval-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.eval-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12.5px;
  background: rgba(255, 255, 255, .018);
}

.eval-t { color: var(--text-2); width: 22px; }
.eval-n { font-variant-numeric: tabular-nums; }
.eval-n.red { color: #e88b7d; margin-left: auto; }
.eval-n.black { color: #a9bfcd; }

.eval-note {
  margin-top: 14px;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.6;
}

/* ---------------- 响应式 ---------------- */

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
    padding: 14px 14px 22px;
  }

  .side {
    height: auto;
    min-height: 420px;
    position: static;
  }

  .stage { width: 100%; }
  #panel-chat .messages { max-height: 60vh; }
  .events { max-height: 420px; }
  .brand-sub { display: none; }
}

@media (max-width: 620px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 14px;
  }

  .status { margin-left: 0; order: 3; width: 100%; }
  .tools { margin-left: auto; }
  .btn { padding: 6px 11px; font-size: 12px; }
  .workspace { gap: 12px; }
}
