:root {
  --bg-0: #05060c;
  --bg-1: #0d1024;
  --gold: #e9c46a;
  --gold-soft: #f4d58d;
  --ink: #f5f1e6;
  --ink-dim: #b9b3a3;
  --line: rgba(233, 196, 106, 0.28);
  --panel-bg: rgba(12, 14, 28, 0.92);
  --yang: #e9c46a;
  --yin: #8fb3c9;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 30%, var(--bg-1), var(--bg-0) 70%);
  color: var(--ink);
  font-family: "Noto Serif SC", "Cinzel", serif;
  -webkit-font-smoothing: antialiased;
}

#scene-container {
  position: fixed;
  inset: 0;
  z-index: 1;
}
#scene-container canvas { display: block; }

/* ---------- Language visibility ---------- */
body[data-lang="en"] .cn-only { display: none; }
body[data-lang="zh"] .en-only { display: none; }

/* ---------- Loader ---------- */
#loader {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: radial-gradient(ellipse at 50% 40%, var(--bg-1), var(--bg-0) 75%);
  transition: opacity 0.8s ease;
}
#loader.gone { opacity: 0; pointer-events: none; }
.taiji {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #f5f1e6 0 50%, #0d1024 50% 100%);
  box-shadow: 0 0 40px rgba(233, 196, 106, 0.35);
  animation: spin 3.4s linear infinite;
  position: relative;
}
.taiji::before, .taiji::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  transform: translateX(-50%);
}
.taiji::before { top: 0; background: #f5f1e6; }
.taiji::after  { bottom: 0; background: #0d1024; }
.loader-text {
  font-family: "Cinzel", "Noto Serif SC", serif;
  letter-spacing: 0.35em;
  color: var(--gold-soft);
  font-size: 1.1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Top bar ---------- */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  background: linear-gradient(to bottom, rgba(5,6,12,0.75), rgba(5,6,12,0));
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-symbol {
  font-size: 1.7rem;
  color: var(--gold);
  text-shadow: 0 0 14px rgba(233,196,106,0.6);
}
.brand-title {
  font-family: "Ma Shan Zheng", "Cinzel", serif;
  font-size: 1.5rem;
  color: var(--gold-soft);
  letter-spacing: 0.06em;
  white-space: nowrap;
}
body[data-lang="en"] .brand-title { font-family: "Cinzel", serif; font-size: 1.25rem; }

.controls { display: flex; align-items: center; gap: 10px; }
#search {
  width: 210px;
  max-width: 44vw;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.35);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
#search:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(233,196,106,0.18);
}
#search::placeholder { color: var(--ink-dim); }

.btn {
  padding: 9px 15px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(233,196,106,0.08);
  color: var(--gold-soft);
  font-family: inherit;
  font-size: 0.88rem;
  letter-spacing: 0.05em;
  cursor: pointer;
  white-space: nowrap;
  transition: background .2s, transform .1s;
}
.btn:hover { background: rgba(233,196,106,0.2); }
.btn:active { transform: scale(0.96); }

/* ---------- Hint ---------- */
#hint {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  color: var(--ink-dim);
  font-size: 0.82rem;
  letter-spacing: 0.05em;
  text-align: center;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(5,6,12,0.4);
  border: 1px solid rgba(255,255,255,0.06);
  transition: opacity .5s;
}
#hint.hidden { opacity: 0; }

/* ---------- Detail panel ---------- */
#panel {
  position: fixed;
  top: 0; right: 0;
  z-index: 30;
  width: min(420px, 92vw);
  height: 100%;
  background: var(--panel-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 50px rgba(0,0,0,0.5);
  padding: 64px 30px 40px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.45s cubic-bezier(.4,.9,.3,1);
}
#panel:not(.hidden) { transform: translateX(0); }
#panel-close {
  position: absolute;
  top: 16px; right: 18px;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--gold-soft);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background .2s;
}
#panel-close:hover { background: rgba(233,196,106,0.15); }

.hx-head { display: flex; align-items: flex-start; gap: 18px; margin-bottom: 18px; }
.hx-number {
  font-family: "Cinzel", serif;
  font-size: 2.6rem;
  color: var(--gold);
  line-height: 1;
  min-width: 64px;
}
.hx-number small { display: block; font-size: 0.7rem; color: var(--ink-dim); letter-spacing: .2em; }
.hx-names { flex: 1; }
.hx-cn {
  font-family: "Ma Shan Zheng", serif;
  font-size: 2.4rem;
  color: var(--gold-soft);
  line-height: 1.1;
}
.hx-py { color: var(--ink-dim); font-style: italic; margin-top: 2px; }
.hx-en { color: var(--ink); font-family: "Cinzel", serif; font-size: 1.05rem; margin-top: 4px; }

/* Big hexagram glyph */
.hx-glyph {
  display: flex;
  flex-direction: column-reverse; /* bottom line first */
  gap: 7px;
  align-items: center;
  padding: 22px 0;
  margin: 4px 0 20px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.hx-line { display: flex; gap: 10px; height: 13px; }
.hx-seg {
  width: 74px;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  box-shadow: 0 0 10px rgba(233,196,106,0.35);
}
.hx-line.yin .hx-seg { width: 32px; }

.hx-trigrams {
  display: flex;
  gap: 10px;
  margin-bottom: 22px;
}
.tg {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
}
.tg-role { font-size: 0.72rem; letter-spacing: .18em; color: var(--ink-dim); text-transform: uppercase; }
.tg-name { font-family: "Ma Shan Zheng", serif; font-size: 1.5rem; color: var(--gold-soft); }
.tg-en { font-size: 0.82rem; color: var(--ink-dim); }

.details-btn {
  display: block;
  width: 100%;
  margin: 0 0 22px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--gold);
  background: linear-gradient(180deg, rgba(233,196,106,0.16), rgba(233,196,106,0.06));
  color: var(--gold-soft);
  font-family: "Cinzel", "Noto Serif SC", serif;
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: background .2s, transform .1s;
}
.details-btn:hover { background: rgba(233,196,106,0.26); }
.details-btn:active { transform: scale(0.98); }

.hx-desc .lang-block { margin-bottom: 22px; }
.hx-desc .lang-block + .lang-block {
  padding-top: 18px;
  border-top: 1px dashed rgba(233,196,106,0.22);
}
.hx-desc h4 {
  font-size: 0.74rem;
  letter-spacing: .2em;
  color: var(--gold);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.hx-desc p {
  color: var(--ink);
  font-size: 1rem;
  margin: 0;
}
.hx-desc p[lang="zh"] { line-height: 1.9; }
.hx-desc p[lang="en"] { line-height: 1.7; font-family: "Cinzel", "Noto Serif SC", serif; }

/* ---------- Details modal ---------- */
#modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 4, 10, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-box {
  position: relative;
  width: min(720px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  padding: 40px 36px 36px;
  border-radius: 18px;
  background: linear-gradient(180deg, #12142a, #0a0b16);
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  animation: modalIn .35s cubic-bezier(.3,.9,.3,1);
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
#modal-close {
  position: absolute;
  top: 14px; right: 16px;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--gold-soft);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  transition: background .2s;
}
#modal-close:hover { background: rgba(233,196,106,0.15); }

.md-head { display: flex; align-items: flex-start; gap: 18px; margin-bottom: 6px; padding-right: 40px; }
.md-num { font-family: "Cinzel", serif; font-size: 2.4rem; color: var(--gold); line-height: 1; }
.md-cn { font-family: "Ma Shan Zheng", serif; font-size: 2.2rem; color: var(--gold-soft); }
.md-py { color: var(--ink-dim); font-style: italic; }
.md-en { font-family: "Cinzel", serif; color: var(--ink); font-size: 1rem; }

.md-section { border-top: 1px solid var(--line); padding: 18px 0; }
.md-section h3 {
  font-size: 0.8rem;
  letter-spacing: .18em;
  color: var(--gold);
  text-transform: uppercase;
  margin-bottom: 12px;
}
.md-classic {
  font-family: "Noto Serif SC", serif;
  font-size: 1.22rem;
  line-height: 2;
  color: var(--gold-soft);
  margin-bottom: 10px;
}
.md-trans { color: var(--ink); line-height: 1.7; font-family: "Cinzel", "Noto Serif SC", serif; }
.md-cnpara { color: var(--ink); line-height: 1.9; margin-bottom: 10px; }
.md-enpara { color: var(--ink-dim); line-height: 1.7; font-family: "Cinzel", "Noto Serif SC", serif; }

@media (max-width: 640px) {
  .modal-box { padding: 36px 20px 26px; }
  .md-classic { font-size: 1.05rem; }
}

#credit {
  position: fixed;
  bottom: 18px; left: 20px;
  z-index: 12;
  color: var(--ink-dim);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  opacity: 0.7;
}

#author {
  position: fixed;
  bottom: 18px; right: 22px;
  z-index: 12;
  color: var(--gold-soft);
  font-family: "Cinzel", "Noto Serif SC", serif;
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  opacity: 0.85;
  text-shadow: 0 0 12px rgba(233,196,106,0.35);
  pointer-events: none;
}

@media (max-width: 640px) {
  .brand-title { font-size: 1.15rem; }
  #search { width: 130px; }
  #credit { display: none; }
  #hint { font-size: 0.72rem; width: 90%; }
}
