:root {
  --bg: #12131c;
  --panel: #1c1e2b;
  --panel2: #252838;
  --line: #3a3e55;
  --text: #ecebe4;
  --muted: #a9a8b8;
  --gold: #e6b450;
  --gold2: #f3d38a;
  --red: #ef7d6d;
  --green: #7fd39b;
  --blue: #8fb8f0;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--gold2); }
h1, h2, h3 { font-family: "Times New Roman", "Noto Serif", serif; font-weight: 600; letter-spacing: .01em; }
header.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: #161722;
  position: sticky; top: 0; z-index: 5;
}
.brand { color: var(--gold); text-decoration: none; font: 700 1.25rem "Times New Roman", "Noto Serif", serif; }
.brand span { color: var(--text); font-weight: 400; }
nav a { color: var(--text); text-decoration: none; margin-left: 18px; opacity: .85; }
nav a.on, nav a:hover { color: var(--gold2); opacity: 1; }
main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 60px; }
footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px 40px; border-top: 1px solid var(--line); }

.hero { text-align: center; padding: 40px 0 20px; }
.hero h1 { font-size: 2.4rem; margin: 0 0 8px; color: var(--gold2); }
.hero p { color: var(--muted); max-width: 640px; margin: 0 auto; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; margin-top: 30px; }
.card {
  display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 24px; text-decoration: none; color: var(--text); transition: border-color .2s, transform .2s;
}
.card:hover { border-color: var(--gold); transform: translateY(-2px); }
.card h2 { margin: 6px 0 8px; color: var(--gold2); }
.card .ico { font-size: 2rem; }
.card p { color: var(--muted); margin: 0; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin-bottom: 20px; }
.panel h2 { margin: 0 0 14px; color: var(--gold2); font-size: 1.3rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
label { display: block; color: var(--muted); font-size: .9rem; margin-bottom: 4px; }
input, select, textarea, button { font: inherit; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; color: var(--muted); border: 0; padding: 8px 14px; cursor: pointer; }
.seg button.on { background: var(--gold); color: #1a1a1a; font-weight: 600; }
.btn {
  background: var(--gold); color: #1a1a1a; border: 0; border-radius: 10px; padding: 12px 22px;
  font-weight: 700; cursor: pointer; font-size: 1rem;
}
.btn:hover { background: var(--gold2); }
.btn.ghost { background: transparent; color: var(--gold2); border: 1px solid var(--gold); }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 16px; }
.note { color: var(--muted); font-size: .88rem; }
.err { color: var(--red); font-weight: 600; }
.hidden { display: none !important; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.check input { width: auto; }

/* Lá số Tử Vi: lưới 4 x 4, giữa là thông tin */
.tv-board {
  display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: minmax(150px, auto);
  gap: 4px; background: var(--line); border: 4px solid var(--line); border-radius: 10px;
}
.tv-cung { background: var(--panel); padding: 6px 7px; display: flex; flex-direction: column; font-size: .82rem; cursor: pointer; position: relative; }
.tv-cung:hover, .tv-cung.sel { background: #262a3c; }
.tv-cung.menh { box-shadow: inset 0 0 0 2px var(--gold); }
.tv-cung.han { background: #23263a; }
.tv-head { display: flex; justify-content: space-between; gap: 4px; align-items: baseline; }
.tv-chuc { color: var(--gold2); font-weight: 700; text-transform: uppercase; font-size: .78rem; }
.tv-than { color: #1a1a1a; background: var(--gold); border-radius: 4px; padding: 0 4px; font-size: .7rem; font-weight: 700; }
.tv-dh { color: var(--muted); font-size: .75rem; }
.tv-chinh { color: #ffb77a; font-weight: 700; font-size: .9rem; line-height: 1.25; margin: 4px 0 2px; }
.tv-hoa { color: var(--green); font-weight: 600; font-size: .72rem; margin-left: 3px; }
.tv-hoa.ky { color: var(--red); }
.tv-sao { line-height: 1.3; }
.tv-sao .cat { color: var(--blue); }
.tv-sao .sat { color: var(--red); }
.tv-sao .vong { color: var(--muted); }
.tv-sao .tt { color: #d9a0ff; font-weight: 700; }
.tv-foot { margin-top: auto; display: flex; justify-content: space-between; gap: 4px; color: var(--muted); font-size: .72rem; border-top: 1px dashed var(--line); padding-top: 3px; }
.tv-center { grid-column: 2 / 4; grid-row: 2 / 4; background: #181a26; padding: 14px; text-align: center; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.tv-center .ten { color: var(--gold2); font: 700 1.25rem "Times New Roman", "Noto Serif", serif; }
.tv-center .dong { font-size: .92rem; }
.tv-center .dong b { color: var(--gold2); font-weight: 600; }
.p1 { grid-column: 3; grid-row: 4; } .p2 { grid-column: 2; grid-row: 4; } .p3 { grid-column: 1; grid-row: 4; }
.p4 { grid-column: 1; grid-row: 3; } .p5 { grid-column: 1; grid-row: 2; } .p6 { grid-column: 1; grid-row: 1; }
.p7 { grid-column: 2; grid-row: 1; } .p8 { grid-column: 3; grid-row: 1; } .p9 { grid-column: 4; grid-row: 1; }
.p10 { grid-column: 4; grid-row: 2; } .p11 { grid-column: 4; grid-row: 3; } .p12 { grid-column: 4; grid-row: 4; }

.giai-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.giai { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.giai.sel { border-color: var(--gold); }
.giai h3 { margin: 0 0 2px; font-size: 1.05rem; color: var(--gold2); }
.giai .sub { color: var(--muted); font-size: .85rem; margin-bottom: 6px; }
.giai ul { margin: 0; padding-left: 18px; }
.giai li { margin: 2px 0; }

/* Bàn Kỳ Môn: lưới 3 x 3 theo hướng (Nam ở trên) */
.km-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--line); border: 4px solid var(--line); border-radius: 10px; }
.km-cung { background: var(--panel); padding: 8px 10px; min-height: 150px; display: flex; flex-direction: column; gap: 2px; position: relative; cursor: pointer; }
.km-cung:hover { background: #262a3c; }
.km-cung.dt { box-shadow: inset 0 0 0 2px var(--gold); }
.km-cung.dung { box-shadow: inset 0 0 0 2px var(--green); }
.km-cung.mid { cursor: default; justify-content: center; text-align: center; background: #181a26; }
.km-top { display: flex; justify-content: space-between; color: var(--muted); font-size: .78rem; }
.km-than { color: #ffb77a; font-weight: 700; }
.km-sao { color: var(--gold2); }
.km-mon { color: var(--blue); font-weight: 700; }
.km-mon.hung { color: var(--red); }
.km-can { margin-top: auto; display: flex; justify-content: space-between; border-top: 1px dashed var(--line); padding-top: 4px; }
.km-can .tb { color: var(--text); font-weight: 600; }
.km-can .db { color: var(--muted); }
.tag { display: inline-block; font-size: .7rem; padding: 0 5px; border-radius: 4px; margin-right: 3px; font-weight: 700; }
.tag.tk { background: #4a3b5c; color: #e8cfff; }
.tag.ma { background: #2f4c3a; color: #bff0cf; }
.info { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 6px 18px; margin-bottom: 14px; }
.info div b { color: var(--gold2); font-weight: 600; }
.ketluan { font-size: 1.08rem; border-left: 4px solid var(--gold); padding: 8px 14px; background: var(--panel2); border-radius: 0 8px 8px 0; margin: 10px 0 16px; }
.spin { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.spin-num {
  width: 76px; height: 76px; border-radius: 50%; border: 3px solid var(--gold); display: flex; align-items: center;
  justify-content: center; font: 700 2rem "Times New Roman", "Noto Serif", serif; color: var(--gold2); background: var(--panel2);
}
.spin-num.chot { border-color: var(--green); color: var(--green); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); font-size: .82rem; margin-top: 8px; }
.legend span::before { content: "■ "; }
.legend .l1::before { color: #ffb77a; } .legend .l2::before { color: var(--gold2); }
.legend .l3::before { color: var(--blue); } .legend .l4::before { color: var(--red); }

/* Luận giải bằng AI */
.ai-form textarea { resize: vertical; }
.ai-chat { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.ai-ban { align-self: flex-end; max-width: 85%; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px 12px 2px 12px; padding: 8px 12px; }
.ai-gentao { border-left: 4px solid var(--gold); padding: 4px 4px 4px 14px; }
.ai-gentao p { margin: 0 0 8px; }
.ai-gentao ul { margin: 0 0 8px; padding-left: 20px; }
.ai-gentao b { color: var(--gold2); }
.ai-cho { color: var(--gold2); font-style: italic; }
.ai-cho::before { content: "✥ "; display: inline-block; animation: xoay 1.6s linear infinite; }
@keyframes xoay { to { transform: rotate(360deg); } }
.ai-more { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.ai-more input { flex: 1; min-width: 200px; }

@media (max-width: 720px) {
  header.top { padding: 10px 12px; }
  nav a { margin-left: 12px; }
  main { padding: 16px 8px 50px; }
  .hero h1 { font-size: 1.8rem; }
  .tv-board { grid-auto-rows: minmax(120px, auto); }
  .tv-cung { font-size: .68rem; padding: 4px; }
  .tv-chinh { font-size: .74rem; }
  .tv-chuc { font-size: .64rem; }
  .tv-center .ten { font-size: 1rem; }
  .tv-center .dong { font-size: .74rem; }
  .km-cung { font-size: .8rem; padding: 6px; min-height: 130px; }
  .panel { padding: 14px; }
}
@media print {
  header.top, footer, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
}
.tv-foot span:last-child { white-space: nowrap; }
/* Trang quản trị */
.qt-login { max-width: 420px; margin: 40px auto; }
.qt-muc { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.qt-muc .giai label { margin-top: 8px; }
.qt-vd { margin-top: 10px; color: var(--gold2); font-size: .9rem; }
.qt-bang { overflow-x: auto; margin-top: 10px; }
.qt-bang table { border-collapse: collapse; width: 100%; font-size: .88rem; }
.qt-bang th, .qt-bang td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: right; white-space: nowrap; }
.qt-bang th:first-child, .qt-bang td:first-child { text-align: left; }
.qt-bang th { color: var(--gold2); font-weight: 600; }
.ai-phi { color: var(--muted); font-size: .85rem; margin-top: -2px; }
.ai-phi b { color: var(--gold2); }
.ai-muc { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.ai-muc label { display: flex; align-items: center; gap: 6px; color: var(--text); margin: 0; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.ai-muc label.on { border-color: var(--gold); background: var(--panel2); }
.ai-muc input { width: auto; }
.ai-muc small { color: var(--muted); }
.ai-tong { color: var(--muted); font-size: .88rem; margin-top: 8px; }
