/* ============================================================
 * 梅花谱 · 书架风格 CSS
 * 暖木色系，线装书质感
 * ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "KaiTi", "STKaiti", "楷体", "Noto Serif SC", serif;
  background: #3d2b1f;
  color: #f5e6d0;
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100vw;
}

body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: 
    repeating-linear-gradient(90deg, transparent, transparent 40px, rgba(0,0,0,0.03) 40px, rgba(0,0,0,0.03) 41px),
    repeating-linear-gradient(0deg, transparent, transparent 8px, rgba(255,220,160,0.04) 8px, rgba(255,220,160,0.04) 9px);
  pointer-events: none;
  z-index: 0;
}

/* ========== 顶部导航 ========== */
.top-bar {
  position: sticky; top: 0; z-index: 100;
  background: linear-gradient(180deg, #5c3d2a, #4a3020);
  border-bottom: 2px solid #8b6914;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
}
.back-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid #8b6914; background: rgba(139,105,20,0.2);
  color: #f5e6d0; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; transition: background 0.2s;
}
.back-btn:active { background: rgba(139,105,20,0.4); }
.back-btn.hidden { visibility: hidden; }
.top-title {
  flex: 1; text-align: center; font-size: 22px; font-weight: bold;
  color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* ========== 搜索栏 ========== */
.search-bar {
  background: linear-gradient(180deg, #6b4c35, #5a3e2a);
  border-bottom: 1px solid #8b6914;
  padding: 10px 16px; display: flex; align-items: center; gap: 8px;
}
.search-bar input {
  flex: 1; background: rgba(0,0,0,0.2);
  border: 1px solid rgba(139,105,20,0.4); border-radius: 6px;
  padding: 8px 12px; color: #f5e6d0; font-size: 14px; font-family: inherit;
}
.search-bar input::placeholder { color: rgba(245,230,208,0.4); }
.search-bar .search-icon { font-size: 16px; opacity: 0.6; }
.search-bar .clear-btn {
  width: 24px; height: 24px; border-radius: 50%; border: none;
  background: rgba(255,255,255,0.15); color: #f5e6d0;
  font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ========== 书架页 ========== */
.shelf-container {
  max-width: 420px; margin: 0 auto; padding: 20px 16px;
}
.shelf-row { position: relative; margin-bottom: 24px; }
.shelf-label {
  text-align: center; color: rgba(245,230,208,0.5);
  font-size: 12px; margin-bottom: 8px; letter-spacing: 4px;
}
.shelf-books {
  display: flex; justify-content: center; gap: 20px;
  padding: 16px 8px;
  background: linear-gradient(180deg, #4a3425, #3d2b1f 50%, #4a3425);
  border-radius: 4px;
  border-top: 3px solid #6b4c35;
  border-bottom: 6px solid #2a1a10;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  flex-wrap: wrap;
}

/* 线装书 */
.book {
  width: 100px; height: 140px;
  cursor: pointer; transition: transform 0.3s, box-shadow 0.3s;
  position: relative;
}
.book:active { transform: scale(0.95); }
.book-cover {
  width: 100%; height: 100%;
  background: linear-gradient(135deg, #1a3a5c, #0f2840 50%, #1a3a5c);
  border-radius: 2px 6px 6px 2px;
  box-shadow: -2px 0 0 #0a1a2a, 2px 2px 8px rgba(0,0,0,0.5),
    inset 0 0 20px rgba(255,255,255,0.05);
  position: relative; overflow: hidden;
}
.book-cover::before {
  content: ''; position: absolute; left: 8px; top: 0; bottom: 0;
  width: 2px; background: rgba(255,255,255,0.15);
}
.book-cover::after {
  content: ''; position: absolute; top: 12px; bottom: 12px; left: 14px;
  width: 1px;
  background: repeating-linear-gradient(180deg,
    rgba(255,255,255,0.2) 0px, rgba(255,255,255,0.2) 3px,
    transparent 3px, transparent 6px);
}
.book-cover .wave {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.03) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(0,0,0,0.1) 0%, transparent 50%);
}
.book-spine-label {
  position: absolute; top: 10px; bottom: 10px; left: 50%;
  transform: translateX(-50%); width: 32px;
  background: #f0e8d8; border-radius: 1px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 6px 2px; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.book-spine-label .char {
  font-size: 14px; font-weight: bold; color: #1a1a1a;
  line-height: 1.4; writing-mode: vertical-rl; letter-spacing: 2px;
}
.book-thread {
  position: absolute; left: 12px; top: 0; bottom: 0; width: 3px;
  display: flex; flex-direction: column; justify-content: space-around; padding: 8px 0;
}
.book-thread span {
  display: block; width: 3px; height: 8px;
  background: rgba(255,255,255,0.25); border-radius: 1px;
}

/* ========== 局列表页 ========== */
.game-list {
  max-width: 420px; margin: 0 auto; padding: 16px;
}
.game-card {
  background: linear-gradient(135deg, #f5edd8, #ede2c8);
  border: 1px solid #c9b88a; border-radius: 8px;
  margin-bottom: 12px; overflow: hidden; cursor: pointer;
  transition: transform 0.2s; box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.game-card:active { transform: scale(0.98); }
.game-card-header {
  background: linear-gradient(135deg, #8b6914, #6b4c10);
  padding: 8px 14px; font-size: 13px; color: #fff; font-weight: bold;
}
.game-card-body {
  padding: 12px 14px; color: #3d2b1f; font-size: 14px; line-height: 1.6;
}
.game-card-body .rounds {
  float: right; color: #8b6914; font-size: 12px;
}

/* ========== 棋谱浏览页 ========== */
.viewer-container {
  max-width: 500px; margin: 0 auto; padding: 16px;
}
.viewer-info { text-align: center; margin-bottom: 12px; color: #f5e6d0; }
.viewer-info h2 { font-size: 18px; margin-bottom: 4px; }
.viewer-info .step { font-size: 13px; color: rgba(245,230,208,0.6); }
.viewer-info .note {
  font-size: 13px; color: rgba(245,230,208,0.8);
  margin-top: 6px; line-height: 1.6; min-height: 40px;
}
.board-wrapper {
  position: relative; display: flex; justify-content: center; margin-bottom: 12px;
}
.board-frame { max-width: 100%; border: 3px solid #8b6914; border-radius: 6px; overflow: hidden; box-shadow: 0 4px 16px rgba(0,0,0,0.4), inset 0 0 0 1px rgba(139,105,20,0.3); }
.board-frame canvas { display: block; max-width: 100%; height: auto; }

.viewer-controls {
  display: flex; justify-content: center; gap: 12px; flex-wrap: wrap;
}
.viewer-controls button {
  background: linear-gradient(180deg, #8b6914, #6b4c10);
  color: #fff; border: 1px solid #a07818; border-radius: 6px;
  padding: 10px 20px; font-size: 14px; font-family: inherit;
  cursor: pointer; transition: background 0.2s; min-width: 80px;
}
.viewer-controls button:active { background: #5a3e08; }
.viewer-controls button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ========== 脚注 ========== */
.footer {
  text-align: center; padding: 24px 16px;
  color: rgba(245,230,208,0.3); font-size: 12px; letter-spacing: 2px;
}

/* ========== 页面切换 ========== */
.page { display: block; }
.page.active { display: block; }
.page-enter { animation: fadeIn 0.3s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========== 响应式 ========== */
@media (max-width: 360px) {
  .book { width: 85px; height: 120px; }
  .book-spine-label { width: 26px; }
  .book-spine-label .char { font-size: 12px; }
  .shelf-books { gap: 12px; padding: 12px 4px; }
}

.loading { text-align: center; padding: 60px 20px; color: rgba(245,230,208,0.5); font-size: 14px; }
