:root {
  color-scheme: light;
  --page: #eeeae4;
  --ink: #2f2924;
  --muted: #756a60;
  --wood: #d3a06d;
  --wood-dark: #b77d4c;
  --wood-line: #4b3527;
  --wood-line-strong: #70492f;
  --cream: #fffdf8;
  --teal: #2c9488;
  --accent: #c76d42;
  --target-mine: #4f865d;
  --target-opponent: #c47b4d;
  --board-size: min(67vw, 600px);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
}

button { font: inherit; }

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

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.eyebrow, .section-label {
  margin: 0 0 8px;
  color: var(--wood-line-strong);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: #2a241f;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.05;
  letter-spacing: 0;
}

.subtitle { margin: 10px 0 0; color: var(--muted); font-size: 15px; }

.action-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #b7987c;
  border-radius: 5px;
  padding: 10px 14px;
  color: var(--ink);
  background: rgba(255, 253, 248, .58);
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease, transform .2s ease;
}

.action-button:hover, .action-button:focus-visible {
  border-color: var(--wood-line-strong);
  background: var(--cream);
  outline: none;
  transform: translateY(-1px);
}

.action-button:disabled { border-color: #c8bcb1; color: #9e9389; background: rgba(255,253,248,.4); cursor: not-allowed; opacity: .7; transform: none; }
.action-button span:first-child { color: var(--wood-line-strong); font-size: 20px; line-height: 1; }

.online-panel {
  margin-bottom: 28px;
  padding: 16px 18px;
  border: 1px solid #d1c3b5;
  border-radius: 5px;
  background: rgba(255, 253, 248, .72);
}

.online-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.online-heading .section-label { margin-bottom: 4px; }
.online-description { margin: 0; color: var(--muted); font-size: 13px; }
.room-code-view { display: inline-flex; align-items: baseline; gap: 8px; color: var(--muted); font-size: 12px; }
.room-code-view strong { color: var(--wood-line-strong); font-size: 22px; letter-spacing: .14em; }
.room-code-view span:last-child { color: var(--teal); }
.room-actions { display: flex; align-items: end; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.primary-action { border-color: #a66d42; color: #fffdf8; background: var(--wood-line-strong); }
.primary-action:hover, .primary-action:focus-visible { border-color: #523321; color: #fffdf8; background: #523321; }
.room-input-label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 11px; }
.room-input-label input { width: 140px; height: 40px; border: 1px solid #c3b1a0; border-radius: 5px; padding: 0 10px; color: var(--ink); background: #fffdf8; font: inherit; letter-spacing: .14em; text-transform: uppercase; }
.room-input-label input:focus { border-color: var(--wood-line-strong); outline: 2px solid rgba(112,73,47,.15); }
.room-status { min-height: 18px; margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.undo-request-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; align-items: start; gap: 34px; }
.board-panel { min-width: 0; }

.board-meta { display: flex; align-items: center; justify-content: space-between; width: min(var(--board-size), 100%); margin: 0 auto 15px; }
.turn-indicator { display: inline-flex; align-items: center; gap: 10px; color: #302a25; font-size: 18px; font-weight: 700; }
.turn-dot, .legend-dot { display: inline-block; width: 13px; height: 13px; border-radius: 50%; }
.black-dot { background: #252321; border: 2px solid #6e655d; box-shadow: 0 0 0 3px rgba(75,53,39,.10); }
.white-dot { background: #fffdf8; border: 2px solid #b9aea2; }
.move-count { color: var(--muted); font-size: 13px; }

.board-frame {
  width: var(--board-size);
  max-width: 100%;
  margin: 0 auto;
  padding: clamp(22px, 3vw, 34px);
  border: 1px solid #a66d42;
  border-radius: 5px;
  background: var(--wood);
  box-shadow: inset 0 0 0 8px rgba(255, 231, 192, .10), 0 12px 25px rgba(91, 57, 31, .18);
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  aspect-ratio: 1;
  background: var(--wood);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-right: 1px solid var(--wood-line);
  border-bottom: 1px solid var(--wood-line);
  background: transparent;
  cursor: pointer;
  transition: background .15s ease, box-shadow .15s ease;
}

.cell:nth-child(-n+9) { border-top: 1px solid var(--wood-line); }
.cell:nth-child(9n + 1) { border-left: 1px solid var(--wood-line); }
.cell:nth-child(9n) { border-right-color: var(--wood-line-strong); }
.cell:nth-child(n+19):nth-child(-n+27), .cell:nth-child(n+46):nth-child(-n+54) { border-bottom-color: var(--wood-line-strong); }
.cell:nth-child(n+73):nth-child(-n+81) { border-bottom-color: var(--wood-line-strong); }

.cell.allowed { background: rgba(255, 243, 215, .16); }
.cell.allowed:hover, .cell:focus-visible { background: rgba(255, 247, 227, .32); outline: none; }
.cell.forbidden { cursor: not-allowed; }
.cell.last-move { box-shadow: inset 0 0 0 2px rgba(199, 109, 66, .58); }
.cell.winning { background: rgba(255, 220, 139, .38); }
.cell.target-cell { background: rgba(255, 248, 228, .12); }

.target-frame {
  position: absolute;
  z-index: 3;
  inset: -2px;
  width: calc(300% + 4px);
  height: calc(300% + 4px);
  border: 2px solid var(--target-opponent);
  border-radius: 4px;
  pointer-events: none;
  box-shadow: 0 0 0 2px rgba(196,123,77,.12);
}
.target-frame.mine { border-color: var(--target-mine); box-shadow: 0 0 0 2px rgba(79,134,93,.13); }
.target-frame-label { position: absolute; top: 3px; left: 5px; padding: 2px 5px; border-radius: 3px; color: #fffdf8; background: var(--target-opponent); font-size: 10px; line-height: 1; }
.target-frame.mine .target-frame-label { background: var(--target-mine); }

.star-point {
  width: 8px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--wood-line-strong);
  box-shadow: 0 1px 1px rgba(255, 233, 192, .3);
  pointer-events: none;
}

.piece {
  position: relative;
  z-index: 4;
  width: 72%;
  aspect-ratio: 1;
  border-radius: 50%;
  transform: scale(.92);
  box-shadow: 0 4px 7px rgba(63, 38, 20, .34), inset -2px -3px 4px rgba(0,0,0,.15);
  animation: place .2s ease-out;
}

.piece.black { background: radial-gradient(circle at 34% 28%, #4a4744 0 8%, #252321 42%, #11100f 100%); border: 1px solid #171513; }
.piece.white { background: radial-gradient(circle at 34% 26%, #ffffff 0 13%, #faf8f2 46%, #cfc8bd 100%); border: 1px solid #b8afa4; }
.piece.winning-piece { box-shadow: 0 0 0 3px var(--accent), 0 4px 10px rgba(63,38,20,.35); }
.last-marker { position: absolute; z-index: 2; width: 22%; aspect-ratio: 1; border-radius: 50%; background: #ce1d1d; box-shadow: 0 0 0 2px rgba(255,255,255,.62); }

@keyframes place { from { transform: scale(.45); opacity: .4; } to { transform: scale(.92); opacity: 1; } }

.status-line { min-height: 24px; width: min(var(--board-size), 100%); margin: 14px auto 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.status-line.win { color: var(--accent); font-weight: 700; }
.status-line.draw { color: var(--teal); font-weight: 700; }

.board-controls { display: flex; justify-content: center; margin-top: 12px; }
.board-controls { align-items: flex-start; gap: 22px; }
.undo-control { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.undo-button {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border: 2px solid #2299e6;
  border-radius: 50%;
  color: #2299e6;
  background: #fffdf9;
  box-shadow: 0 2px 4px rgba(72, 74, 73, .14);
  cursor: pointer;
  transition: transform .2s ease, background .2s ease, opacity .2s ease;
}

.undo-button span { display: block; font-size: 25px; line-height: 1; }
.undo-button:hover:not(:disabled), .undo-button:focus-visible:not(:disabled) { background: #eaf6ff; outline: none; transform: translateY(-2px); }
.undo-button:disabled { color: #9ca8ae; border-color: #b9c2c5; cursor: not-allowed; opacity: .75; }
.undo-label { color: var(--muted); font-size: 13px; line-height: 1; }
.surrender-control { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.surrender-button { min-width: 58px; height: 50px; border: 1px solid #c47b67; border-radius: 5px; color: #a94f37; background: rgba(255,253,248,.72); cursor: pointer; transition: background .2s ease, transform .2s ease; }
.surrender-button:hover:not(:disabled), .surrender-button:focus-visible:not(:disabled) { background: #fff0eb; outline: none; transform: translateY(-2px); }
.surrender-button:disabled { border-color: #d6cbc2; color: #aea39a; cursor: not-allowed; opacity: .7; }
.surrender-label { color: var(--muted); font-size: 13px; line-height: 1; }

.undo-modal[hidden] { display: none; }
.undo-modal { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(41, 33, 27, .28); }
.undo-modal-card { width: min(360px, 100%); padding: 24px; border: 1px solid #c6ae96; border-radius: 7px; background: #fffdf8; box-shadow: 0 20px 55px rgba(65, 44, 28, .26); }
.undo-modal-card h2 { margin: 6px 0 8px; color: #2c241e; font-size: 24px; }
.undo-modal-card p:not(.section-label) { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.undo-modal-card .undo-request-actions { justify-content: flex-end; }

.side-panel { display: flex; flex-direction: column; gap: 22px; padding-top: 4px; }
.info-section { padding-bottom: 22px; border-bottom: 1px solid #d4c8bb; }
.focus-section { padding: 18px; border: 1px solid #c6ae96; border-radius: 5px; background: rgba(255,253,248,.62); }
.target-block { margin-top: 12px; color: #2c241e; font-size: 30px; font-weight: 700; line-height: 1; }
.focus-section p { margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.block-index { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.block-index span { display: grid; place-items: center; aspect-ratio: 1.35; border: 1px solid #c8b8a9; border-radius: 4px; color: var(--muted); font-size: 13px; }
.block-index span.active { border-color: var(--teal); color: var(--teal); background: rgba(44,148,136,.10); }
.block-index span.center { color: var(--wood-line-strong); }

.rules-section ol { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.75; }
.legend { display: flex; gap: 18px; color: var(--muted); font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }

@media (max-width: 860px) {
  :root { --board-size: min(86vw, 600px); }
  .app-shell { width: min(100% - 28px, 680px); padding-top: 28px; }
  .game-layout { grid-template-columns: 1fr; gap: 28px; }
  .side-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 18px; }
  .rules-section { grid-column: 1 / -1; }
  .legend { grid-column: 1 / -1; }
}

@media (max-width: 540px) {
  .topbar { align-items: stretch; flex-direction: column; gap: 18px; margin-bottom: 24px; }
  .topbar-actions { align-self: flex-start; }
  .online-heading { align-items: flex-start; flex-direction: column; gap: 12px; }
  .room-actions { align-items: stretch; }
  .room-input-label { width: 100%; }
  .room-input-label input { width: 100%; }
  .board-controls { gap: 16px; }
  .side-panel { display: flex; }
  .board-frame { padding: 17px; }
  .status-line { font-size: 13px; }
}
