/* ==========================================================================
   theme.css — Nimitr Tarot shared design tokens
   ใช้ร่วมกันระหว่าง index.html / room.html / library.html
   ========================================================================== */

/* ฟ้อนต์หลักของทั้งเว็บ: Anuphan รองรับภาษาไทย+อังกฤษครบถ้วน */
@import url('https://fonts.googleapis.com/css2?family=Anuphan:wght@100..700&display=swap');

/* ===== TOKENS ===== */
:root {
  --bg:        #0d0820;
  --surface:   #1a1245;
  --mid:       #2d1f6e;
  --gold:      #c9a55f;
  --gold-lt:   #e8d5a3;
  --gold-dim:  rgba(201,165,95,0.18);
  --violet:    #927CB4;
  --white:     #f5f3ff;
  --text-muted:#9d92c8;
  --card-w:    88px;
  --card-h:    154px;

  /* ===== ขนาด/รูปทรงไพ่ "จุดเดียว" ของทั้งระบบ =====
     ปรับ --card-ratio ตัวเดียว ทุกหน้า (index/room/library) จะตามอัตโนมัติ
     ไฟล์ภาพต้นฉบับแนะนำ: 455×780px (ตรงสัดส่วน 7:12 พอดี ไม่ต้อง crop) */
  --card-ratio: 7 / 12;
  --card-radius: 12px;

  /* category accent colours (ตรงกับ index.html CATEGORIES) */
  --c-daily:    #7b6bb5;
  --c-monthly:  #6b7bb5;
  --c-love:     #b56b8a;
  --c-fellows:  #7bb56b;
  --c-study:    #6bb5a5;
  --c-career:   #b5956b;
  --c-money:    #c9a55f;
  --c-health:   #6ba8b5;
  --c-luck:     #a56bb5;
  --c-yesno:    #b5846b;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

html { background: var(--bg); } /* base color ให้ bg-photo-layer transparent ผ่าน */

/* v74: ย้าย overflow-x:hidden จาก body มาไว้ที่ html แทน — เดิมตั้งไว้ที่ body ทำให้ browser
   บังคับ overflow-y ของ body กลายเป็น auto ไปด้วย (ตาม spec: แกนนึง non-visible บังคับอีกแกนด้วย)
   body เลยกลายเป็น scroll container ของตัวเอง ซึ่งเป็นสาเหตุคลาสสิกที่ทำให้ position:fixed
   (เช่น #music-player) เพี้ยนบนมือถือ — เลื่อนตามเนื้อหาแทนที่จะลอยนิ่งกับจอจริง */
html { overflow-x: hidden; }

body {
  background: transparent;      /* เดิม var(--bg) ทำให้ bg-photo-layer โดนบัง */
  color: var(--white);
  font-family: "Anuphan", sans-serif;
  font-weight: 300;
  line-height: 1.7;
}

/* ===== BG HOURLY COLOR TOKENS (ค่า default — JS จะ override ทุก 1 ชม.) ===== */
:root {
  --bg-c1: rgba(45,31,110,0.55);   /* สีหลักวง 1 */
  --bg-c2: rgba(123,107,181,0.2);  /* สีหลักวง 2 */
  --bg-c3: rgba(201,165,95,0.07);  /* accent */
}

/* ===== BG PHOTO LAYERS (ภาพพื้นหลังตามกลุ่มชั่วโมง — สลับ crossfade โดย components.js) ===== */
.bg-photo-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 2.4s ease;
}
.bg-photo-layer.is-active { opacity: 1; }

/* ===== STARS BG / สี tint ตามชั่วโมง (ลอยอยู่เหนือภาพ) ===== */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, var(--bg-c1) 0%, transparent 70%),
    radial-gradient(ellipse 40% 30% at 80% 20%, var(--bg-c2) 0%, transparent 60%),
    radial-gradient(ellipse 30% 20% at 10% 60%, var(--bg-c3) 0%, transparent 50%);
  transition: background 2s ease;
}

/* ===== STARFIELD CANVAS — inject โดย components.js (~300 ดวง กระพริบ rAF) ===== */
#star-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
  mix-blend-mode: screen; /* ดำ = transparent, ดาวสว่างผสมกับ bg-photo */
}

/* ===== SHOOTING STARS (pure CSS, สุ่มจังหวะแบบ "ห่าง" ~10-20 วิ ด้วย duration ที่ไม่ลงตัวกัน) =====
   ใช้ html::before / html::after เพราะ body::before/::after ถูกใช้ไปแล้ว (กันชนกับ backdrop-filter ของ nav) */
html::before,
html::after {
  content: '';
  position: fixed;
  width: 130px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(255,255,255,0.95), rgba(255,255,255,0));
  z-index: 0;
  pointer-events: none;
  opacity: 0;
}
html::before {
  top: 8%;
  left: 65%;
  animation: shootingStar1 17s linear infinite;
}
html::after {
  top: 4%;
  left: 25%;
  animation: shootingStar2 23s linear infinite;
  animation-delay: 6s;
}
@keyframes shootingStar1 {
  0%   { opacity: 0; transform: translate(0, 0) rotate(-35deg); }
  3%   { opacity: 1; }
  9%   { opacity: 0; transform: translate(-260px, 200px) rotate(-35deg); }
  100% { opacity: 0; transform: translate(-260px, 200px) rotate(-35deg); }
}
@keyframes shootingStar2 {
  0%   { opacity: 0; transform: translate(0, 0) rotate(-35deg); }
  3%   { opacity: 1; }
  8%   { opacity: 0; transform: translate(-220px, 170px) rotate(-35deg); }
  100% { opacity: 0; transform: translate(-220px, 170px) rotate(-35deg); }
}

/* ===== SHARED NAVBAR ===== */
nav.site-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 48px;
  padding: 20px 40px;
  background: linear-gradient(to bottom, rgba(13,8,32,0.95) 0%, transparent 100%);
  backdrop-filter: blur(2px);
}

.nav-logo {
  font-family: "Anuphan", sans-serif;
  font-size: 18px;
  color: var(--gold);
  letter-spacing: 2px;
  text-decoration: none;
  white-space: nowrap;
}
.nav-logo span { color: var(--gold-lt); }

/* v61: nav-logo แบบภาพ — ถ้ามี images/ui/logo.png จะโชว์ภาพแทนข้อความ (onload ใส่ class has-logo-img)
   ถ้าโหลดไม่ได้ onerror จะลบ <img> ทิ้ง เหลือข้อความเดิม */
.nav-logo { display: flex; align-items: center; }
.nav-logo__img {
  display: none;
  height: 34px;
  width: auto;
}
.nav-logo.has-logo-img .nav-logo__img { display: inline-block; }
.nav-logo.has-logo-img .nav-logo__text { display: none; }

.nav-links { display: flex; gap: 36px; }
.nav-links a {
  font-family: "Anuphan", sans-serif;
  font-size: 16px;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-decoration: none;
  text-transform: uppercase;
  transition: color 0.2s;
}
.nav-links a:hover,
.nav-links a.is-active { color: var(--gold-lt); }

/* ปุ่มเต็มจอ — โชว์เฉพาะมือถือ (ดู @media 768px ด้านล่าง) */
.nav-fullscreen-btn {
  display: none;
  cursor: pointer;
  color: #e8d5a3;
  background: rgba(13,8,32,0.55);
  border: 1px solid rgba(201,165,95,0.3);
}
.nav-fullscreen-icon { width: 16px; height: 16px; display: block; }

/* ===== MEMBER ICON + LOGIN MODAL + DROPDOWN ===== */
.nav-member-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  padding: 2px;
  cursor: pointer;
  background: rgba(13,8,32,0.55);
  border: 1.5px solid rgba(201,165,95,0.4);
  flex-shrink: 0;
  transition: border-color 0.2s;
}
.nav-member-btn:hover { border-color: var(--gold-lt); }
.nav-member-avatar { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }

.login-modal-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(6,4,18,0.75);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-modal-overlay[hidden] { display: none; }
.login-modal {
  position: relative;
  width: 100%; max-width: 340px;
  background: linear-gradient(160deg, rgba(30,20,58,0.98), rgba(13,8,32,0.98));
  border: 1px solid rgba(201,165,95,0.35);
  border-radius: 18px;
  padding: 32px 24px 28px;
  text-align: center;
}
.login-modal-close {
  position: absolute; top: 10px; right: 14px;
  background: none; border: none;
  color: var(--text-muted);
  font-size: 22px; cursor: pointer; line-height: 1;
}
.login-modal-close:hover { color: var(--gold-lt); }
.login-modal-title {
  font-family: "Anuphan", sans-serif;
  color: var(--gold); font-size: 19px;
  letter-spacing: 1px; margin: 0 0 10px;
}
.login-modal-desc { color: var(--text-muted); font-size: 13.5px; margin: 0 0 22px; line-height: 1.6; }
.google-signin-btn-holder { display: flex; justify-content: center; min-height: 44px; }
.login-modal-error {
  margin-top: 16px; color: #e08787; font-size: 13px; line-height: 1.5;
}

.member-dropdown {
  position: fixed;
  top: 66px; right: 24px;
  z-index: 1999;
  width: 220px;
  background: linear-gradient(160deg, rgba(30,20,58,0.98), rgba(13,8,32,0.98));
  border: 1px solid rgba(201,165,95,0.35);
  border-radius: 14px;
  padding: 16px;
}
.member-dropdown-name { color: var(--gold-lt); font-size: 15px; font-weight: 700; margin: 0 0 4px; }
.member-dropdown-tier { color: var(--text-muted); font-size: 12px; margin: 0 0 14px; line-height: 1.5; }
.member-dropdown-link {
  display: block; text-align: center;
  padding: 9px 0; margin-bottom: 8px;
  border: 1px solid rgba(201,165,95,0.4); border-radius: 999px;
  color: var(--gold); text-decoration: none; font-size: 13px;
  transition: border-color 0.2s;
}
.member-dropdown-link:hover { border-color: var(--gold-lt); }
.member-dropdown-logout {
  display: block; width: 100%; text-align: center;
  padding: 9px 0;
  background: none; border: 1px solid rgba(224,135,135,0.4); border-radius: 999px;
  color: #e08787; font-size: 13px; cursor: pointer;
  transition: border-color 0.2s;
}
.member-dropdown-logout:hover { border-color: #e08787; }

/* ===== PORTRAIT LOCK OVERLAY — บังคับมือถือจริงใช้แนวตั้งเท่านั้น ===== */
#portrait-lock-overlay {
  display: none; /* JS สลับเป็น flex เมื่อ landscape จริง */
  position: fixed; inset: 0; z-index: 99999;
  background: #0d0820;
  flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 30px;
}
.portrait-lock-icon {
  font-size: 56px;
  margin-bottom: 20px;
  animation: portrait-lock-rotate 1.8s ease-in-out infinite;
}
@keyframes portrait-lock-rotate {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}
.portrait-lock-text {
  font-family: "Anuphan", sans-serif;
  color: var(--gold-lt);
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}
.portrait-lock-sub {
  color: var(--text-muted);
  font-size: 13px;
  max-width: 280px;
  line-height: 1.6;
}

/* ===== ช่องคำถามไม่บังคับ ก่อนกด AI ทำนายละเอียด ===== */
.ai-question-row { margin-bottom: 14px; }
.ai-question-row textarea {
  width: 100%; min-height: 56px; resize: vertical;
  padding: 10px 14px; border-radius: 12px;
  background: rgba(13,8,32,0.5); border: 1px solid rgba(201,165,95,0.25);
  color: var(--white, #f5f3ff); font-size: 13.5px; font-family: "Anuphan", sans-serif;
  line-height: 1.6;
}
.ai-question-row textarea:focus { outline: none; border-color: var(--gold-lt); }
.ai-question-count { display: block; text-align: right; font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ===== PARTICLES ===== */
.particle {
  position: fixed;
  pointer-events: none;
  border-radius: 50%;
  background: var(--gold);
  z-index: 490;
  animation: particle-fly 0.8s ease-out forwards;
}
@keyframes particle-fly {
  from { opacity: 1; transform: scale(1) translate(0,0); }
  to   { opacity: 0; transform: scale(0) translate(var(--dx), var(--dy)); }
}

/* ===== FOOTER ===== */
footer.site-footer {
  position: relative;
  z-index: 1;
  border-top: 1px solid rgba(201,165,95,0.1);
  padding: 40px 60px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 32px;
}
.footer-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.footer-links a {
  font-family: "Anuphan", sans-serif;
  font-size: 16px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}
.footer-links a:hover { color: var(--gold); }
.footer-version {
  justify-self: center;
  align-self: center;
  font-family: "Anuphan", sans-serif;
  font-size: 13px;
  letter-spacing: 1.5px;
  color: var(--gold);
  opacity: 0.75;
  white-space: nowrap;
}
.footer-desc { max-width: 340px; text-align: right; justify-self: end; }
.footer-desc__logo {
  font-family: "Anuphan", sans-serif;
  font-size: 14px;
  color: var(--gold);
  margin-bottom: 8px;
}
.footer-desc__body {
  font-size: 16px;
  color: var(--text-muted);
  line-height: 1.7;
}

/* ===== MINI MUSIC PLAYER (compact pill, SVG icons) =====
   v70: ไม่ได้เป็นลูกของ <nav> แล้ว (ดูเหตุผลใน components.js buildNav) — ยึด viewport เอง
   ตำแหน่ง desktop นี้จงใจให้ตรงกับตำแหน่งเดิมตอนยังอยู่ใน nav (มุมขวาบน)
   v83: #music-player เป็นแค่ wrapper ตำแหน่ง (positioning wrapper) เฉยๆ แล้ว — pill styling
   จริงย้ายไปอยู่ที่ .mp-panel แทน เพราะตอนนี้มี .mp-toggle (ปุ่มวงกลม, มือถือ) เป็นพี่น้องด้วย
   translateZ(0)/will-change: บังคับให้ element ได้ compositing layer ของตัวเอง กัน browser
   มือถือบางรุ่นเลื่อน position:fixed ตามเนื้อหาระหว่าง scroll (compositing quirk) */
#music-player {
  position: fixed;
  top: 20px;
  right: 40px;
  z-index: 1000;
  transform: translateZ(0);
  will-change: transform;
}
.mp-panel {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(13,8,32,0.55);
  border: 1px solid rgba(201,165,95,0.3);
  border-radius: 999px;
  padding: 4px 10px 4px 4px;
  transition: border-color 0.2s;
}
#music-player:hover .mp-panel { border-color: rgba(201,165,95,0.6); }
.mp-toggle { display: none; } /* desktop: ไม่ต้องมีปุ่มวงกลม โชว์ panel ตรงๆ เหมือนเดิม */

.mp-btn {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(201,165,95,0.35);
  background: rgba(201,165,95,0.1);
  color: #e8d5a3;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
  padding: 0;
}
.mp-btn:hover { background: rgba(201,165,95,0.25); border-color: #c9a55f; }
.mp-btn.is-muted { color: #9d92c8; border-color: rgba(201,165,95,0.15); }
.mp-icon { width: 13px; height: 13px; display: block; }

/* play button: เน้นนิดหน่อยให้รู้ว่าเป็นปุ่มหลัก */
.mp-play {
  width: 28px; height: 28px;
  background: rgba(201,165,95,0.18);
}

/* แถบ progress ของเพลง — เติม % ผ่าน inline style (ไม่พึ่ง CSS var) */
.mp-track {
  position: relative;
  width: 46px;
  height: 4px;
  border-radius: 3px;
  background: rgba(201,165,95,0.2);
  overflow: hidden;
  flex-shrink: 0;
}
.mp-track__fill {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 0%;
  background: #c9a55f;
  border-radius: 3px;
}

/* volume slider — fill เติมด้วย inline background (background-size trick, cross-browser) */
.mp-vol {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 52px; height: 14px;
  background: transparent;
  outline: none;
  cursor: pointer;
  flex-shrink: 0;
  margin: 0;
}
.mp-vol::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 3px;
  background: transparent; /* fill มาจาก inline background ของ input เอง ที่ JS เซ็ตเป็น % ตรงๆ */
}
.mp-vol::-moz-range-track {
  height: 4px;
  border-radius: 3px;
  background: rgba(201,165,95,0.2);
}
.mp-vol::-moz-range-progress {
  height: 4px;
  border-radius: 3px;
  background: #c9a55f;
}
.mp-vol::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px; height: 10px;
  margin-top: -3px;
  border-radius: 50%;
  background: #e8d5a3;
  box-shadow: 0 0 4px rgba(201,165,95,0.6);
  cursor: pointer;
}
.mp-vol::-moz-range-thumb {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #e8d5a3;
  border: none;
  cursor: pointer;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  /* nav มือถือ: แถว 1 โลโก้กลาง (+ปุ่มเต็มจอมุมขวาบน) / แถว 2 pill เมนูคั่นด้วยเส้น */
  nav.site-nav {
    position: fixed;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px 16px;
    padding: 22px 10px 12px; /* v72: top เพิ่มจาก 14→22 กันโลโก้ติดขอบจอ, sides ลดจาก 16→10 ให้ pill เมนูกว้างขึ้น */
  }
  .nav-logo { order: 1; width: 100%; justify-content: center; font-size: 26px; }
  .nav-logo__img { height: 46px; }

  .nav-fullscreen-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 20px; /* v72: ตามแนวเดียวกับโลโก้ที่ padding-top ขยับเป็น 22px */
    right: 10px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
  }

  .nav-member-btn {
    position: absolute;
    top: 20px;
    left: 10px;
    width: 32px;
    height: 32px;
  }

  .member-dropdown {
    top: 64px;
    left: 10px;
    right: 10px;
    width: auto;
  }

  /* v71: pill เมนู — ไม่กว้างเต็มจอ เว้นช่องไฟจากขอบจอสองข้าง (margin) — ข้างในยังแบ่ง 3 ช่องเท่ากัน (flex:1)
     กัน overflow กรณีข้อความยาว ("คลังความหมายไพ่") บนจอแคบ ให้ตัดขึ้นบรรทัดใหม่ได้แทนล้นออกนอก pill */
  .nav-links {
    order: 2;
    width: auto;
    margin: 0 4px; /* v73: ลดอีกนิดให้กว้างขึ้นอีก ตามภาพอ้างอิง */
    justify-content: center;
    align-items: center;
    gap: 0;
    background: rgba(13,8,32,0.55);
    border: 1.5px solid rgba(201,165,95,0.4);
    border-radius: 999px;
    padding: 15px 6px; /* v73: ขยายวง pill ให้ใหญ่ขึ้นตามภาพที่ 2 */
  }
  .nav-links a {
    flex: 1;
    text-align: center;
    font-size: 13.5px;
    font-weight: 700; /* v72: หนาขึ้นตามที่ขอ */
    line-height: 1.3;
    letter-spacing: 0.1px;
    padding: 0 8px;
    border-right: 1px solid rgba(201,165,95,0.25);
    white-space: nowrap;
  }
  .nav-links a:last-child { border-right: none; }

  /* music player — v83: มุมซ้ายล่าง เป็นวงกลม toggle เล็กๆ กดแล้ว panel เด้งขึ้นมาด้านบน
     (ลดพื้นที่จอที่บังตลอดเวลา, ไม่ต้องลอยกลางจอเหมือนก่อน) */
  #music-player {
    top: auto;
    bottom: 16px;
    left: 16px;
    right: auto;
  }
  .mp-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(13,8,32,0.75);
    border: 1.5px solid rgba(201,165,95,0.4);
    color: #e8d5a3;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    transition: border-color 0.2s;
  }
  .mp-toggle-icon { width: 20px; height: 20px; display: block; }
  #music-player.is-expanded .mp-toggle { border-color: var(--gold); }
  .mp-panel {
    position: absolute;
    left: calc(100% + 10px); /* v84: เด้งไปทางขวาของปุ่มวงกลม แทนด้านบน */
    top: 50%;
    bottom: auto;
    opacity: 0;
    transform: translateY(-50%) translateX(-8px) scale(0.9);
    transform-origin: left center;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
  }
  #music-player.is-expanded .mp-panel {
    opacity: 1;
    transform: translateY(-50%) translateX(0) scale(1);
    pointer-events: auto;
  }

  footer.site-footer { grid-template-columns: 1fr; justify-items: center; text-align: center; padding: 32px 24px; }
  .footer-desc { text-align: center; justify-self: center; }
  .footer-version { order: 2; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ===== TITLE BADGE (v1) =====
   ใช้สำหรับหัวข้อที่ต้องการพื้นหลังทอง+ลายจุด ตัดกับพื้นหลังหลัก
   ใช้ร่วมกัน: index.html (guide-card / about-card), library.html ฯลฯ */
.title-badge {
  display: inline-block;
  font-family: "Anuphan", sans-serif;
  font-weight: 700;
  color: var(--white);
  background: var(--gold);
  border-radius: 6px;
  padding: 5px 14px;
  letter-spacing: 0.3px;
}

/* modifier: ข้อควรระวัง - พื้นหลังแดง ตัวอักษรขาว */
.title-badge--danger {
  color: var(--white);
  background: #b33a3a;
}
