:root {
  color-scheme: light;
  --ink: #17201b;
  --muted: #6f7a72;
  --paper: #f6f1e8;
  --surface: #fffdf8;
  --line: #d8c9b0;
  --line-soft: #e8ddca;
  --primary: #24584d;
  --primary-strong: #173f36;
  --gold: #b98536;
  --red: #b32721;
  --red-soft: #f1d7d3;
  --black: #202020;
  --board: #dda75c;
  --board-deep: #cf8b43;
  --board-line: #8b5424;
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(36, 88, 77, 0.07) 1px, transparent 1px),
    linear-gradient(180deg, rgba(36, 88, 77, 0.07) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
}

button,
input {
  font: inherit;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
  cursor: pointer;
  padding: 0 18px;
  font-size: 1rem;
  font-weight: 800;
  transition:
    transform 140ms ease,
    background 140ms ease,
    box-shadow 140ms ease,
    opacity 140ms ease;
}

button:hover:not(:disabled) {
  background: var(--primary-strong);
  box-shadow: 0 10px 20px rgba(23, 63, 54, 0.16);
  transform: translateY(-1px);
}

button:focus-visible,
input:focus-visible,
.point:focus-visible {
  outline: 3px solid rgba(36, 88, 77, 0.34);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  padding: 0 16px;
  text-transform: uppercase;
}

input::placeholder {
  color: rgba(111, 122, 114, 0.8);
}

.app-shell {
  width: min(1360px, calc(100vw - 36px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(620px, 1fr) 360px;
  gap: clamp(22px, 3vw, 42px);
  align-items: start;
  padding: 18px 0 22px;
}

.mode-switch {
  position: fixed;
  left: 14px;
  top: 112px;
  z-index: 15;
  display: grid;
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(36, 88, 77, 0.28);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 14px 28px rgba(23, 32, 27, 0.12);
  backdrop-filter: blur(12px);
}

.mode-button {
  width: 44px;
  min-height: 58px;
  padding: 8px 0;
  border-radius: 999px;
  color: var(--primary);
  background: transparent;
  font-size: 0.92rem;
  line-height: 1.05;
  writing-mode: vertical-rl;
}

.mode-button.active {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 10px 20px rgba(23, 63, 54, 0.18);
}

.mode-button:hover:not(:disabled) {
  color: #fff;
}

.app-shell.focus-mode {
  width: min(980px, calc(100vw - 36px));
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.focus-mode .side-panel {
  display: none;
}

.app-shell.focus-mode .board-wrap {
  width: min(840px, 100%, calc((100vh - 112px) * 8 / 9));
}

.app-shell.focus-mode .board-wrap.go-wrap {
  width: min(840px, 100%, calc(100vh - 112px));
}

.board-pane {
  min-width: 0;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 10px;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 3.1vw, 3rem);
  line-height: 1;
  letter-spacing: 0;
}

.top-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.panel-toggle {
  min-height: 40px;
  padding: 0 14px;
  white-space: nowrap;
}

.identity {
  display: grid;
  gap: 4px;
  text-align: right;
  white-space: nowrap;
}

.identity span,
.section-title span,
.players span,
.seat span,
.board-state span,
.move-list span,
.empty-moves {
  color: var(--muted);
  font-size: 0.9rem;
}

.identity strong,
.section-title strong,
.seat strong,
.board-state strong {
  font-size: 1.05rem;
  font-weight: 900;
}

.play-strip {
  min-height: 52px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, auto) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
  padding: 8px 12px;
  border: 1px solid rgba(139, 84, 36, 0.2);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.72);
}

.seat,
.board-state {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.black-seat {
  text-align: right;
}

.seat strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-state {
  text-align: center;
}

.board-state strong {
  font-size: 1.2rem;
}

.board-stage {
  display: flex;
  justify-content: center;
}

.board-wrap {
  width: min(780px, 100%, calc((100vh - 112px) * 8 / 9));
  min-width: 460px;
  padding: 22px;
  border: 1px solid rgba(139, 84, 36, 0.24);
  border-radius: 8px;
  background: linear-gradient(135deg, #efbd72, var(--board));
  box-shadow: 0 18px 44px rgba(23, 32, 27, 0.16);
}

.board-wrap.go-wrap {
  width: min(780px, 100%, calc(100vh - 112px));
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 8 / 9;
  border: 3px solid var(--board-line);
  background:
    radial-gradient(circle at 27% 22%, rgba(255, 255, 255, 0.22), transparent 20%),
    linear-gradient(135deg, #edb86c 0%, var(--board) 45%, var(--board-deep) 100%);
  overflow: visible;
}

.go-board {
  aspect-ratio: 1;
  background:
    radial-gradient(circle at 24% 22%, rgba(255, 255, 255, 0.18), transparent 20%),
    linear-gradient(135deg, #e9bd73 0%, #dca257 58%, #c9873f 100%);
}

.rank-line,
.file-line {
  position: absolute;
  display: block;
  background: var(--board-line);
  pointer-events: none;
}

.rank-line {
  left: 0;
  width: 100%;
  height: 2px;
  transform: translateY(-1px);
}

.file-line {
  width: 2px;
  transform: translateX(-1px);
}

.palace-line {
  position: absolute;
  pointer-events: none;
}

.palace-line::before {
  content: "";
  position: absolute;
  inset: 0;
  border-top: 2px solid var(--board-line);
  transform: skewY(42deg);
  transform-origin: left top;
}

.palace-line.flip::before {
  transform: skewY(-42deg);
  transform-origin: right top;
}

.river {
  position: absolute;
  left: 0;
  right: 0;
  top: 44.5%;
  height: 11%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(125, 75, 36, 0.7);
  font-family: "Kaiti SC", "STKaiti", "KaiTi", serif;
  font-size: clamp(1.55rem, 3.2vw, 2.35rem);
  letter-spacing: 0;
  pointer-events: none;
  z-index: 1;
}

.point {
  position: absolute;
  width: clamp(38px, 5.4vw, 72px);
  height: clamp(38px, 5.4vw, 72px);
  min-height: 0;
  border: 0;
  border-radius: 50%;
  color: inherit;
  background: transparent;
  padding: 0;
  transform: translate(-50%, -50%);
  z-index: 3;
}

.point:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.18);
  box-shadow: none;
  transform: translate(-50%, -50%) scale(1.03);
}

.point.selected {
  outline: 3px solid rgba(36, 88, 77, 0.74);
  outline-offset: 4px;
}

.point.playable .piece {
  box-shadow:
    0 0 0 4px rgba(36, 88, 77, 0.13),
    inset 0 -5px 10px rgba(91, 47, 16, 0.14),
    0 7px 12px rgba(78, 46, 22, 0.22);
}

.point.opponent-flash .piece {
  animation: opponent-piece-flash 520ms ease-in-out 2;
}

.point.last-move::after {
  content: "";
  position: absolute;
  inset: 15%;
  border-radius: 50%;
  background: rgba(36, 88, 77, 0.18);
  z-index: -1;
}

.piece {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border: 2.5px solid currentColor;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 25%, rgba(255, 255, 255, 0.86), transparent 28%),
    #fff6de;
  box-shadow:
    inset 0 -5px 10px rgba(91, 47, 16, 0.14),
    0 7px 12px rgba(78, 46, 22, 0.22);
  font-family: "Kaiti SC", "STKaiti", "KaiTi", serif;
  font-size: clamp(1.35rem, 3vw, 2.25rem);
  font-weight: 800;
  line-height: 1;
}

@keyframes opponent-piece-flash {
  0%,
  100% {
    filter: brightness(1);
    transform: scale(1);
    box-shadow:
      inset 0 -5px 10px rgba(91, 47, 16, 0.14),
      0 7px 12px rgba(78, 46, 22, 0.22);
  }

  45% {
    filter: brightness(1.18);
    transform: scale(1.08);
    box-shadow:
      0 0 0 6px rgba(185, 133, 54, 0.22),
      0 0 18px rgba(185, 133, 54, 0.42),
      inset 0 -5px 10px rgba(91, 47, 16, 0.14),
      0 10px 16px rgba(78, 46, 22, 0.25);
  }
}

.piece.red {
  color: var(--red);
}

.piece.black {
  color: var(--black);
}

.go-line {
  position: absolute;
  display: block;
  background: rgba(92, 57, 27, 0.82);
  pointer-events: none;
}

.go-rank-line {
  left: 0;
  width: 100%;
  height: 2px;
  transform: translateY(-1px);
}

.go-file-line {
  top: 0;
  width: 2px;
  height: 100%;
  transform: translateX(-1px);
}

.go-star {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(92, 57, 27, 0.86);
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 1;
}

.go-point {
  position: absolute;
  width: clamp(18px, 3.5vw, 34px);
  height: clamp(18px, 3.5vw, 34px);
  min-height: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  padding: 0;
  transform: translate(-50%, -50%);
  z-index: 3;
}

.go-point:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.22);
  box-shadow: none;
  transform: translate(-50%, -50%) scale(1.08);
}

.go-point.playable:hover:not(:disabled)::before {
  content: "";
  position: absolute;
  inset: 24%;
  border-radius: 50%;
  background: rgba(23, 32, 27, 0.16);
}

.go-point.last-move::after {
  content: "";
  position: absolute;
  inset: -3px;
  border: 2px solid rgba(36, 88, 77, 0.62);
  border-radius: 50%;
  pointer-events: none;
}

.go-point.opponent-flash .stone {
  animation: opponent-piece-flash 520ms ease-in-out 2;
}

.stone {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  box-shadow: 0 7px 12px rgba(23, 32, 27, 0.24);
}

.go-black {
  background:
    radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.18), transparent 24%),
    #151515;
}

.go-white {
  border: 1px solid rgba(23, 32, 27, 0.18);
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.9), transparent 28%),
    #f7f1e3;
}

.side-panel {
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 36px);
  display: grid;
  gap: 16px;
  overflow: auto;
  padding-right: 4px;
}

.panel-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  padding: 18px 20px;
  box-shadow: 0 18px 42px rgba(23, 32, 27, 0.08);
}

.room-panel {
  min-height: 176px;
}

.status-panel {
  min-height: 224px;
}

.online-section {
  min-height: 220px;
}

.chat-section {
  min-height: 300px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.room-actions {
  display: grid;
  gap: 12px;
}

.join-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 12px;
}

.ghost {
  color: var(--primary);
  border: 1px solid rgba(36, 88, 77, 0.26);
  background: transparent;
}

.ghost:hover:not(:disabled) {
  color: #fff;
}

.danger {
  width: 100%;
  margin-top: 18px;
  color: var(--red);
  background: var(--red-soft);
}

.danger:hover:not(:disabled) {
  color: #fff;
  background: var(--red);
  box-shadow: 0 10px 20px rgba(179, 39, 33, 0.14);
}

.status-text {
  min-height: 34px;
  font-size: 1.65rem;
  font-weight: 950;
  line-height: 1.15;
}

.players {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.players div {
  display: grid;
  grid-template-columns: 12px 52px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.players strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 900;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.red-dot {
  background: var(--red);
}

.black-dot {
  background: var(--black);
}

.go-mode .red-dot {
  background: #151515;
}

.go-mode .black-dot {
  border: 1px solid rgba(23, 32, 27, 0.24);
  background: #f7f1e3;
}

.invite-list {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.invite-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(185, 133, 54, 0.3);
  border-radius: 8px;
  background: rgba(185, 133, 54, 0.1);
}

.invite-card span {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 850;
}

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

.invite-actions button,
.online-user button,
.chat-form button {
  min-height: 38px;
  padding: 0 12px;
  font-size: 0.9rem;
}

.online-list,
.chat-list {
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.online-list {
  max-height: 230px;
}

.online-user {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  gap: 10px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--line-soft);
}

.online-user div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.online-user strong,
.online-user small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.online-user strong {
  font-size: 0.96rem;
  font-weight: 900;
}

.online-user small {
  color: var(--muted);
  font-size: 0.78rem;
}

.chat-list {
  max-height: 220px;
  padding-right: 4px;
}

.chat-list li {
  display: grid;
  gap: 6px;
  padding: 12px 0;
  border-top: 1px solid var(--line-soft);
}

.chat-list li.mine {
  color: var(--primary);
}

.chat-list div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.chat-list strong {
  overflow: hidden;
  font-size: 0.86rem;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-list small {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.76rem;
}

.chat-list p {
  margin: 0;
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px;
  gap: 10px;
  margin-top: 12px;
}

.chat-form input {
  min-height: 38px;
  padding: 0 12px;
  text-transform: none;
}

.moves-section {
  min-height: 284px;
}

.ranking-section {
  min-height: 220px;
}

.move-list,
.ranking-list {
  max-height: 264px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.move-list li,
.ranking-list li {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 0;
  border-top: 1px solid var(--line-soft);
}

.ranking-list li {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 64px 50px;
  align-items: center;
}

.ranking-list li.mine {
  color: var(--primary);
}

.rank-number {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--muted);
  background: rgba(36, 88, 77, 0.08);
  font-size: 0.78rem;
  font-weight: 900;
}

.rank-code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.move-list strong {
  color: var(--ink);
  font-size: 1rem;
  font-weight: 850;
  text-align: right;
}

.ranking-list strong {
  font-size: 1rem;
  text-align: right;
}

.ranking-list small {
  color: var(--muted);
  font-size: 0.78rem;
  text-align: right;
}

.move-list .empty-moves,
.ranking-list .empty-rankings,
.online-list .empty-online,
.chat-list .empty-chat {
  grid-template-columns: 1fr;
  display: grid;
  min-height: 180px;
  place-items: center;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 8px;
  color: #fff;
  background: rgba(23, 32, 27, 0.92);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1180px) {
  .mode-switch {
    position: static;
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin: 0 0 10px;
    padding: 4px;
    border-radius: 12px;
    box-shadow: none;
    backdrop-filter: none;
  }

  .mode-button {
    width: 100%;
    min-height: 38px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: 0.92rem;
    line-height: 1;
    writing-mode: horizontal-tb;
  }

  .app-shell {
    width: min(100vw - 32px, 840px);
    min-height: auto;
    grid-template-columns: 1fr;
    gap: 28px;
    align-items: start;
    padding: 28px 0 36px;
  }

  .app-shell.focus-mode {
    width: min(100vw - 32px, 840px);
  }

  .board-wrap {
    width: min(760px, 100%);
    min-width: 0;
  }

  .board-wrap.go-wrap {
    width: min(760px, 100%);
  }

  .side-panel {
    position: static;
    max-height: none;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    overflow: visible;
    padding-right: 0;
  }

  .chat-section,
  .moves-section {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw - 18px, 560px);
    gap: 16px;
    padding: 14px 0 24px;
  }

  .top-bar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
    gap: 10px;
  }

  h1 {
    font-size: clamp(1.95rem, 9vw, 2.55rem);
  }

  .identity {
    min-width: 0;
    gap: 2px;
    text-align: left;
    white-space: normal;
  }

  .identity strong {
    max-width: 100%;
    overflow: hidden;
    font-size: 0.98rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .panel-toggle {
    min-height: 38px;
    padding: 0 12px;
    font-size: 0.94rem;
  }

  .play-strip {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
  }

  .seat,
  .black-seat,
  .board-state {
    grid-template-columns: 44px minmax(0, 1fr);
    align-items: center;
    text-align: left;
  }

  .board-state span {
    text-align: right;
  }

  .board-wrap {
    padding: 18px;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .panel-section {
    padding: 18px;
  }

  .join-row {
    grid-template-columns: 1fr 94px;
  }

  .point {
    width: clamp(32px, 11vw, 52px);
    height: clamp(32px, 11vw, 52px);
  }

  .go-point {
    width: clamp(16px, 5.2vw, 28px);
    height: clamp(16px, 5.2vw, 28px);
  }

  .piece {
    font-size: clamp(1.05rem, 6.2vw, 1.65rem);
    border-width: 2px;
  }

  .river {
    font-size: clamp(1.1rem, 6vw, 1.7rem);
  }
}

@media (max-width: 420px) {
  .board-wrap {
    padding: 14px;
  }

  button,
  input {
    min-height: 44px;
  }

  .section-title {
    margin-bottom: 14px;
  }
}
