/* ============================================
   唐诗时光长河 — 全局样式
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --gold-bright: #f5d89a;
  --gold-core: #d4a44c;
  --gold-dark: #a07830;
  --gold-dim: #6b5020;
  --bg-dark: #0a0806;
  --bg-deep: #050a15;
  --panel-bg: rgba(12, 10, 8, 0.88);
  --panel-border: rgba(212, 164, 76, 0.4);
  --text-primary: #e8dcc8;
  --text-secondary: #a89878;
  --text-gold: #d4a44c;
  --font-serif: 'Noto Serif SC', 'Songti SC', 'SimSun', serif;
  --font-cursive: 'Ma Shan Zheng', 'KaiTi', cursive;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-dark);
  font-family: var(--font-serif);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* --- 3D Container --- */
#container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* --- Labels Container --- */
#labels-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}

/* --- Poet Label --- */
.poet-label {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: center bottom;
  white-space: nowrap;
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 42px;
  color: var(--gold-bright);
  text-shadow:
    0 0 15px rgba(0, 0, 0, 1),
    0 0 8px rgba(0, 0, 0, 1),
    0 0 10px rgba(212, 164, 76, 0.9),
    0 0 20px rgba(212, 164, 76, 0.5);
  letter-spacing: 2px;
  opacity: 0.9;
  transition: opacity 0.6s ease, transform 0.6s ease, text-shadow 0.6s ease, font-size 0.3s ease;
  pointer-events: none;
  user-select: none;
}

.poet-label.dimmed {
  opacity: 0.12;
  text-shadow: none;
}

.poet-label.highlighted {
  opacity: 1;
  font-size: 56px;
  color: #fff;
  text-shadow:
    0 0 20px rgba(0, 0, 0, 1),
    0 0 15px rgba(255, 220, 140, 1),
    0 0 40px rgba(212, 164, 76, 0.9);
}

/* --- Loading Screen --- */
#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  background: radial-gradient(ellipse at center, #120e08 0%, #0a0806 50%, #050a15 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 1.5s ease, visibility 1.5s ease;
}

#loading-screen.fade-out {
  opacity: 0;
  visibility: hidden;
}

#loading-content {
  text-align: center;
}

.loading-title {
  font-family: var(--font-cursive);
  font-size: clamp(48px, 8vw, 96px);
  color: var(--gold-bright);
  letter-spacing: 16px;
  text-shadow:
    0 0 30px rgba(212, 164, 76, 0.6),
    0 0 60px rgba(212, 164, 76, 0.3),
    0 0 100px rgba(212, 164, 76, 0.1);
  animation: titlePulse 3s ease-in-out infinite;
  margin-bottom: 16px;
}

.loading-subtitle {
  font-family: var(--font-serif);
  font-size: clamp(14px, 2vw, 20px);
  color: var(--text-secondary);
  letter-spacing: 8px;
  margin-bottom: 40px;
  opacity: 0;
  animation: subtitleFadeIn 2s ease forwards 0.5s;
}

.loading-bar {
  width: 200px;
  height: 2px;
  background: rgba(212, 164, 76, 0.15);
  border-radius: 1px;
  margin: 0 auto;
  overflow: hidden;
}

.loading-progress {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--gold-dark), var(--gold-bright), var(--gold-dark));
  border-radius: 1px;
  animation: loadingFill 2.5s ease forwards 0.3s;
}

@keyframes titlePulse {
  0%, 100% { text-shadow: 0 0 30px rgba(212, 164, 76, 0.6), 0 0 60px rgba(212, 164, 76, 0.3); }
  50% { text-shadow: 0 0 40px rgba(212, 164, 76, 0.8), 0 0 80px rgba(212, 164, 76, 0.4), 0 0 120px rgba(212, 164, 76, 0.2); }
}

@keyframes subtitleFadeIn {
  to { opacity: 0.7; }
}

@keyframes loadingFill {
  to { width: 100%; }
}

/* ============================================
   中央诗人面板（居中弹出）
   ============================================ */
#panel-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}

#panel-overlay.active {
  pointer-events: auto;
  opacity: 1;
}

#poet-panel {
  position: relative;
  width: 420px;
  max-width: 85vw;
  max-height: 70vh;
  background: var(--panel-bg);
  backdrop-filter: blur(30px) saturate(130%);
  -webkit-backdrop-filter: blur(30px) saturate(130%);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow:
    0 0 60px rgba(0, 0, 0, 0.6),
    0 0 30px rgba(212, 164, 76, 0.08),
    inset 0 1px 0 rgba(212, 164, 76, 0.1);
  padding: 36px 32px 28px;
  overflow-y: auto;
  overflow-x: hidden;
  transform: scale(0.85) translateY(20px);
  opacity: 0;
  transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.4s ease;
}

#panel-overlay.active #poet-panel {
  transform: scale(1) translateY(0);
  opacity: 1;
}

/* Scrollbar */
#poet-panel::-webkit-scrollbar {
  width: 4px;
}
#poet-panel::-webkit-scrollbar-track {
  background: transparent;
}
#poet-panel::-webkit-scrollbar-thumb {
  background: var(--gold-dim);
  border-radius: 2px;
}

/* Close button */
#panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(212, 164, 76, 0.2);
  background: rgba(212, 164, 76, 0.05);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  z-index: 51;
}

#panel-close:hover {
  background: rgba(212, 164, 76, 0.15);
  color: var(--gold-bright);
  border-color: var(--gold-core);
  transform: rotate(90deg);
}

/* Panel Header */
.panel-header {
  text-align: center;
  margin-bottom: 20px;
}

#poet-name {
  font-family: var(--font-cursive);
  font-size: 38px;
  color: var(--gold-bright);
  letter-spacing: 8px;
  margin-bottom: 6px;
  text-shadow: 0 0 20px rgba(212, 164, 76, 0.3);
}

#poet-courtesy {
  font-size: 14px;
  color: var(--text-secondary);
  letter-spacing: 2px;
  display: block;
  margin-bottom: 6px;
}

#poet-years {
  font-size: 14px;
  color: var(--gold-dark);
  letter-spacing: 1px;
  margin-bottom: 4px;
}

#poet-era {
  display: inline-block;
  font-size: 12px;
  color: var(--gold-core);
  letter-spacing: 2px;
  padding: 3px 14px;
  border: 1px solid rgba(212, 164, 76, 0.25);
  border-radius: 12px;
  margin-top: 6px;
}

/* Panel Divider */
.panel-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--panel-border), transparent);
  margin: 16px 0;
}

/* Panel Body */
#poet-bio {
  font-size: 14px;
  line-height: 2;
  color: var(--text-primary);
  text-align: justify;
  letter-spacing: 0.5px;
}

/* Panel Works — clickable title list */
.panel-works h3 {
  font-family: var(--font-cursive);
  font-size: 20px;
  color: var(--gold-core);
  letter-spacing: 4px;
  margin-bottom: 14px;
  text-align: center;
}

.work-title-btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 8px;
  background: rgba(212, 164, 76, 0.04);
  border: 1px solid rgba(212, 164, 76, 0.12);
  border-radius: 8px;
  color: var(--gold-bright);
  font-family: var(--font-cursive);
  font-size: 18px;
  letter-spacing: 3px;
  cursor: pointer;
  text-align: center;
  transition: all 0.3s ease;
}

.work-title-btn:hover {
  background: rgba(212, 164, 76, 0.12);
  border-color: rgba(212, 164, 76, 0.35);
  text-shadow: 0 0 12px rgba(212, 164, 76, 0.4);
  transform: scale(1.02);
}

.work-title-btn:active {
  transform: scale(0.98);
}

/* ============================================
   右侧诗文展示面板（打字机效果）
   ============================================ */
#poem-display {
  position: fixed;
  top: 0;
  right: 0;
  width: fit-content;
  min-width: 50vw;
  max-width: 90vw;
  height: 100vh;
  z-index: 60;
  background: linear-gradient(90deg, rgba(8, 6, 4, 0) 0%, rgba(8, 6, 4, 0.95) 15%, rgba(8, 6, 4, 0.98) 100%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-start;
  align-items: stretch;
  padding: 0 20px 0 40px;
  gap: 40px;
  transform: translateX(100%);
  opacity: 0;
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.5s ease;
  pointer-events: none;
}

#poem-display.active {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

#poem-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(212, 164, 76, 0.2);
  background: rgba(212, 164, 76, 0.05);
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  z-index: 61;
}

#poem-close:hover {
  background: rgba(212, 164, 76, 0.15);
  color: var(--gold-bright);
  border-color: var(--gold-core);
  transform: rotate(90deg);
}

#poem-header {
  flex-shrink: 0;
  border-left: 1px solid rgba(212, 164, 76, 0.15);
  padding-left: 30px;
  writing-mode: vertical-rl;
  display: flex;
  justify-content: center;
  align-items: center;
}

#poem-title {
  font-family: var(--font-cursive);
  font-size: 32px;
  color: var(--gold-bright);
  letter-spacing: 8px;
  text-align: center;
  text-shadow: 0 0 15px rgba(212, 164, 76, 0.3);
  margin-right: 20px; /* spacing between title and author in vertical mode */
}

#poem-author {
  font-size: 15px;
  color: var(--text-secondary);
  letter-spacing: 5px;
  text-align: center;
}

#poem-body {
  display: flex;
  flex-direction: row-reverse;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
  height: 100vh; /* Use full viewport height */
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0;
  scroll-behavior: smooth;
}

/* Custom Scrollbar at the very bottom */
#poem-body::-webkit-scrollbar {
  height: 6px;
}
#poem-body::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.3);
}
#poem-body::-webkit-scrollbar-thumb {
  background: var(--gold-dark);
  border-radius: 0;
}

/* Each column of text (traditional vertical Chinese) */
.poem-column {
  writing-mode: vertical-rl;
  font-family: var(--font-serif);
  font-size: 20px;
  line-height: 2.2;
  letter-spacing: 4px;
  color: var(--text-primary);
  max-height: 70vh;
  flex-shrink: 0;
}

/* Individual character in typewriter animation */
.poem-char {
  display: inline;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.poem-char.visible {
  opacity: 1;
}

/* ============================================
   操作提示
   ============================================ */
#hint {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  font-size: 13px;
  color: var(--text-secondary);
  letter-spacing: 2px;
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
  text-shadow: 0 0 10px rgba(0,0,0,0.8);
  animation: hintFadeIn 3s ease forwards 3s;
}

@keyframes hintFadeIn {
  from { opacity: 0; }
  to { opacity: 0.5; }
}

#hint.hidden {
  opacity: 0;
}

/* --- Title Overlay --- */
#title-overlay {
  position: fixed;
  top: 24px;
  left: 32px;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  animation: overlayFadeIn 2s ease forwards 3.5s;
}

#title-overlay h1 {
  font-family: var(--font-cursive);
  font-size: 28px;
  color: var(--gold-bright);
  letter-spacing: 8px;
  text-shadow: 0 0 20px rgba(212, 164, 76, 0.3);
  opacity: 0.6;
}

#title-overlay .era-range {
  font-size: 12px;
  color: var(--text-secondary);
  letter-spacing: 3px;
  margin-top: 4px;
  opacity: 0.4;
}

@keyframes overlayFadeIn {
  to { opacity: 1; }
}

/* --- UI Sand Particles --- */
.ui-sand-particle {
  position: fixed;
  background: var(--gold-bright);
  border-radius: 50%;
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 0 6px var(--gold-core);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  #poet-panel {
    width: 92vw;
    padding: 28px 20px 20px;
  }

  #poem-display {
    width: 80vw;
    padding: 40px 20px;
  }

  .poet-label {
    font-size: 24px;
  }

  #title-overlay h1 {
    font-size: 22px;
  }
}

/* --- Sand texture overlay --- */
#container::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    radial-gradient(1px 1px at 20% 30%, rgba(212, 164, 76, 0.03) 50%, transparent 100%),
    radial-gradient(1px 1px at 80% 70%, rgba(212, 164, 76, 0.02) 50%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}
