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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", "Songti SC", serif;
  background: #1a1a24;
  color: #e0d8c8;
}

/* ── Canvas Container ── */
#canvas-container {
  width: 100%; height: 100%;
  position: relative;
}

/* ── Top Bar ── */
#top-bar {
  position: absolute; top: 14px; right: 20px;
  z-index: 5; display: flex; gap: 10px;
}
#top-bar button {
  width: 38px; height: 38px;
  border-radius: 50%; border: 1px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.4); color: #ddd;
  font-size: 1.1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
  transition: background 0.2s;
}
#top-bar button:hover { background: rgba(255,255,255,0.12); }
#top-bar.hidden { opacity: 0; pointer-events: none; transition: opacity 0.2s; }

/* ── Loading ── */
#loading {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.2rem;
  color: #887766;
  pointer-events: none;
  z-index: 2;
}

/* ── CSS2D Labels ── */
.hex-label {
  color: #d4c8a8;
  font-size: 13px;
  font-weight: bold;
  text-shadow: 0 0 8px rgba(0,0,0,0.8);
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
}

/* ── Detail Panel (floating, no full-screen overlay) ── */
#detail-overlay {
  position: absolute; top: 0; right: 0;
  width: 0; height: 100%;
  z-index: 10;
  pointer-events: none;
}
#detail-overlay.hidden {
  overflow: hidden;
  visibility: hidden;
}
#detail-overlay:not(.hidden) { pointer-events: auto; }

#detail-panel {
  position: absolute; top: 0; right: 0;
  width: 480px; max-width: 92vw; height: 100%;
  background: #1e1e30;
  border-left: 2px solid #3a3a5a;
  box-shadow: -8px 0 30px rgba(0,0,0,0.6);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 2rem 2rem 3rem;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.22, 0.61, 0.36, 1);
}
#detail-overlay:not(.hidden) #detail-panel {
  transform: translateX(0);
}

#detail-close {
  position: absolute; top: 0.8rem; right: 1rem;
  background: none; border: none;
  color: #887766; font-size: 1.8rem;
  cursor: pointer;
  line-height: 1;
}
#detail-close:hover { color: #d4c8a8; }

/* ── Detail Content ── */
.detail-header {
  text-align: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid #333355;
}
.detail-name {
  font-size: 2.6rem;
  font-weight: bold;
  color: #6ee0b0;
  margin-bottom: 0.3rem;
}
.detail-number {
  font-size: 0.9rem;
  color: #887766;
}
.detail-trigrams {
  font-size: 1.1rem;
  color: #8ad0b0;
  margin-top: 0.3rem;
  font-weight: bold;
}
.detail-trigrams-sub {
  font-size: 0.8rem;
  color: #665544;
  margin-top: 0.15rem;
}

.detail-section {
  margin-bottom: 1.5rem;
}
.section-title {
  font-size: 0.8rem;
  color: #887766;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.4rem;
  padding-left: 0.3rem;
  border-left: 2px solid #6ee0b0;
}
.section-text {
  font-size: 1rem;
  line-height: 2.0;
  color: #c8c0b0;
  padding: 0.2rem 0.5rem;
  overflow-wrap: break-word;
  word-break: break-all;
}

/* ── Line Items ── */
.lines-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.detail-line {
  display: flex;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: 4px;
  background: rgba(255,255,255,0.03);
}
.detail-line > div {
  min-width: 0;
  flex: 1;
}
.detail-line.extra {
  border-top: 1px dashed #333355;
  margin-top: 0.3rem;
  padding-top: 0.7rem;
}
.line-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  width: 1.4rem;
  text-align: center;
}
.line-yang .line-icon { color: #6ee0b0; }
.line-yin .line-icon { color: #55c898; }
.extra .line-icon { color: #887766; }

.line-name {
  font-size: 0.75rem;
  color: #887766;
  margin-bottom: 0.15rem;
}
.line-text {
  font-size: 0.95rem;
  line-height: 1.8;
  color: #c8c0b0;
  overflow-wrap: break-word;
}
.line-xiang {
  font-size: 0.85rem;
  color: #887766;
  margin-top: 0.2rem;
  font-style: italic;
  overflow-wrap: break-word;
}

/* ── Wenyan ── */
.wenyan {
  font-size: 0.9rem;
  color: #b0a898;
}

/* ── Scrollbar ── */
#detail-panel::-webkit-scrollbar { width: 4px; }
#detail-panel::-webkit-scrollbar-track { background: transparent; }
#detail-panel::-webkit-scrollbar-thumb { background: #333355; border-radius: 2px; }

/* ── Responsive ── */
@media (max-width: 600px) {
  #detail-overlay:not(.hidden) {
    width: 100%;
    background: rgba(0,0,0,0.35);
    pointer-events: auto;
  }
  #detail-panel {
    width: 88vw;
    padding: 1.5rem 1.2rem 2rem;
  }
  .detail-name { font-size: 2rem; }
}


/* ── Trigram Labels ── */
.trigram-label {
  color: #556677;
  font-size: 11px;
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
}


/* ── Mobile tweaks ── */
@media (max-width: 600px) {
  #top-bar { top: 8px; right: 10px; gap: 6px; }
  #top-bar button { width: 32px; height: 32px; font-size: 0.95rem; }
}

/* ── Prevent body scroll when panel open ── */
body.panel-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}
