:root {
  color-scheme: light;
  --ink: #241b15;
  --muted: #71655b;
  --paper: #f5efe4;
  --paper-2: #fffaf1;
  --line: rgba(67, 45, 29, .14);
  --wood: #d9a86f;
  --wood-dark: #81502e;
  --accent: #be442f;
  --gold: #d49a32;
  --green: #318664;
  --purple: #6f5bb4;
  --shadow: 0 28px 70px rgba(48, 31, 20, .13);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: #ebe2d3; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% -6%, rgba(215, 168, 111, .28), transparent 35rem),
    radial-gradient(circle at 92% 90%, rgba(133, 87, 52, .14), transparent 38rem),
    linear-gradient(150deg, #f8f3e9 0%, #eee4d5 100%);
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow-x: hidden;
}

button, select, input { font: inherit; }
button, select { color: inherit; }
button { touch-action: manipulation; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ambient {
  position: fixed;
  z-index: -1;
  border: 1px solid rgba(123, 83, 53, .09);
  border-radius: 50%;
  pointer-events: none;
}

.ambient-one { width: 31rem; height: 31rem; top: 9rem; left: -21rem; }
.ambient-two { width: 22rem; height: 22rem; right: -12rem; bottom: 3rem; }

.site-header {
  width: min(1480px, calc(100% - 48px));
  height: 88px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, 11px);
  gap: 4px;
  padding: 9px;
  border: 1px solid rgba(56, 38, 26, .22);
  border-radius: 12px;
  transform: rotate(45deg);
}

.brand-mark i { width: 11px; height: 11px; border-radius: 50%; background: var(--ink); }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { background: var(--paper-2); box-shadow: inset 0 0 0 1px rgba(36, 27, 21, .18); }

.brand > span:last-child { display: flex; flex-direction: column; line-height: 1; }
.brand strong { font-family: Georgia, "Times New Roman", serif; font-size: 25px; letter-spacing: .1em; }
.brand small { margin-top: 6px; color: var(--muted); font-size: 9px; letter-spacing: .17em; }

.header-actions { display: flex; align-items: center; gap: 12px; }
.home-link, .icon-button {
  border: 1px solid rgba(57, 39, 28, .18);
  background: rgba(255, 251, 244, .62);
  color: var(--ink);
  text-decoration: none;
  transition: .2s ease;
}
.home-link { padding: 10px 17px; border-radius: 999px; font-size: 13px; }
.icon-button { width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-family: Georgia, serif; font-size: 18px; }
.home-link:hover, .icon-button:hover { transform: translateY(-1px); border-color: rgba(57, 39, 28, .38); background: #fffaf1; }

.app-shell { width: min(1480px, calc(100% - 48px)); margin: 0 auto; padding: 42px 0 72px; }

.intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  padding: 0 4px 30px;
}

.eyebrow { margin: 0 0 8px; color: #9a6b47; font-size: 11px; font-weight: 700; letter-spacing: .23em; }
.intro h1 { margin: 0; font-family: Georgia, "Noto Serif SC", serif; font-size: clamp(38px, 4vw, 64px); font-weight: 500; letter-spacing: .06em; }
.intro > div > p:last-child { max-width: 620px; margin: 10px 0 0; color: var(--muted); font-size: 15px; line-height: 1.7; }
.rule-pill { flex: 0 0 auto; display: flex; align-items: center; gap: 9px; margin-bottom: 7px; color: #614d3e; font-size: 13px; }
.rule-pill span { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 5px rgba(190, 68, 47, .1); }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 354px; gap: 22px; align-items: start; }
.board-card, .control-card {
  border: 1px solid rgba(81, 54, 35, .13);
  border-radius: 25px;
  background: rgba(255, 251, 243, .72);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.board-card { padding: 20px; min-width: 0; }
.board-heading { display: flex; align-items: center; justify-content: space-between; min-height: 48px; padding: 0 6px 15px; }
.board-heading > div:first-child { display: flex; align-items: center; gap: 11px; }
.board-heading small, .move-counter small { display: block; color: var(--muted); font-size: 10px; letter-spacing: .08em; }
.board-heading strong { display: block; margin-top: 3px; font-size: 17px; }
.turn-stone { width: 31px; height: 31px; border-radius: 50%; transition: .25s ease; }
.turn-stone.black { background: radial-gradient(circle at 35% 28%, #555 0, #171717 52%, #050505 100%); box-shadow: 0 5px 12px rgba(0, 0, 0, .28); }
.turn-stone.white { background: radial-gradient(circle at 34% 25%, #fff 0, #f2eee6 58%, #c9c0b4 100%); box-shadow: inset 0 0 0 1px rgba(30, 20, 12, .15), 0 5px 12px rgba(60, 40, 25, .14); }
.move-counter { text-align: right; }
.move-counter strong { margin-top: 3px; font-family: Georgia, serif; font-size: 19px; font-variant-numeric: tabular-nums; }

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 17px;
  background: #d9a86f;
  box-shadow: inset 0 0 0 1px rgba(59, 35, 19, .25), 0 12px 34px rgba(61, 40, 24, .16);
}

#board { display: block; width: 100%; height: 100%; cursor: crosshair; outline: none; }
#board.is-busy { cursor: wait; }
#board.is-review { cursor: default; }

.thinking {
  position: absolute;
  top: 14px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 13px;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 999px;
  background: rgba(36, 27, 21, .86);
  color: white;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  transform: translateX(-50%);
  pointer-events: none;
}
.thinking[hidden] { display: none; }
.thinking span { width: 5px; height: 5px; border-radius: 50%; background: #e8b46d; animation: think 1s ease-in-out infinite; }
.thinking span:nth-child(2) { animation-delay: .12s; }
.thinking span:nth-child(3) { animation-delay: .24s; }
.thinking b { margin-left: 5px; font-size: 11px; font-weight: 600; }
@keyframes think { 0%, 100% { transform: translateY(0); opacity: .45; } 50% { transform: translateY(-3px); opacity: 1; } }

.result-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle, rgba(35, 25, 18, .58), rgba(25, 17, 12, .83));
  color: #fffaf1;
  backdrop-filter: blur(4px);
  animation: overlay-in .35s ease both;
}
.result-overlay[hidden] { display: none; }
.result-overlay span { margin-bottom: 8px; color: #e9c99d; font-size: 11px; letter-spacing: .2em; }
.result-overlay strong { font-family: Georgia, "Noto Serif SC", serif; font-size: clamp(35px, 5vw, 68px); font-weight: 500; letter-spacing: .08em; }
.result-overlay button { margin-top: 24px; padding: 11px 21px; border: 1px solid rgba(255, 255, 255, .45); border-radius: 999px; background: rgba(255, 255, 255, .1); color: white; cursor: pointer; }
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

.board-tools { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 3px 0; }
.tool-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 11px;
  border: 1px solid rgba(71, 47, 31, .12);
  border-radius: 10px;
  background: rgba(236, 226, 211, .54);
  color: #85766a;
  font-size: 11px;
  cursor: pointer;
  transition: .18s ease;
}
.tool-toggle span { display: grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; background: rgba(75, 55, 41, .08); font-size: 10px; }
.tool-toggle:hover { border-color: rgba(71, 47, 31, .26); }
.tool-toggle.is-on { background: #f7ead8; color: #513d30; border-color: rgba(155, 99, 55, .28); }
.tool-toggle.is-on span { background: #8a5736; color: white; }

.review-bar { margin-top: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(244, 236, 223, .62); }
.review-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.review-meta strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.review-controls { display: grid; grid-template-columns: 30px 1fr 30px auto; align-items: center; gap: 8px; margin-top: 7px; }
.review-controls button { height: 29px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.55); cursor: pointer; }
.review-controls button:disabled { opacity: .4; cursor: default; }
.review-controls .latest-button { padding: 0 12px; color: var(--muted); font-size: 10px; }
.review-controls input { width: 100%; accent-color: #8a5736; }

.control-card { position: sticky; top: 18px; padding: 16px; }
.status-card { padding: 18px; border-radius: 17px; background: #292019; color: #fff8ed; box-shadow: 0 15px 35px rgba(37, 27, 20, .2); }
.status-topline { display: flex; align-items: center; justify-content: space-between; color: #ccbda9; font-size: 10px; letter-spacing: .06em; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #76695e; box-shadow: 0 0 0 4px rgba(255,255,255,.04); }
.status-dot.active { background: #e25e42; box-shadow: 0 0 0 5px rgba(226, 94, 66, .12); }
.clock { margin: 12px 0 7px; font-family: Georgia, "Times New Roman", serif; font-size: 39px; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: .03em; }
.status-card p { min-height: 32px; margin: 0; color: #ccbda9; font-size: 11px; line-height: 1.5; }

.control-section { padding: 20px 4px 5px; border-bottom: 1px solid var(--line); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-title > span { font-size: 13px; font-weight: 700; }
.section-title small { color: var(--muted); font-size: 9px; }
.section-title button { padding: 0; border: 0; background: none; color: #94603d; font-size: 10px; cursor: pointer; }
.field { display: grid; grid-template-columns: 103px 1fr; align-items: center; gap: 8px; margin-bottom: 9px; color: var(--muted); font-size: 11px; }
.field select {
  width: 100%;
  min-width: 0;
  padding: 9px 27px 9px 10px;
  border: 1px solid rgba(71, 47, 31, .13);
  border-radius: 9px;
  outline: 0;
  background: #f8f1e6;
  font-size: 11px;
}
.field select:focus { border-color: rgba(138, 87, 54, .55); box-shadow: 0 0 0 3px rgba(138, 87, 54, .08); }

.switch-field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0 12px; cursor: pointer; }
.switch-field > span { display: flex; flex-direction: column; }
.switch-field b { font-size: 11px; }
.switch-field small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.switch-field input { position: absolute; opacity: 0; pointer-events: none; }
.switch-field i { position: relative; flex: 0 0 auto; width: 38px; height: 22px; border-radius: 999px; background: #cfc3b2; transition: .2s; }
.switch-field i::after { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; border-radius: 50%; background: white; box-shadow: 0 2px 5px rgba(0,0,0,.18); transition: .2s; }
.switch-field input:checked + i { background: #8a5736; }
.switch-field input:checked + i::after { transform: translateX(16px); }
.switch-field input:focus-visible + i { outline: 2px solid #94603d; outline-offset: 2px; }

.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 16px 4px; }
.action-grid button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid rgba(71, 47, 31, .15);
  border-radius: 10px;
  background: #f8f1e6;
  font-size: 11px;
  cursor: pointer;
  transition: .18s ease;
}
.action-grid button:hover { transform: translateY(-1px); border-color: rgba(71, 47, 31, .32); }
.action-grid button span { font-size: 16px; line-height: 1; }
.action-grid .primary-action { background: #875536; border-color: #875536; color: #fffaf3; }

.legend-card { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin: 1px 4px 18px; padding: 12px; border-radius: 12px; background: rgba(239, 229, 213, .58); }
.legend-card > div { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 9px; }
.legend-card b { color: var(--ink); margin-right: 2px; }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; }
.legend-dot.red { background: var(--accent); }
.legend-dot.amber { background: var(--gold); }
.legend-dot.green { background: var(--green); }

.quick-rules { padding: 0 4px; }
.quick-rules ol { list-style: none; margin: 0; padding: 0; }
.quick-rules li { display: grid; grid-template-columns: 28px 1fr; gap: 9px; padding: 8px 0; border-top: 1px solid var(--line); }
.quick-rules li > span { padding-top: 2px; color: #b28b68; font-family: Georgia, serif; font-size: 10px; }
.quick-rules p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.55; }
.control-card footer { margin: 17px 4px 2px; padding-top: 13px; border-top: 1px solid var(--line); color: #a09286; font-family: Georgia, "Noto Serif SC", serif; font-size: 9px; line-height: 1.65; text-align: right; }

.rules-dialog {
  width: min(570px, calc(100% - 32px));
  max-height: min(760px, calc(100vh - 32px));
  padding: 0;
  border: 1px solid rgba(72, 48, 31, .16);
  border-radius: 22px;
  background: #fbf5ea;
  color: var(--ink);
  box-shadow: 0 34px 90px rgba(34, 24, 17, .3);
}
.rules-dialog::backdrop { background: rgba(30, 22, 17, .58); backdrop-filter: blur(5px); }
.rules-dialog form { position: relative; padding: 32px; }
.rules-dialog h2 { margin: 0 0 23px; font-family: Georgia, "Noto Serif SC", serif; font-size: 31px; font-weight: 500; }
.dialog-close { position: absolute; top: 18px; right: 18px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #eee3d4; font-size: 21px; cursor: pointer; }
.dialog-rule { display: grid; grid-template-columns: 34px 1fr; gap: 12px; padding: 15px 0; border-top: 1px solid var(--line); }
.dialog-rule > span { color: #b48763; font-family: Georgia, serif; font-size: 12px; }
.dialog-rule h3 { margin: 0 0 5px; font-size: 13px; }
.dialog-rule p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.7; }
.dialog-confirm { width: 100%; margin-top: 18px; padding: 12px; border: 0; border-radius: 11px; background: #875536; color: white; cursor: pointer; }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  background: rgba(36, 27, 21, .92);
  color: #fffaf2;
  font-size: 11px;
  opacity: 0;
  transform: translate(-50%, 14px);
  transition: .25s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1100px) {
  .game-layout { grid-template-columns: minmax(0, 1fr) 318px; }
  .control-card { padding: 13px; }
  .board-card { padding: 16px; }
}

@media (max-width: 880px) {
  .game-layout { grid-template-columns: 1fr; }
  .control-card { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
  .status-card, .action-grid, .legend-card, .control-card footer { grid-column: 1 / -1; }
  .quick-rules { padding-top: 20px; }
  .control-section { padding-top: 20px; }
}

@media (max-width: 620px) {
  .site-header, .app-shell { width: min(100% - 24px, 1480px); }
  .site-header { height: 70px; }
  .home-link { display: none; }
  .app-shell { padding: 27px 0 48px; }
  .intro { align-items: flex-start; padding: 0 3px 21px; }
  .intro > div > p:last-child { font-size: 12px; }
  .rule-pill { display: none; }
  .game-layout { gap: 13px; }
  .board-card { padding: 10px; border-radius: 17px; }
  .canvas-wrap { border-radius: 12px; }
  .board-heading { padding: 4px 4px 11px; }
  .board-tools { gap: 6px; }
  .tool-toggle { flex: 1 1 calc(33% - 6px); justify-content: center; padding: 8px 6px; }
  .review-controls { grid-template-columns: 28px 1fr 28px; }
  .review-controls .latest-button { grid-column: 1 / -1; }
  .control-card { display: block; padding: 11px; border-radius: 17px; }
  .status-card { padding: 16px; }
  .legend-card { margin-bottom: 14px; }
  .rules-dialog form { padding: 27px 21px 22px; }
}

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