:root {
  --ink: #23212a;
  --muted: #6b6678;
  --panel: #fff9ed;
  --line: #3f2d22;
  --board: #e9b65f;
  --board-edge: #b57330;
  --mint: #7ac9a7;
  --coral: #ff7f6e;
  --sky: #80bde8;
  --sun: #ffd166;
  --shadow: 0 20px 50px rgba(55, 39, 23, 0.18);
}

/* 2.0 Xiao Qishi visual system */
:root {
  --ink: #2f2925;
  --muted: #756962;
  --panel: #fffaf0;
  --line: #5a3521;
  --board: #e8b25d;
  --board-edge: #ad5b32;
  --mint: #55bca1;
  --coral: #f05a50;
  --sky: #58aee3;
  --sun: #ffbe3d;
  --cream: #fff4dd;
  --shadow: 0 14px 34px rgba(90, 53, 33, 0.15);
}

body {
  background: #fff7e8;
}

.app-shell {
  width: min(1320px, calc(100vw - 28px));
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
}

.play-area,
.side-panel,
.review-workspace {
  border: 3px solid #f0dfc4;
  background: #fffdf8;
  box-shadow: var(--shadow);
}

.play-area {
  padding: 20px;
  border-radius: 8px;
}

.side-panel {
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  border-radius: 8px;
  background: #fffaf0;
}

.topbar {
  align-items: center;
}

.brand-lockup,
.top-actions,
.panel-title-row,
.command-row,
.ai-actions,
.review-header,
.review-header-actions,
.review-controls {
  display: flex;
  align-items: center;
}

.brand-lockup {
  min-width: 0;
  gap: 12px;
}

.brand-lockup h1 {
  color: #36271f;
  font-size: clamp(1.55rem, 3vw, 2.5rem);
}

.brand-subtitle {
  margin: 5px 0 0;
  color: #a44f39;
  font-size: 0.86rem;
  font-weight: 900;
}

.eyebrow {
  color: #c24e3e;
}

.top-actions {
  gap: 8px;
}

.turn-pill {
  min-width: 154px;
  padding: 9px 12px;
  background: #ffca55;
  border-color: #cf8234;
}

.mascot-sprite {
  display: block;
  flex: 0 0 auto;
  background-image: url("./assets/mascot/xiaoqishi-sheet.png");
  background-repeat: no-repeat;
}

.mascot-head {
  width: 62px;
  height: 62px;
  border: 3px solid #ffc54b;
  border-radius: 50%;
  background-size: 234px 234px;
  background-position: -21px -23px;
  background-color: #fff3d6;
  box-shadow: 0 6px 12px rgba(164, 79, 57, 0.15);
}

.mascot-full {
  width: 126px;
  height: 160px;
  background-size: 292px 292px;
  background-position: -2px -21px;
}

.mascot-thinking {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background-size: 294px 294px;
  background-position: -173px -118px;
  background-color: #fff4dc;
}

.mascot-panel {
  min-height: 164px;
  display: flex;
  align-items: flex-end;
  gap: 5px;
  padding: 10px 14px 0;
  overflow: hidden;
  background: #ffedc4;
  border-bottom: 3px solid #f2d59e;
}

.mascot-copy {
  min-width: 0;
  align-self: center;
  display: grid;
  gap: 5px;
  padding-bottom: 12px;
}

.mascot-copy strong {
  color: #a43f35;
  font-size: 1rem;
}

.mascot-copy > span:last-child {
  color: #76655a;
  font-size: 0.8rem;
  font-weight: 750;
  line-height: 1.45;
}

.mascot-name {
  width: fit-content;
  padding: 4px 8px;
  border-radius: 8px;
  color: #fff;
  background: #ef5a4d;
  font-size: 0.76rem;
  font-weight: 950;
}

.panel-section {
  padding: 14px;
  border-bottom: 2px solid #f0dfc4;
}

.panel-section h2 {
  color: #46362d;
}

.setup-panel {
  display: grid;
  gap: 12px;
}

.setup-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.setup-row > div {
  min-width: 0;
  display: grid;
  gap: 7px;
}

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

.segmented button {
  min-width: 0;
  color: #5b4c45;
  background: #fffdf8;
  border-color: #e7d5ba;
}

.segmented button.active {
  color: #fff;
  background: #ee6255;
  border-color: #c9453d;
}

.segmented-boards {
  grid-template-columns: repeat(5, 1fr);
}

.command-row {
  gap: 8px;
}

.command-row .primary-button {
  flex: 1 1 auto;
}

.primary-button,
.ai-button,
.icon-text-button,
.square-button {
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 950;
}

.primary-button,
.ai-button {
  color: #fff;
  background: #e95249;
  border: 2px solid #c9433c;
}

.primary-button:hover,
.ai-button:hover {
  background: #d94740;
}

.ai-button,
.icon-text-button {
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 8px;
}

.icon-text-button {
  color: #704231;
  background: #fff2d3;
  border: 2px solid #e7c485;
}

.square-button {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  color: #6d4738;
  background: #fff5df;
  border: 2px solid #e5c99b;
  font-size: 1.05rem;
}

.board-stage {
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
}

.board-wrap {
  width: 100%;
}

.board {
  border: 8px solid #ae6238;
  background: #e8b25d;
  box-shadow: inset 0 0 0 3px #f8d48d, 0 14px 26px rgba(86, 50, 29, 0.2);
}

.grid-line {
  background: #563421;
}

.grid-line.horizontal.edge,
.grid-line.vertical.edge {
  background: #4c2b1c;
}

.hoshi::before {
  background: #70412a;
}

.stone {
  border-width: 2px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.12), inset 0 3px 0 rgba(255, 255, 255, 0.2), 0 3px 7px rgba(63, 42, 29, 0.28);
}

.stone.black {
  color: #fff7e7;
  background: #363136;
  border-color: #171417;
}

.stone.white {
  color: #473d36;
  background: #fff8e9;
  border-color: #cdbda4;
}

.stone::before {
  content: "";
  position: absolute;
  left: 18%;
  top: 12%;
  width: 25%;
  height: 12%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  transform: rotate(-22deg);
}

.stone.danger {
  outline: 3px solid rgba(239, 83, 73, 0.6);
  outline-offset: 1px;
}

.coach-note {
  position: absolute;
  left: 12px;
  bottom: 10px;
  max-width: 230px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px 7px;
  border: 2px solid #efc879;
  border-radius: 8px;
  color: #704230;
  background: rgba(255, 250, 236, 0.94);
  box-shadow: 0 8px 18px rgba(85, 53, 30, 0.12);
  font-size: 0.82rem;
  font-weight: 850;
  line-height: 1.4;
  z-index: 5;
}

.coach-note .coach-avatar {
  width: 44px;
  height: 44px;
  background-size: 226px 226px;
  background-position: -132px -90px;
}

.message {
  border-color: #ecd5ac;
  background: #fff7e7;
}

.ai-panel {
  display: grid;
  gap: 10px;
  background: #fff1dd;
}

.panel-title-row {
  justify-content: space-between;
  gap: 10px;
}

.ai-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #8a786e;
  font-size: 0.74rem;
  font-weight: 900;
}

.ai-status i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e4a43a;
}

.ai-status.ready i {
  background: #39a77f;
}

.ai-status.offline i {
  background: #df5a52;
}

.ai-level-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 9px;
}

.ai-level-row label {
  color: #775d50;
  font-size: 0.8rem;
  font-weight: 850;
}

.ai-level-row select {
  width: 100%;
  min-height: 36px;
  border: 2px solid #e6cda4;
  border-radius: 8px;
  padding: 5px 8px;
  color: #3e342e;
  background: #fffdf7;
  font: inherit;
  font-weight: 850;
}

.ai-actions {
  gap: 8px;
}

.ai-actions > * {
  flex: 1 1 0;
}

.ai-insight {
  min-height: 62px;
  display: grid;
  gap: 3px;
  padding: 10px;
  border-left: 5px solid #58aee3;
  border-radius: 4px;
  background: #fffdf8;
}

.ai-insight strong {
  color: #3a6785;
  font-size: 0.86rem;
}

.ai-insight span {
  color: #6f6761;
  font-size: 0.78rem;
  line-height: 1.42;
}

.ai-marker-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.ai-marker {
  position: absolute;
  left: calc(var(--grid-start) + var(--x) * var(--cell));
  top: calc(var(--grid-start) + var(--y) * var(--cell));
  width: clamp(18px, calc(var(--cell) * 0.7), 32px);
  height: clamp(18px, calc(var(--cell) * 0.7), 32px);
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  border: 3px solid #fff;
  border-radius: 50%;
  color: #fff;
  background: #e95349;
  box-shadow: 0 3px 8px rgba(76, 42, 27, 0.3);
  font-size: 0.72rem;
  font-weight: 950;
}

.ai-marker:nth-child(2) { background: #4f9fd1; }
.ai-marker:nth-child(3) { background: #49aa87; }

.player-card.active {
  border-color: #f05a50;
  background: #fff0d5;
}

.current-player,
.player-card,
.position-panel,
.analysis-summary,
.analysis-card {
  border-color: #ead8bb;
  background: #fffdf8;
}

.review-workspace {
  width: min(1320px, calc(100vw - 28px));
  margin: 0 auto 18px;
  border-radius: 8px;
  overflow: hidden;
}

.review-header {
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 3px solid #f0dfc4;
  background: #fff1d7;
}

.review-header h2 {
  color: #4b3328;
  font-size: 1.25rem;
}

.review-header-actions {
  gap: 8px;
}

.review-layout {
  padding: 16px;
}

.review-controls {
  gap: 8px;
  margin-bottom: 14px;
}

.review-controls input[type="range"] {
  min-width: 0;
  flex: 1 1 auto;
  accent-color: #e95349;
}

.review-main {
  display: grid;
  grid-template-columns: minmax(220px, 0.34fr) minmax(0, 1fr);
  gap: 14px;
}

.review-move-list {
  max-height: 360px;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 6px;
}

.review-move-button {
  width: 100%;
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 9px;
  border: 2px solid #ead9bf;
  border-radius: 8px;
  color: #4d4038;
  background: #fffdf8;
  text-align: left;
  cursor: pointer;
}

.review-move-button.active {
  border-color: #e95349;
  background: #fff0d9;
}

.review-move-number {
  color: #a3523d;
  font-weight: 950;
}

.review-detail {
  min-height: 260px;
  padding: 16px;
  border: 2px solid #ead9bf;
  border-radius: 8px;
  background: #fffdf8;
}

.review-empty {
  min-height: 220px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: #79695f;
  text-align: center;
}

.review-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.review-stat {
  padding: 10px;
  border-radius: 8px;
  background: #fff1d9;
}

.review-stat span {
  display: block;
  color: #847168;
  font-size: 0.72rem;
  font-weight: 850;
}

.review-stat strong {
  display: block;
  margin-top: 3px;
  color: #3e312b;
  font-size: 1.15rem;
}

.review-commentary {
  margin: 0;
  color: #5f534c;
  line-height: 1.75;
  font-weight: 750;
}

.review-progress {
  margin-top: 10px;
  color: #9c5947;
  font-size: 0.82rem;
  font-weight: 900;
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    max-height: none;
    order: 0;
  }

  .mascot-panel {
    min-height: 132px;
  }

  .mascot-full {
    width: 110px;
    height: 132px;
    background-size: 254px 254px;
    background-position: -1px -18px;
  }
}

@media (max-width: 620px) {
  .app-shell,
  .review-workspace {
    width: min(100vw - 12px, 560px);
  }

  .play-area,
  .side-panel {
    padding: 0;
  }

  .play-area {
    padding: 12px;
  }

  .topbar {
    gap: 10px;
  }

  .brand-lockup {
    width: 100%;
  }

  .mascot-head {
    width: 50px;
    height: 50px;
    background-size: 190px 190px;
    background-position: -17px -18px;
  }

  .brand-lockup h1 {
    font-size: 1.45rem;
  }

  .top-actions {
    width: 100%;
  }

  .turn-pill {
    min-width: 0;
    flex: 1 1 auto;
  }

  .coach-note {
    left: 6px;
    bottom: 6px;
    max-width: 185px;
    padding: 6px 8px 6px 5px;
    font-size: 0.72rem;
  }

  .coach-note .coach-avatar {
    width: 36px;
    height: 36px;
    background-size: 184px 184px;
    background-position: -107px -73px;
  }

  .setup-row {
    grid-template-columns: 1fr;
  }

  .review-main {
    grid-template-columns: 1fr;
  }

  .review-move-list {
    max-height: 190px;
  }

  .review-stats {
    grid-template-columns: 1fr 1fr;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Nunito", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(circle at 8% 10%, rgba(255, 209, 102, 0.45), transparent 24%),
    radial-gradient(circle at 92% 15%, rgba(128, 189, 232, 0.35), transparent 25%),
    linear-gradient(135deg, #f7f0de 0%, #e8f5ef 48%, #f9e6e1 100%);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
}

.play-area,
.side-panel {
  border: 3px solid rgba(63, 45, 34, 0.14);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
}

.play-area {
  min-width: 0;
  padding: 24px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  border-radius: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.65rem, 3vw, 2.8rem);
  line-height: 1.05;
}

h2 {
  font-size: 1rem;
}

.turn-pill {
  flex: 0 0 auto;
  min-width: 166px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 8px;
  color: #20180f;
  font-weight: 900;
  background: var(--sun);
  border: 2px solid rgba(63, 45, 34, 0.24);
}

.mini-stone {
  width: 26px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  font-size: 0.7rem;
  line-height: 1;
}

.mini-stone.black {
  color: #fff;
  background: #25222b;
}

.mini-stone.white {
  color: #222;
  background: #fffef8;
  border: 1px solid #bdb4a6;
}

.board-wrap {
  min-height: 0;
  display: grid;
  place-items: center;
}

.board {
  --board-size: clamp(260px, min(calc(100vw - 430px), calc(100vh - 220px)), 760px);
  --grid-start: 20px;
  --board-steps: 8;
  --cell: calc((var(--board-size) - 48px) / var(--board-steps));
  --point-size: min(46px, calc(var(--cell) * 1.35));
  --stone-size: min(42px, calc(var(--cell) * 1.08));
  --face-size: min(18px, calc(var(--stone-size) * 0.46));
  --hair-size: min(12px, calc(var(--stone-size) * 0.28));
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  border-radius: 8px;
  border: 6px solid var(--board-edge);
  background: var(--board);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.22), 0 16px 34px rgba(73, 46, 20, 0.22);
}

.board[data-size="3"] {
  --point-size: min(56px, calc(var(--cell) * 1.45));
  --stone-size: min(52px, calc(var(--cell) * 1.2));
  --face-size: min(22px, calc(var(--stone-size) * 0.48));
  --hair-size: min(15px, calc(var(--stone-size) * 0.3));
}

.board[data-size="5"] {
  --point-size: min(52px, calc(var(--cell) * 1.42));
  --stone-size: min(48px, calc(var(--cell) * 1.16));
  --face-size: min(20px, calc(var(--stone-size) * 0.47));
  --hair-size: min(14px, calc(var(--stone-size) * 0.29));
}

.board[data-size="9"] {
  --point-size: min(46px, calc(var(--cell) * 1.34));
  --stone-size: min(42px, calc(var(--cell) * 1.08));
  --face-size: min(18px, calc(var(--stone-size) * 0.46));
  --hair-size: min(12px, calc(var(--stone-size) * 0.28));
}

.board[data-size="13"] {
  --point-size: min(36px, calc(var(--cell) * 1.24));
  --stone-size: min(31px, calc(var(--cell) * 0.96));
  --face-size: min(14px, calc(var(--stone-size) * 0.42));
  --hair-size: min(10px, calc(var(--stone-size) * 0.24));
}

.board[data-size="19"] {
  --point-size: min(32px, calc(var(--cell) * 1.04));
  --stone-size: min(26px, calc(var(--cell) * 0.86));
  --face-size: min(10px, calc(var(--stone-size) * 0.38));
  --hair-size: min(6px, calc(var(--stone-size) * 0.16));
}

.grid-line {
  position: absolute;
  display: block;
  background: var(--line);
  pointer-events: none;
  z-index: 0;
}

.grid-line.horizontal {
  left: var(--grid-start);
  top: calc(var(--grid-start) + var(--i) * var(--cell));
  width: calc(var(--cell) * var(--board-steps));
  height: 1px;
  transform: translateY(-0.5px);
}

.grid-line.vertical {
  left: calc(var(--grid-start) + var(--i) * var(--cell));
  top: var(--grid-start);
  width: 1px;
  height: calc(var(--cell) * var(--board-steps));
  transform: translateX(-0.5px);
}

.grid-line.edge {
  z-index: 1;
}

.grid-line.horizontal.edge {
  height: 4px;
  transform: translateY(-2px);
}

.grid-line.vertical.edge {
  width: 4px;
  transform: translateX(-2px);
}

.point {
  position: absolute;
  left: calc(var(--grid-start) + var(--x) * var(--cell));
  top: calc(var(--grid-start) + var(--y) * var(--cell));
  width: var(--point-size);
  height: var(--point-size);
  border: 0;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  z-index: 2;
}

.point::after {
  content: "";
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: rgba(63, 45, 34, 0.16);
  transform: scale(0);
  transition: transform 140ms ease;
}

.point:hover::after,
.point:focus-visible::after {
  transform: scale(1);
}

.territory-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.territory-dot {
  position: absolute;
  left: calc(var(--grid-start) + var(--x) * var(--cell));
  top: calc(var(--grid-start) + var(--y) * var(--cell));
  width: 13px;
  height: 13px;
  border-radius: 50%;
  display: block;
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 4px rgba(35, 29, 20, 0.22);
}

.territory-dot.black {
  background: #17151c;
  border: 1px solid rgba(255, 255, 255, 0.28);
}

.territory-dot.white {
  background: #fffdf4;
  border: 1px solid rgba(63, 45, 34, 0.55);
}

.hoshi::before {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(63, 45, 34, 0.82);
}

.stone {
  position: relative;
  width: var(--stone-size);
  height: var(--stone-size);
  inline-size: var(--stone-size);
  block-size: var(--stone-size);
  min-width: var(--stone-size);
  min-height: var(--stone-size);
  max-width: var(--stone-size);
  max-height: var(--stone-size);
  flex: 0 0 auto;
  aspect-ratio: 1 / 1;
  box-sizing: border-box;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: var(--face-size);
  line-height: 1;
  overflow: hidden;
  box-shadow: inset -6px -7px 12px rgba(0, 0, 0, 0.18), inset 5px 5px 12px rgba(255, 255, 255, 0.24), 0 6px 10px rgba(37, 25, 12, 0.25);
}

.stone.black {
  color: #fff8e8;
  background: radial-gradient(circle at 33% 28%, #696273, #26232c 58%, #141219);
  border: 2px solid #111018;
}

.stone.white {
  color: #33303a;
  background: radial-gradient(circle at 33% 28%, #ffffff, #fff8e5 58%, #d7cab4);
  border: 2px solid #b9ad9c;
}

.stone .hair {
  position: absolute;
  top: calc(var(--stone-size) * 0.03);
  font-size: var(--hair-size);
  line-height: 1;
}

.stone .face {
  max-width: 82%;
  overflow: hidden;
  white-space: nowrap;
  text-align: center;
  transform: translateY(calc(var(--stone-size) * 0.04));
  font-size: var(--face-size);
  line-height: 1;
}

.stone .face.face-single {
  font-size: calc(var(--face-size) * 1);
}

.stone .face.face-mid {
  font-size: calc(var(--face-size) * 0.88);
}

.stone .face.face-wide {
  font-size: calc(var(--face-size) * 0.72);
}

.stone .eye,
.stone .brow,
.stone .mouth,
.stone .cheek,
.stone .mood-mark,
.stone .hand,
.stone .caption-mark {
  position: absolute;
  display: block;
}

.stone .eye {
  top: 12px;
  width: 9px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
  border: 2px solid currentColor;
  transform: rotate(10deg);
}

.stone .eye.left {
  left: 10px;
}

.stone .eye.right {
  right: 10px;
  transform: rotate(-10deg);
}

.stone .brow {
  top: 8px;
  width: 9px;
  height: 2px;
  border-radius: 99px;
  background: currentColor;
  opacity: 0;
}

.stone .brow.left {
  left: 10px;
  transform: rotate(-12deg);
}

.stone .brow.right {
  right: 10px;
  transform: rotate(12deg);
}

.stone .mouth {
  left: 50%;
  top: 27px;
  width: 8px;
  height: 6px;
  border: 2px solid currentColor;
  border-top: 0;
  border-right: 0;
  border-radius: 0 0 0 8px;
  transform: translateX(-50%);
}

.stone .cheek {
  top: 22px;
  width: 6px;
  height: 5px;
  border-radius: 50%;
  background: #ff9da5;
  opacity: 0;
}

.stone .cheek.left {
  left: 7px;
}

.stone .cheek.right {
  right: 7px;
}

.stone .mood-mark {
  right: 0;
  top: 17px;
  width: 6px;
  height: 12px;
  border-radius: 70% 70% 70% 0;
  background: #6ec6ff;
  opacity: 0;
  transform: rotate(20deg);
}

.stone .hand {
  right: -3px;
  top: 24px;
  width: 8px;
  height: 8px;
  border: 2px solid currentColor;
  border-left: 0;
  border-radius: 0 8px 8px 0;
  opacity: 0;
}

.stone .caption-mark {
  left: 50%;
  top: -14px;
  min-width: 20px;
  color: currentColor;
  font-size: 8px;
  font-weight: 950;
  line-height: 1;
  text-align: center;
  opacity: 0;
  transform: translateX(-50%) rotate(-5deg);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}

.stone.danger {
  animation: wobble 0.58s ease-in-out infinite;
}

.stone.low {
  filter: saturate(0.88);
}

.stone.low .mood-mark,
.stone.danger .mood-mark {
  opacity: 1;
}

.stone.danger .mood-mark {
  width: 7px;
  height: 15px;
  background: #4eb5ff;
}

.stone.low .mouth {
  top: 27px;
  width: 8px;
  height: 6px;
  border-top: 3px solid currentColor;
  border-bottom: 0;
  border-left: 0;
  border-radius: 18px 18px 0 0;
}

.stone.danger .mouth {
  top: 26px;
  width: 11px;
  height: 11px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.stone.danger .eye {
  border-color: currentColor;
  background: #fffaf0;
}

.stone.danger .cheek {
  opacity: 0.25;
}

.face-happy .eye,
.face-laugh .eye {
  top: 13px;
  height: 5px;
  border-top: 2px solid currentColor;
  border-bottom: 0;
  border-left: 0;
  border-right: 0;
  border-radius: 99px;
}

.face-happy .mouth {
  top: 22px;
  width: 18px;
  height: 13px;
  background: #ff9fa8;
  border: 2px solid currentColor;
  border-radius: 3px 3px 16px 16px;
  animation: happy-mouth 1.8s ease-in-out infinite;
}

.face-smile .eye {
  top: 13px;
  width: 6px;
  height: 8px;
  background: currentColor;
  border: 0;
}

.face-smile .mouth {
  top: 25px;
  width: 13px;
  height: 7px;
  border: 2px solid currentColor;
  border-top: 0;
  border-left: 0;
  border-right: 0;
  border-radius: 0 0 12px 12px;
}

.face-laugh .mouth {
  top: 21px;
  width: 24px;
  height: 15px;
  background: #ff9fa8;
  border: 2px solid currentColor;
  border-radius: 4px 4px 18px 18px;
  animation: happy-mouth 1.5s ease-in-out infinite;
}

.face-cool .eye {
  top: 14px;
  width: 12px;
  height: 7px;
  border: 0;
  border-radius: 3px;
  background: #111116;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.face-cool::after {
  content: "";
  position: absolute;
  right: -3px;
  top: -5px;
  width: 13px;
  height: 13px;
  background: #ffd95a;
  clip-path: polygon(50% 0, 62% 34%, 100% 50%, 62% 66%, 50% 100%, 38% 66%, 0 50%, 38% 34%);
  animation: sparkle-pop 1.6s ease-in-out infinite;
}

.face-cool .eye.left {
  left: 8px;
}

.face-cool .eye.right {
  right: 8px;
}

.face-cool .brow {
  top: 13px;
  left: 13px;
  width: 17px;
  height: 2px;
  opacity: 1;
}

.face-cool .mouth,
.face-proud .mouth {
  top: 27px;
  width: 13px;
  height: 6px;
  border: 2px solid currentColor;
  border-top: 0;
  border-left: 0;
  border-right: 0;
  border-radius: 0 0 12px 12px;
}

.face-angry .brow,
.face-bad .brow {
  opacity: 1;
}

.face-angry .brow.left,
.face-bad .brow.left {
  transform: rotate(24deg);
}

.face-angry .brow.right,
.face-bad .brow.right {
  transform: rotate(-24deg);
}

.face-angry .eye,
.face-bad .eye {
  top: 14px;
  width: 7px;
  height: 7px;
  background: currentColor;
  border: 0;
}

.face-angry .mouth {
  top: 28px;
  width: 15px;
  height: 8px;
  border-top: 2px solid currentColor;
  border-bottom: 0;
  border-left: 0;
  border-right: 0;
  border-radius: 12px 12px 0 0;
}

.face-angry .caption-mark {
  left: -3px;
  top: -5px;
  min-width: auto;
  color: #ff4c4c;
  opacity: 1;
  transform: rotate(-20deg);
}

.face-angry .caption-mark::before {
  content: "〽";
  font-size: 18px;
}

.face-nervous .brow,
.face-sad .brow {
  opacity: 0.9;
}

.face-nervous .brow.left,
.face-sad .brow.left {
  transform: rotate(-16deg);
}

.face-nervous .brow.right,
.face-sad .brow.right {
  transform: rotate(16deg);
}

.face-nervous .eye,
.face-sad .eye,
.face-surprise .eye {
  top: 13px;
  width: 7px;
  height: 8px;
  background: currentColor;
  border: 0;
}

.face-nervous .mouth {
  top: 28px;
  width: 15px;
  height: 5px;
  border: 0;
  background: transparent;
}

.face-nervous .mouth::before {
  content: "〰";
  position: absolute;
  left: 0;
  top: -5px;
  font-size: 16px;
  font-weight: 950;
}

.face-nervous .mood-mark {
  opacity: 1;
  animation: sweat-slide 0.85s ease-in-out infinite;
}

.face-sad .eye {
  background: #fffaf0;
  border: 2px solid currentColor;
}

.face-sad .mouth {
  top: 29px;
  width: 13px;
  height: 7px;
  border-top: 2px solid currentColor;
  border-bottom: 0;
  border-left: 0;
  border-right: 0;
  border-radius: 12px 12px 0 0;
}

.face-sad .mood-mark {
  left: 12px;
  top: 21px;
  width: 5px;
  height: 16px;
  border-radius: 9px;
  background: #66c8ff;
  opacity: 1;
  box-shadow: 14px 0 0 #66c8ff;
  transform: none;
  animation: sweat-slide 1.1s ease-in-out infinite;
}

.face-surprise .mouth {
  top: 25px;
  width: 11px;
  height: 11px;
  border: 3px solid currentColor;
  border-radius: 50%;
  animation: surprise-pop 1.1s ease-in-out infinite;
}

.face-surprise .caption-mark {
  left: auto;
  right: -8px;
  top: -9px;
  min-width: auto;
  color: #ff4c4c;
  opacity: 1;
  transform: rotate(9deg);
  animation: alert-bounce 0.9s ease-in-out infinite;
}

.face-surprise .caption-mark::before {
  content: "!";
  font-size: 24px;
}

.face-proud .eye {
  top: 14px;
  width: 11px;
  height: 7px;
  border: 2px solid currentColor;
  border-top: 0;
  border-left: 0;
  border-right: 0;
  border-radius: 0 0 50% 50%;
}

.face-proud .eye.left {
  transform: rotate(5deg);
}

.face-proud .eye.right {
  transform: rotate(-5deg);
}

.face-bad .mouth {
  top: 24px;
  width: 18px;
  height: 9px;
  background: #fffaf0;
  border: 2px solid currentColor;
  border-radius: 4px;
  animation: teeth-rattle 0.8s steps(2, end) infinite;
}

.face-bad .mouth::before {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  top: 4px;
  height: 1px;
  background: currentColor;
  box-shadow: 4px 0 0 currentColor, 8px 0 0 currentColor;
}

.face-sleepy .eye {
  top: 15px;
  height: 3px;
  border-top: 2px solid currentColor;
  border-bottom: 0;
  border-left: 0;
  border-right: 0;
  border-radius: 99px;
  transform: rotate(-10deg);
}

.face-sleepy .eye.right {
  transform: rotate(10deg);
}

.face-sleepy .mouth {
  top: 27px;
  width: 10px;
  height: 10px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.face-sleepy .mood-mark {
  right: -6px;
  top: -4px;
  width: auto;
  height: auto;
  color: #6ebcff;
  background: transparent;
  opacity: 1;
  transform: rotate(10deg);
}

.face-sleepy .mood-mark::before {
  content: "Z";
  font-size: 12px;
  font-weight: 950;
  animation: z-float 1.7s ease-in-out infinite;
}

.face-dizzy .eye {
  top: 12px;
  width: 10px;
  height: 10px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  background: transparent;
}

.face-dizzy .eye.left {
  transform: rotate(30deg);
  animation: dizzy-spin-left 1.3s linear infinite;
}

.face-dizzy .eye.right {
  transform: rotate(-30deg);
  animation: dizzy-spin-right 1.3s linear infinite;
}

.face-dizzy .mouth {
  top: 28px;
  width: 15px;
  height: 5px;
  border: 0;
  background: transparent;
}

.face-dizzy .mouth::before {
  content: "〰";
  position: absolute;
  left: 0;
  top: -5px;
  font-size: 16px;
  font-weight: 950;
}

.face-happy .cheek,
.face-smile .cheek,
.face-laugh .cheek,
.face-cool .cheek,
.face-angry .cheek,
.face-nervous .cheek,
.face-sad .cheek,
.face-surprise .cheek,
.face-proud .cheek,
.face-bad .cheek {
  opacity: 0.88;
}

.stone.low .brow.left,
.stone.danger .brow.left {
  opacity: 0.9;
  transform: rotate(18deg);
}

.stone.low .brow.right,
.stone.danger .brow.right {
  opacity: 0.9;
  transform: rotate(-18deg);
}

@keyframes wobble {
  0%,
  100% {
    transform: rotate(-3deg);
  }
  50% {
    transform: rotate(3deg);
  }
}

@keyframes happy-mouth {
  0%,
  100% {
    transform: translateX(-50%) scaleY(1);
  }
  50% {
    transform: translateX(-50%) scaleY(1.13);
  }
}

@keyframes sparkle-pop {
  0%,
  100% {
    transform: scale(0.8) rotate(0deg);
    opacity: 0.75;
  }
  50% {
    transform: scale(1.15) rotate(18deg);
    opacity: 1;
  }
}

@keyframes surprise-pop {
  0%,
  100% {
    transform: translateX(-50%) scale(1);
  }
  50% {
    transform: translateX(-50%) scale(1.18);
  }
}

@keyframes alert-bounce {
  0%,
  100% {
    transform: translateY(0) rotate(9deg);
  }
  50% {
    transform: translateY(-4px) rotate(9deg);
  }
}

@keyframes z-float {
  0% {
    transform: translateY(2px) scale(0.9);
    opacity: 0.4;
  }
  55% {
    transform: translateY(-5px) scale(1.1);
    opacity: 1;
  }
  100% {
    transform: translateY(-8px) scale(0.95);
    opacity: 0;
  }
}

@keyframes dizzy-spin-left {
  to {
    transform: rotate(390deg);
  }
}

@keyframes dizzy-spin-right {
  to {
    transform: rotate(-390deg);
  }
}

@keyframes teeth-rattle {
  0%,
  100% {
    transform: translateX(-50%);
  }
  50% {
    transform: translateX(calc(-50% + 1px));
  }
}

@keyframes sweat-slide {
  0%,
  100% {
    transform: translateY(-2px) rotate(20deg);
  }
  50% {
    transform: translateY(3px) rotate(20deg);
  }
}

@keyframes sprite-worry {
  0%,
  100% {
    transform: scale(0.92) translateY(0);
  }
  50% {
    transform: scale(0.92) translateY(1.5px);
  }
}

@keyframes sprite-shake {
  0%,
  100% {
    transform: scale(0.92) translateX(-1px) rotate(-2deg);
  }
  50% {
    transform: scale(0.92) translateX(1px) rotate(2deg);
  }
}

@keyframes capture-fly {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.65) rotate(0deg);
  }
  55% {
    opacity: 1;
    transform: translate(-50%, -92%) scale(1.25) rotate(18deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -145%) scale(0.25) rotate(75deg);
  }
}

.stone.low .mood-mark,
.stone.danger .mood-mark {
  animation: sweat-slide 0.85s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .stone,
  .stone *,
  .stone::after {
    animation: none !important;
  }
}

.message-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.message {
  flex: 1 1 auto;
  min-height: 46px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #fffdf7;
  border: 2px solid rgba(63, 45, 34, 0.12);
  color: #4f4551;
  font-weight: 800;
}

.ghost-button,
.primary-button,
.segmented button {
  min-height: 42px;
  border-radius: 8px;
  border: 2px solid rgba(63, 45, 34, 0.18);
  cursor: pointer;
  font-weight: 900;
}

.ghost-button {
  padding: 0 18px;
  color: #352b2b;
  background: #fffaf0;
}

.panel-section .ghost-button {
  width: 100%;
}

.ghost-button:disabled,
.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.finish-button {
  background: #ffe2dc;
}

.primary-button {
  width: 100%;
  color: #172119;
  background: var(--mint);
}

.side-panel {
  padding: 18px;
  border-radius: 8px;
  background: rgba(255, 249, 237, 0.86);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-section {
  display: grid;
  gap: 10px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.segmented-boards {
  grid-template-columns: repeat(5, 1fr);
}

.segmented button {
  background: #fffdf8;
  color: #4b4042;
}

.segmented button.active {
  background: var(--sky);
  color: #102231;
}

.current-player,
.player-card {
  border-radius: 8px;
  border: 2px solid rgba(63, 45, 34, 0.12);
  background: rgba(255, 255, 255, 0.68);
}

.current-player {
  min-height: 86px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.current-player > .stone,
.player-card > .stone {
  --stone-size: 42px;
  --face-size: 16px;
  --hair-size: 10px;
  width: 42px;
  height: 42px;
  inline-size: 42px;
  block-size: 42px;
  min-width: 42px;
  min-height: 42px;
  max-width: 42px;
  max-height: 42px;
  aspect-ratio: 1 / 1;
  justify-self: center;
  align-self: center;
  overflow: visible;
}

.current-player > .stone .face,
.player-card > .stone .face {
  max-width: 78%;
}

.current-player > .stone .hair,
.player-card > .stone .hair {
  top: -4px;
}

.player-list {
  display: grid;
  gap: 8px;
  max-height: 330px;
  overflow: auto;
  padding-right: 4px;
}

.player-card {
  min-height: 64px;
  padding: 10px;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 28px;
  align-items: center;
  column-gap: 10px;
}

.player-card.active {
  border-color: rgba(255, 127, 110, 0.9);
  background: #fff5e2;
}

.player-name {
  display: block;
  font-weight: 950;
}

.player-name-field {
  min-width: 0;
  display: grid;
  width: 100%;
  gap: 4px;
  align-self: center;
  justify-self: stretch;
}

.player-name-field input {
  display: block;
  width: 100%;
  min-height: 34px;
  border: 2px solid rgba(63, 45, 34, 0.14);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--ink);
  background: #fffefa;
  font: inherit;
  font-weight: 900;
}

.player-name-field input:focus {
  outline: 3px solid rgba(128, 189, 232, 0.42);
  border-color: rgba(39, 105, 150, 0.55);
}

.player-meta {
  display: block;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 800;
}

.capture-count {
  min-width: 28px;
  text-align: center;
  font-weight: 950;
  color: #322a31;
  justify-self: end;
  align-self: center;
}

.score-grid {
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.score-grid > div {
  padding: 12px;
  border-radius: 8px;
  background: #fffdf7;
  border: 2px solid rgba(63, 45, 34, 0.12);
}

.score-label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.score-grid strong {
  font-size: 1.8rem;
}

.position-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 8px;
  border: 2px solid rgba(63, 45, 34, 0.12);
  background: #fffdf7;
}

.position-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 950;
}

.position-head span {
  color: var(--muted);
  font-size: 0.82rem;
}

.position-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.position-grid > div {
  padding: 9px;
  border-radius: 8px;
  background: #f7f1e4;
}

.position-grid strong {
  font-size: 1.45rem;
}

.position-panel p {
  margin: 0;
  color: #5e5260;
  font-size: 0.84rem;
  font-weight: 800;
  line-height: 1.45;
}

.analysis-section {
  border-top: 2px dashed rgba(63, 45, 34, 0.18);
  padding-top: 12px;
}

.analysis-summary,
.analysis-card {
  border-radius: 8px;
  border: 2px solid rgba(63, 45, 34, 0.12);
  background: #fffdf7;
}

.analysis-summary {
  display: grid;
  gap: 4px;
  padding: 12px;
  color: #51464f;
  font-size: 0.9rem;
  font-weight: 800;
}

.analysis-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding-right: 2px;
}

.analysis-card {
  padding: 10px;
}

.analysis-card-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.analysis-card p {
  margin: 8px 0;
  color: #534856;
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.45;
}

.analysis-rank {
  display: inline-block;
  margin: 0 0 8px;
  padding: 5px 8px;
  border-radius: 8px;
  color: #1d2420;
  background: #dff4e7;
  font-size: 0.8rem;
  font-weight: 950;
}

.analysis-card dl {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.analysis-card dl div {
  padding: 7px;
  border-radius: 8px;
  background: #f7f1e4;
}

.analysis-card dt {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
}

.analysis-card dd {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 950;
}

.analysis-tag {
  display: inline-block;
  margin-top: 8px;
  padding: 5px 8px;
  border-radius: 8px;
  color: #261f19;
  background: var(--sun);
  font-size: 0.8rem;
  font-weight: 950;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    order: -1;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100vw - 16px, 560px);
    margin: 8px auto;
  }

  .play-area,
  .side-panel {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .turn-pill {
    width: 100%;
  }

  .board {
    --board-size: calc(100vw - 40px);
    --cell: calc((var(--board-size) - 48px) / var(--board-steps));
    width: var(--board-size);
    height: var(--board-size);
    --point-size: min(38px, calc(var(--cell) * 1.3));
    --stone-size: min(35px, calc(var(--cell) * 1.04));
    --face-size: min(15px, calc(var(--stone-size) * 0.44));
    --hair-size: min(10px, calc(var(--stone-size) * 0.24));
  }

  .board[data-size="3"] {
    --point-size: min(48px, calc(var(--cell) * 1.42));
    --stone-size: min(44px, calc(var(--cell) * 1.16));
    --face-size: min(18px, calc(var(--stone-size) * 0.46));
    --hair-size: min(12px, calc(var(--stone-size) * 0.28));
  }

  .board[data-size="5"] {
    --point-size: min(44px, calc(var(--cell) * 1.36));
    --stone-size: min(40px, calc(var(--cell) * 1.1));
    --face-size: min(16px, calc(var(--stone-size) * 0.45));
    --hair-size: min(11px, calc(var(--stone-size) * 0.26));
  }

  .board[data-size="9"] {
    --point-size: min(34px, calc(var(--cell) * 1.24));
    --stone-size: min(30px, calc(var(--cell) * 0.98));
    --face-size: min(13px, calc(var(--stone-size) * 0.43));
    --hair-size: min(9px, calc(var(--stone-size) * 0.22));
  }

  .board[data-size="13"] {
    --point-size: min(28px, calc(var(--cell) * 1.12));
    --stone-size: min(23px, calc(var(--cell) * 0.84));
    --face-size: min(10px, calc(var(--stone-size) * 0.4));
    --hair-size: min(7px, calc(var(--stone-size) * 0.18));
  }

  .board[data-size="19"] {
    --point-size: min(24px, calc(var(--cell) * 0.98));
    --stone-size: min(20px, calc(var(--cell) * 0.8));
    --face-size: min(8px, calc(var(--stone-size) * 0.36));
    --hair-size: min(5px, calc(var(--stone-size) * 0.15));
  }

  .message-row {
    align-items: stretch;
    flex-direction: column;
  }

  .player-card {
    grid-template-columns: 46px minmax(0, 1fr) 24px;
    column-gap: 8px;
  }

  .player-name-field {
    gap: 3px;
  }

  .player-meta {
    font-size: 0.8rem;
  }

  .player-name-field input {
    min-height: 32px;
    padding: 5px 8px;
  }

  .capture-count {
    min-width: 24px;
  }
}
