:root {
  --bg: #edf1ee;
  --surface: #f7f9f8;
  --surface-muted: #e5ece8;
  --line: #d2dcd6;
  --ink: #16221e;
  --muted: #4b5e57;
  --accent: #1f5b4c;
  --accent-hover: #17473b;
  --accent-soft: #deebe6;
  --warn: #8c4b14;
  --error: #a62c2b;

  /* 严格 3 级正文与界面字号（标题 wordmark 独立） */
  --text-lg: 1.125rem;
  --text-base: 0.9375rem;
  --text-sm: 0.8125rem;

  --radius-sm: 6px;
  --radius-md: 10px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font-sans: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font-family: inherit;
  font-size: var(--text-base);
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* 顶部单行导航栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background-color: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 32%, #4a5256 0%, #161b1e 48%, #090b0c 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14), 0 1px 3px rgba(22, 34, 30, 0.25);
}

.brand-title {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--ink);
}

.mode-switch {
  display: inline-flex;
  align-items: center;
  background-color: var(--surface-muted);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}

.mode-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: var(--text-base);
  font-weight: 500;
  padding: 6px 16px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}

.mode-tab:hover {
  color: var(--ink);
}

.mode-tab.is-active {
  background-color: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(22, 34, 30, 0.08);
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.tool-toggle {
  border: 1px solid var(--line);
  background-color: transparent;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 160ms var(--ease), color 160ms var(--ease), border-color 160ms var(--ease);
}

.tool-toggle:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.tool-toggle.is-active {
  background-color: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* 主工作区：左棋盘 + 右控制栏 */
.workspace {
  flex: 1;
  width: 100%;
  max-width: 1140px;
  margin: 0 auto;
  padding: 20px 24px 28px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 28px;
  align-items: start;
}

.board-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.board-frame {
  width: min(100%, 640px, calc(100dvh - 112px));
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  box-shadow:
    0 18px 38px -18px rgba(22, 34, 30, 0.28),
    0 2px 6px rgba(22, 34, 30, 0.12),
    0 0 0 1px rgba(84, 58, 24, 0.24);
  background-color: #dcbb80;
  display: flex;
  align-items: center;
  justify-content: center;
}

#boardCanvas {
  display: block;
  touch-action: manipulation;
  user-select: none;
}

/* 右侧控制栏：单层克制容器 + 细分割线 */
.control-panel {
  background-color: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
}

.panel-section {
  padding: 16px 20px;
}

.panel-section + .panel-section {
  border-top: 1px solid var(--line);
}

.turn-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.stone-indicator {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: transform 180ms var(--ease);
}

.stone-indicator.is-black {
  background: radial-gradient(circle at 34% 32%, #52595d 0%, #1f2326 42%, #0a0c0e 100%);
  box-shadow: 0 3px 8px rgba(10, 12, 14, 0.26);
}

.stone-indicator.is-white {
  background: radial-gradient(circle at 32% 30%, #ffffff 0%, #eff2f0 64%, #c7ceca 100%);
  box-shadow: inset 0 0 0 1px rgba(72, 84, 78, 0.26), 0 3px 8px rgba(22, 34, 30, 0.14);
}

.stone-indicator.is-draw {
  background: linear-gradient(135deg, #1b2023 0%, #1b2023 50%, #eef1ef 50%, #eef1ef 100%);
  box-shadow: inset 0 0 0 1px rgba(22, 34, 30, 0.22);
}

.turn-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
}

.turn-sub {
  margin: 3px 0 0;
  font-size: var(--text-sm);
  color: var(--muted);
}

.meta-row {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: var(--text-sm);
  color: var(--muted);
}

.meta-item strong {
  color: var(--ink);
  font-weight: 600;
}

/* 区块标题与表单 */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  margin: 0;
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--ink);
}

.conn-state,
.chat-hint {
  font-size: var(--text-sm);
  color: var(--muted);
  font-weight: 500;
}

.conn-state.is-connected {
  color: var(--accent);
}

.conn-state.is-error {
  color: var(--error);
}

.field-group + .field-group {
  margin-top: 12px;
}

.field-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

.text-input {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background-color: #ffffff;
  color: var(--ink);
  font-size: var(--text-sm);
  transition: border-color 160ms var(--ease);
}

.text-input:focus {
  outline: none;
  border-color: var(--accent);
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.create-row,
.join-row {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.create-row .segmented {
  flex: 1;
}

.join-row .text-input {
  flex: 1;
}

/* 活跃房间大厅 */
.lobby-rooms-block {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.lobby-rooms-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.lobby-rooms-head .field-label {
  margin-bottom: 0;
}

.lobby-rooms-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 150px;
  overflow-y: auto;
}

.empty-rooms-text {
  margin: 2px 0 0;
  font-size: var(--text-sm);
  color: var(--muted);
}

.lobby-room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background-color: var(--surface-muted);
  border-radius: var(--radius-sm);
}

.lobby-room-info {
  min-width: 0;
  flex: 1;
}

.lobby-room-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.lobby-room-code {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.lobby-room-meta {
  font-size: var(--text-sm);
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-room-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* 自定义公网服务器折叠区 */
.server-config {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.server-summary {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.server-summary:hover {
  color: var(--ink);
}

.server-config-body {
  margin-top: 8px;
}

/* 分段选择器 */
.segmented {
  display: flex;
  background-color: var(--surface-muted);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}

.seg-btn:hover {
  color: var(--ink);
}

.seg-btn.is-active {
  background-color: #ffffff;
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(22, 34, 30, 0.08);
}

/* 房间信息 */
.room-code-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.room-code-value {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  line-height: 1.2;
}

.room-code-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.text-action {
  border: 0;
  background: transparent;
  padding: 2px 0;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  white-space: nowrap;
  transition: color 140ms var(--ease);
}

.text-action:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.text-action.is-danger {
  color: var(--error);
}

.seats-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.seat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-base);
}

.stone-mini {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stone-mini.is-black {
  background: #14181a;
}

.stone-mini.is-white {
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(22, 34, 30, 0.35);
}

.seat-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
  font-weight: 500;
}

.seat-status {
  font-size: var(--text-sm);
  color: var(--muted);
  flex-shrink: 0;
}

.seat-status.is-online {
  color: var(--accent);
}

.seat-status.is-offline {
  color: var(--warn);
}

.spectator-bar {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  font-size: var(--text-sm);
  color: var(--muted);
}

.spectator-summary {
  flex: 1;
  min-width: 0;
  line-height: 1.45;
  word-break: break-word;
}

.request-banner {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background-color: var(--accent-soft);
}

.request-text {
  margin: 0 0 10px;
  font-size: var(--text-sm);
  color: var(--ink);
  font-weight: 500;
}

.request-actions {
  display: flex;
  gap: 8px;
}

/* 房间聊天室 */
.chat-head {
  margin-bottom: 8px;
}

.chat-messages {
  height: 176px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  background-color: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.chat-empty {
  margin: auto 0;
  text-align: center;
  font-size: var(--text-sm);
  color: var(--muted);
}

.chat-item {
  font-size: var(--text-sm);
  line-height: 1.45;
  word-break: break-word;
}

.chat-item.is-system {
  color: var(--muted);
}

.chat-meta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-right: 6px;
  vertical-align: baseline;
}

.chat-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.chat-dot.is-black {
  background-color: #14181a;
}

.chat-dot.is-white {
  background-color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(22, 34, 30, 0.45);
}

.chat-role-tag {
  color: var(--accent);
  font-weight: 600;
}

.chat-sender {
  font-weight: 600;
  color: var(--ink);
}

.chat-time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chat-body {
  color: var(--ink);
}

.chat-form {
  margin-top: 8px;
  display: flex;
  gap: 6px;
}

.chat-input {
  flex: 1;
}

.hint-text,
.rules-text {
  margin: 10px 0 0;
  font-size: var(--text-sm);
  color: var(--muted);
  line-height: 1.55;
}

.rules-section .section-title {
  margin-bottom: 6px;
}

.rules-section .rules-text {
  margin-top: 0;
}

.feedback-line {
  margin: 0;
  padding: 0 20px;
  min-height: 0;
  font-size: var(--text-sm);
  color: var(--accent);
  font-weight: 500;
}

.feedback-line:not(:empty) {
  padding-top: 10px;
  padding-bottom: 10px;
  border-top: 1px solid var(--line);
}

.feedback-line.is-warn {
  color: var(--warn);
}

.feedback-line.is-error {
  color: var(--error);
}

/* 按钮 */
.actions-section {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.btn {
  height: 40px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease), transform 120ms var(--ease);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.46;
  cursor: not-allowed;
}

.btn-compact {
  height: 36px;
  padding: 0 12px;
  font-size: var(--text-sm);
}

.btn-primary {
  border: 1px solid var(--accent);
  background-color: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  border: 1px solid var(--line);
  background-color: #ffffff;
  color: var(--ink);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

/* 响应式：平板与手机竖屏 */
@media (max-width: 960px) {
  .topbar {
    flex-wrap: wrap;
    padding: 10px 16px;
    gap: 10px;
  }

  .mode-switch {
    order: 3;
    width: 100%;
    justify-content: stretch;
  }

  .mode-tab {
    flex: 1;
    padding: 7px 10px;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    padding: 14px 14px 24px;
    gap: 16px;
  }

  .board-frame {
    width: min(100%, 560px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
