:root {
  color-scheme: dark;
  --ink: #f8ebc9;
  --soft-ink: #dcc59d;
  --muted: #9d8a6b;
  --line: rgba(219, 174, 104, 0.34);
  --line-strong: rgba(244, 202, 129, 0.64);
  --panel: rgba(13, 18, 20, 0.78);
  --panel-deep: rgba(6, 9, 11, 0.9);
  --gold: #d9ad68;
  --gold-2: #f4db9a;
  --red: #b94132;
  --black: #0c1115;
  --green: #355b4f;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: #05090b;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Serif SC", system-ui, sans-serif;
  overflow-x: hidden;
}

button,
a {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(11, 16, 18, 0.72);
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--gold);
  color: #fff3cf;
}

button:disabled {
  cursor: wait;
  opacity: 0.5;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.shanhai-stage {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  isolation: isolate;
  display: grid;
  grid-template-columns: 118px minmax(480px, 1fr) 285px;
  grid-template-rows: 96px minmax(390px, 1fr) auto 58px;
  gap: 18px 18px;
  padding: 22px 24px 18px;
}

.scene-bg {
  position: absolute;
  inset: 0;
  z-index: -3;
  background:
    linear-gradient(180deg, rgba(3, 7, 10, 0.28), rgba(3, 7, 10, 0.76)),
    linear-gradient(90deg, rgba(4, 8, 10, 0.44), rgba(4, 8, 10, 0.08) 42%, rgba(4, 8, 10, 0.52)),
    url("/assets/shanhai-zhishu/frontend-reference.png") center / cover no-repeat;
  filter: saturate(1.04) contrast(1.03);
}

.scene-bg::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 12%, rgba(229, 183, 104, 0.14), transparent 26%),
    radial-gradient(circle at 53% 56%, rgba(241, 217, 167, 0.08), transparent 24%),
    rgba(2, 7, 9, 0.16);
  mix-blend-mode: screen;
}

.scene-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 225, 154, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 225, 154, 0.04) 1px, transparent 1px);
  background-size: 72px 72px;
  mask-image: radial-gradient(circle at 50% 50%, black, transparent 76%);
}

.topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: start;
  gap: 16px;
  min-width: 0;
}

.brand {
  display: inline-grid;
  grid-template-columns: 48px auto;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: 100%;
}

.brand-seal,
.avatar,
.quick-tools button,
.left-nav span,
.card-icon,
.social button {
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  color: var(--gold-2);
  background: rgba(6, 10, 11, 0.62);
  box-shadow: inset 0 0 18px rgba(217, 173, 104, 0.12), 0 0 18px rgba(0, 0, 0, 0.28);
}

.brand-seal {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 24px;
  font-family: "KaiTi", "STKaiti", serif;
}

.brand strong {
  display: block;
  font-size: 17px;
  line-height: 1.15;
  letter-spacing: 0;
}

.brand small {
  display: block;
  margin-top: 4px;
  color: var(--soft-ink);
  font-size: 10px;
  letter-spacing: 1px;
}

.player-card {
  display: grid;
  grid-template-columns: 42px auto 78px;
  align-items: center;
  gap: 9px;
  padding: 2px 0;
  cursor: pointer;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-weight: 800;
}

.player-meta {
  min-width: 0;
}

.player-meta strong {
  display: block;
  font-size: 13px;
}

.player-meta span {
  display: block;
  margin-top: 3px;
  color: var(--soft-ink);
  font-size: 12px;
}

.level-bar {
  width: 78px;
  height: 5px;
  border-radius: 999px;
  background: rgba(231, 200, 139, 0.28);
  overflow: hidden;
}

.level-bar span {
  display: block;
  width: 62%;
  height: 100%;
  background: linear-gradient(90deg, #f7e5ac, #b77a38);
}

.quick-tools {
  display: flex;
  gap: 12px;
}

.quick-tools button,
.social button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  padding: 0;
}

.left-nav {
  grid-column: 1;
  grid-row: 2 / 4;
  align-self: center;
  display: grid;
  gap: 14px;
  width: 95px;
}

.left-nav a {
  display: grid;
  grid-template-columns: 42px auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  color: var(--soft-ink);
  font-size: 14px;
}

.left-nav span {
  width: 42px;
  height: 42px;
  border-radius: 50%;
}

.left-nav a.active {
  color: #fff3ca;
}

.left-nav a.active span {
  background: linear-gradient(135deg, rgba(246, 220, 155, 0.34), rgba(110, 71, 31, 0.5));
}

.hero-title {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: start;
  justify-self: center;
  padding-top: 82px;
  text-align: center;
  pointer-events: none;
}

.hero-title h1 {
  position: relative;
  font-family: "STXingkai", "KaiTi", "STKaiti", serif;
  font-size: clamp(58px, 8vw, 112px);
  line-height: 0.95;
  letter-spacing: 0;
  color: #fff7d6;
  text-shadow:
    0 0 12px rgba(249, 226, 162, 0.46),
    0 5px 24px rgba(0, 0, 0, 0.64);
  white-space: nowrap;
}

.hero-title p {
  margin-top: 10px;
  color: var(--gold-2);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(23px, 3vw, 42px);
  letter-spacing: 14px;
  text-indent: 14px;
}

.title-mark {
  position: absolute;
  transform: translate(355px, 58px);
  border: 1px solid rgba(195, 58, 39, 0.82);
  color: #e34334;
  padding: 4px 5px;
  font-size: 13px;
  writing-mode: vertical-rl;
  letter-spacing: 0;
}

.board-zone {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  place-items: end center;
  min-width: 0;
  padding-top: min(25vh, 230px);
}

.board-frame {
  position: relative;
  width: min(54vw, calc((100vh - 258px) * 0.913), 650px);
  min-width: 420px;
  aspect-ratio: 432 / 473;
  transform: perspective(1200px) rotateX(17deg);
  transform-origin: 50% 76%;
  border: 1px solid rgba(236, 195, 115, 0.64);
  background: #241914;
  box-shadow:
    0 22px 16px rgba(0, 0, 0, 0.44),
    0 44px 90px rgba(0, 0, 0, 0.58),
    inset 0 0 26px rgba(245, 214, 143, 0.14);
}

.board-frame::before {
  content: "";
  position: absolute;
  inset: -18px;
  border: 1px solid rgba(207, 160, 82, 0.42);
  background:
    linear-gradient(90deg, rgba(222, 172, 91, 0.12), transparent 18%, transparent 82%, rgba(222, 172, 91, 0.12)),
    rgba(6, 8, 8, 0.2);
  box-shadow: inset 0 0 0 4px rgba(11, 8, 7, 0.52);
  z-index: -1;
}

.board-frame::after {
  content: "";
  position: absolute;
  inset: -26px -36px -32px;
  z-index: -2;
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(20, 11, 7, 0.62), rgba(4, 4, 4, 0.88));
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  contain: strict;
}

.battle-panel {
  grid-column: 3;
  grid-row: 2;
  align-self: center;
}

.panel-shell,
.history-drawer,
.engine-drawer {
  position: relative;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(31, 33, 31, 0.76), rgba(9, 13, 14, 0.9)),
    rgba(8, 12, 13, 0.84);
  box-shadow: inset 0 0 0 1px rgba(255, 234, 179, 0.06), 0 18px 44px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(8px);
}

.panel-shell {
  padding: 19px 16px 16px;
}

.panel-shell::before,
.history-drawer::before,
.engine-drawer::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(240, 203, 132, 0.13);
  pointer-events: none;
}

.panel-header {
  display: grid;
  gap: 7px;
  text-align: center;
}

.panel-kicker {
  color: #fff1c5;
  font-size: 22px;
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 2px;
}

.panel-header h2 {
  margin-top: 70px;
  color: #fff1c5;
  font-size: 28px;
  letter-spacing: 5px;
  text-indent: 5px;
}

.panel-header p {
  color: var(--soft-ink);
  font-size: 13px;
}

.ai-emblem {
  position: absolute;
  top: 72px;
  left: 50%;
  width: 72px;
  height: 72px;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  border: 1px solid rgba(241, 206, 135, 0.52);
  border-radius: 50%;
  color: #ffe7a5;
  font-size: 24px;
  letter-spacing: 0;
  box-shadow: inset 0 0 20px rgba(222, 174, 89, 0.14), 0 0 24px rgba(0, 0, 0, 0.35);
}

.status-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 18px;
}

.status-strip > div {
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid rgba(223, 181, 110, 0.22);
  background: rgba(0, 0, 0, 0.16);
}

.status-strip span,
.difficulty-group > span,
dt {
  color: var(--muted);
  font-size: 12px;
}

.status-strip strong {
  min-width: 0;
  color: #fff2c7;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.difficulty-group {
  display: grid;
  gap: 9px;
  margin-top: 17px;
  padding: 14px 12px;
  border: 1px solid rgba(223, 181, 110, 0.19);
  background: rgba(3, 7, 8, 0.24);
}

.difficulty-group button {
  height: 35px;
  border-radius: 999px;
  padding: 0 12px;
  color: var(--soft-ink);
  background: rgba(8, 14, 16, 0.58);
}

.difficulty-group button.selected {
  border-color: rgba(255, 222, 153, 0.84);
  color: #fff4cc;
  background: linear-gradient(90deg, rgba(169, 104, 44, 0.74), rgba(36, 31, 22, 0.72));
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 13px;
}

.controls button {
  min-height: 36px;
  padding: 0 10px;
  font-size: 13px;
}

.primary-action {
  grid-column: 1 / -1;
  min-height: 47px !important;
  border-color: rgba(255, 221, 151, 0.8);
  color: #4b2f12;
  background:
    linear-gradient(180deg, rgba(255, 241, 199, 0.95), rgba(203, 156, 83, 0.95)),
    #d7ad72;
  font-size: 18px !important;
  font-weight: 800;
}

.message-line {
  min-height: 18px;
  margin-top: 8px;
  color: #ffb49a;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.stream-log {
  display: grid;
  gap: 4px;
  max-height: 92px;
  overflow: auto;
  margin-top: 7px;
  padding: 8px;
  border: 1px solid rgba(223, 181, 110, 0.2);
  background: rgba(0, 0, 0, 0.25);
  color: var(--soft-ink);
  font-size: 12px;
  line-height: 1.45;
}

.stream-log:empty {
  display: none;
}

.stream-entry {
  overflow-wrap: anywhere;
}

.stream-entry.move,
.stream-entry.reason,
.stream-entry.info {
  color: #ffe0a2;
  font-weight: 700;
}

.stream-entry.error {
  color: #ff9b7f;
}

.mode-cards {
  grid-column: 2;
  grid-row: 3;
  justify-self: center;
  display: grid;
  grid-template-columns: repeat(4, minmax(128px, 176px));
  gap: 16px;
  width: min(760px, 100%);
}

.mode-cards article {
  display: grid;
  grid-template-columns: 52px 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  align-items: center;
  min-height: 78px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  background: rgba(11, 15, 15, 0.68);
  box-shadow: inset 0 0 0 1px rgba(255, 233, 173, 0.05);
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease, background 120ms ease;
}

.mode-cards article:hover,
.mode-cards article.active {
  border-color: rgba(255, 222, 153, 0.76);
  background: rgba(48, 37, 23, 0.72);
  transform: translateY(-1px);
}

.card-icon {
  grid-row: 1 / 3;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-family: "KaiTi", "STKaiti", serif;
  font-size: 21px;
}

.mode-cards h3 {
  color: #fff0c2;
  font-size: 16px;
  line-height: 1.2;
}

.mode-cards p {
  color: var(--muted);
  font-size: 12px;
}

.history-drawer,
.engine-drawer {
  grid-row: 2;
  align-self: end;
  max-height: min(42vh, 310px);
  overflow: auto;
  padding: 14px;
}

.history-drawer {
  grid-column: 1 / 3;
  justify-self: start;
  width: min(330px, 26vw);
  margin-left: 116px;
  opacity: 0.92;
}

.engine-drawer {
  grid-column: 3;
  justify-self: stretch;
  max-height: 190px;
}

.history-drawer h2,
.engine-drawer h2 {
  margin-bottom: 10px;
  color: #fff0c2;
  font-size: 15px;
}

.history {
  margin: 0;
  padding: 0 0 0 22px;
  font-size: 13px;
  line-height: 1.65;
}

.history li {
  padding: 4px 0 7px;
}

.history .red {
  color: #ffb6a4;
}

.history .black {
  color: #d9c8a5;
}

.move-line {
  font-weight: 700;
}

.engine-note {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.engine-output {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.engine-output summary {
  cursor: pointer;
}

.engine-output pre {
  margin: 6px 0 0;
  max-height: 130px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid rgba(223, 181, 110, 0.22);
  padding: 8px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--soft-ink);
}

.config-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.config-list div {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 8px;
  align-items: baseline;
}

dd {
  min-width: 0;
  margin: 0;
  color: var(--soft-ink);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.footer-bar {
  grid-column: 1 / -1;
  grid-row: 4;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 18px;
  color: var(--soft-ink);
}

.notice,
.social {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.notice {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(223, 181, 110, 0.24);
  border-radius: 999px;
  background: rgba(3, 7, 8, 0.32);
  cursor: pointer;
}

.notice span,
.notice strong,
.social span {
  white-space: nowrap;
  font-size: 12px;
}

.notice p {
  min-width: 0;
  overflow: hidden;
  color: var(--soft-ink);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 1180px) {
  .shanhai-stage {
    grid-template-columns: 82px minmax(390px, 1fr) 270px;
    gap: 14px;
    padding: 18px;
  }

  .left-nav {
    width: 74px;
  }

  .left-nav a {
    grid-template-columns: 38px;
    justify-items: center;
    font-size: 12px;
  }

  .left-nav span {
    width: 38px;
    height: 38px;
  }

  .hero-title h1 {
    font-size: clamp(48px, 7vw, 86px);
  }

  .board-frame {
    min-width: 360px;
  }

  .mode-cards {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .shanhai-stage {
    min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto auto auto auto;
    gap: 14px;
    padding: 14px;
  }

  .topbar,
  .hero-title,
  .left-nav,
  .board-zone,
  .battle-panel,
  .mode-cards,
  .history-drawer,
  .engine-drawer,
  .footer-bar {
    grid-column: 1;
    grid-row: auto;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .player-card,
  .quick-tools {
    display: none;
  }

  .left-nav {
    width: 100%;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    overflow-x: auto;
    align-self: auto;
  }

  .left-nav a {
    grid-template-columns: 34px auto;
    justify-content: center;
    white-space: nowrap;
  }

  .left-nav span {
    width: 34px;
    height: 34px;
  }

  .hero-title {
    padding-top: 6px;
  }

  .hero-title h1 {
    white-space: normal;
    font-size: clamp(42px, 14vw, 66px);
  }

  .hero-title p {
    font-size: 24px;
    letter-spacing: 9px;
    text-indent: 9px;
  }

  .title-mark {
    display: none;
  }

  .board-zone {
    padding-top: 0;
    place-items: center;
  }

  .board-frame {
    width: min(100%, 520px);
    min-width: 0;
    transform: none;
  }

  .mode-cards {
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .history-drawer,
  .engine-drawer {
    width: 100%;
    max-height: 260px;
    margin: 0;
    transform: none;
  }

  .footer-bar {
    grid-template-columns: 1fr;
  }

  .notice {
    border-radius: 4px;
  }
}

@media (max-width: 520px) {
  .shanhai-stage {
    padding: 10px;
  }

  .brand {
    grid-template-columns: 40px auto;
  }

  .brand-seal {
    width: 40px;
    height: 40px;
  }

  .left-nav {
    grid-auto-columns: max-content;
  }

  .mode-cards {
    grid-template-columns: 1fr;
  }

  .controls,
  .status-strip {
    grid-template-columns: 1fr;
  }
}
