/* ========== 基础样式 ========== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: linear-gradient(135deg, #2c2419 0%, #3d3224 50%, #2c2419 100%);
  font-family: 'Noto Serif SC', serif;
  color: #2c2419;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ========== 颜色系统 ========== */

:root {
  --parchment: #f5e6c8;
  --parchment-dark: #e8d5a8;
  --ink: #2c2419;
  --ink-light: #5c4d3c;
  --magic-blue: #4a7c9b;
  --magic-gold: #c9a227;
  --wood: #8b6914;
}

.text-ink { color: var(--ink); }
.text-ink-light { color: var(--ink-light); }
.text-magic-blue { color: var(--magic-blue); }
.text-magic-gold { color: var(--magic-gold); }

.bg-wood\/5 { background: rgba(139, 105, 20, 0.05); }
.bg-wood\/10 { background: rgba(139, 105, 20, 0.1); }
.bg-wood\/20 { background: rgba(139, 105, 20, 0.2); }
.bg-magic-gold\/10 { background: rgba(201, 162, 39, 0.1); }
.bg-magic-gold\/20 { background: rgba(201, 162, 39, 0.2); }

.border-wood { border-color: var(--wood); }
.border-wood\/10 { border-color: rgba(139, 105, 20, 0.1); }
.border-wood\/20 { border-color: rgba(139, 105, 20, 0.2); }
.border-wood\/30 { border-color: rgba(139, 105, 20, 0.3); }
.border-magic-gold { border-color: var(--magic-gold); }
.border-magic-gold\/30 { border-color: rgba(201, 162, 39, 0.3); }

.bg-magic-gold { background: var(--magic-gold); }
.bg-magic-blue { background: var(--magic-blue); }
.bg-wood { background: var(--wood); }

/* ========== 羊皮纸卡片 ========== */

.parchment-bg {
  background: linear-gradient(180deg, #f5e6c8 0%, #e8d5a8 100%);
  box-shadow: inset 0 0 60px rgba(139, 105, 20, 0.2), 0 4px 20px rgba(0,0,0,0.3);
  position: relative;
}

.magic-glow {
  box-shadow: 0 0 20px rgba(74, 124, 155, 0.3), 0 0 40px rgba(201, 162, 39, 0.1);
}

/* ========== 纹理 ========== */

.grain-texture {
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.03;
  pointer-events: none;
}

.star-filled { color: #c9a227; }
.star-empty { color: #d4d4d4; }

/* ========== 动画 ========== */

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 10px rgba(201, 162, 39, 0.3); }
  50% { box-shadow: 0 0 25px rgba(201, 162, 39, 0.6); }
}

.animate-glow {
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
  animation: fade-in 0.5s ease-out;
}

@keyframes scale-in {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

.animate-scale-in {
  animation: scale-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes slide-in-right {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

.animate-slide-in-right {
  animation: slide-in-right 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* ========== 字体 ========== */

.font-display { font-family: 'Cinzel', 'Noto Serif SC', serif; }
.font-serif { font-family: 'Noto Serif SC', serif; }

/* ========== 导航按钮 ========== */

.nav-btn {
  transition: all 0.2s ease;
  cursor: pointer;
}

.nav-btn:hover {
  transform: translateY(-1px);
}

/* ========== 书籍卡片 ========== */

.book-card {
  transition: all 0.2s ease;
}

.book-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

/* ========== 章节阅读 ========== */

.reading-page {
  font-size: 1.05rem;
  line-height: 2;
}

.reading-page p {
  margin-bottom: 1.2em;
  text-indent: 2em;
}

/* ========== 滚动条 ========== */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: #f5e6c8;
}

::-webkit-scrollbar-thumb {
  background: #8b6914;
  border-radius: 3px;
}

/* ========== 响应式 ========== */

@media (max-width: 768px) {
  .text-6xl { font-size: 3rem !important; }
  .text-7xl { font-size: 3.5rem !important; }
  .grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-cols-5 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .p-6 { padding: 1rem; }
  .p-8 { padding: 1.5rem; }
  .text-6xl { font-size: 2.5rem !important; }
}

/* ========== 缮写动画 ========== */

.writing-anim-wrapper {
  max-width: 720px;
  width: 100%;
}

.writing-scene {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: 480px;
}

.writing-candle-glow {
  position: absolute;
  top: -20px;
  right: 10%;
  width: 30%;
  height: 50%;
  background: radial-gradient(circle, rgba(255,180,80,0.25) 0%, transparent 70%);
  pointer-events: none;
  animation: writing-candle-flicker 3s ease-in-out infinite;
}

@keyframes writing-candle-flicker {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  25% { opacity: 0.9; transform: scale(1.08); }
  50% { opacity: 0.65; transform: scale(0.95); }
  75% { opacity: 0.85; transform: scale(1.04); }
}

.writing-book {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) perspective(1200px) rotateX(3deg);
  width: 90%;
  height: 85%;
  display: flex;
  transform-style: preserve-3d;
}

.writing-spine {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 6px;
  transform: translateX(-50%);
  background: linear-gradient(to right,
    #3d2b1f 0%, #5a3d2e 30%, #8b6914 50%, #5a3d2e 70%, #3d2b1f 100%);
  z-index: 10;
  border-radius: 2px;
}

.writing-page {
  flex: 1;
  position: relative;
  background: linear-gradient(175deg, #f5e6c8 0%, #ede0c1 30%, #f0e4ca 60%, #e8d5a8 100%);
  overflow: hidden;
}

.writing-page-left {
  border-radius: 10px 0 0 10px;
  margin-right: 3px;
  box-shadow: inset -3px 0 8px rgba(0,0,0,0.06);
}

.writing-page-right {
  border-radius: 0 10px 10px 0;
  margin-left: 3px;
  box-shadow: inset 3px 0 8px rgba(0,0,0,0.06);
}

/* 纸页横线纹理 */
.writing-page::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.07;
  background-image: repeating-linear-gradient(
    0deg, transparent, transparent 26px, rgba(139,105,20,0.3) 26px, rgba(139,105,20,0.3) 27px
  );
  pointer-events: none;
}

.writing-page-left::after {
  content: '';
  position: absolute;
  right: 24px;
  top: 20px;
  bottom: 20px;
  width: 1px;
  background: rgba(139,105,20,0.1);
}

.writing-page-right::after {
  content: '';
  position: absolute;
  left: 24px;
  top: 20px;
  bottom: 20px;
  width: 1px;
  background: rgba(139,105,20,0.1);
}

.writing-area {
  position: absolute;
  top: 24px;
  bottom: 24px;
  left: 32px;
  right: 32px;
  font-family: 'Zhi Mang Xing', 'Ma Shan Zheng', 'STKaiti', 'KaiTi', cursive, serif;
  font-size: 17px;
  line-height: 1.9;
  letter-spacing: 0.04em;
  color: #2c2419;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.writing-written-line {
  position: relative;
  white-space: pre-wrap;
  word-break: break-all;
}

.writing-char {
  display: inline;
  transition: color 0.3s;
}

.writing-char.writing-fresh {
  color: #ffd700;
  text-shadow: 0 0 8px rgba(255,215,0,0.9), 0 0 18px rgba(255,215,0,0.5);
  animation: writing-ink-dry 1.8s ease-out forwards;
}

@keyframes writing-ink-dry {
  0% { color: #d4a017; text-shadow: 0 0 8px rgba(212,160,23,0.8), 0 0 16px rgba(212,160,23,0.4); }
  30% { color: #b8860b; text-shadow: 0 0 4px rgba(184,134,11,0.4); }
  100% { color: #3d2b1f; text-shadow: none; }
}

.writing-current-line {
  position: relative;
}

/* 羽毛笔 */
.writing-quill-container {
  position: absolute;
  pointer-events: none;
  z-index: 20;
  transition: left 0.12s ease-out, top 0.12s ease-out;
}

.writing-quill-inner {
  font-size: 30px;
  filter: drop-shadow(2px 3px 3px rgba(0,0,0,0.35));
  animation: writing-quill-wobble 1.2s ease-in-out infinite;
}

@keyframes writing-quill-wobble {
  0%, 100% { transform: rotate(-8deg) translateY(0); }
  25% { transform: rotate(-4deg) translateY(-2px); }
  50% { transform: rotate(-10deg) translateY(1px); }
  75% { transform: rotate(-3deg) translateY(-1px); }
}

/* 金色粒子 */
.writing-particle {
  position: absolute;
  pointer-events: none;
  z-index: 25;
  background: radial-gradient(circle, #ffd700, #c9a227);
  border-radius: 50%;
  animation: writing-particle-rise 0.9s ease-out forwards;
}

@keyframes writing-particle-rise {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0); }
}

/* 翻页过渡 */
.writing-page-right .writing-area {
  transition: opacity 0.35s ease;
}

.writing-page-right.writing-fading .writing-area {
  opacity: 0;
}

/* 状态栏 */
.writing-status-bar {
  text-align: center;
  color: rgba(201,162,39,0.7);
  font-size: 12px;
  letter-spacing: 0.1em;
  margin-top: 6px;
}

/* 移动端适配 */
@media (max-width: 768px) {
  .writing-scene { max-height: 340px; }
  .writing-area { font-size: 14px; line-height: 1.8; }
  .writing-page::before {
    background-image: repeating-linear-gradient(
      0deg, transparent, transparent 24px, rgba(139,105,20,0.3) 24px, rgba(139,105,20,0.3) 25px
    );
  }
}

@media (max-width: 480px) {
  .writing-scene { max-height: 260px; }
  .writing-area { font-size: 13px; line-height: 1.7; top: 16px; bottom: 16px; left: 20px; right: 20px; }
  .writing-quill-inner { font-size: 22px; }
}
