:root {
  --ink: #f0eee5;
  --muted: #a9b2a6;
  --subtle: #718076;
  --night: #0b110e;
  --night-2: #111b16;
  --line: rgba(224, 228, 215, 0.14);
  --board: #d6ad67;
  --board-light: #eccb91;
  --board-dark: #bb8240;
  --jade: #9ac08d;
  --red: #c95745;
  font-family: Manrope, system-ui, sans-serif;
  color: var(--ink);
  background: var(--night);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  position: relative;
  isolation: isolate;
  overflow-x: hidden;
  background: #0b110e;
}

.china-backdrop {
  position: fixed;
  z-index: -2;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(3, 8, 5, .42), transparent 20%, transparent 80%, rgba(3, 8, 5, .38)),
    radial-gradient(circle at 50% 12%, rgba(116, 142, 112, .13), transparent 30rem),
    linear-gradient(156deg, #0a100d 0%, #15231b 48%, #09110d 100%);
}
.china-backdrop::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(201, 182, 137, .08);
  background:
    linear-gradient(90deg, rgba(196, 178, 131, .38) 18px, transparent 18px) 0 0 / 70px 1px no-repeat,
    linear-gradient(rgba(196, 178, 131, .38) 18px, transparent 18px) 0 0 / 1px 70px no-repeat,
    linear-gradient(-90deg, rgba(196, 178, 131, .38) 18px, transparent 18px) 100% 100% / 70px 1px no-repeat,
    linear-gradient(0deg, rgba(196, 178, 131, .38) 18px, transparent 18px) 100% 100% / 1px 70px no-repeat;
  opacity: .7;
}
.china-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .1;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.45'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}
.backdrop-sun {
  position: absolute;
  top: clamp(84px, 12vh, 138px);
  right: clamp(38px, 8vw, 150px);
  width: clamp(130px, 16vw, 245px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 42% 37%, #d9705d, #b74434 66%, #813024 100%);
  box-shadow: 0 0 80px rgba(197, 72, 53, .16);
  opacity: .72;
}
.ink-landscape { position: absolute; inset: 0; width: 100%; height: 100%; }
.cloud-strokes { opacity: .13; }
.mountain-far { opacity: .86; }
.mountain-near { opacity: .9; }
.pine-trees { opacity: .68; }
.seal-mark {
  position: absolute;
  right: clamp(28px, 3vw, 52px);
  top: clamp(270px, 34vh, 340px);
  bottom: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 54px;
  height: 54px;
  padding: 6px;
  border: 2px solid rgba(202, 83, 63, .62);
  color: rgba(218, 104, 85, .76);
  font: 700 17px/1 "Noto Serif SC", serif;
  transform: rotate(-3deg);
}
.seal-mark span { display: grid; place-items: center; border: 1px solid rgba(202, 83, 63, .28); }
.backdrop-script {
  position: absolute;
  left: clamp(24px, 3vw, 54px);
  top: 25%;
  color: rgba(213, 216, 201, .23);
  font: 600 clamp(10px, .85vw, 13px)/1.8 "Noto Serif SC", serif;
  letter-spacing: .42em;
  writing-mode: vertical-rl;
}

button { font: inherit; }

.app-shell {
  width: min(1500px, calc(100% - 48px));
  margin: auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 31px 0 22px;
}

.topbar { display: flex; justify-content: space-between; align-items: center; min-height: 68px; border-bottom: 1px solid var(--line); padding-bottom: 24px; }
.brand, .game-meta, .player-heading, .board-title-row, .board-caption, .control-strip, .legend-row { display: flex; align-items: center; }
.brand { gap: 14px; }
.brand-mark { width: 39px; height: 39px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; transform: rotate(45deg); border: 1px solid rgba(145, 209, 124, 0.45); padding: 6px; }
.brand-mark span { background: var(--jade); }
.brand-mark span:last-child { opacity: .27; }
.eyebrow, .section-label { margin: 0; font: 500 10px/1.2 "DM Mono", monospace; letter-spacing: .17em; color: var(--jade); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font: 800 25px/.95 "Noto Serif SC", serif; letter-spacing: .05em; }
h1 span { font: 700 10px/1 Manrope, sans-serif; vertical-align: middle; letter-spacing: .18em; margin-left: 7px; color: var(--muted); }
.game-meta { gap: 11px; color: var(--muted); font: 500 10px "DM Mono", monospace; letter-spacing: .11em; }
.meta-dot { width: 6px; height: 6px; background: var(--jade); border-radius: 50%; box-shadow: 0 0 12px var(--jade); }
.meta-divider { height: 12px; width: 1px; background: var(--line); }
.quiet-button, .text-button { border: 0; background: transparent; color: var(--ink); cursor: pointer; font: 600 10px Manrope, sans-serif; letter-spacing: .12em; }
.quiet-button { border: 1px solid rgba(206, 230, 201, .28); padding: 10px 14px; transition: background .2s, border-color .2s; }
.quiet-button:hover { background: rgba(139, 209, 124, .11); border-color: var(--jade); }
.quiet-button span { color: var(--jade); font-size: 14px; margin-left: 5px; }

.game-layout { flex: 1; display: grid; grid-template-columns: minmax(150px, 1fr) minmax(520px, 810px) minmax(150px, 1fr); align-items: center; gap: clamp(20px, 3vw, 56px); padding: clamp(25px, 5.5vh, 76px) 0 clamp(24px, 4vh, 56px); }
.side-panel { align-self: center; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 16px 0 18px; min-height: 185px; }
.player-heading { gap: 7px; color: var(--muted); font: 500 9px "DM Mono", monospace; letter-spacing: .13em; }
.stone-indicator { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.stone-indicator.black { background: #040707; box-shadow: 0 1px 2px rgba(255,255,255,.3) inset, 0 0 0 1px rgba(255,255,255,.1); }
.stone-indicator.white { background: #f3f3e9; box-shadow: 0 0 0 1px rgba(0,0,0,.2); }
.turn-pill { margin-left: auto; color: var(--jade); font-size: 8px; letter-spacing: .08em; }
.white-panel .turn-pill { color: var(--subtle); }
.side-panel h2 { font: 600 27px/1.1 "Noto Serif SC", serif; margin: 19px 0 27px; }
.captured-stat { display: flex; align-items: flex-end; justify-content: space-between; color: var(--muted); font: 500 9px "DM Mono", monospace; letter-spacing: .12em; }
.captured-stat strong { color: var(--ink); font: 500 24px/.75 "DM Mono", monospace; letter-spacing: 0; }
.player-note { margin-top: 15px; color: var(--subtle); font-size: 10px; line-height: 1.6; }

.board-zone { min-width: 0; }
.board-title-row { justify-content: space-between; margin-bottom: 12px; }
.board-title-row p { margin: 0; color: var(--muted); font: 500 9px "DM Mono", monospace; letter-spacing: .15em; }
.text-button { color: var(--jade); font-size: 8px; opacity: .8; }
.text-button:hover { opacity: 1; }
.board-frame { position: relative; width: 100%; padding: clamp(18px, 3.1vw, 35px); aspect-ratio: 1; background: linear-gradient(145deg, #e3bd78, #bd8442); box-shadow: 0 18px 42px rgba(0,0,0,.35), 0 0 0 1px rgba(252, 220, 150, .19) inset; }
.board-frame::before { content: ""; position: absolute; inset: 6px; border: 1px solid rgba(69, 37, 15, .22); pointer-events: none; }
.board-light { position: absolute; inset: 0; opacity: .22; background-image: repeating-linear-gradient(91deg, rgba(255,255,255,.2) 0 1px, transparent 1px 5px), repeating-linear-gradient(0deg, rgba(73,42,15,.22) 0 1px, transparent 1px 6px); mix-blend-mode: overlay; pointer-events: none; }
.go-board { position: relative; width: 100%; height: 100%; display: grid; grid-template-columns: repeat(19, 1fr); grid-template-rows: repeat(19, 1fr); }
.intersection { padding: 0; border: 0; background: transparent; position: relative; cursor: pointer; outline-offset: 3px; z-index: 1; }
.intersection::before, .intersection::after { content: ""; position: absolute; background: rgba(48, 25, 10, .82); pointer-events: none; }
.intersection::before { height: 1px; top: 50%; left: 0; right: 0; }
.intersection::after { width: 1px; left: 50%; top: 0; bottom: 0; }
.intersection.top::after { top: 50%; }
.intersection.bottom::after { bottom: 50%; }
.intersection.left::before { left: 50%; }
.intersection.right::before { right: 50%; }
.intersection.star::marker { color: transparent; }
.intersection.star .star-point { position: absolute; width: 7px; height: 7px; background: #4b270f; border-radius: 50%; left: calc(50% - 3.5px); top: calc(50% - 3.5px); z-index: 0; }
.board-coordinate { position: absolute; color: rgba(67, 35, 12, .9); font: 600 8px "DM Mono", monospace; font-style: normal; pointer-events: none; z-index: 4; }
.board-coordinate.horizontal { top: calc(100% + 8px); left: 50%; transform: translateX(-50%); }
.board-coordinate.vertical { top: 50%; right: calc(100% + 9px); transform: translateY(-50%); }
.hide-coordinates .board-coordinate { display: none; }
.stone { position: absolute; width: 88%; aspect-ratio: 1; left: 6%; top: 6%; border-radius: 50%; z-index: 2; pointer-events: none; animation: land .22s cubic-bezier(.18,.8,.35,1.25) both; }
.stone.black { background: radial-gradient(circle at 34% 24%, #596b62 0%, #1b2821 17%, #09100d 52%, #010302 100%); box-shadow: 2px 3px 3px rgba(30,15,5,.42), -1px -1px 1px rgba(255,255,255,.12) inset; }
.stone.white { background: radial-gradient(circle at 33% 24%, #fffef9 0%, #e4e7de 43%, #aeb6a8 100%); box-shadow: 2px 3px 3px rgba(30,15,5,.4), -1px -1px 1px white inset; }
.stone.last::after { content: ""; position: absolute; width: 21%; height: 21%; left: 39.5%; top: 39.5%; border-radius: 50%; background: var(--jade); box-shadow: 0 0 0 1px rgba(0,0,0,.4), 0 0 8px rgba(139, 209, 124, .65); }
.intersection:not(.occupied):hover::before, .intersection:not(.occupied):hover::after { background: #2d1a0d; }
.intersection:not(.occupied):hover .preview { position: absolute; width: 72%; aspect-ratio: 1; left: 14%; top: 14%; border-radius: 50%; z-index: 1; opacity: .34; background: #101713; }
.intersection:not(.occupied).preview-white:hover .preview { background: #f4f4e9; opacity: .64; }
@keyframes land { from { transform: scale(.4); opacity: .2; } to { transform: scale(1); opacity: 1; } }

.board-caption { justify-content: space-between; margin-top: 13px; color: var(--subtle); font: 500 8px "DM Mono", monospace; letter-spacing: .1em; }
.board-caption #statusText { color: var(--jade); text-align: center; }
.control-strip { justify-content: space-between; gap: 20px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 16px 0; }
.last-move, .match-info { min-width: 145px; display: flex; flex-direction: column; gap: 7px; }
.last-move strong, .match-info strong { font: 500 10px "DM Mono", monospace; color: var(--muted); letter-spacing: .08em; }
.match-info { text-align: right; }
.actions { display: flex; gap: 8px; }
.control-button { cursor: pointer; border: 1px solid rgba(211,232,203,.2); color: var(--ink); background: transparent; padding: 10px 15px; font: 600 9px Manrope, sans-serif; letter-spacing: .1em; transition: .2s; }
.control-button:hover:not(:disabled) { border-color: var(--jade); background: rgba(139,209,124,.08); }
.control-button:disabled { opacity: .28; cursor: not-allowed; }
.primary-control { border-color: rgba(139,209,124,.55); color: var(--jade); }
.danger-control:hover:not(:disabled) { color: var(--red); border-color: var(--red); background: rgba(230,120,104,.08); }
.legend-row { justify-content: center; gap: 30px; margin-top: 20px; color: var(--subtle); font: 500 8px "DM Mono", monospace; letter-spacing: .1em; }
.legend-row span { display: flex; align-items: center; gap: 6px; }
.legend-line { display: block; height: 2px; width: 16px; background: var(--jade); }
.legend-cross { display: block; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }

.result-dialog { max-width: 430px; width: calc(100% - 40px); border: 1px solid rgba(139,209,124,.37); color: var(--ink); background: linear-gradient(150deg, #153124, #081b13); box-shadow: 0 28px 90px rgba(0,0,0,.7); text-align: center; padding: 39px 35px 35px; }
.result-dialog::backdrop { background: rgba(2,12,8,.75); backdrop-filter: blur(4px); }
.result-knot { width: 53px; height: 53px; margin: 0 auto 20px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--jade); color: var(--jade); font: 700 26px "Noto Serif SC", serif; }
.result-dialog h2 { margin: 11px 0 6px; font: 700 34px/1.1 "Noto Serif SC", serif; }
.result-dialog > p:not(.eyebrow) { color: var(--muted); font: 500 13px "DM Mono", monospace; }
.score-summary { display: grid; grid-template-columns: 1fr 1fr; margin: 23px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 15px 0; color: var(--muted); font: 500 9px "DM Mono", monospace; letter-spacing: .08em; }
.score-summary strong { display: block; color: var(--ink); font-size: 21px; margin-top: 5px; }
.play-again { width: 100%; border: 0; background: var(--jade); color: #0a2015; cursor: pointer; padding: 13px; font: 800 10px Manrope, sans-serif; letter-spacing: .14em; }
.play-again:hover { background: #a6ea97; }
.play-again.ghost { margin-top: 9px; background: transparent; color: var(--muted); border: 1px solid var(--line); }
.play-again.ghost:hover { background: rgba(139,209,124,.12); color: var(--ink); }

@media (max-width: 900px) {
  .app-shell { width: min(720px, calc(100% - 32px)); padding-top: 20px; }
  .game-layout { grid-template-columns: 1fr 1fr; gap: 13px; padding: 30px 0 25px; }
  .board-zone { grid-column: 1 / -1; grid-row: 1; }
  .side-panel { min-height: 130px; }
  .side-panel h2 { margin: 12px 0 16px; }
  .player-note { display: none; }
  .white-panel { grid-column: 2; grid-row: 2; }
  .black-panel { grid-column: 1; grid-row: 2; }
}
@media (max-width: 590px) {
  .seal-mark, .backdrop-script { display: none; }
  .backdrop-sun { top: 90px; right: -46px; opacity: .48; }
  .app-shell { width: min(100% - 22px, 490px); padding-top: 12px; }
  .topbar { padding-bottom: 14px; min-height: 55px; }
  .brand-mark { width: 31px; height: 31px; }
  h1 { font-size: 20px; }
  .game-meta, .quiet-button { display: none; }
  .board-frame { padding: 17px; }
  .board-caption { font-size: 6px; margin-top: 9px; }
  .control-strip { flex-wrap: wrap; padding: 13px 0; }
  .actions { order: -1; width: 100%; }
  .control-button { flex: 1; padding: 10px 8px; }
  .last-move, .match-info { min-width: auto; font-size: 8px; }
  .legend-row { margin-top: 14px; justify-content: space-between; gap: 5px; font-size: 6px; }
  .legend-row span:last-child { display: none; }
}
