/* Tử Vi Việt — giao diện tối tím/vàng, mobile-first */
:root {
  --bg: #140b26;
  --bg2: #1d1238;
  --card: #221642;
  --card2: #2a1b52;
  --gold: #f0c75e;
  --gold2: #ffdf8e;
  --purple: #8b6cff;
  --text: #efeaff;
  --muted: #b3a6d9;
  --danger: #ff7a7a;
  --ok: #7fe0a7;
  --border: #3d2b73;
  --radius: 14px;
}

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

html { scroll-behavior: smooth; }

/* ===== Nền huyền bí: sao Bắc Đẩu + vòng 12 cung chìm dưới nội dung ===== */
.bg-art {
  position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
  color: var(--gold);
  opacity: 0.5;
}
.bg-dipper, .bg-wheel { position: absolute; width: 44vw; min-width: 320px; opacity: 0.10; }
.bg-dipper { top: 6vh; left: -4vw; transform: rotate(-8deg); }
.bg-wheel { bottom: -12vh; right: -8vw; opacity: 0.09; animation: drift 90s linear infinite alternate; }
.dipper-stars circle, .wheel-star { filter: drop-shadow(0 0 6px currentColor); }
@keyframes drift { from { transform: rotate(0deg); } to { transform: rotate(14deg); } }

.bg-stars { position: absolute; inset: -20%; background-repeat: repeat; }
.bg-stars-a {
  background-image:
    radial-gradient(1.5px 1.5px at 22px 34px, rgba(255, 235, 190, 0.9) 50%, transparent 51%),
    radial-gradient(1px 1px at 120px 90px, rgba(255, 255, 255, 0.8) 50%, transparent 51%),
    radial-gradient(2px 2px at 240px 160px, rgba(255, 220, 150, 0.7) 50%, transparent 51%),
    radial-gradient(1px 1px at 300px 60px, rgba(255, 255, 255, 0.75) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 70px 210px, rgba(200, 180, 255, 0.8) 50%, transparent 51%);
  background-size: 340px 340px;
  animation: twinkle 5.5s ease-in-out infinite;
}
.bg-stars-b {
  background-image:
    radial-gradient(1px 1px at 60px 140px, rgba(255, 255, 255, 0.7) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 190px 40px, rgba(255, 224, 170, 0.85) 50%, transparent 51%),
    radial-gradient(1px 1px at 280px 230px, rgba(180, 200, 255, 0.75) 50%, transparent 51%),
    radial-gradient(2px 2px at 150px 280px, rgba(255, 235, 190, 0.6) 50%, transparent 51%);
  background-size: 460px 460px;
  animation: twinkle 8.5s ease-in-out 1.8s infinite;
}
@keyframes twinkle { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.85; } }
@media (prefers-reduced-motion: reduce) {
  .bg-stars-a, .bg-stars-b, .bg-wheel { animation: none; }
}
html[data-theme="light"] .bg-art { color: var(--purple); opacity: 0.35; }
html[data-theme="light"] .bg-stars-a { background-image:
    radial-gradient(1.5px 1.5px at 22px 34px, rgba(106, 75, 216, 0.8) 50%, transparent 51%),
    radial-gradient(1px 1px at 120px 90px, rgba(106, 75, 216, 0.65) 50%, transparent 51%),
    radial-gradient(2px 2px at 240px 160px, rgba(138, 109, 0, 0.5) 50%, transparent 51%),
    radial-gradient(1px 1px at 300px 60px, rgba(106, 75, 216, 0.6) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 70px 210px, rgba(138, 109, 0, 0.55) 50%, transparent 51%);
}
html[data-theme="light"] .bg-stars-b { background-image:
    radial-gradient(1px 1px at 60px 140px, rgba(106, 75, 216, 0.55) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 190px 40px, rgba(138, 109, 0, 0.6) 50%, transparent 51%),
    radial-gradient(1px 1px at 280px 230px, rgba(106, 75, 216, 0.5) 50%, transparent 51%),
    radial-gradient(2px 2px at 150px 280px, rgba(106, 75, 216, 0.45) 50%, transparent 51%);
}
html[data-theme="light"] .bg-dipper, html[data-theme="light"] .bg-wheel { opacity: 0.09; }

body {
  background: radial-gradient(1200px 600px at 80% -10%, #35205e 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  min-height: 100vh;
  padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.92em; }

/* ===== Sidebar menu (desktop cố định / mobile trượt) ===== */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: 252px; z-index: 70;
  background: linear-gradient(180deg, #1d1140 0%, #140b26 70%);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 12px calc(12px + env(safe-area-inset-bottom, 0px));
  transition: transform 0.25s ease;
}
.sb-head { display: flex; justify-content: space-between; align-items: center; padding: 0 6px 14px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.sb-close { display: none; background: var(--bg2); color: var(--text); border: 1px solid var(--border); border-radius: 50%; width: 32px; height: 32px; cursor: pointer; }
.sb-nav { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; scrollbar-width: thin; }
.sb-group { font-size: 0.68em; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: #8a7fb8; padding: 14px 12px 5px; }
.sb-group:first-child { padding-top: 2px; }
.nav-btn {
  background: transparent; color: var(--text); border: 1px solid transparent;
  cursor: pointer; font-family: inherit; text-align: left;
  display: inline-flex; align-items: center; gap: 10px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sidebar .nav-btn {
  width: 100%; justify-content: flex-start; gap: 11px;
  padding: 10px 12px; border-radius: 12px; font-size: 0.95em;
  border: 1px solid transparent; position: relative;
}
.sidebar .nav-btn .n-ico { width: 21px; height: 21px; flex: 0 0 auto; opacity: 0.9; }
.sidebar .nav-btn .d-label { display: flex; flex-direction: column; text-align: left; line-height: 1.25; }
.sidebar .nav-btn .d-label b { font-size: 0.7em; color: var(--muted); font-weight: 400; }
.sidebar .nav-btn:hover { background: rgba(139, 108, 255, 0.1); }
.sidebar .nav-btn.active {
  background: linear-gradient(135deg, rgba(139, 108, 255, 0.22), rgba(240, 199, 94, 0.08));
  border-color: rgba(139, 108, 255, 0.45);
  box-shadow: none;
}
.sidebar .nav-btn.active::before {
  content: ''; position: absolute; left: -1px; top: 22%; bottom: 22%; width: 3px;
  border-radius: 3px; background: linear-gradient(180deg, var(--gold2), var(--purple));
}
.sidebar .nav-btn.active .d-label b { color: #b9a9e8; }
.sb-foot { border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.sb-act {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: var(--bg2); color: var(--muted); border: 1px solid var(--border);
  border-radius: 12px; padding: 9px 12px; cursor: pointer; font-size: 0.9em; font-family: inherit;
  transition: color 0.15s, border-color 0.15s;
}
.sb-act:hover { color: var(--gold); border-color: var(--purple); }
.sb-act .n-ico { width: 18px; height: 18px; }
.nav-backdrop { position: fixed; inset: 0; z-index: 65; background: rgba(10, 5, 24, 0.6); backdrop-filter: blur(2px); }

/* ===== Top bar (chỉ mobile) ===== */
.topbar {
  display: none;
  position: sticky; top: 0; z-index: 55;
  background: rgba(20, 11, 38, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px calc(10px + env(safe-area-inset-bottom, 0px));
  align-items: center; gap: 10px;
}
.logo { font-size: 1.15em; font-weight: 700; color: var(--gold); letter-spacing: 0.5px; white-space: nowrap; }
.logo-star { color: var(--gold2); }
.theme-btn {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text);
  border-radius: 50%; width: 38px; height: 38px; cursor: pointer; font-size: 1.05em;
  flex: 0 0 auto; transition: border-color 0.15s;
}
.theme-btn:hover { border-color: var(--purple); }
.top-actions { display: flex; gap: 6px; margin-left: auto; align-items: center; }
.nav-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, rgba(139, 108, 255, 0.3), rgba(240, 199, 94, 0.15));
  color: var(--gold2); border: 1px solid var(--purple);
  border-radius: 10px; width: 40px; height: 40px; cursor: pointer;
}
.nav-toggle .n-ico { width: 20px; height: 20px; }
html[data-theme="light"] .sidebar { background: linear-gradient(180deg, #ffffff 0%, #f4f1fb 70%); }
html[data-theme="light"] .topbar { background: rgba(255, 255, 255, 0.92); }
html[data-theme="light"] .sb-group { color: #8a7fb0; }

@media (min-width: 980px) {
  body { padding-left: 252px; }
  .topbar { display: none; }
  .sb-close { display: none; }
}
@media (max-width: 979px) {
  .sidebar { transform: translateX(-105%); box-shadow: 10px 0 50px rgba(0, 0, 0, 0.5); width: min(320px, 88vw); }
  .sidebar.open { transform: translateX(0); }
  .sb-close { display: inline-flex; align-items: center; justify-content: center; }
  .topbar { display: flex; }
}

main { max-width: 1080px; margin: 0 auto; padding: 16px; position: relative; z-index: 1; }
.footer { position: relative; z-index: 1; }

.view { display: none; }
.view.active { display: block; }

/* ===== Cards ===== */
.card {
  background: linear-gradient(160deg, var(--card) 0%, var(--bg2) 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.card h2 {
  color: var(--gold); font-size: 1.15em; margin-bottom: 14px;
  position: relative; padding-bottom: 9px;
}
.card h2::after {
  content: ''; position: absolute; left: 0; bottom: 0; width: 44px; height: 3px;
  border-radius: 3px; background: linear-gradient(90deg, var(--gold2), rgba(139, 108, 255, 0.6));
}
.section-title { margin-top: 18px; }
.section-title:first-child { margin-top: 0; }

/* ===== Form ===== */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; align-items: end; }
.form-row label { flex: 1 1 160px; display: flex; flex-direction: column; gap: 6px; font-size: 0.9em; color: var(--muted); }
.leap-label { flex: 0 1 auto !important; flex-direction: row !important; align-items: center; gap: 8px !important; padding-bottom: 10px; }
input, select {
  background: var(--bg2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; font-size: 1em; outline: none;
  color-scheme: dark; width: 100%;
}
input:focus, select:focus { border-color: var(--purple); }
input[type="checkbox"] { width: auto; }

.calendar-toggle { gap: 8px; }
.toggle-btn {
  flex: 1 1 130px; padding: 10px; border-radius: 10px; cursor: pointer;
  background: var(--bg2); color: var(--muted); border: 1px solid var(--border); font-size: 0.95em;
}
.toggle-btn.active { background: var(--card2); color: var(--gold); border-color: var(--purple); }

.btn-primary {
  background: linear-gradient(135deg, var(--purple) 0%, #6a4bd8 100%);
  color: #fff; border: none; border-radius: 10px; padding: 12px 22px;
  font-size: 1.02em; font-weight: 600; cursor: pointer; transition: filter 0.15s;
}
.btn-primary:hover { filter: brightness(1.15); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }

/* ===== Profile card ===== */
.profile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.profile-item { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.profile-item .k { font-size: 0.78em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.profile-item .v { font-size: 1.02em; color: var(--gold2); margin-top: 3px; font-weight: 600; }
.profile-name { font-size: 1.3em; color: var(--gold); font-weight: 700; margin-bottom: 10px; }

/* ===== Lá số grid ===== */
.laso-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, minmax(120px, auto));
  gap: 6px;
}
.palace {
  background: linear-gradient(170deg, #251a4a 0%, #1e133c 100%);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  font-size: 0.86em;
  position: relative;
  overflow: hidden;
  min-height: 120px;
}
.palace.p-menh { border-color: var(--gold); box-shadow: inset 0 0 24px rgba(240, 199, 94, 0.12); }
.palace.p-than { border-color: #c084fc; }
.palace .p-head { display: flex; justify-content: space-between; gap: 4px; align-items: baseline; border-bottom: 1px dashed var(--border); padding-bottom: 4px; margin-bottom: 5px; padding-right: 42px; }
.palace .p-head .p-chi { white-space: nowrap; }
.palace .p-name { color: var(--gold); font-weight: 700; }
.palace.p-menh .p-name { color: var(--gold2); }
.palace .p-chi { color: var(--muted); font-size: 0.85em; }
.palace .p-dv { font-size: 0.75em; color: #9d8fd0; }
.palace .star { display: block; line-height: 1.5; }
.palace .star.major { color: #ffe9b8; font-weight: 600; }
.palace .star.minor { color: #9fe8ff; }
.palace .star.adj { color: #8f82b8; font-size: 0.9em; }
.palace .br { color: #ffd27a; font-size: 0.8em; padding-left: 4px; }
.palace .ki { color: var(--danger); }
.palace .badges { position: absolute; top: 6px; right: 6px; display: flex; gap: 3px; }
.badge { font-size: 0.68em; background: var(--purple); color: #fff; border-radius: 4px; padding: 1px 5px; }
.badge.gold { background: var(--gold); color: #3a2a00; }

/* trung tâm */
.palace-center {
  grid-row: 2 / span 2;
  grid-column: 2 / span 2;
  background: radial-gradient(circle at 30% 20%, #3a2769 0%, #1d1238 70%);
  border: 1px solid #55409c;
  border-radius: 12px;
  padding: 14px;
  display: flex; flex-direction: column; justify-content: center; gap: 6px;
  text-align: center;
}
.palace-center .c-name { color: var(--gold2); font-weight: 700; font-size: 1.1em; }
.palace-center .c-line { color: var(--muted); font-size: 0.88em; }
.palace-center .c-cuc { color: var(--gold); font-weight: 600; }

/* ===== Aspects ===== */
.aspect-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.aspect-tab {
  background: var(--bg2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: 7px 13px; cursor: pointer; font-size: 0.9em;
}
.aspect-tab.active { background: var(--card2); color: var(--gold); border-color: var(--purple); }
.score-bar { height: 8px; background: var(--bg2); border-radius: 999px; overflow: hidden; margin: 8px 0 14px; }
.score-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--purple), var(--gold)); transition: width 0.5s; }
.score-label { font-size: 0.88em; color: var(--muted); }
.aspect-content p { line-height: 1.65; margin-bottom: 10px; font-size: 0.97em; }
.aspect-content p b { color: var(--gold2); }
.sub-scores { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-top: 10px; }
.sub-score { background: var(--bg2); border-radius: 8px; padding: 8px 10px; font-size: 0.85em; }
.sub-score .k { color: var(--muted); }
.sub-score .v { color: var(--gold2); font-weight: 700; }

/* ===== Đại vận / lưu niên ===== */
.daivan-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.daivan-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 0.9em; }
.daivan-card.now { border-color: var(--gold); box-shadow: inset 0 0 18px rgba(240, 199, 94, 0.15); }
.daivan-card .dv-range { color: var(--gold2); font-weight: 700; }
.daivan-card .dv-stars { color: var(--muted); margin-top: 4px; }
.daivan-card .dv-hoa { color: #9fe8ff; font-size: 0.9em; margin-top: 4px; }
.luunien-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.luunien-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 0.88em; }
.luunien-card.now { border-color: var(--gold); }
.luunien-card .ln-year { color: var(--gold2); font-weight: 700; font-size: 1.05em; }
.luunien-card .ln-cc { color: var(--muted); }
.luunien-card .ln-text { margin-top: 5px; line-height: 1.5; }
.luunien-card .ln-hoa { color: #9fe8ff; margin-top: 4px; font-size: 0.88em; }

/* ===== Hôm nay / hợp tuổi / giờ tốt ===== */
.today-block { margin-bottom: 14px; }
.today-block h3 { color: var(--gold); font-size: 1em; margin-bottom: 6px; }
.today-block .p { color: var(--muted); font-size: 0.9em; line-height: 1.6; }
.today-block .stars-line { color: #9fe8ff; font-size: 0.9em; }
.hop-row { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--border); font-size: 0.95em; line-height: 1.55; }
.hop-row .loai { font-weight: 700; white-space: nowrap; }
.loai.good { color: var(--ok); }
.loai.bad { color: var(--danger); }
.loai.mid { color: var(--gold2); }
.gio-card { display: inline-block; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin: 5px; text-align: center; }
.gio-card .g-chi { color: var(--gold2); font-weight: 700; font-size: 1.15em; }
.gio-card .g-khung { color: var(--muted); font-size: 0.85em; margin-top: 3px; }
.gio-card .g-ten { color: #9fe8ff; font-size: 0.82em; margin-top: 2px; }

/* ===== Section head + nút phụ ===== */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.section-actions { display: flex; gap: 6px; }
.btn-ghost {
  background: var(--bg2); color: var(--muted); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 0.88em;
}
.btn-ghost:hover { color: var(--gold); border-color: var(--purple); }
.btn-danger {
  background: transparent; color: var(--danger); border: 1px solid var(--danger);
  border-radius: 10px; padding: 10px 14px; cursor: pointer; font-size: 0.9em;
}
.btn-danger:hover { background: rgba(255, 122, 122, 0.12); }
.small-hint { font-size: 0.85em; margin-bottom: 10px; }
.lunar-preview { flex: 1 1 100%; font-size: 0.9em; color: var(--muted); padding: 2px 4px; }
.lunar-preview b { color: var(--gold2); }

/* Cung bấm được */
.palace { text-align: left; cursor: pointer; transition: border-color 0.15s, transform 0.1s; font-family: inherit; color: inherit; }
.palace:hover { border-color: var(--purple); transform: translateY(-1px); }

/* ===== Modal luận giải cung ===== */
.modal {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 5, 24, 0.72);
  display: flex; align-items: center; justify-content: center;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px));
  backdrop-filter: blur(4px);
}
.modal-box {
  position: relative; background: linear-gradient(160deg, #2a1b52 0%, #1d1238 100%);
  border: 1px solid var(--purple); border-radius: 16px; padding: 22px;
  max-width: 720px; width: 100%; max-height: 86vh; overflow-y: auto;
  box-shadow: 0 10px 60px rgba(0, 0, 0, 0.6);
}
.modal-close {
  position: absolute; top: 12px; right: 12px; background: var(--bg2); color: var(--text);
  border: 1px solid var(--border); border-radius: 50%; width: 34px; height: 34px; cursor: pointer; font-size: 1em;
}
.modal-title { color: var(--gold); font-size: 1.2em; font-weight: 700; margin-bottom: 14px; padding-right: 40px; }
.modal-score { color: var(--gold2); font-size: 0.85em; background: var(--bg2); border-radius: 6px; padding: 2px 8px; }
.modal-sec { margin-bottom: 14px; }
.modal-sec h4 { color: #9fe8ff; font-size: 0.95em; margin-bottom: 6px; }
.modal-sec p { line-height: 1.7; font-size: 0.96em; color: var(--text); }
.modal-sec p b { color: var(--gold2); }

/* ===== Biểu đồ lưu niên ===== */
.nam-chart {
  display: flex; align-items: flex-end; gap: 6px; height: 110px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px 6px; margin-bottom: 14px; overflow-x: auto;
}
.nam-col { flex: 1 1 0; min-width: 34px; display: flex; flex-direction: column; align-items: center; height: 100%; cursor: pointer; }
.nam-bar-wrap { flex: 1; width: 100%; max-width: 34px; display: flex; align-items: flex-end; }
.nam-bar {
  width: 100%; border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, var(--gold) 0%, var(--purple) 100%);
  min-height: 8%;
  transition: height 0.4s;
}
.nam-col:hover .nam-bar { filter: brightness(1.25); }
.nam-col.now .nam-bar { background: linear-gradient(180deg, var(--gold2) 0%, #ff9d5c 100%); }
/* màu cột theo điểm năm */
.nam-bar.s-mid { background: linear-gradient(180deg, var(--gold) 0%, var(--purple) 100%); }
.nam-bar.s-hi { background: linear-gradient(180deg, #ffe9a8 0%, #6fcf97 100%); }
.nam-bar.s-low { background: linear-gradient(180deg, #ffb36b 0%, #b34a3a 100%); }
.nam-bar.s-vlow { background: linear-gradient(180deg, #ff7a7a 0%, #7a2431 100%); }
.nam-col.now .nam-bar.s-hi { background: linear-gradient(180deg, var(--gold2) 0%, #6fcf97 100%); }
.nam-col.now .nam-bar.s-low { background: linear-gradient(180deg, var(--gold2) 0%, #b34a3a 100%); }
.nam-col.now .nam-bar.s-vlow { background: linear-gradient(180deg, var(--gold2) 0%, #7a2431 100%); }
.nam-yy { font-size: 0.75em; color: var(--muted); margin-top: 4px; }
.nam-col.now .nam-yy { color: var(--gold2); font-weight: 700; }

.luunien-card .ln-head { display: flex; justify-content: space-between; align-items: baseline; }
.luunien-card .ln-score { color: var(--gold2); font-weight: 700; font-size: 0.9em; }

.profile-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.profile-head .profile-name { margin-bottom: 0; }

/* ===== Thẻ tử vi hằng ngày ===== */
.daily-card { background: linear-gradient(150deg, rgba(139, 108, 255, 0.16) 0%, var(--card) 55%, var(--bg2) 100%); }
.dh-top { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.dh-score { text-align: center; flex: 0 0 auto; min-width: 110px; }
.dh-num { font-size: 3.2em; font-weight: 800; color: var(--gold2); line-height: 1; text-shadow: 0 0 30px rgba(240, 199, 94, 0.35); }
.dh-max { font-size: 1.1em; color: var(--muted); }
.dh-label { margin-top: 6px; color: var(--gold); font-weight: 700; }
.dh-info { flex: 1 1 260px; }
.dh-title { color: var(--gold2); font-weight: 700; font-size: 1.08em; }
.dh-tone { color: var(--muted); font-size: 0.94em; margin: 4px 0 10px; line-height: 1.55; }
.dh-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--bg2); border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px; font-size: 0.84em; color: var(--text); }
.chip b { color: var(--gold2); }
.chip.warn { border-color: var(--danger); color: var(--danger); }
.chip.streak { border-color: #ff9d5c; color: #ff9d5c; }
.dh-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
details { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; background: var(--bg2); }
details summary { cursor: pointer; color: var(--gold); font-weight: 600; font-size: 0.95em; }
details[open] summary { margin-bottom: 8px; }
details .p { color: var(--muted); font-size: 0.92em; line-height: 1.6; }
details .p b { color: var(--gold2); }
html[data-theme="light"] .daily-card { background: linear-gradient(150deg, rgba(106, 75, 216, 0.08) 0%, #fff 55%, var(--bg2) 100%); }

/* ===== Thầy AI ===== */
.ai-note { background: rgba(255, 157, 92, 0.1); border: 1px solid rgba(255, 157, 92, 0.4); border-radius: 8px; padding: 8px 12px; font-size: 0.85em; color: var(--muted); margin-bottom: 12px; }
.ai-answer { line-height: 1.75; font-size: 0.97em; }
.ai-answer b { color: var(--gold2); }

/* ===== In / PDF ===== */
@media print {
  body { background: #fff; color: #111; }
  .topbar, .footer, .form-card, .section-actions, .btn-ghost, .btn-primary, .btn-danger,
  #toast, .modal, .small-hint, .aspect-tabs, #namChart, .sidebar, .nav-backdrop, .nav-toggle,
  .dh-actions, .bg-art, #view-home { display: none !important; }
  .card { border: 1px solid #ccc; box-shadow: none; background: #fff; break-inside: avoid; }
  .profile-item .k, .p-dv, .muted { color: #555 !important; }
  .palace { background: #fafafa; border-color: #bbb; min-height: auto; }
  .palace .star.major { color: #7a5b00; }
  .palace .star.minor { color: #16606e; }
  .palace .p-name, .profile-name, .card h2, .section-title { color: #6b4f00; }
  .c-name, .c-cuc { color: #6b4f00; }
  .modal-box { display: none; }
  .hidden { display: none !important; }
}

/* ===== Tra cứu sao ===== */
#saoSearch { margin-bottom: 14px; }
.sao-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.sao-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font-size: 0.9em;
}
.sao-name { color: var(--gold); font-weight: 700; font-size: 1.05em; margin-bottom: 8px; }
.sao-row { display: flex; gap: 8px; padding: 4px 0; line-height: 1.55; }
.sao-row .k { color: var(--muted); white-space: nowrap; min-width: 82px; font-size: 0.9em; padding-top: 1px; }
.sao-row .v { flex: 1; color: var(--text); }

/* ===== Giao diện sáng ===== */
html[data-theme="light"] {
  --bg: #f4f1fb;
  --bg2: #ffffff;
  --card: #ffffff;
  --card2: #f0eaff;
  --gold: #8a6d00;
  --gold2: #9a7a0a;
  --purple: #6a4bd8;
  --text: #241a3f;
  --muted: #6b6288;
  --border: #d8d0ee;
}
html[data-theme="light"] body { background: radial-gradient(1200px 600px at 80% -10%, #ece5ff 0%, #f4f1fb 55%); }
html[data-theme="light"] .topbar { background: rgba(255, 255, 255, 0.92); }
html[data-theme="light"] input, html[data-theme="light"] select { color-scheme: light; }
html[data-theme="light"] .card { box-shadow: 0 4px 18px rgba(80, 60, 160, 0.1); }
html[data-theme="light"] .palace { background: linear-gradient(170deg, #faf8ff 0%, #f3f0fc 100%); }
html[data-theme="light"] .palace.p-menh { box-shadow: inset 0 0 24px rgba(138, 109, 0, 0.12); }
html[data-theme="light"] .palace .star.major { color: #7a5b00; }
html[data-theme="light"] .palace .star.minor { color: #16606e; }
html[data-theme="light"] .palace .star.adj { color: #7d74a0; }
html[data-theme="light"] .palace .br { color: #9a7a0a; }
html[data-theme="light"] .palace .p-dv { color: #8a7fb0; }
html[data-theme="light"] .palace-center { background: radial-gradient(circle at 30% 20%, #efe9ff 0%, #f4f1fb 70%); }
html[data-theme="light"] .modal { background: rgba(60, 45, 110, 0.35); }
html[data-theme="light"] .modal-box { background: #fff; }
html[data-theme="light"] .toast { background: #fff; color: var(--text); }
html[data-theme="light"] .badge.gold { color: #fff; }

/* ===== Hạn tuổi / trực / cờ hạn ===== */
.han-row { background: var(--bg2); border: 1px solid var(--border); border-left: 4px solid var(--ok); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; }
.han-row.bad { border-left-color: var(--danger); }
.han-row.good { border-left-color: var(--ok); }
.han-row .h-name { color: var(--gold2); font-weight: 600; }
.han-row.bad .h-name { color: var(--danger); }
.han-row .h-text { color: var(--muted); font-size: 0.9em; margin-top: 4px; line-height: 1.55; }
.nhan-dinh { color: var(--text); line-height: 1.6; margin-bottom: 12px; font-size: 0.95em; }
.han-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 6px; }
.han-cell { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 6px; text-align: center; font-size: 0.82em; }
.han-cell.good { border-color: rgba(127, 224, 167, 0.4); }
.han-cell.bad { border-color: rgba(255, 122, 122, 0.55); background: rgba(255, 122, 122, 0.08); }
.han-cell .c-y { color: var(--gold2); font-weight: 700; }
.han-cell .c-tags { color: var(--muted); margin-top: 3px; line-height: 1.35; }
.han-cell.bad .c-tags { color: var(--danger); }
.card h3.mt { margin-top: 14px; }
.truc-block { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-top: 12px; }
.truc-block h3 { color: var(--gold); font-size: 1em; margin-bottom: 6px; }
.truc-block .p { color: var(--muted); font-size: 0.9em; line-height: 1.6; margin-bottom: 4px; }
.truc-block b { color: var(--gold2); }
.ln-flag { color: var(--danger); font-size: 0.85em; font-weight: 600; }

/* ===== Tử vi xem gì / bảng tháng ===== */
.cm-row { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--border); font-size: 0.94em; line-height: 1.65; align-items: baseline; }
.cm-row:last-child { border-bottom: none; }
.cm-dot { flex: 0 0 auto; font-size: 0.8em; }
.cm-dot.ok { color: var(--ok); }
.cm-link { color: var(--purple); white-space: nowrap; text-decoration: none; font-weight: 600; }
html[data-theme="light"] .cm-link { color: #5a3fd6; }
.cm-link:hover { text-decoration: underline; }
.pp-table { display: flex; flex-direction: column; gap: 8px; }
.pp-row { display: grid; grid-template-columns: 130px 1fr 230px; gap: 10px; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 0.9em; line-height: 1.55; align-items: start; }
.pp-row.pp-head { background: transparent; border: none; color: var(--muted); font-weight: 700; font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.4px; padding-bottom: 0; }
.pp-name { color: var(--gold2); font-weight: 700; }
.pp-status { font-weight: 600; }
.pp-status.full { color: var(--ok); }
.pp-status.part { color: var(--gold2); }
.pp-status.none { color: var(--muted); }
.thang-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.thang-cell { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 9px 10px; font-size: 0.85em; }
.thang-cell .t-name { color: var(--gold2); font-weight: 700; }
.thang-cell .t-cc { color: var(--muted); font-size: 0.9em; }
.thang-cell .t-cung { color: var(--text); font-weight: 600; margin-top: 3px; }
.thang-cell .t-sao { color: #9fe8ff; font-size: 0.88em; margin-top: 2px; }
html[data-theme="light"] .thang-cell .t-sao { color: #16606e; }

/* ===== Bát tự / Nhân tướng ===== */
.tru-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 12px; }
.tru-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; text-align: center; }
.tru-card .t-ten { color: var(--muted); font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.4px; }
.tru-card .t-note { display: block; font-size: 0.85em; color: #9d8fd0; text-transform: none; letter-spacing: 0; }
html[data-theme="light"] .tru-card .t-note { color: #7d74a0; }
.tru-card .t-gia { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; align-items: center; }
.h-chip { display: inline-block; border-radius: 6px; padding: 3px 10px; font-weight: 700; font-size: 0.95em; background: var(--card2); }
.h-kim { color: #e8e8f5; }
.h-moc { color: #7fe0a7; }
.h-thuy { color: #9fe8ff; }
.h-hoa { color: #ff9d9d; }
.h-tho { color: #ffdf8e; }
html[data-theme="light"] .h-kim { color: #555; }
.cnt-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.cnt-bar { flex: 1; height: 12px; background: rgba(128, 128, 160, 0.15); border-radius: 999px; overflow: hidden; }
.cnt-fill { height: 100%; border-radius: 999px; opacity: 0.85; }
.cnt-n { color: var(--muted); font-size: 0.82em; white-space: nowrap; }
.nt-media { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-start; }
.nt-photo { max-width: 100%; max-height: 340px; border-radius: 12px; border: 1px solid var(--border); }
.nt-diagram { flex: 0 0 200px; text-align: center; }
.nt-diagram svg { width: 100%; max-width: 200px; background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; }
.tips-list { margin-top: 8px; }
.nt-group { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.nt-gname { color: var(--gold); font-weight: 700; margin-bottom: 4px; }
.nt-intro { color: var(--muted); font-size: 0.88em; line-height: 1.6; margin-bottom: 8px; }
.nt-opt { display: flex; gap: 8px; align-items: baseline; padding: 6px 0; border-bottom: 1px dashed var(--border); cursor: pointer; font-size: 0.92em; }
.nt-opt:last-child { border-bottom: none; }
.nt-opt input { width: auto; }

.thang-grid.clickable .thang-cell { cursor: pointer; transition: border-color 0.15s, transform 0.1s; }
.thang-grid.clickable .thang-cell:hover { border-color: var(--purple); transform: translateY(-1px); }
.thang-cell .t-head { display: flex; justify-content: space-between; align-items: baseline; }
.thang-cell .t-score { color: var(--gold2); font-weight: 700; font-size: 0.92em; }
.thang-cell .t-nhan { color: var(--muted); font-size: 0.85em; margin-top: 2px; }
.thang-cell .t-cung { color: var(--text); font-weight: 600; margin-top: 3px; line-height: 1.4; }

/* ===== Từ điển thuật ngữ / giải mơ ===== */
.tu-dien { border-color: var(--purple); background: rgba(139, 108, 255, 0.06); }
.tu-dien summary { font-weight: 700; }
.td-row { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 0.92em; line-height: 1.6; align-items: baseline; }
.td-row:last-of-type { border-bottom: none; }
.td-term { color: var(--gold2); font-weight: 700; white-space: nowrap; min-width: 150px; }
.td-plain { color: var(--muted); flex: 1; }
.dream-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.dream-nhom { grid-column: 1 / -1; margin-top: 6px; color: var(--gold); }
.dream-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; font-size: 0.9em; }
.dream-card .dc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.dream-card .dc-emoji { font-size: 1.4em; }
.dream-card .dc-title { color: var(--gold); font-weight: 700; font-size: 1.05em; }
.dream-card .dc-so { color: #9fe8ff; font-size: 0.85em; margin-bottom: 6px; }
html[data-theme="light"] .dream-card .dc-so { color: #16606e; }
.dream-card .dc-ynghia { line-height: 1.65; color: var(--text); }
.dream-card .dc-hoagiai { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); color: var(--ok); font-size: 0.92em; line-height: 1.55; }
textarea { background: var(--bg2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 1em; outline: none; width: 100%; font-family: inherit; }
textarea:focus { border-color: var(--purple); }
.gio-card .g-viet { color: var(--muted); font-weight: 400; font-size: 0.82em; }
.gio-card .g-nen { color: var(--muted); font-size: 0.8em; margin-top: 5px; line-height: 1.45; text-align: left; max-width: 210px; }
.gio-card.g-hac { opacity: 0.85; border-style: dashed; }

/* ===== Trang chủ — bản đồ sao ===== */
.star-map { position: relative; min-height: calc(100vh - 60px); }
.sm-lines { position: absolute; inset: 0; width: 100%; height: 100%; color: var(--purple); }
.sm-center {
  position: absolute; left: 50%; top: 48%; transform: translate(-50%, -50%);
  text-align: center; pointer-events: none; width: min(260px, 40vw); z-index: 1;
}
.sm-logo { font-size: 2.6em; color: var(--gold2); text-shadow: 0 0 34px rgba(240, 199, 94, 0.55); animation: pulse 4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.85; transform: scale(1); } 50% { opacity: 1; transform: scale(1.08); } }
.sm-title { color: var(--gold); font-weight: 800; font-size: 1.3em; letter-spacing: 1px; margin-top: 4px; }
.sm-sub { color: var(--muted); font-size: 0.85em; margin-top: 6px; line-height: 1.5; }
.sm-sub b { color: var(--gold2); }
.sm-hint { color: #8a7fb8; font-size: 0.78em; margin-top: 8px; font-style: italic; }
.star-node {
  position: absolute; transform: translate(-50%, -50%); z-index: 2;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: transparent; border: none; cursor: pointer; width: 140px;
  color: var(--text); font-family: inherit; padding: 0;
}
.sn-disc {
  position: relative; width: 58px; height: 58px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 28%, rgba(240, 199, 94, 0.28), rgba(139, 108, 255, 0.16) 58%, rgba(20, 11, 38, 0.5));
  border: 1px solid var(--border); color: var(--gold2);
  box-shadow: 0 0 22px rgba(139, 108, 255, 0.35), inset 0 0 14px rgba(240, 199, 94, 0.12);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.sn-disc .n-ico { width: 26px; height: 26px; }
.sn-dot {
  position: absolute; top: -3px; right: -3px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--gold2); box-shadow: 0 0 10px var(--gold2); opacity: 0.9;
}
.star-node:hover .sn-disc, .star-node:focus-visible .sn-disc {
  transform: scale(1.14); border-color: var(--gold);
  box-shadow: 0 0 42px rgba(240, 199, 94, 0.5), inset 0 0 18px rgba(240, 199, 94, 0.2);
}
.sn-label { font-weight: 700; color: var(--gold); font-size: 0.95em; }
.sn-sub { font-size: 0.72em; color: var(--muted); text-align: center; line-height: 1.3; }
@media (max-width: 760px) {
  .star-map { min-height: 0; display: flex; flex-direction: column; gap: 12px; padding-bottom: 18px; }
  .sm-lines { display: none; }
  .sm-center { position: static; transform: none; width: auto; margin: 4px 0 10px; }
  .sm-logo { font-size: 2.1em; }
  .star-node {
    position: static; transform: none; width: auto; flex-direction: row; gap: 12px;
    background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
    padding: 10px 12px; text-align: left;
  }
  .star-node:nth-child(odd) { margin-right: 8%; }
  .star-node:nth-child(even) { margin-left: 8%; }
  .sn-disc { width: 48px; height: 48px; flex: 0 0 auto; }
  .sn-label { font-size: 1em; }
  .sn-sub { text-align: left; }
}
@media (prefers-reduced-motion: reduce) { .sm-logo { animation: none; } }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%);
  background: #33205e; color: var(--text); border: 1px solid var(--purple);
  border-radius: 10px; padding: 12px 20px; z-index: 99; max-width: 90vw;
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.5); font-size: 0.95em;
}
.toast.error { border-color: var(--danger); }

/* ===== Footer ===== */
.footer { text-align: center; color: var(--muted); font-size: 0.85em; padding: 20px 16px; line-height: 1.7; }

/* ===== Mobile: lưới 4x4 co nhỏ, chữ gọn ===== */
@media (max-width: 720px) {
  main { padding: 12px; }
  .card { padding: 14px; }
  .pp-row { grid-template-columns: 1fr; gap: 4px; }
  .pp-row.pp-head { display: none; }
  .thang-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .han-grid { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); }
  .dh-num { font-size: 2.6em; }
  .dh-top { gap: 12px; }
  .laso-grid {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, minmax(96px, auto));
    gap: 4px;
    font-size: 0.78em;
  }
  .palace { min-height: 96px; padding: 6px; }
  .palace-center { padding: 10px 8px; }
  .palace-center .c-line { font-size: 0.78em; }
  .topbar { padding: 8px 10px; }
  .logo { font-size: 1em; }
}

@media (max-width: 430px) {
  .palace { font-size: 0.72em; padding: 5px; min-height: 88px; }
  .palace .star.adj { display: none; }
  .palace .p-dv { display: none; }
}
