:root {
  --paper: #f4efe6;
  --paper-deep: #ebe2d1;
  --ink: #241e17;
  --ink-soft: #6f6152;
  --ink-faint: #9b8c79;
  --line: rgba(70, 48, 26, 0.13);
  --line-strong: rgba(70, 48, 26, 0.22);
  --accent: #b1402f;
  --accent-soft: rgba(177, 64, 47, 0.1);
  --card: rgba(255, 253, 247, 0.86);
  --card-solid: #fffdf8;
  --wood-hi: #8a5a34;
  --wood-lo: #63401f;
  --shadow-lg: 0 24px 48px -24px rgba(56, 34, 12, 0.45), 0 8px 18px -12px rgba(56, 34, 12, 0.35);
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", SimSun, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-sans);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(1100px 620px at 12% -8%, #fdfaf3 0%, rgba(253, 250, 243, 0) 62%),
    radial-gradient(900px 520px at 102% 4%, #f0e4cf 0%, rgba(240, 228, 207, 0) 58%),
    radial-gradient(760px 460px at 50% 108%, #eee3d0 0%, rgba(238, 227, 208, 0) 64%);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
}

.page {
  position: relative;
  z-index: 1;
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: clamp(20px, 4.5vw, 48px) clamp(16px, 4vw, 40px) 24px;
}

/* ---------- 顶栏 ---------- */

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 22px;
  margin-bottom: clamp(20px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.seal {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 11px;
  background: linear-gradient(150deg, #c0503c, #9c3325);
  color: #fdf6ea;
  font-family: var(--font-serif);
  font-size: 24px;
  line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 6px 14px -6px rgba(120, 38, 26, 0.65);
  transform: rotate(-2deg);
}

.brand-text h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(22px, 2.6vw, 28px);
  font-weight: 600;
  letter-spacing: 0.12em;
}

.brand-text p {
  margin: 3px 0 0;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

.board-meta {
  margin: 0 0 4px;
  font-size: 12.5px;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

/* ---------- 布局 ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 336px;
  gap: clamp(20px, 3vw, 36px);
  align-items: start;
}

/* ---------- 棋盘 ---------- */

.board-card {
  min-width: 0;
}

.board-frame {
  padding: clamp(10px, 1.4vw, 16px);
  border-radius: 22px;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.16), rgba(0, 0, 0, 0.18)),
    linear-gradient(150deg, var(--wood-hi), var(--wood-lo));
  box-shadow:
    inset 0 1px 0 rgba(255, 236, 205, 0.35),
    inset 0 -2px 6px rgba(38, 22, 8, 0.5),
    var(--shadow-lg);
}

.board-frame canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  touch-action: none;
  cursor: crosshair;
  box-shadow: inset 0 0 0 1px rgba(88, 56, 28, 0.45), inset 0 2px 10px rgba(70, 40, 12, 0.22);
}

.board-frame canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

/* ---------- 侧栏 ---------- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 28px;
}

.status-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 17px 18px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: blur(10px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 14px 28px -24px rgba(56, 34, 12, 0.55);
  transition: border-color 0.3s ease, background-color 0.3s ease;
}

.status-card[data-state="thinking"] {
  border-color: var(--line-strong);
}

.status-card[data-state="win"] {
  border-color: rgba(177, 64, 47, 0.4);
  background: linear-gradient(180deg, rgba(255, 250, 244, 0.9), rgba(250, 240, 230, 0.85));
}

.status-card[data-state="lose"] {
  border-color: rgba(70, 48, 26, 0.2);
}

.status-stone {
  position: relative;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #5d5d5d, #1d1d1d 62%, #050505);
  box-shadow: 0 3px 6px rgba(20, 15, 10, 0.35), inset 0 1px 1px rgba(255, 255, 255, 0.22);
}

.status-stone[data-color="white"] {
  background: radial-gradient(circle at 34% 30%, #ffffff, #f1ebdd 58%, #d3c7b2);
  box-shadow: 0 3px 6px rgba(20, 15, 10, 0.28), inset 0 1px 1px rgba(255, 255, 255, 0.9),
    inset 0 -1px 2px rgba(120, 100, 70, 0.25);
}

.status-stone::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 1.5px solid rgba(177, 64, 47, 0.5);
  opacity: 0;
}

.status-card[data-state="thinking"] .status-stone::after {
  animation: pulse 1.4s ease-out infinite;
}

@keyframes pulse {
  0% {
    opacity: 0.7;
    transform: scale(0.82);
  }
  70%,
  100% {
    opacity: 0;
    transform: scale(1.35);
  }
}

.status-copy {
  min-width: 0;
}

.status-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.status-card[data-state="win"] .status-title {
  color: var(--accent);
}

.status-sub {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--ink-soft);
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
}

/* ---------- 控件 ---------- */

.control {
  padding: 15px 16px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: blur(10px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 14px 28px -26px rgba(56, 34, 12, 0.45);
}

.control-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 11px;
}

.control-head h2,
.field > span {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
}

.control-note {
  font-size: 11.5px;
  color: var(--ink-faint);
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  padding: 3px;
  border-radius: 11px;
  background: rgba(58, 40, 20, 0.07);
}

.segmented button {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 8px 4px;
  font: inherit;
  font-size: 13px;
  color: var(--ink-soft);
  background: transparent;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button.is-active {
  color: var(--ink);
  background: var(--card-solid);
  box-shadow: 0 1px 2px rgba(60, 40, 20, 0.12), 0 4px 10px -6px rgba(60, 40, 20, 0.4);
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding: 9px 30px 9px 11px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 9px;
  background-color: var(--card-solid);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2382705c' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field select:hover {
  border-color: var(--line-strong);
}

.field select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.actions {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 10px;
}

.btn {
  appearance: none;
  padding: 11px 14px;
  font: inherit;
  font-size: 13.5px;
  letter-spacing: 0.04em;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(255, 252, 245, 0.7);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease,
    border-color 0.2s ease, opacity 0.2s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  box-shadow: 0 8px 16px -12px rgba(50, 32, 14, 0.6);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary {
  border-color: transparent;
  background: linear-gradient(160deg, #35291e, #241d16);
  color: #f8f2e6;
  box-shadow: 0 10px 20px -12px rgba(45, 28, 10, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(160deg, #3e3024, #2a221a);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn:focus-visible,
.segmented button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.footnote {
  margin: 2px 2px 0;
  font-size: 12px;
  line-height: 1.75;
  color: var(--ink-faint);
}

/* ---------- 页脚 ---------- */

.colophon {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: clamp(26px, 4vw, 44px);
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
}

/* ---------- 响应式 ---------- */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel {
    position: static;
    max-width: 620px;
    width: 100%;
    margin: 0 auto;
  }

  .board-card {
    width: 100%;
    max-width: 620px;
    margin: 0 auto;
  }

  .masthead {
    align-items: center;
  }

  .board-meta {
    margin-bottom: 0;
  }
}

/* 手机：棋盘贴边铺满，整体字号再放大一档 */
@media (max-width: 640px) {
  .page {
    padding: 0 0 20px;
  }

  .masthead {
    padding: 16px 16px 14px;
    margin: 0 0 10px;
  }

  .board-card {
    width: 100%;
    max-width: none;
    margin: 0;
  }

  .board-frame {
    padding: 5px;
    border-radius: 0;
    box-shadow:
      inset 0 1px 0 rgba(255, 236, 205, 0.3),
      0 14px 24px -18px rgba(56, 34, 12, 0.55);
  }

  .board-frame canvas {
    border-radius: 0;
  }

  .panel {
    width: auto;
    max-width: none;
    margin: 16px 12px 0;
  }

  .status-title {
    font-size: 18px;
  }

  .status-sub {
    font-size: 13px;
  }

  .segmented button {
    font-size: 14px;
    padding: 9px 2px;
  }

  .field select {
    font-size: 14px;
    padding: 10px 30px 10px 11px;
  }

  .btn {
    font-size: 14.5px;
    padding: 12px 14px;
  }

  .control-head h2,
  .field > span {
    font-size: 12.5px;
  }

  .footnote {
    font-size: 12.5px;
  }

  .colophon {
    margin-left: 16px;
    margin-right: 16px;
  }
}

@media (max-width: 560px) {
  .masthead {
    padding-bottom: 14px;
    margin-bottom: 10px;
  }

  .seal {
    width: 38px;
    height: 38px;
    font-size: 21px;
  }

  .brand-text p {
    letter-spacing: 0.1em;
    font-size: 11px;
  }

  .board-meta {
    font-size: 11.5px;
  }

  .status-card,
  .control {
    padding: 14px;
  }

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

  .colophon {
    gap: 8px;
    letter-spacing: 0.06em;
  }
}

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