/* ==========================================================================
   日本将棋（Shogi）
   ========================================================================== */

/* 统一布局：模式按钮（共用 .mode-tabs）居中，内容列等宽 */
.sg-app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.sg {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(94vw, 470px);
  position: relative;
}

.sg-slot:empty { display: none; }

/* ------------------------------ 状态栏 ---------------------------------- */

.sg-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  background: var(--surface);
}

.sg-turn { display: inline-flex; align-items: center; gap: 10px; font-size: 14.5px; font-weight: 600; }

.sg-turn-text { min-width: 0; line-height: 1.4; }

.sg-turn-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.14);
  transition: background .25s, box-shadow .25s;
}
.sg-turn-dot.is-red {
  background: radial-gradient(circle at 32% 28%, #fb9a7f, #d43a17 60%, #8d1e05);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.sg-turn-dot.is-blue {
  background: radial-gradient(circle at 32% 28%, #9ec5fb, #2f7fd6 60%, #14508f);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.sg-turn-dot.is-finished { background: rgba(255, 255, 255, 0.08); box-shadow: none; }

.sg-count { display: inline-flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }

.sg-count-item {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 12px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.035);
  color: var(--text-dim);
}
.sg-count-item small { font-size: 11px; font-weight: 600; color: var(--text-mute); }

.sg-count-ico {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  align-self: center;
  flex: 0 0 auto;
}
.sg-count-ico.is-red { background: radial-gradient(circle at 32% 28%, #fb9a7f, #d43a17 60%, #8d1e05); }
.sg-count-ico.is-blue { background: radial-gradient(circle at 32% 28%, #9ec5fb, #2f7fd6 60%, #14508f); }
.sg-count-sep { color: var(--text-mute); font-weight: 700; }

/* ------------------------------ 结果横幅 -------------------------------- */

.sg-banner {
  padding: 16px 18px;
  text-align: center;
  border-radius: var(--radius);
  border: 1px solid rgba(139, 92, 246, 0.4);
  background: linear-gradient(120deg, rgba(139, 92, 246, 0.18), rgba(34, 211, 238, 0.1));
  animation: sg-banner-in .28s cubic-bezier(.2, .8, .3, 1);
}
.sg-banner[hidden] { display: none; }
.sg-banner.is-red { border-color: rgba(244, 114, 82, 0.5); }
.sg-banner.is-blue { border-color: rgba(96, 165, 250, 0.5); }
.sg-banner.is-draw { border-color: rgba(251, 191, 36, 0.4); }

@keyframes sg-banner-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

.sg-banner-title { font-size: 18px; font-weight: 700; }
.sg-banner-detail { margin-top: 6px; font-size: 13px; color: var(--text-dim); }
.sg-banner-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 14px; }
.sg-banner-actions:empty { display: none; }

/* ------------------------------ 棋盘区 ---------------------------------- */

.sg-board-wrap { display: grid; place-items: center; }

.sg-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(100%, 470px);
}

/* 持驹栏 */
.sg-hand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 10px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.38);
  background:
    radial-gradient(120% 130% at 18% 0%, rgba(255, 255, 255, 0.08), transparent 55%),
    linear-gradient(155deg, #30342c, #252922 60%, #1c201a);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.sg-hand-label { flex: 0 0 auto; font-size: 11px; color: var(--text-mute); }

.sg-hand-pieces { display: flex; flex-wrap: wrap; gap: 6px; min-height: 28px; }

.sg-hand-none { font-size: 12px; color: var(--text-mute); opacity: 0.65; align-self: center; }

.sg-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.45);
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow .15s, border-color .15s, transform .15s;
}
.sg-chip b {
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
  color: #2b1c10;
}
.sg-chip i {
  position: absolute;
  right: -5px;
  bottom: -6px;
  font-style: normal;
  font-size: 10px;
  font-weight: 700;
  padding: 0 3px;
  border-radius: 999px;
  color: #fff;
  background: rgba(139, 92, 246, 0.9);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
}
.sg-chip.is-red { background: linear-gradient(160deg, #e8b98f, #d8a26c); }
.sg-chip.is-blue { background: linear-gradient(160deg, #9db4c9, #7e97ad); }
.sg-chip.is-playable { cursor: pointer; }
.sg-chip.is-playable:hover { border-color: rgba(139, 92, 246, 0.75); }
.sg-chip.is-sel {
  border-color: rgba(250, 204, 21, 0.9);
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.45), 0 2px 4px rgba(0, 0, 0, 0.45);
}
.sg-chip:disabled { cursor: default; }

/* 棋盘 */
.sg-board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 0;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid #4a3620;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.1),
    0 26px 54px -26px rgba(0, 0, 0, 0.95);
  background:
    radial-gradient(130% 120% at 16% 0%, rgba(255, 255, 255, 0.12), transparent 52%),
    linear-gradient(155deg, #d8ac72, #c69a5e 55%, #b8894f);
  user-select: none;
  touch-action: manipulation;
  transition: transform .3s ease;
}

/* 执蓝视角：整体旋转 180°（棋子反旋回来） */
.sg-board.is-flipped { transform: rotate(180deg); }
.sg-board.is-flipped .sg-piece { transform: rotate(180deg); }
.sg-board.is-flipped .sg-piece.is-opp { transform: none; }

/* 格子 */
.sg-cell {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-right: 1px solid rgba(74, 54, 32, 0.55);
  border-bottom: 1px solid rgba(74, 54, 32, 0.55);
  background: transparent;
  -webkit-tap-highlight-color: transparent;
  transition: background .12s;
}
.sg-cell:nth-child(9n) { border-right: 0; }
.sg-cell:nth-last-child(-n+9) { border-bottom: 0; }

.sg-cell.is-own { cursor: pointer; }
.sg-cell.is-own:hover { background: rgba(255, 255, 255, 0.14); }

.sg-cell.is-last-from,
.sg-cell.is-last-to { background: rgba(250, 204, 21, 0.18); }
.sg-cell.is-sel { background: rgba(139, 92, 246, 0.3); }
.sg-cell.is-check { background: rgba(244, 63, 94, 0.35); box-shadow: inset 0 0 0 2px rgba(244, 63, 94, 0.75); }

.sg-cell.is-dest::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(34, 197, 94, 0.75);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}
.sg-cell.has-piece.is-dest::after {
  width: 88%;
  height: 88%;
  background: transparent;
  border: 2.5px solid rgba(34, 197, 94, 0.9);
  box-shadow: none;
}

/* 棋子（五边形棋子用 clip-path 近似；升变子红字红底） */
.sg-piece {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 84%;
  height: 84%;
  padding-top: 10%;
  font-size: clamp(14px, 4.2vw, 22px);
  font-weight: 800;
  line-height: 1;
  border-radius: 3px;
  clip-path: polygon(50% 0, 88% 16%, 100% 100%, 0 100%, 12% 16%);
  color: #2b1c10;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.35);
}
.sg-piece.is-red { background: linear-gradient(170deg, #efc79b, #dcae78 60%, #cd9f66); }
.sg-piece.is-blue { background: linear-gradient(170deg, #b6c8d9, #95a9bd 60%, #8398ad); }

.sg-piece.is-promoted {
  color: #b8261d;
  background: linear-gradient(170deg, #f3d3ab, #e2b382 55%, #d8a468);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.35), inset 0 0 0 1.5px rgba(184, 38, 29, 0.55);
}

/* ------------------------------- 控制区 --------------------------------- */

.sg-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
}
.sg-controls:empty { display: none; }

/* ------------------------------ 升变弹窗 -------------------------------- */

.sg-promo-mask {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(6, 9, 18, 0.62);
  backdrop-filter: blur(2px);
  animation: sg-banner-in .18s ease;
}

.sg-promo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 24px 60px -18px rgba(0, 0, 0, 0.9);
}

.sg-promo-title { font-size: 15px; font-weight: 700; }

.sg-promo-btns { display: flex; gap: 14px; }

.sg-promo-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 20px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.sg-promo-btn:hover { border-color: rgba(139, 92, 246, 0.7); background: rgba(139, 92, 246, 0.12); }
.sg-promo-btn b {
  font-size: 30px;
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 6px;
  color: #2b1c10;
  background: linear-gradient(170deg, #efc79b, #dcae78 60%, #cd9f66);
}
.sg-promo-btn b.is-promoted { background: linear-gradient(170deg, #d98d7a, #c85a40 60%, #b04830); color: #fff; }
.sg-promo-btn small { font-size: 12px; color: var(--text-dim); }

.sg-promo-cancel {
  padding: 6px 14px;
  font-size: 12.5px;
  color: var(--text-mute);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  font-family: inherit;
}
.sg-promo-cancel:hover { color: var(--text-dim); }

/* ------------------------------ 房间模式 -------------------------------- */

.sg-lobby {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  width: min(94vw, 620px);
  align-items: stretch;
}
.sg-lobby > .sg-notice { grid-column: 1 / -1; }

.sg-card {
  display: flex;
  flex-direction: column;
  padding: 22px;
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
}
.sg-card h3 { margin: 0 0 6px; font-size: 16px; }
.sg-card .hint { margin: 0 0 16px; font-size: 12.5px; line-height: 1.6; color: var(--text-mute); }

.sg-field { display: block; margin-bottom: 14px; }
.sg-field > span { display: block; margin-bottom: 7px; font-size: 12.5px; color: var(--text-dim); }

.sg-input {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(6, 9, 18, 0.55);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.sg-input:focus { border-color: rgba(139, 92, 246, 0.7); box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18); }
.sg-input::placeholder { color: var(--text-mute); }
.sg-input.is-room { letter-spacing: 0.22em; text-align: center; font-size: 20px; font-weight: 700; }

.sg-lobby-actions { display: flex; gap: 10px; margin-top: auto; }
.sg-lobby-actions .btn { flex: 1 1 auto; }

.sg-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  padding: 14px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  background: var(--surface);
}

.sg-room-code { display: flex; align-items: center; gap: 10px; }
.sg-room-code small { font-size: 12px; color: var(--text-mute); }
.sg-room-code b { font-size: 22px; letter-spacing: 0.16em; font-variant-numeric: tabular-nums; }
.sg-copy { padding: 6px 12px; font-size: 12px; border-radius: 999px; }

.sg-seats { display: flex; flex-wrap: wrap; gap: 10px; }

.sg-seat {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.035);
  color: var(--text-dim);
}
.sg-seat-dot {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.16);
}
.sg-seat-dot.is-red { background: radial-gradient(circle at 32% 28%, #fb9a7f, #d43a17 60%, #8d1e05); }
.sg-seat-dot.is-blue { background: radial-gradient(circle at 32% 28%, #9ec5fb, #2f7fd6 60%, #14508f); }
.sg-seat.is-active { color: var(--text); border-color: rgba(139, 92, 246, 0.5); background: rgba(139, 92, 246, 0.12); }
.sg-seat.is-me { box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.5); }
.sg-seat.is-offline { opacity: 0.55; }
.sg-seat.is-empty { opacity: 0.6; }

.sg-seat-info { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.sg-seat-info b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 8em; }
.sg-seat-info small { font-size: 11.5px; color: var(--text-mute); }

.sg-wait { font-size: 12.5px; color: var(--text-dim); align-self: center; }

.sg-notice {
  width: 100%;
  padding: 10px 16px;
  font-size: 12.5px;
  text-align: center;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  border: 1px solid var(--border-soft);
  background: var(--surface);
}
.sg-notice[hidden] { display: none; }
.sg-notice.is-error {
  color: #fda4af;
  border-color: rgba(251, 113, 133, 0.4);
  background: rgba(251, 113, 133, 0.12);
}

/* ------------------------------ 规则面板 -------------------------------- */

.sg-rules { width: 100%; }
.sg-rules h4 { margin: 14px 0 6px; font-size: 13.5px; color: var(--text); }
.sg-rules h4:first-child { margin-top: 0; }
.sg-rules p,
.sg-rules li { font-size: 12.8px; line-height: 1.75; color: var(--text-dim); }
.sg-rules ul { margin: 0; padding-left: 18px; }

/* ------------------------------ 响应式 ---------------------------------- */

@media (max-width: 640px) {
  .sg-status { padding: 11px 14px; }
  .sg-bar { flex-direction: column; align-items: flex-start; }
  .sg-lobby { gap: 12px; }
  .sg-card { padding: 15px; }
  .sg-seat-info b { max-width: 6em; }
  .sg-hand { padding: 5px 8px; }
  .sg-chip { width: 27px; height: 27px; }
  .sg-chip b { font-size: 14px; }
}
