:root {
  --bg: #1c140d;
  --bg2: #2a1d12;
  --wood: #c98a4b;
  --wood-d: #7a3b16;
  --cream: #f6e7cf;
  --red: #c0392b;
  --green: #1f6f43;
  --gold: #e0a008;
  --ink: #2a2018;
  --panel: #2e2116;
  --panel2: #3a2a1b;
  --line: rgba(255, 240, 220, 0.12);
  --txt: #f3e7d4;
  --txt-dim: #c7b49a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: radial-gradient(circle at 50% 0%, #2a1d12, #160f09 70%);
  color: var(--txt);
  overflow: hidden;
}
body { display: flex; flex-direction: column; }

.btn {
  border: none; border-radius: 10px; padding: 11px 16px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: transform .08s, filter .15s, background .15s; font-family: inherit;
  color: #fff;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: linear-gradient(160deg, #d4512f, #a8341c); box-shadow: 0 3px 0 #7a230f; }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: rgba(255, 235, 210, 0.1); color: var(--txt); border: 1px solid var(--line); }
.btn-soft { background: var(--panel2); color: var(--txt); border: 1px solid var(--line); }
.btn-soft.danger { color: #ff9b8a; }
.btn-block { width: 100%; }
.btn-lg { padding: 15px; font-size: 17px; }
.icon-btn {
  background: transparent; border: none; color: var(--txt-dim);
  font-size: 18px; cursor: pointer; padding: 6px 10px; border-radius: 8px;
}
.icon-btn:hover { background: rgba(255, 255, 255, .08); color: var(--txt); }

/* ===== 登录 ===== */
.login-screen {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 26px; padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: linear-gradient(170deg, #34251700, #2e2116);
  background: var(--panel);
  border: 1px solid var(--line); border-radius: 22px; padding: 34px 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.brand { text-align: center; margin-bottom: 26px; }
.brand-logo {
  width: 76px; height: 76px; margin: 0 auto 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffaf0, #f0dcb8);
  color: var(--red); font-size: 44px; font-weight: 700; font-family: "KaiTi", serif;
  display: flex; align-items: center; justify-content: center;
  border: 3px solid var(--red); box-shadow: 0 6px 18px rgba(0, 0, 0, .4);
}
.brand h1 { margin: 0; font-size: 27px; letter-spacing: 3px; }
.brand-sub { margin: 6px 0 0; color: var(--txt-dim); font-size: 13px; }
.login-form label { display: block; font-size: 13px; color: var(--txt-dim); margin: 14px 0 7px; }
.input-row { display: flex; gap: 8px; margin-bottom: 6px; }
.input-row input {
  flex: 1; background: #1d140d; border: 1px solid var(--line); border-radius: 10px;
  padding: 13px 14px; color: var(--txt); font-size: 16px; outline: none; min-width: 0;
}
.input-row input:focus { border-color: var(--gold); }
#btn-send-code { white-space: nowrap; flex: 0 0 auto; }
.dev-hint {
  background: rgba(224, 160, 8, .12); border: 1px dashed var(--gold); color: var(--gold);
  font-size: 12.5px; padding: 8px 11px; border-radius: 8px; margin: 8px 0;
}
.login-tip { text-align: center; color: var(--txt-dim); font-size: 12.5px; margin: 14px 0 0; }
.btn-block { margin-top: 14px; }
.login-feat { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; color: var(--txt-dim); font-size: 13px; }

/* ===== 主程序 ===== */
.app-screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: rgba(0, 0, 0, .25); border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.logo-mini { font-weight: 700; font-size: 17px; letter-spacing: 1px; display: flex; align-items: center; gap: 8px; }
.logo-coin {
  width: 28px; height: 28px; border-radius: 50%; background: #f0dcb8; color: var(--red);
  font-family: "KaiTi", serif; font-size: 18px; display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--red);
}
.profile-chip { display: flex; align-items: center; gap: 10px; }
.pc-rating { text-align: center; line-height: 1.05; }
.pc-rating b { font-size: 20px; color: var(--gold); }
.pc-rating small { display: block; font-size: 10px; color: var(--txt-dim); }
.pc-info { text-align: right; line-height: 1.25; }
.pc-email { font-size: 12.5px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-record { font-size: 11.5px; color: var(--txt-dim); }

.game-main { flex: 1; display: flex; min-height: 0; padding: 16px; gap: 16px; }
.board-area { flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; }
.board-wrap {
  width: 100%; height: 100%; max-width: min(72vh, 560px); max-height: 100%;
  display: flex; align-items: center; justify-content: center;
}
#board-canvas { display: block; border-radius: 14px; box-shadow: 0 14px 40px rgba(0, 0, 0, .5); touch-action: none; }

.side-panel { flex: 0 0 300px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.status-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px;
}
.status-line { display: flex; align-items: center; justify-content: space-between; font-size: 16px; font-weight: 600; }
.check-badge { background: var(--red); color: #fff; font-size: 12px; padding: 3px 9px; border-radius: 20px; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.move-count { color: var(--txt-dim); font-size: 13px; margin-top: 4px; }

/* 教练点评条 */
.coach-card {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--gold);
  border-radius: 12px; padding: 11px 14px; font-size: 14px; line-height: 1.5;
  animation: fade .2s;
}
.coach-card.good { border-left-color: #6fe39b; }
.coach-card.warn { border-left-color: var(--gold); }
.coach-card.bad { border-left-color: #ff8e7a; }
.coach-tag {
  display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 20px;
  margin-right: 4px; color: #1c140d; font-weight: 700;
}
.coach-tag.good { background: #6fe39b; }
.coach-tag.warn { background: var(--gold); }
.coach-tag.bad { background: #ff8e7a; }

/* 复盘 */
.review-box { margin-top: 16px; text-align: left; border-top: 1px solid var(--line); padding-top: 14px; }
.review-head { font-size: 16px; font-weight: 700; margin-bottom: 10px; }
.review-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.review-chip { font-size: 12px; padding: 4px 10px; border-radius: 20px; background: rgba(255,255,255,.06); border: 1px solid var(--line); }
.review-chip.good { color: #6fe39b; } .review-chip.warn { color: var(--gold); } .review-chip.bad { color: #ff8e7a; }
.review-subhead { font-size: 13px; color: var(--txt-dim); margin: 6px 0 8px; }
.review-row { font-size: 13px; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,.05); line-height: 1.5; }
.review-empty { color: var(--txt-dim); text-align: center; padding: 14px; }

.panel-stack { display: flex; flex-direction: column; gap: 12px; flex: 1; min-height: 0; }
.btn-train { background: linear-gradient(160deg, #2e9e6b, #1f7a4f); box-shadow: 0 3px 0 #155c3a; color: #fff; }
.btn-train:hover { filter: brightness(1.08); }

/* 训练面板 */
.puzzle-head { display: flex; align-items: center; justify-content: space-between; }
.puzzle-title { font-size: 17px; font-weight: 700; }
.puzzle-prompt { font-size: 15px; color: var(--gold); font-weight: 600; }
.puzzle-tip { font-size: 13px; color: var(--txt-dim); line-height: 1.5; white-space: pre-line; }
.opening-picker { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.opening-btn { text-align: left; background: rgba(0,0,0,.2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 13px; cursor: pointer; color: var(--txt); }
.opening-btn:hover { border-color: var(--gold); background: rgba(224,160,8,.08); }
.ob-name { font-weight: 700; font-size: 14px; }
.ob-line { font-size: 12px; color: var(--txt-dim); margin-top: 2px; }
.puzzle-feedback { min-height: 22px; font-size: 14px; font-weight: 600; }
.puzzle-feedback.good { color: #6fe39b; }
.puzzle-feedback.bad { color: #ff8e7a; }
.puzzle-feedback.warn { color: var(--gold); }
.puzzle-progress { font-size: 12.5px; color: var(--txt-dim); }

/* 训练中心 */
.learn-path { background: linear-gradient(160deg, rgba(46,158,107,.16), rgba(46,158,107,.06)); border: 1px solid rgba(46,158,107,.4); border-radius: 14px; padding: 14px 16px; margin-bottom: 14px; }
.lp-head { font-size: 16px; font-weight: 700; color: #8fe7b8; }
.lp-focus { font-size: 13px; color: var(--txt-dim); margin: 5px 0 10px; line-height: 1.5; }
.lp-track { height: 8px; background: rgba(0,0,0,.3); border-radius: 5px; overflow: hidden; }
.lp-fill { height: 100%; background: linear-gradient(90deg, #6fe39b, #2e9e6b); border-radius: 5px; transition: width .4s; }
.lp-cap { font-size: 12px; color: var(--txt-dim); margin-top: 6px; }

.train-stats { display: flex; gap: 10px; margin-bottom: 14px; }
.ts-item { flex: 1; background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; }
.ts-num { font-size: 24px; font-weight: 700; color: var(--green); }
.ts-label { font-size: 11px; color: var(--txt-dim); margin-top: 3px; }

.train-actions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.train-card { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 13px 15px; cursor: pointer; color: var(--txt); transition: all .12s; }
.train-card:hover:not(:disabled) { border-color: var(--green); background: rgba(46,158,107,.08); }
.train-card:disabled { opacity: .5; cursor: not-allowed; }
.tc-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.tc-sub { font-size: 12.5px; color: var(--txt-dim); margin-top: 3px; }
.tc-badge { background: var(--red); color: #fff; font-size: 12px; padding: 0 8px; border-radius: 20px; font-weight: 700; }

.wk-section-title { font-size: 13px; color: var(--txt-dim); margin-bottom: 10px; }
.wk-head { font-size: 15px; font-weight: 700; margin-bottom: 12px; }
.wk-bars { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 12px; }
.wk-row { display: flex; align-items: center; gap: 10px; }
.wk-label { width: 38px; font-size: 13px; color: var(--txt-dim); }
.wk-track { flex: 1; height: 10px; background: rgba(255,255,255,.07); border-radius: 6px; overflow: hidden; }
.wk-fill { height: 100%; background: #6f9; background: linear-gradient(90deg, #3aa, #2e9e6b); border-radius: 6px; }
.wk-fill.bad { background: linear-gradient(90deg, #d4512f, #ff8e7a); }
.wk-val { width: 22px; text-align: right; font-size: 13px; }
.trend { display: flex; align-items: flex-end; gap: 4px; height: 56px; padding: 6px 0; }
.trend-bar { flex: 1; background: linear-gradient(180deg, #6fe39b, #2e9e6b); border-radius: 3px 3px 0 0; min-height: 4px; }
.trend-cap { font-size: 11px; color: var(--txt-dim); margin-bottom: 12px; }
.wk-tips { display: flex; flex-direction: column; gap: 6px; }
.wk-tip { font-size: 13px; color: var(--txt); line-height: 1.5; background: rgba(224,160,8,.08); border-left: 2px solid var(--gold); padding: 7px 10px; border-radius: 6px; }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.controls .btn-primary { grid-column: span 1; }

.movelist-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ml-title { font-size: 13px; color: var(--txt-dim); margin-bottom: 8px; }
.move-list { flex: 1; overflow-y: auto; font-size: 14px; }
.move-row { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 6px; padding: 4px 4px; border-radius: 6px; }
.move-row:nth-child(even) { background: rgba(255, 255, 255, .03); }
.mv-no { color: var(--txt-dim); }
.mv.red { color: #f4a; color: #ff8e7a; }
.mv.black { color: #cfe; color: #9fd6b4; }

/* ===== 弹窗 ===== */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .6); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 18px;
}
.modal.open { display: flex; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal-card {
  width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line); border-radius: 20px; padding: 22px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .6);
}
.modal-card.slim { max-width: 360px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head.center { justify-content: center; }
.modal-head h2 { margin: 0; font-size: 20px; }

.home-stats { display: flex; gap: 10px; margin-bottom: 8px; }
.hs-item { flex: 1; background: rgba(0, 0, 0, .25); border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; }
.hs-num { font-size: 26px; font-weight: 700; color: var(--gold); }
.hs-num.sm { font-size: 15px; line-height: 1.3; padding-top: 5px; }
.hs-label { font-size: 11px; color: var(--txt-dim); margin-top: 3px; }
.calib-tip { color: var(--txt-dim); font-size: 12.5px; text-align: center; margin: 8px 0 14px; }

.resume-box {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: rgba(224, 160, 8, .1); border: 1px solid var(--gold); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 16px;
}
.resume-title { font-weight: 600; }
.resume-info { font-size: 12.5px; color: var(--txt-dim); margin-top: 2px; }

.picker-label { font-size: 12.5px; color: var(--txt-dim); margin-bottom: 10px; }
.level-picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 18px; }
.level-btn {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 4px; cursor: pointer; color: var(--txt); display: flex; flex-direction: column;
  align-items: center; gap: 2px; transition: all .12s;
}
.level-btn .lv-num { font-weight: 700; font-size: 14px; }
.level-btn .lv-name { font-size: 10px; color: var(--txt-dim); }
.level-btn.active { background: linear-gradient(160deg, #d4512f, #a8341c); border-color: var(--red); }
.level-btn.active .lv-name { color: #ffd9cf; }

.options-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.opt { font-size: 13px; color: var(--txt-dim); display: flex; align-items: center; gap: 6px; }
.opt select { background: #1d140d; color: var(--txt); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-family: inherit; }
.opt.switch input { width: 18px; height: 18px; accent-color: var(--red); }

.result-body { text-align: center; padding: 6px 0 14px; }
.result-reason { color: var(--txt-dim); margin: 0 0 14px; }
.rating-change { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.rating-big { font-size: 34px; font-weight: 700; }
.rating-big .up { color: #6fe39b; font-size: 22px; }
.rating-big .down { color: #ff8e7a; font-size: 22px; }
.rank-tag { color: var(--gold); font-size: 16px; }
.next-rec { color: var(--txt-dim); font-size: 13px; margin-top: 8px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

.history-body { max-height: 60vh; overflow-y: auto; }
.hist-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.hist-table th { text-align: left; color: var(--txt-dim); font-weight: 500; padding: 8px 6px; border-bottom: 1px solid var(--line); font-size: 12px; }
.hist-table td { padding: 9px 6px; border-bottom: 1px solid rgba(255, 255, 255, .05); }
.r-win { color: #6fe39b; font-weight: 700; }
.r-loss { color: #ff8e7a; font-weight: 700; }
.r-draw { color: var(--gold); font-weight: 700; }
.up { color: #6fe39b; } .down { color: #ff8e7a; }
.empty { text-align: center; color: var(--txt-dim); padding: 30px; }

.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(20, 14, 9, .95); color: var(--txt); padding: 11px 20px; border-radius: 30px;
  border: 1px solid var(--line); font-size: 14px; opacity: 0; pointer-events: none;
  transition: all .25s; z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 响应式：手机 ===== */
@media (max-width: 820px) {
  .game-main { flex-direction: column; padding: 10px; gap: 10px; overflow-y: auto; }
  .board-area { flex: 0 0 auto; }
  .board-wrap { max-width: min(94vw, 460px); max-height: none; }
  .side-panel { flex: 0 0 auto; }
  .movelist-card { max-height: 130px; }
  .move-list { max-height: 90px; }
  .pc-email { max-width: 110px; }
  .level-picker { grid-template-columns: repeat(5, 1fr); }
}
@media (max-width: 380px) {
  .level-picker { grid-template-columns: repeat(5, 1fr); gap: 5px; }
  .level-btn { padding: 7px 2px; }
}
