/**
 * Chess960 模块样式（WEB 端）
 * 移植自小程序 packages/chess960/pages/index/index.wxss（结构/配色一致）
 * 主题：跟随站点紫色渐变（#667eea → #764ba2）
 * 棋盘色：使用 index.php 注入的 CSS 变量 --sq-light / --sq-dark
 */

/* ============== 基础 ============== */
.c960-page {
    max-width: 920px;
    margin: 0 auto;
    padding: 12px 16px 80px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    color: #333;
}
.c960-page button { font-family: inherit; }
.c960-muted { color: #999; font-size: 12px; font-weight: normal; }
.c960-page[hidden] { display: none !important; }

/* ============== 顶部标题 ============== */
.c960-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 14px;
}
.c960-header-titles { display: flex; flex-direction: column; }
.c960-title { margin: 0; font-size: 22px; color: #333; font-weight: 600; }
.c960-subtitle { margin: 2px 0 0; color: #888; font-size: 12px; }
.c960-header-link {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 6px 14px; background: #fff; color: #667eea;
    border: 1px solid #d8def0; border-radius: 18px;
    font-size: 13px; text-decoration: none; transition: all .15s;
}
.c960-header-link:hover { background: #667eea; color: #fff; border-color: #667eea; }
.c960-header-arrow { font-weight: bold; }

/* ============== 玩家卡（顶部/底部） ============== */
.c960-player-bar { margin-bottom: 8px; }
.c960-player-card {
    display: flex; align-items: center; gap: 12px;
    padding: 8px 12px; background: #fff; border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.c960-player-bottom .c960-player-card { background: linear-gradient(135deg, #f0f2ff, #faf5ff); }
.c960-player-top .c960-player-card { background: #fff; }

.c960-player-avatar {
    position: relative; width: 42px; height: 42px;
    border-radius: 50%; background: #ede7f6; overflow: visible;
    flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.c960-player-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.c960-player-badge {
    position: absolute; right: -4px; bottom: -4px;
    width: 20px; height: 20px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; line-height: 1;
}
.c960-player-badge.white { color: #fff; text-shadow: 0 0 2px #333; }
.c960-player-badge.black { color: #333; }

.c960-player-info { flex: 1; min-width: 0; }
.c960-player-name {
    font-size: 15px; font-weight: 500; color: #333;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.c960-player-meta {
    font-size: 12px; color: #888; margin-top: 2px;
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.c960-player-capture {
    font-family: 'Segoe UI Symbol', 'Arial Unicode MS', sans-serif;
    letter-spacing: -2px; font-size: 14px; color: #666;
    min-height: 16px; display: inline-block;
}
.c960-sp-tag {
    display: inline-block; padding: 1px 8px; border-radius: 10px;
    background: #ede7f6; color: #667eea; font-size: 11px; font-weight: 600;
}

/* ============== 棋盘 ============== */
.c960-board-wrap {
    display: flex; justify-content: center;
    margin: 8px auto;
}
.c960-board {
    position: relative;
    width: min(560px, calc(100vw - 32px));
    aspect-ratio: 1 / 1;
    background: var(--sq-light, #f0d9b5);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,.15);
    overflow: hidden;
    user-select: none;
}
.c960-board-grid {
    position: absolute; inset: 0;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
}
.c960-board-anno {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 5;
}

.c960-sq {
    position: relative; cursor: pointer;
    transition: background-color .12s;
}
.c960-sq.light { background: var(--sq-light, #f0d9b5); }
.c960-sq.dark  { background: var(--sq-dark, #b58863); }
.c960-sq .coord {
    position: absolute; font-size: 10px; font-weight: 700;
    opacity: .55; pointer-events: none; line-height: 1;
}
.c960-sq .coord.file { right: 3px; bottom: 1px; }
.c960-sq .coord.rank { left: 3px; top: 1px; }
.c960-sq.light .coord { color: var(--sq-dark, #b58863); }
.c960-sq.dark  .coord { color: var(--sq-light, #f0d9b5); }

.c960-sq .chess-piece {
    position: absolute; inset: 0; width: 100%; height: 100%;
    object-fit: contain; pointer-events: none; user-select: none;
}
.c960-sq.selected::after {
    content: ''; position: absolute; inset: 0;
    background: rgba(102,126,234,.45); pointer-events: none;
}
.c960-sq.last-move::after {
    content: ''; position: absolute; inset: 0;
    background: rgba(255,213,79,.42); pointer-events: none;
}
.c960-sq.valid-dot::before {
    content: ''; position: absolute; left: 50%; top: 50%;
    width: 26%; height: 26%; margin: -13% 0 0 -13%;
    background: rgba(102,126,234,.55); border-radius: 50%;
    pointer-events: none;
}
.c960-sq.valid-cap::before {
    content: ''; position: absolute; inset: 6%;
    border: 3px solid rgba(102,126,234,.55); border-radius: 50%;
    pointer-events: none;
}
.c960-sq.in-check {
    background: radial-gradient(circle, rgba(244,67,54,.85) 30%, transparent 60%) !important;
}
.c960-sq.flipped-rank .coord.rank { left: auto; right: 3px; }
.c960-sq.flipped-rank .coord.file { right: auto; left: 3px; bottom: 1px; }
.c960-sq.flipped-coord .coord.file { bottom: auto; top: 1px; }
.c960-sq.flipped-coord .coord.rank { top: auto; bottom: 1px; }

/* ============== 棋盘下方：编号显示 + 提示 ============== */
.c960-board-foot { margin: 10px 0; }
.c960-sp-display {
    display: flex; align-items: center; justify-content: center;
    gap: 10px; padding: 8px 12px; background: #fff;
    border-radius: 10px; box-shadow: 0 2px 6px rgba(0,0,0,.05);
}
.c960-sp-label { font-size: 12px; color: #888; }
.c960-sp-number {
    font-size: 18px; font-weight: 700; color: #667eea;
    font-family: 'SF Mono', Consolas, monospace;
}
.c960-sp-rank {
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 14px; color: #555; letter-spacing: 1px;
}
.c960-message {
    margin-top: 8px; padding: 8px 14px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff; border-radius: 8px;
    font-size: 14px; text-align: center;
    animation: c960MsgIn .25s ease-out;
}
@keyframes c960MsgIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ============== 提示条 ============== */
.c960-hint {
    margin: 10px 0;
    padding: 10px 14px;
    background: linear-gradient(90deg, #fff7e6, #fff);
    border-left: 3px solid #ffa726;
    border-radius: 8px;
    font-size: 13px; color: #5d4037;
    display: flex; align-items: center; gap: 8px;
}
.c960-hint-icon { font-size: 16px; }

/* 库限制脚注（始终显示） */
.c960-footnote {
    margin: 6px 0 12px;
    padding: 6px 12px;
    background: #f5f5f5; border-radius: 6px;
    font-size: 11px; color: #888;
    text-align: center; line-height: 1.5;
}

/* ============== 快速开始按钮 ============== */
.c960-quick-start-bar { margin: 14px 0; text-align: center; }
.c960-btn {
    padding: 10px 22px; border: 1px solid #e0e0e0; border-radius: 8px;
    background: #fff; color: #333; font-size: 14px;
    cursor: pointer; transition: all .15s; white-space: nowrap;
    display: inline-flex; align-items: center; gap: 6px;
}
.c960-btn:hover { border-color: #667eea; color: #667eea; transform: translateY(-1px); }
.c960-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.c960-btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    border: none; color: #fff; box-shadow: 0 4px 14px rgba(102,126,234,.35);
}
.c960-btn-primary:hover { color: #fff; opacity: .92; }
.c960-btn-quick {
    font-size: 16px; font-weight: 600;
    padding: 12px 32px; border-radius: 28px;
}

/* ============== 走子记录 ============== */
.c960-moves-card {
    background: #fff; border-radius: 10px; padding: 10px 14px;
    margin: 10px 0; box-shadow: 0 2px 6px rgba(0,0,0,.05);
}
.c960-moves-title {
    font-size: 12px; color: #888; margin-bottom: 6px; font-weight: 600;
}
.c960-moves {
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 13px; line-height: 1.7; color: #333;
    max-height: 96px; overflow-y: auto;
}
.c960-moves .c960-move-item {
    display: inline-block; padding: 1px 4px; margin: 1px 2px;
    border-radius: 4px;
}
.c960-moves .c960-move-item.mine { background: #ede7f6; color: #667eea; font-weight: 600; }

/* ============== 工具栏 ============== */
.c960-toolbar {
    position: sticky; bottom: 12px;
    display: flex; gap: 8px;
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(8px);
    padding: 8px 10px; border-radius: 14px;
    box-shadow: 0 4px 18px rgba(0,0,0,.12);
    margin-top: 14px;
    z-index: 50;
}
.c960-tool {
    flex: 1; padding: 8px 4px;
    border: none; background: transparent;
    border-radius: 10px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    color: #555; font-size: 12px;
    transition: background .12s;
}
.c960-tool:hover { background: #f0f2ff; color: #667eea; }
.c960-tool.disabled { opacity: .4; pointer-events: none; }
.c960-tool-icon { font-size: 18px; line-height: 1; }
.c960-tool-text { font-size: 11px; }

/* ============== 弹窗（通用） ============== */
.c960-modal {
    position: fixed; inset: 0; z-index: 9000;
    display: flex; align-items: center; justify-content: center;
    animation: c960FadeIn .2s ease-out;
}
@keyframes c960FadeIn { from { opacity: 0; } to { opacity: 1; } }
.c960-modal[hidden] { display: none !important; }
.c960-modal-mask {
    position: absolute; inset: 0;
    background: rgba(0,0,0,.45);
    backdrop-filter: blur(2px);
}
.c960-modal-content {
    position: relative;
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    width: calc(100% - 32px);
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    animation: c960SlideIn .25s ease-out;
}
@keyframes c960SlideIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

.c960-modal-sm { max-width: 380px; text-align: center; }
.c960-modal-header {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    margin-bottom: 16px; padding-bottom: 14px;
    border-bottom: 1px solid #f0f0f0;
}
.c960-modal-icon { font-size: 22px; }
.c960-modal-title {
    font-size: 18px; font-weight: 600; color: #333;
}
.c960-modal-title-sm { font-size: 16px; font-weight: 500; color: #333; }
.c960-modal-desc { color: #666; font-size: 14px; line-height: 1.6; margin: 10px 0 16px; }

.c960-modal-actions {
    display: flex; gap: 10px; justify-content: flex-end;
    margin-top: 18px;
}
.c960-modal-sm .c960-modal-actions { justify-content: center; flex-wrap: wrap; }

/* 开局弹窗 - 起始位置区块 */
.c960-modal-body { padding: 0; }
.c960-position-block {
    margin-bottom: 14px; padding: 14px;
    background: linear-gradient(135deg, #f7f8ff, #faf5ff);
    border-radius: 12px;
}
.c960-position-block-head {
    display: flex; align-items: center; gap: 6px;
    margin-bottom: 12px;
}
.c960-row-icon { font-size: 16px; }
.c960-row-label { font-size: 13px; color: #555; flex: 1; }
.c960-position-input-btn {
    padding: 4px 12px; border: 1px solid #667eea;
    background: #fff; color: #667eea;
    border-radius: 14px; font-size: 12px;
    cursor: pointer; transition: all .15s;
}
.c960-position-input-btn:hover { background: #667eea; color: #fff; }

.c960-position-block-row {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px;
}
.c960-position-number-large {
    font-size: 24px; font-weight: 700; color: #667eea;
    font-family: 'SF Mono', Consolas, monospace;
}
.c960-position-random-btn {
    padding: 8px 18px;
    border: none; border-radius: 20px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff; font-size: 14px; font-weight: 500;
    cursor: pointer; box-shadow: 0 4px 12px rgba(102,126,234,.3);
    transition: all .15s;
}
.c960-position-random-btn:hover { transform: translateY(-1px); }

.c960-position-slider {
    width: 100%; height: 28px; -webkit-appearance: none; appearance: none;
    background: transparent;
}
.c960-position-slider::-webkit-slider-runnable-track {
    height: 6px; border-radius: 3px;
    background: linear-gradient(90deg, #d8def0, #e0d8f0);
}
.c960-position-slider::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 22px; height: 22px; border-radius: 50%;
    background: #667eea; cursor: pointer;
    margin-top: -8px; box-shadow: 0 2px 6px rgba(102,126,234,.5);
    border: 2px solid #fff;
}
.c960-position-slider::-moz-range-track {
    height: 6px; border-radius: 3px; background: #d8def0;
}
.c960-position-slider::-moz-range-thumb {
    width: 22px; height: 22px; border-radius: 50%;
    background: #667eea; cursor: pointer; border: 2px solid #fff;
}

/* 模式/难度行 */
.c960-set-row {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 10px;
    background: #fff; margin-bottom: 8px;
    border: 1px solid #f0f0f0;
}
.c960-set-row .c960-row-label { flex: 0 0 50px; }
.c960-select {
    flex: 1; padding: 8px 10px; border: 1px solid #ddd;
    border-radius: 8px; background: #fff; font-size: 14px;
    color: #333; cursor: pointer;
}
.c960-select:focus { outline: none; border-color: #667eea; }

/* 编号输入弹窗 */
.c960-modal-header-bar {
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid #f0f0f0; padding: 14px 16px;
    margin: 0;
}
.c960-modal-link {
    background: none; border: none; color: #888;
    font-size: 14px; cursor: pointer; padding: 4px 8px;
}
.c960-modal-link-primary { color: #667eea; font-weight: 500; }
.c960-modal-body-pad { padding: 16px; }
.c960-number-hint { color: #888; font-size: 13px; margin: 0 0 12px; text-align: center; }
.c960-number-input {
    width: 100%; padding: 12px 14px; border: 1px solid #ddd;
    border-radius: 10px; font-size: 18px; text-align: center;
    font-family: 'SF Mono', Consolas, monospace;
    box-sizing: border-box;
}
.c960-number-input:focus { outline: none; border-color: #667eea; }
.c960-number-presets {
    display: flex; gap: 8px; margin-top: 12px;
}
.c960-preset {
    flex: 1; padding: 10px 6px;
    border: 1px solid #e0e0e0; border-radius: 8px;
    background: #fff; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    transition: all .15s;
}
.c960-preset:hover { border-color: #667eea; background: #f7f8ff; }
.c960-preset-num { font-size: 16px; font-weight: 700; color: #667eea; }
.c960-preset-desc { font-size: 11px; color: #888; }

/* 升变弹窗 */
.c960-modal-promotion { text-align: center; }
.c960-promotion-choices {
    display: flex; gap: 12px; justify-content: center;
    margin-top: 14px;
}
.c960-promotion-choice {
    width: 64px; height: 64px;
    border: 2px solid #e0e0e0; border-radius: 10px;
    background: #fff; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; transition: all .15s;
}
.c960-promotion-choice:hover { border-color: #667eea; transform: translateY(-2px); }
.c960-promotion-choice img { width: 44px; height: 44px; }
.c960-promotion-choice span { font-size: 11px; color: #888; }

/* 结果弹窗 */
.c960-modal-result { text-align: center; }
.c960-result-icon { font-size: 64px; margin: 8px 0 12px; }
.c960-result-title { font-size: 26px; font-weight: 700; margin-bottom: 6px; }
.c960-modal-result.win .c960-result-title { color: #667eea; }
.c960-modal-result.lose .c960-result-title { color: #c62828; }
.c960-modal-result.draw .c960-result-title { color: #888; }
.c960-result-desc { color: #666; font-size: 14px; margin-bottom: 18px; }
.c960-result-stats {
    display: flex; gap: 24px; justify-content: center;
    margin-bottom: 18px;
    padding: 12px; background: #f7f8ff; border-radius: 10px;
}
.c960-stat-item { display: flex; flex-direction: column; gap: 4px; }
.c960-stat-label { font-size: 12px; color: #888; }
.c960-stat-value { font-size: 18px; font-weight: 600; color: #333; }

/* PGN 文本 */
.c960-pgn-textarea {
    width: 100%; min-height: 120px; margin-top: 10px;
    padding: 10px; border: 1px solid #e0e0e0; border-radius: 8px;
    font-family: 'SF Mono', Consolas, monospace; font-size: 12px;
    background: #fafafa; resize: vertical;
    box-sizing: border-box;
}

/* ============== 移动端适配 ============== */
@media (max-width: 640px) {
    .c960-page { padding: 8px 10px 90px; }
    .c960-title { font-size: 18px; }
    .c960-subtitle { font-size: 11px; }
    .c960-header-link { font-size: 12px; padding: 4px 10px; }
    .c960-player-avatar { width: 36px; height: 36px; }
    .c960-player-name { font-size: 14px; }
    .c960-player-meta { font-size: 11px; }
    .c960-board { width: calc(100vw - 20px); }
    .c960-board-foot { margin: 8px 0; }
    .c960-sp-display { padding: 6px 10px; }
    .c960-sp-number { font-size: 16px; }
    .c960-sp-rank { font-size: 12px; }
    .c960-modal-content { padding: 18px; }
    .c960-modal-title { font-size: 16px; }
    .c960-position-number-large { font-size: 20px; }
    .c960-position-random-btn { padding: 6px 14px; font-size: 13px; }
    .c960-btn { padding: 8px 16px; font-size: 13px; }
    .c960-btn-quick { font-size: 14px; padding: 10px 24px; }
    .c960-toolbar { padding: 6px 8px; gap: 4px; }
    .c960-tool { padding: 6px 2px; }
    .c960-tool-icon { font-size: 16px; }
    .c960-tool-text { font-size: 10px; }
    .c960-result-icon { font-size: 48px; }
    .c960-result-title { font-size: 22px; }
    .c960-result-stats { gap: 16px; padding: 10px; }
    .c960-stat-value { font-size: 16px; }
    .c960-promotion-choice { width: 56px; height: 56px; }
    .c960-promotion-choice img { width: 38px; height: 38px; }
    .c960-number-presets { flex-direction: column; }
    .c960-preset { flex-direction: row; justify-content: space-between; padding: 8px 12px; }
}

/* ============== 主题色（跟随站点） ============== */
body.theme-dark .c960-page { color: #e5e7eb; }
body.theme-dark .c960-player-card { background: #1f2937; color: #e5e7eb; }
body.theme-dark .c960-sp-display,
body.theme-dark .c960-moves-card { background: #1f2937; color: #e5e7eb; }
body.theme-dark .c960-modal-content { background: #1f2937; color: #e5e7eb; }
body.theme-dark .c960-modal-title,
body.theme-dark .c960-modal-title-sm { color: #e5e7eb; }
body.theme-dark .c960-toolbar { background: rgba(31,41,55,.92); }
body.theme-dark .c960-tool { color: #cbd5e1; }
body.theme-dark .c960-tool:hover { background: #374151; color: #fff; }
body.theme-dark .c960-select,
body.theme-dark .c960-number-input { background: #111827; color: #e5e7eb; border-color: #374151; }
body.theme-dark .c960-set-row { background: #1f2937; border-color: #374151; }
body.theme-dark .c960-position-block { background: linear-gradient(135deg, #1e1b4b, #1f2937); }
