:root {
  color-scheme: light;
  --ink: #241a14;
  --muted: #7f6a58;
  --paper: #fffdf8;
  --paper-soft: #f8f1e7;
  --wood-light: #e7b873;
  --wood-mid: #c9853f;
  --wood-dark: #6c3e1b;
  --sage: #496a5a;
  --sage-deep: #294b3e;
  --line: rgba(103, 69, 40, 0.18);
  --shadow: 0 24px 70px rgba(70, 42, 18, 0.16);
  --board-size: min(78vmin, 720px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  color: var(--ink);
  overflow-x: hidden;
  background:
    radial-gradient(circle at 12% 10%, rgba(255, 252, 241, 0.92), transparent 28rem),
    radial-gradient(circle at 90% 100%, rgba(176, 119, 60, 0.2), transparent 34rem),
    linear-gradient(135deg, #f6efe4 0%, #ead5b7 48%, #c4935b 100%);
}

button {
  font: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(47, 111, 98, 0.42);
  outline-offset: 3px;
}

.app-shell {
  width: min(1280px, calc(100vw - 56px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  gap: clamp(28px, 5vw, 72px);
  align-items: center;
  padding: 42px 0 54px;
}

.game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.board-heading {
  width: min(var(--board-size), 100%);
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 14px;
}

.board-heading h2 {
  margin: 0;
  font-size: clamp(1.15rem, 2vw, 1.45rem);
  letter-spacing: -0.03em;
}

.board-badge {
  padding: 7px 11px;
  border: 1px solid rgba(73, 106, 90, 0.2);
  border-radius: 999px;
  color: var(--sage-deep);
  background: rgba(255, 253, 248, 0.58);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.board-wrap {
  width: var(--board-size);
  max-width: 100%;
  aspect-ratio: 1;
  padding: clamp(13px, 2.2vmin, 21px);
  border-radius: 24px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.18), transparent 18%, rgba(111, 63, 24, 0.16) 56%, transparent),
    repeating-linear-gradient(102deg, var(--wood-light) 0 18px, #d99f56 18px 35px, var(--wood-mid) 35px 52px);
  border: 2px solid rgba(86, 48, 17, 0.66);
  box-shadow:
    0 30px 80px rgba(62, 34, 13, 0.26),
    inset 0 0 0 2px rgba(255, 239, 198, 0.34),
    inset 0 0 30px rgba(81, 42, 14, 0.16);
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(91, 53, 23, 0.78);
  border-radius: 12px;
  background:
    linear-gradient(rgba(91, 53, 23, 0.16), rgba(91, 53, 23, 0.04)),
    rgba(219, 160, 82, 0.48);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  appearance: none;
  border: 0;
  border-right: 1px solid rgba(83, 47, 20, 0.76);
  border-bottom: 1px solid rgba(83, 47, 20, 0.76);
  background: transparent;
  cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}

.cell:not(:disabled):hover {
  z-index: 1;
  background: rgba(255, 249, 224, 0.2);
}

.cell:nth-child(15n) {
  border-right: 0;
}

.cell:nth-last-child(-n + 15) {
  border-bottom: 0;
}

.cell:focus-visible {
  z-index: 4;
  outline: 2px solid #2f6f62;
  outline-offset: -2px;
}

.cell.star-point::before {
  content: "";
  width: 19%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: #5b3517;
  box-shadow: 0 1px 2px rgba(255, 233, 185, 0.28);
}

.stone {
  width: 76%;
  aspect-ratio: 1;
  border-radius: 999px;
  z-index: 2;
  transform: translateZ(0) scale(0.98);
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.stone.black {
  background: radial-gradient(circle at 32% 26%, #5b5651 0%, #171411 56%, #050403 100%);
  box-shadow:
    inset -4px -5px 10px rgba(0, 0, 0, 0.55),
    inset 3px 3px 7px rgba(255, 255, 255, 0.12),
    0 3px 8px rgba(43, 22, 7, 0.5);
}

.stone.white {
  background: radial-gradient(circle at 32% 26%, #ffffff 0%, #fff5dc 48%, #d6c4a1 100%);
  border: 1px solid rgba(73, 52, 34, 0.55);
  box-shadow:
    inset -4px -5px 10px rgba(120, 94, 56, 0.18),
    inset 3px 3px 7px rgba(255, 255, 255, 0.76),
    0 3px 8px rgba(43, 22, 7, 0.34);
}

.stone.winner {
  outline: 3px solid #2f6f62;
  outline-offset: 2px;
  animation: winner-pulse 1.4s ease-in-out infinite;
}

@keyframes winner-pulse {
  0%,
  100% { box-shadow: 0 0 0 0 rgba(47, 111, 98, 0.12), 0 3px 8px rgba(43, 22, 7, 0.42); }
  50% { box-shadow: 0 0 0 7px rgba(47, 111, 98, 0.08), 0 3px 8px rgba(43, 22, 7, 0.42); }
}

.panel {
  width: 100%;
  align-self: center;
  padding: 28px;
  border-radius: 24px;
  background: rgba(255, 253, 248, 0.86);
  border: 1px solid rgba(95, 59, 28, 0.14);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.panel-header {
  margin-bottom: 26px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--sage);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.25rem, 4vw, 3.2rem);
  line-height: 1.1;
  letter-spacing: -0.06em;
}

.panel-subtitle {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 3.15em;
  margin: 18px 0 0;
  padding: 13px 15px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  color: #f9f4e8;
  background: linear-gradient(135deg, #27483b, #527461);
  line-height: 1.35;
}

.status::before {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9fe3b9;
  box-shadow: 0 0 0 4px rgba(159, 227, 185, 0.14);
}

.control-group {
  margin-top: 22px;
}

.control-group.muted {
  opacity: 0.62;
}

.control-label {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(95, 59, 28, 0.1);
  border-radius: 12px;
  background: rgba(94, 59, 30, 0.07);
}

.mode-segments {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segment,
.primary-action,
.secondary-action {
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease, filter 160ms ease;
}

.segment {
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.segment.active {
  color: #fff8eb;
  background: var(--sage-deep);
  box-shadow: 0 7px 18px rgba(40, 59, 49, 0.2);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 28px;
}

.room-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.room-input {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 0 13px;
  border: 1px solid rgba(95, 59, 28, 0.18);
  border-radius: 12px;
  color: var(--ink);
  background: #fff8eb;
  font: inherit;
  font-weight: 700;
  text-transform: uppercase;
}

.room-input:focus {
  outline: 2px solid #2f6f62;
  outline-offset: 1px;
}

.online-choice {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid rgba(95, 59, 28, 0.1);
  border-radius: 14px;
  background: rgba(248, 241, 231, 0.64);
}

.online-info {
  min-height: 1.4em;
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--sage);
  font-size: 0.86rem;
  line-height: 1.35;
  background: rgba(73, 106, 90, 0.07);
}

.latency-indicator {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 1.4em;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.latency-indicator::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 14%, transparent);
}

.latency-indicator[data-latency="good"] {
  color: #2f6f62;
}

.latency-indicator[data-latency="fair"] {
  color: #9a6a2b;
}

.latency-indicator[data-latency="poor"] {
  color: #a04e3d;
}

.latency-indicator[data-latency="unknown"] {
  color: var(--muted);
}

.status[data-connection="reconnecting"] {
  background: linear-gradient(135deg, #6f4f2b, #9a743d);
}

.status[data-connection="reconnecting"]::before {
  background: #ffe0a2;
  box-shadow: 0 0 0 4px rgba(255, 224, 162, 0.14);
}

.status[data-connection="disconnected"] {
  background: linear-gradient(135deg, #713a2f, #a05b43);
}

.status[data-connection="disconnected"]::before {
  background: #ffc1ad;
  box-shadow: 0 0 0 4px rgba(255, 193, 173, 0.14);
}

.board.connection-paused {
  opacity: 0.82;
}

.primary-action {
  color: #fff8eb;
  background: linear-gradient(135deg, #77451f, #9d612d);
  border-color: rgba(67, 34, 11, 0.38);
  font-weight: 800;
  box-shadow: 0 10px 18px rgba(111, 63, 24, 0.18);
}

.secondary-action {
  color: var(--ink);
  background: rgba(255, 253, 248, 0.86);
  border-color: rgba(95, 59, 28, 0.18);
  font-weight: 800;
}

.primary-action:hover,
.secondary-action:hover,
.segment:hover {
  filter: brightness(1.03);
  transform: translateY(-1px);
}

.primary-action:active,
.secondary-action:active,
.segment:active {
  transform: translateY(0);
}

.room-controls #leaveOnline {
  grid-column: 1 / -1;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

@media (max-width: 880px) {
  :root {
    --board-size: min(calc(100vw - 42px), 680px);
  }

  .app-shell {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 22px;
    padding-top: 24px;
  }

  .game-area {
    order: -1;
  }

  .panel {
    order: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    padding: 20px;
  }

  .panel-header,
  .control-group,
  .actions {
    margin: 0;
  }

  .panel-header {
    grid-column: 1 / -1;
  }

  .actions {
    align-self: end;
  }

  #onlineGroup {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  :root {
    --board-size: min(calc(100vw - 42px), 620px);
  }

  .app-shell {
    width: calc(100vw - 18px);
    padding: 9px 0 14px;
  }

  .panel {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 1.8rem;
  }

  .board-wrap {
    padding: 12px;
  }

  .stone.winner {
    outline-width: 2px;
    outline-offset: 1px;
  }

  .room-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: calc(100vw - 24px);
    padding: 18px 0 28px;
  }

  .panel {
    padding: 18px;
    border-radius: 20px;
  }

  .panel-header {
    margin-bottom: 20px;
  }

  h1 {
    font-size: 2.35rem;
  }

  .board-heading {
    margin-bottom: 10px;
  }

  .board-wrap {
    padding: 9px;
    border-radius: 18px;
  }

  .board {
    border-radius: 9px;
  }

  .stone.winner {
    outline-width: 2px;
    outline-offset: 1px;
  }
}
