/* ══════════════════════════════════════════════════════════════
   style.css — 萬年曆 · Ten Thousand Year Calendar
   Responsive design: Mobile-first, scales gracefully to desktop.
   ══════════════════════════════════════════════════════════════ */

/* ─── Design Tokens ─────────────────────────────────────────── */
:root {
  --ink:        #130e08;
  --paper:      #f2e8d8;
  --gold:       #c9922a;
  --gold-light: #e0b050;
  --gold-dim:   rgba(201,146,42,0.15);
  --red:        #b83020;
  --jade:       #2e6e50;
  --indigo:     #1a2744;
  --ash:        #8a7860;
  --pale:       #faf4ea;
  --dim:        rgba(242,232,216,0.6);
  --border:     rgba(201,146,42,0.2);
  --border-dim: rgba(201,146,42,0.09);
  --sidebar-w:  240px;
  --topbar-h:   52px;
}

/* ─── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }
html { scroll-behavior:smooth; font-size:16px; }
body {
  background: var(--ink);
  color: var(--paper);
  font-family: 'Cormorant Garamond', Georgia, serif;
  overflow-x: hidden;
  line-height: 1.6;
}

/* Subtle grain texture */
body::after {
  content:'';
  position:fixed;
  inset:0;
  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.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events:none;
  z-index:9999;
  opacity:.3;
}

/* ─── Typography ────────────────────────────────────────────── */
.font-zh    { font-family: 'Noto Serif SC', serif; }
.font-mono  { font-family: 'Space Mono', monospace; }
.font-serif { font-family: 'Cormorant Garamond', Georgia, serif; }

h1,h2,h3 { font-weight: 300; line-height: 1.2; }

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-light); }

/* ─── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  z-index: 200;
  background: rgba(13,9,4,0.98);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s ease;
}

.site-logo {
  font-family: 'Noto Serif SC', serif;
  font-size: 1.5rem;
  color: var(--gold);
  padding: 1.5rem 1.4rem 1.1rem;
  border-bottom: 1px solid var(--border);
  display: block;
  line-height: 1;
  transition: color 0.2s;
}
.site-logo:hover { color: var(--gold-light); }
.site-logo-sub {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.65rem;
  font-style: italic;
  color: var(--ash);
  letter-spacing: 0.18em;
  margin-top: 0.35rem;
  display: block;
}

.nav-tabs {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(201,146,42,.2) transparent;
}
.nav-tabs::-webkit-scrollbar { width: 3px; }
.nav-tabs::-webkit-scrollbar-thumb { background: rgba(201,146,42,.2); }

.nav-section-divider {
  font-family: 'Space Mono', monospace;
  font-size: 0.42rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(201,146,42,0.35);
  padding: 0.8rem 1.4rem 0.25rem;
  display: block;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 1.4rem;
  font-family: 'Space Mono', monospace;
  font-size: 0.52rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ash);
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.2s;
  border-left: 2px solid transparent;
}
.nav-zh {
  font-family: 'Noto Serif SC', serif;
  font-size: 0.85rem;
  color: rgba(242,232,216,0.5);
  transition: color 0.2s, opacity 0.2s;
  text-transform: none;
  letter-spacing: 0.05em;
}
.nav-link:hover,
.nav-link.active {
  color: var(--gold);
  background: rgba(201,146,42,0.07);
  border-left-color: var(--gold);
}
.nav-link:hover .nav-zh,
.nav-link.active .nav-zh { color: var(--gold); opacity: 1; }

.nav-footer {
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--border-dim);
  font-size: 0.55rem;
  color: rgba(242,232,216,0.2);
  font-style: italic;
  line-height: 1.7;
}

/* ─── Mobile top-bar (hidden on desktop) ────────────────────── */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: rgba(13,9,4,0.98);
  border-bottom: 1px solid var(--border);
  z-index: 300;
  align-items: center;
  padding: 0 1rem;
  gap: 0.9rem;
}
.mobile-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gold);
  font-size: 1.3rem;
  padding: 0.3rem;
  line-height: 1;
}
.mobile-logo {
  font-family: 'Noto Serif SC', serif;
  font-size: 1.15rem;
  color: var(--gold);
}

/* Mobile overlay */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 199;
  transition: opacity 0.3s;
}
.overlay.show { display: block; }

/* ─── Main layout ───────────────────────────────────────────── */
.page-wrap {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

/* ─── Page hero header ──────────────────────────────────────── */
.page-hero {
  padding: 3.5rem 2.5rem 2rem;
  max-width: 1300px;
  margin: 0 auto;
}
.page-hero .ch {
  font-family: 'Noto Serif SC', serif;
  font-size: clamp(2.2rem, 5vw, 4.5rem);
  font-weight: 300;
  color: var(--gold);
  line-height: 1;
}
.page-hero .en {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: clamp(0.95rem, 1.8vw, 1.3rem);
  color: var(--ash);
  margin-top: 0.5rem;
  letter-spacing: 0.14em;
}
.page-hero .desc {
  max-width: 700px;
  font-size: 1.05rem;
  line-height: 1.9;
  color: var(--dim);
  margin-top: 1rem;
  font-style: italic;
}
.divider {
  width: 60px;
  height: 1px;
  background: linear-gradient(90deg, var(--gold), transparent);
  margin: 1.4rem 0;
}

/* ─── Container ─────────────────────────────────────────────── */
.container {
  max-width: 1300px;
  margin: 0 auto;
  padding: 0 2.5rem 4rem;
}

/* ─── Section labels ────────────────────────────────────────── */
.sec-label {
  font-family: 'Space Mono', monospace;
  font-size: 0.57rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}
.sec-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--border), transparent);
}

.sec-title {
  font-family: 'Noto Serif SC', serif;
  font-size: 1.5rem;
  font-weight: 300;
  color: var(--paper);
  margin-bottom: 1.2rem;
}
.sec-title span { color: var(--gold); }

.gap-block { margin-top: 2.8rem; }

/* ─── Info box ──────────────────────────────────────────────── */
.info-box {
  padding: 1.3rem 1.8rem;
  border-left: 3px solid var(--gold);
  background: rgba(201,146,42,0.05);
  margin: 1.2rem 0;
  font-size: 0.95rem;
  line-height: 1.9;
  color: var(--dim);
  font-style: italic;
}
.info-box strong { color: var(--gold); font-style: normal; }

/* ─── Cards ─────────────────────────────────────────────────── */
.card {
  padding: 1.6rem;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.018);
  transition: border-color 0.3s, background 0.3s;
}
.card:hover {
  border-color: rgba(201,146,42,0.45);
  background: rgba(201,146,42,0.04);
}
.card-clickable { cursor: pointer; }

/* ─── Grids ─────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.4rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 1.4rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 1.2rem; }
.grid-5 { display: grid; grid-template-columns: repeat(5,1fr); gap: 1rem; }

/* ─── Tables ────────────────────────────────────────────────── */
.scroll-table { overflow-x: auto; }
.scroll-table::-webkit-scrollbar { height: 4px; }
.scroll-table::-webkit-scrollbar-track { background: rgba(255,255,255,.02); }
.scroll-table::-webkit-scrollbar-thumb { background: rgba(201,146,42,.3); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
th {
  font-family: 'Space Mono', monospace;
  font-size: 0.52rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  padding: 0.8rem 1rem;
  border: 1px solid var(--border-dim);
  background: rgba(201,146,42,0.07);
  text-align: left;
  white-space: nowrap;
}
td {
  padding: 0.65rem 1rem;
  border: 1px solid var(--border-dim);
  color: var(--dim);
  vertical-align: top;
}
tr:hover td { background: rgba(201,146,42,0.03); }
.ch-cell { font-family: 'Noto Serif SC', serif; font-size: 1.2rem; color: var(--gold); }
.ch-sm   { font-family: 'Noto Serif SC', serif; font-size: 1rem;   color: var(--paper); }
.fw7 { font-weight: 600; }

/* ─── Element colour classes ────────────────────────────────── */
.wood  { color: #4caf7d; }
.fire  { color: #e05a4a; }
.earth { color: var(--gold); }
.metal { color: #c0c0c8; }
.water { color: #5a9fd4; }

/* ─── Tags ──────────────────────────────────────────────────── */
.tag {
  display: inline-block;
  padding: 0.22rem 0.65rem;
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-style: italic;
  color: var(--dim);
  margin: 0.2rem;
}

/* ─── Interaction pairs ─────────────────────────────────────── */
.pair {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border-dim);
}
.pair:last-child { border: none; }
.pair .ch  { font-family: 'Noto Serif SC', serif; font-size: 1.2rem; color: var(--paper); min-width: 90px; }
.pair .arr { color: var(--red); font-size: 1rem; }
.pair .res { font-size: 0.9rem; font-style: italic; color: var(--dim); }

/* ─── Pillar display ────────────────────────────────────────── */
.pillars { display: flex; justify-content: center; gap: 0; margin: 2rem 0; flex-wrap: wrap; }
.pillar  { width: 110px; border: 1px solid var(--border); text-align: center; margin: 0 -0.5px; }
.pillar-top    { padding: 0.5rem; background: rgba(201,146,42,.1); font-family: 'Space Mono',monospace; font-size: 0.48rem; letter-spacing: .1em; color: var(--ash); border-bottom: 1px solid var(--border); }
.pillar-stem   { padding: 1.3rem 0; font-family: 'Noto Serif SC',serif; font-size: 2rem; color: var(--gold); border-bottom: 1px solid var(--border-dim); }
.pillar-branch { padding: 1.3rem 0; font-family: 'Noto Serif SC',serif; font-size: 2rem; color: var(--paper); }
.pillar-bot    { padding: 0.4rem; background: rgba(0,0,0,.2); border-top: 1px solid var(--border-dim); font-size: 0.58rem; font-style: italic; color: rgba(242,232,216,.35); }

/* ─── Lo Shu grid ───────────────────────────────────────────── */
.lo-shu { display: grid; grid-template-columns: repeat(3,80px); gap: 2px; margin: 1.5rem auto; }
.lo-cell {
  width: 80px; height: 80px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.02);
}
.lo-num { font-family: 'Cormorant Garamond', serif; font-size: 2rem; font-weight: 300; }
.lo-dir { font-family: 'Space Mono', monospace; font-size: 0.42rem; color: var(--ash); margin-top: .2rem; }

/* ─── Hexagram grid ─────────────────────────────────────────── */
.hex-grid { display: grid; grid-template-columns: repeat(8,1fr); gap: 1px; border: 1px solid var(--border); }
.hex-cell { padding: 0.55rem 0.35rem; border: 1px solid var(--border-dim); text-align: center; cursor: default; transition: background .2s; }
.hex-cell:hover { background: rgba(201,146,42,.07); }
.hex-ch { font-family: 'Noto Serif SC', serif; font-size: 0.7rem; color: var(--gold); line-height: 1.3; }
.hex-en { font-size: 0.5rem; color: rgba(242,232,216,.35); margin-top: .15rem; }

/* ─── Flying Star controls ──────────────────────────────────── */
.fs-controls { margin: 1rem 0 1.5rem; display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; }
.fs-ctrl-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.fs-ctrl-row label { font-family: 'Space Mono', monospace; font-size: 0.58rem; letter-spacing: .1em; color: var(--ash); text-transform: uppercase; }
.fs-btn {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ash);
  font-family: 'Space Mono', monospace;
  font-size: 0.62rem;
  cursor: pointer;
  transition: all .2s;
}
.fs-btn:hover, .fs-btn-active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(201,146,42,.08);
}
.fs-chart { display: grid; grid-template-columns: repeat(3,1fr); gap: 2px; max-width: 480px; margin: 0 auto; }
.fs-cell {
  padding: 1rem 0.5rem;
  border: 1px solid var(--border-dim);
  text-align: center;
  background: rgba(255,255,255,.015);
}
.fs-cell-nums { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.3rem; font-family: 'Cormorant Garamond', serif; font-size: 1.4rem; }
.fs-mstar { color: #5a9fd4; }
.fs-base  { font-size: 0.7rem; color: rgba(242,232,216,.3); align-self: center; }
.fs-wstar { color: #e05a4a; }
.fs-dir   { font-family: 'Space Mono', monospace; font-size: 0.42rem; letter-spacing: .1em; color: rgba(242,232,216,.3); }

/* ─── Hero page ─────────────────────────────────────────────── */
.hero-bg {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  position: relative; overflow: hidden;
  padding: 6rem 2rem 4rem;
}
.hero-ring {
  position: absolute;
  border: 1px solid rgba(201,146,42,.06);
  border-radius: 50%;
}
.hero-ring:nth-child(1) { width: 500px; height: 500px; animation: spin 120s linear infinite; }
.hero-ring:nth-child(2) { width: 750px; height: 750px; animation: spin 200s linear infinite reverse; }
.hero-ring:nth-child(3) { width: 1000px; height: 1000px; animation: spin 280s linear infinite; }
@keyframes spin { from { transform:rotate(0deg) } to { transform:rotate(360deg) } }

.hero-ch {
  font-family: 'Noto Serif SC', serif;
  font-size: clamp(5rem, 15vw, 11rem);
  font-weight: 300;
  color: var(--gold);
  letter-spacing: .4em;
  text-shadow: 0 0 80px rgba(201,146,42,.2);
  position: relative;
  animation: fadeUp 1.2s forwards;
}
.hero-en {
  font-style: italic;
  font-size: clamp(0.85rem, 2.2vw, 1.3rem);
  color: var(--ash);
  letter-spacing: .28em;
  animation: fadeUp 1.2s forwards .4s; opacity: 0;
}
.hero-line {
  width: 80px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  margin: 1.8rem auto;
  animation: fadeUp 1s forwards .7s; opacity: 0;
}
.hero-p {
  max-width: 560px;
  text-align: center;
  font-size: 1.05rem;
  line-height: 1.9;
  color: var(--dim);
  font-style: italic;
  animation: fadeUp 1s forwards 1s; opacity: 0;
}
@keyframes fadeUp {
  from { opacity:0; transform:translateY(18px) }
  to   { opacity:1; transform:translateY(0) }
}

/* ─── Calendar search ───────────────────────────────────────── */
.cal-search {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.cal-search input {
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  color: var(--paper);
  font-family: 'Space Mono', monospace;
  font-size: 0.78rem;
  padding: 0.55rem 1rem;
  outline: none;
  transition: border-color .2s;
  width: 160px;
}
.cal-search input:focus { border-color: var(--gold); }
.cal-search input::placeholder { color: var(--ash); }
.cal-search label { font-family: 'Space Mono', monospace; font-size: 0.55rem; letter-spacing: .12em; color: var(--ash); text-transform: uppercase; }

/* ─── Print-friendly data table ─────────────────────────────── */
.data-table-wrap { overflow-x: auto; border: 1px solid var(--border); }
.data-table-wrap table td, .data-table-wrap table th { font-size: 0.82rem; padding: 0.6rem 0.9rem; }

/* ─── Responsive breakpoints ────────────────────────────────── */
@media (max-width: 1100px) {
  :root { --sidebar-w: 200px; }
  .grid-4 { grid-template-columns: repeat(2,1fr); }
  .grid-5 { grid-template-columns: repeat(3,1fr); }
}

@media (max-width: 860px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .hex-grid { grid-template-columns: repeat(4,1fr); }
}

@media (max-width: 650px) {
  /* Sidebar off-canvas on mobile */
  .sidebar {
    transform: translateX(-100%);
    width: 260px;
    z-index: 400;
  }
  .sidebar.open { transform: translateX(0); }

  .mobile-topbar { display: flex; }

  .page-wrap {
    margin-left: 0;
    padding-top: var(--topbar-h);
  }

  .page-hero { padding: 2rem 1.2rem 1.2rem; }
  .container { padding: 0 1.2rem 3rem; }

  .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }
  .hex-grid { grid-template-columns: repeat(4,1fr); }
  .lo-shu   { grid-template-columns: repeat(3,70px); }
  .lo-cell  { width: 70px; height: 70px; }
  .pillars  { gap: 0.4rem; }
  .pillar   { width: 90px; }
  .pillar-stem, .pillar-branch { font-size: 1.6rem; padding: 1rem 0; }
  .fs-chart { max-width: 100%; }
}

@media (max-width: 400px) {
  .hero-ch { letter-spacing: .2em; }
  .hex-grid { grid-template-columns: repeat(3,1fr); }
}
