/* Giao diện Con Ếch Xanh: phẳng, tối giản, nhấn xanh lá. */
:root {
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(60, 60, 67, .14);
  --line-strong: rgba(60, 60, 67, .26);
  --accent: #16a34a;
  --accent-soft: rgba(22, 163, 74, .10);
  --focus: rgba(22, 163, 74, .22);

  --glass: #fff;
  --glass-strong: #fff;
  --glass-edge: #e4ebe6;
  --glass-blur: none;
  --glass-shadow: 0 1px 2px rgba(16, 40, 24, .05);
  --r-lg: 16px;
  --r-md: 14px;
  --r-pill: 999px;
  --page-w: 660px; /* một cột như tờ A4, mọi mục dùng chung */

  --kim: #7a7a7f;
  --moc: #1f8a44;
  --thuy: #1d4fb8;
  --hoa: #d1301f;
  --tho: #b26b0f;
  --loc: #1f9d4a;
  --quyen: #8a45c7;
  --khoa: #1f7ae0;
  --ky: #e0301e;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  padding: 0 16px 52px;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: transparent;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--glass-shadow);
  border-radius: var(--r-lg);
}

.top { max-width: var(--page-w); margin: 0 auto; padding: 22px 4px 6px; text-align: center; }
.top h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.4px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* Form gọn một hàng */
.form { max-width: var(--page-w); margin: 10px auto 16px; padding: 10px 10px 20px; }
.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
input[type=text], input[type=number], select {
  font: inherit; font-size: 13.5px; color: var(--ink); height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--r-pill);
  background: var(--glass-strong); outline: none; transition: box-shadow .15s, border-color .15s;
  -webkit-appearance: none; appearance: none;
}
select {
  padding-right: 28px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, #8e8e93 50%), linear-gradient(135deg, #8e8e93 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
  background-size: 5px 5px; background-repeat: no-repeat;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--focus); }
input::placeholder { color: #a1a1a6; }
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; text-align: center; }
.f-ten { flex: 0 0 calc(24.75% - 6px); min-width: 0; }

.date { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--glass-strong); overflow: hidden; }
.date input, .date select { border: 0; border-radius: 0; background-color: transparent; width: 72px; padding: 0 22px 0 10px; text-align: center; text-align-last: center; }
.date > select + select { border-left: 1px solid var(--line); }
.date .f-nam { width: 82px; }
.date:focus-within { box-shadow: 0 0 0 4px var(--focus); }
.nx { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.nx select { width: 84px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }

.btn {
  font: inherit; font-size: 13.5px; font-weight: 600; height: 34px; padding: 0 18px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--glass-strong); cursor: pointer; color: var(--ink);
  transition: transform .1s, filter .15s;
}
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: none;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: scale(.97); }

.adv { margin: 8px 4px 0; }
.adv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px 12px; margin-top: 10px; }
.adv-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--muted); }
.adv-grid input, .adv-grid select { width: 100%; }
.adv-chk { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 10px 0 2px; }
.err { display: block; color: var(--ky); font-size: 13px; margin: 6px 6px 0; }
.err:empty { display: none; }

main { max-width: var(--page-w); margin: 0 auto; }

/* Thanh công cụ và nút phân đoạn */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 14px;
  max-width: var(--page-w); margin: 0 auto 8px; padding: 0;
}
.toolbar .chk { font-weight: 600; }
.toolbar .small { font-size: 11.5px; }
.toolbar.vong .only-vuong { display: none !important; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-pill); background: rgba(118, 118, 128, .12); }
.seg button {
  font: inherit; font-size: 12.5px; font-weight: 500; padding: 5px 12px; border: 0; border-radius: var(--r-pill);
  background: none; cursor: pointer; color: var(--ink); transition: background .2s, box-shadow .2s;
}
.seg button.on { background: #fff; font-weight: 600; box-shadow: 0 2px 8px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); }

/* Lá số vuông */
.chart-scroll { overflow-x: auto; padding: 2px 2px 6px; }
.chart-wrap { position: relative; max-width: var(--page-w); min-width: 480px; margin: 0 auto; }
.chart {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(195px, auto));
  border-radius: var(--r-md); overflow: hidden;
  background: var(--glass-strong); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-edge); box-shadow: var(--glass-shadow);
}
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }

.cell {
  position: relative; border: .5px solid var(--line); padding: 6px 7px 19px; cursor: pointer;
  display: flex; flex-direction: column; font-size: 10.8px; line-height: 1.2; overflow-wrap: anywhere;
  transition: background .15s;
}
.cell:hover { background: rgba(255, 255, 255, .6); }
.cell.co-hoa:hover { background: var(--nen); filter: brightness(1.03); }
.cell.co-hoa { background: var(--nen); }
/* Đang rê chuột trên lá số: ẩn nền tứ hóa gốc cho dễ nhìn tam hợp, xung chiếu */
#chart.hv .cell.co-hoa:not(.tp):not(.sel) { background: none; }
.cell.tp, .cell.tp:hover { background: rgba(255, 214, 120, .35); }
.cell.sel { background: rgba(255, 214, 120, .35); box-shadow: inset 0 0 0 2px rgba(230, 160, 30, .8); z-index: 2; }
.cell.target { background: rgba(31, 122, 224, .08); }
.cell.dv { box-shadow: inset 0 0 0 2px rgba(31, 122, 224, .3); }
.head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 2px; }
.cc { font-size: 10.2px; color: var(--muted); }
.pn { text-align: center; font-weight: 700; font-size: 11.4px; color: var(--accent); text-transform: uppercase; letter-spacing: .2px; }
.pn .than { display: block; font-size: 9.6px; color: var(--ky); }
.dvn { text-align: right; font-weight: 700; font-size: 12px; }
.tags { text-align: center; font-size: 9px; color: var(--khoa); min-height: 10px; }
.tags span { margin: 0 1px; }
.tags .ln { color: var(--quyen); }
.mains { text-align: center; margin: 2px 0 3px; font-weight: 700; font-size: 11.4px; text-transform: uppercase; }
.mains .vcd { color: var(--muted); font-weight: 400; text-transform: none; font-style: italic; font-size: 10.2px; }
.hg { display: inline-block; padding: 0 5px; border-radius: var(--r-pill); font-size: 9px; font-weight: 700; color: #fff; text-transform: none; box-shadow: 0 1px 2px rgba(0, 0, 0, .18); }
.hg.h0 { background: var(--loc); color: #fff; }
.hg.h1 { background: var(--quyen); color: #fff; }
.hg.h2 { background: var(--khoa); color: #fff; }
.hg.h3 { background: var(--ky); color: #fff; }
.minors { display: grid; grid-template-columns: 1fr 1fr; gap: 0 3px; align-items: start; font-weight: 600; }
.minors > div:last-child { text-align: right; }
.minors .sl { font-style: italic; }
.luu { display: grid; grid-template-columns: 1fr 1fr; gap: 0 3px; margin-top: 3px; padding-top: 2px; border-top: 1px dotted var(--line-strong); font-style: italic; }
.luu div:last-child { text-align: right; }
.foot { position: absolute; left: 7px; right: 7px; bottom: 5px; display: grid; grid-template-columns: 1fr auto 1fr; font-size: 9.6px; color: var(--muted); }
.foot .th { font-weight: 700; color: var(--ink); text-align: center; }
.foot .lnm { text-align: right; }
.marks { text-align: center; font-size: 9.6px; font-weight: 700; min-height: 10px; }
.tt { display: inline-block; margin: 2px 2px 0; padding: 0 5px; border-radius: var(--r-pill); background: rgba(29, 29, 31, .82); color: #fff; font-size: 9px; font-weight: 700; }
.Kim { color: var(--kim); } .Mộc { color: var(--moc); } .Thủy { color: var(--thuy); } .Hỏa { color: var(--hoa); } .Thổ { color: var(--tho); }
.h0 { color: var(--loc); } .h1 { color: var(--quyen); } .h2 { color: var(--khoa); } .h3 { color: var(--ky); }

.phihoa { display: none; margin-top: 4px; padding: 3px 2px 0; font-size: 10.8px; font-weight: 600; line-height: 1.35; }
.phihoa .ttl { color: var(--muted); font-weight: 400; font-size: 9.6px; }
.chart.phi .phihoa { display: block; }
.chart.phi .minors, .chart.phi .luu { display: none; }

.center {
  grid-column: 2 / 4; grid-row: 2 / 4; border: .5px solid var(--line); padding: 8px 10px;
  display: flex; flex-direction: column; justify-content: center; background: rgba(255, 255, 255, .45); cursor: default;
}
.center h2 { margin: 0 0 2px; text-align: center; color: var(--accent); font-size: 16.8px; letter-spacing: 1px; }
.center .nm { text-align: center; font-size: 14.4px; font-weight: 700; margin-bottom: 4px; }
.center table { width: 100%; border-collapse: collapse; font-size: 11.4px; }
.center td { padding: 1px 2px; vertical-align: top; }
.center td:first-child { color: var(--muted); width: 34%; white-space: nowrap; }
.center .note { margin-top: 6px; font-size: 10.2px; color: var(--muted); text-align: center; }

/* Vòng phi hóa */
.muc { max-width: var(--page-w); margin: 0 auto 22px; }
.muc-ttl { text-align: center; margin: 0 4px 10px; font-size: 17px; font-weight: 700; letter-spacing: -.3px; }
.form-ttl { margin: 2px 4px 10px; }
#vongWrap { max-width: var(--page-w); margin: 0 auto 22px; }
#vong {
  width: 100%; height: auto; display: block; border-radius: var(--r-lg);
  background: var(--glass); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-edge); box-shadow: var(--glass-shadow);
}
#vong .cung { cursor: pointer; }
#vong .cung rect.o { fill: rgba(255, 255, 255, .92); stroke: rgba(60, 60, 67, .28); stroke-width: 1.3; filter: drop-shadow(0 3px 6px rgba(30, 36, 70, .12)); }
#vong .cung:hover rect.o { fill: #fff; }
#vong .cung.than rect.o, #vong .cung.menh rect.o { stroke: #db2777; stroke-width: 2.45; }
#vong .cung.sel rect.o { fill: #ecfdf3; stroke: #16a34a; stroke-width: 3.5; }
#vong .cung.tgt rect.o { fill: #eef5ff; stroke: var(--khoa); stroke-width: 2.5; }
#vong text { font-family: inherit; pointer-events: none; }
.loops:empty { display: none; }
.loops { margin: 10px 0 0; padding: 10px 14px; font-size: 12.5px; border-radius: var(--r-md); background: var(--glass); border: 1px solid var(--glass-edge); box-shadow: var(--glass-shadow); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); }
.loops ul { margin: 4px 0 0; padding-left: 18px; }
.loops li { margin: 2px 0; }

/* Bảng và ghi chú */
.hint { color: var(--muted); font-size: 12px; margin: 8px auto 14px; max-width: var(--page-w); text-align: center; }
.panel { padding: 14px 18px; margin-bottom: 14px; }
.panel[hidden] { display: none; }
.panel h3 { margin: 0 0 8px; font-size: 15px; font-weight: 700; letter-spacing: -.2px; }
.panel table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; background: rgba(255, 255, 255, .5); }
.panel th, .panel td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.panel tr:last-child td { border-bottom: 0; }
.panel th { background: rgba(255, 255, 255, .6); font-weight: 600; }
.panel td.self { background: rgba(255, 214, 120, .3); font-weight: 700; }
.panel ul { margin: 4px 0; padding-left: 20px; }
.ok { color: var(--loc); font-weight: 700; }
.bad { color: var(--ky); font-weight: 700; }
.small { font-size: 12px; color: var(--muted); }

@media (max-width: 640px) {
  .bar > select, .nx { flex: 1 1 auto; }
  .btn.primary { flex: 1 1 100%; }
}

@media print {
  body { background: #fff; padding: 0; }
  .bg, .form, .top .sub, .hint, .toolbar, .vong-rail, #phiPanel, #test, .arrows { display: none !important; }
  .glass, .chart, #vong { box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; background: #fff; }
  .chart-wrap { min-width: 0; }
  .cell.sel, .cell.target { background: none; box-shadow: none; }
  .panel { break-inside: avoid; }
}

/* Bảng vòng lặp và làm nổi trên vòng phi hóa */
.loops-hd { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 10px; margin-bottom: 8px; }
.loops-hd .small { font-size: 11px; }
.loops-tb { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; background: rgba(255, 255, 255, .5); }
.loops-tb th, .loops-tb td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.loops-tb th { font-weight: 600; font-size: 11px; color: var(--muted); background: rgba(255, 255, 255, .6); }
.loops-tb tr:last-child td { border-bottom: 0; }
.loops-tb tbody tr { cursor: pointer; transition: background .15s; }
.loops-tb tbody tr:hover, .loops-tb tbody tr.on { background: rgba(255, 214, 120, .28); }
.loops-tb td:first-child { color: var(--muted); width: 24px; }
.loops-tb td:last-child { white-space: nowrap; color: var(--muted); font-size: 11px; }
.loops-tb .hg { font-size: 10.5px; padding: 1px 6px; margin: 1px 0; }
#vong [data-e], #vong .cung { transition: opacity .2s, stroke-width .2s; }
#vong.focus [data-e] { opacity: .1; }
#lopNoi { pointer-events: none; }
#vong.focus .cung:not(.on) { opacity: .35; }

/* Form gọn: tên chiếm 1/3 hàng, các ô còn lại xếp sát nhau */
.bar { gap: 6px; }
.bar input[type=text], .bar input[type=number], .bar select { font-size: 13px; padding: 0 10px; }
.bar select { padding-right: 24px; }
.bar .date select { padding: 0 22px 0 10px; }

/* Menu vòng lặp: cột số 1, 2, 3… gắn mép phải bản đồ, nằm ngoài các cung */
.vong-box { position: relative; }
.loop-menu::-webkit-scrollbar { display: none; }
.loop-menu:empty { display: none; }
.loop-menu button {
  font: inherit; font-size: 11px; font-weight: 700; width: 24px; height: 24px; flex: 0 0 24px; padding: 0;
  border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; transition: background .15s, color .15s, transform .1s;
}
.loop-menu button:hover, .loop-menu button.on { background: var(--accent); color: #fff; transform: scale(1.08); }

/* Nút Tùy chọn nằm cạnh ô Năm xem (đã bỏ nút Lập lá số: đổi ô nào là lá số tự lập lại) */
.adv-tg {
  font: inherit; font-size: 12.5px; height: 34px; padding: 0 4px; border-radius: var(--r-pill); cursor: pointer;
  border: 0; background: none; color: var(--muted);
  display: inline-flex; align-items: center; gap: 1px;
}
.adv-tg::before { content: '›'; font-size: 15px; transition: transform .2s; }
.adv-tg[aria-expanded="true"] { color: var(--ink); }
.adv-tg[aria-expanded="true"]::before { transform: rotate(90deg); }
.adv[hidden] { display: none; }
/* Màn hình hẹp không còn chỗ bên ngoài: dán sát mép phải bên trong khung */

/* Điều khiển nằm trong khung vòng phi hóa:
   hàng mức xem và lọc tứ hóa ở đáy, cột số vòng lặp dọc ở mép phải */
.vong-rail {
  position: absolute; left: 0; right: 0; bottom: 8px;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; pointer-events: none;
}
.rail-col {
  display: flex; gap: 2px; padding: 3px; pointer-events: auto;
  border-radius: var(--r-pill); background: rgba(255, 255, 255, .72); border: 1px solid var(--glass-edge);
  box-shadow: 0 4px 14px rgba(30, 36, 70, .14); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
}
.rail-col button, .rail-hoa label {
  font: inherit; font-size: 11px; font-weight: 600; padding: 4px 9px; border: 0; border-radius: var(--r-pill);
  background: none; color: var(--ink); cursor: pointer; white-space: nowrap; transition: background .15s, color .15s;
}
.rail-lv button:hover { background: rgba(118, 118, 128, .12); }
.rail-lv button.on { background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .12); font-weight: 700; color: var(--accent); }
.rail-hoa input { position: absolute; opacity: 0; pointer-events: none; }
.rail-hoa label { position: relative; font-weight: 700; opacity: .4; }
.rail-hoa label:has(input:checked) { opacity: 1; }
.rail-hoa label.h0:has(input:checked) { background: rgba(31, 157, 74, .14); }
.rail-hoa label.h1:has(input:checked) { background: rgba(138, 69, 199, .14); }
.rail-hoa label.h2:has(input:checked) { background: rgba(31, 122, 224, .14); }
.rail-hoa label.h3:has(input:checked) { background: rgba(224, 48, 30, .14); }

.loop-menu {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 3px; padding: 4px 3px; max-height: 70%; overflow-y: auto; scrollbar-width: none;
  border-radius: var(--r-pill); background: rgba(255, 255, 255, .72); border: 1px solid var(--glass-edge);
  box-shadow: 0 4px 14px rgba(30, 36, 70, .14); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
}
.loop-menu button {
  font: inherit; font-size: 11px; font-weight: 700; width: 24px; height: 24px; flex: 0 0 24px; padding: 0;
  border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; transition: background .15s, color .15s;
}
.loop-menu button:hover, .loop-menu button.on { background: var(--accent); color: #fff; }

.loops[hidden] { display: none !important; }

/* Đại vận: biểu đồ sóng Thiên thời và bảng 10 vận */
.dv-box { padding: 14px 14px 10px; border-radius: var(--r-lg); }
.dv-tuoi { text-align: center; margin: 0 0 6px; }
.dv-svg { display: block; width: 100%; height: auto; overflow: visible; }
.dv-bang { width: 100%; margin-top: 10px; border-collapse: separate; border-spacing: 0; font-size: 12px; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; background: rgba(255, 255, 255, .5); }
.dv-bang th, .dv-bang td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--line); }
.dv-bang th { font-weight: 600; font-size: 11px; color: var(--muted); background: rgba(255, 255, 255, .6); }
.dv-bang tr:last-child td { border-bottom: 0; }
.dv-bang tr.on { background: rgba(255, 214, 120, .28); font-weight: 600; }
.dv-muc { display: inline-block; padding: 1px 8px; border-radius: var(--r-pill); font-weight: 700; color: #fff; background: var(--m); }

/* Lưu Lộc Tồn: 4 thẻ tóm tắt theo cung rồi bảng các năm */
.ll-tom { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ll-the {
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 6px; text-align: center;
  border-radius: var(--r-md); background: rgba(255, 255, 255, .55); border: 1px solid var(--glass-edge);
}
.ll-the b { font-size: 12.5px; color: #14532d; }
.ll-so { font-size: 20px; font-weight: 800; color: var(--loc); line-height: 1.2; }
.ll-the .small { font-size: 10.5px; line-height: 1.35; }
.ll-the[data-nhat] b, .ll-the[data-nhat] .ll-so, .ll-the[data-nhat] .small { color: #1c1c1e; }
.ll-the[data-dam] b, .ll-the[data-dam] .ll-so, .ll-the[data-dam] .small { color: #fff; }
@media (max-width: 480px) { .ll-tom { grid-template-columns: repeat(2, 1fr); } }

/* Tam Tai & Thái Tuế: nhãn phạm cùng kiểu viên với các mục khác */
.tt-tom { grid-template-columns: repeat(3, 1fr); margin-bottom: 0; }
.tt-ds { display: flex; flex-wrap: wrap; gap: 3px; justify-content: inherit; }
.ll-the .tt-ds { justify-content: center; margin-top: 3px; }
.tt-chip {
  display: inline-block; padding: 1px 7px; border-radius: var(--r-pill); font-size: 10.5px; font-weight: 700; white-space: nowrap; cursor: help;
  color: var(--m); background: color-mix(in srgb, var(--m) 13%, transparent); border: 1px solid color-mix(in srgb, var(--m) 35%, transparent);
}
@media (max-width: 480px) { .tt-tom { grid-template-columns: 1fr; } }

/* Tab phía trên vòng phi hóa: kiểu segmented control, cùng hệ kính với hàng điều khiển */
.vong-tab {
  display: flex; width: max-content; margin: 0 auto 8px; gap: 2px; padding: 3px;
  border-radius: var(--r-pill); background: rgba(118, 118, 128, .12); border: 1px solid var(--glass-edge);
}
.vong-tab button {
  font: inherit; font-size: 12px; font-weight: 600; padding: 5px 14px; border: 0; border-radius: var(--r-pill);
  background: none; color: var(--muted); cursor: pointer; transition: background .15s, color .15s;
}
.vong-tab button.on { background: #fff; color: var(--accent); font-weight: 700; box-shadow: 0 2px 8px rgba(0, 0, 0, .12); }
.rail-col[hidden] { display: none !important; }
.rail-tang label:has(input:checked) { background: var(--accent-soft); color: var(--accent); }

/* Chọn vận 10 năm và năm ở tab Tứ hóa theo vận: hai hàng viên nhỏ, cuộn ngang khi hẹp */
.van-pick[hidden] { display: none !important; }
.van-pick { display: flex; flex-direction: column; gap: 4px; margin: 10px 0 0; }
.van-row {
  display: flex; gap: 3px; padding: 3px; overflow-x: auto; scrollbar-width: none; margin: 0 auto; max-width: 100%;
  border-radius: var(--r-pill); background: rgba(255, 255, 255, .6); border: 1px solid var(--glass-edge);
}
.van-row::-webkit-scrollbar { display: none; }
.van-row button {
  font: inherit; font-size: 11px; font-weight: 700; padding: 3px 9px; border: 0; border-radius: var(--r-pill); flex: 0 0 auto;
  background: none; color: var(--ink); cursor: pointer; display: flex; flex-direction: column; align-items: center; line-height: 1.15;
  transition: background .15s, color .15s;
}
.van-row button small { font-size: 9px; font-weight: 600; color: var(--muted); }
.van-row button:hover { background: rgba(118, 118, 128, .12); }
.van-row button.on { background: var(--accent); color: #fff; }
.van-row button.on small { color: rgba(255, 255, 255, .85); }
.van-row button[data-nay]:not(.on) { box-shadow: inset 0 0 0 1.5px var(--accent); }

/* Bảng Tam Tai: cột cố định, mọi ô canh giữa theo chiều dọc */
.dv-bang td { vertical-align: middle; }
.tt-bang { table-layout: fixed; }
.tt-bang th:nth-child(1) { width: 9%; }
.tt-bang th:nth-child(2) { width: 7%; }
.tt-bang th:nth-child(3) { width: 25%; }
.tt-bang th:nth-child(4) { width: 16%; }
.tt-bang th:nth-child(5) { width: 20%; }
.tt-bang th:nth-child(6) { width: 23%; }
.tt-bang td:nth-child(2) { text-align: center; }
.tt-bang th:nth-child(2) { text-align: center; }
.tt-bang .tt-ds { flex-direction: column; align-items: flex-start; gap: 3px; }
.tt-bang .tt-chip { white-space: normal; line-height: 1.25; padding: 2px 7px; }
.tt-bang .dv-muc { display: inline-block; white-space: normal; font-size: 10.5px; line-height: 1.25; padding: 2px 7px; border: 1px solid transparent; }
.tt-bang td { overflow-wrap: break-word; vertical-align: top; }
@media (max-width: 640px) {
  .tt-bang { table-layout: auto; }
  .tt-bang th { width: auto !important; }
}

/* Nút bấm: không bôi đen chữ khi bấm nhanh, có nền và bóng như nút, nhấn thì lún nhẹ */
button, .rail-hoa label, .chk, #vong, #vong *, .chart .cell, .loop-menu, .vong-tab, .van-row {
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.rail-col button, .rail-hoa label, .vong-tab button, .van-row button, .loop-menu button {
  background: rgba(255, 255, 255, .7); box-shadow: 0 1px 2px rgba(30, 36, 70, .12), inset 0 0 0 1px rgba(60, 60, 67, .12);
  transition: background .15s, color .15s, transform .1s, box-shadow .15s;
}
.rail-col button:active, .rail-hoa label:active, .vong-tab button:active, .van-row button:active, .loop-menu button:active { transform: scale(.94); }
.rail-col, .vong-tab, .van-row { gap: 4px; }
.loop-menu { gap: 4px; }
.tt-moc { position: absolute; z-index: 3; margin: 0; pointer-events: none; white-space: nowrap; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
/* Tạm ẩn nhãn ĐV./LN. dưới tên cung */
.cell .tags { display: none; }
/* Tạm ẩn ký hiệu tự hóa ↑ và hướng tâm ↓ dưới chính tinh */
.cell .marks { display: none; }
/* Nhấn giữ nút hóa: viền sáng dần trong 1,3 giây báo sắp chỉ bật riêng hóa đó */
.rail-hoa label.giu { animation: giuHoa .5s linear forwards; }
@keyframes giuHoa { from { box-shadow: inset 0 0 0 1px rgba(60, 60, 67, .12); } to { box-shadow: inset 0 0 0 2.5px var(--accent); } }

/* Thương hiệu Con Ếch Xanh */
.top { padding: 26px 4px 8px; }
.top h1 { font-size: 24px; font-weight: 800; letter-spacing: -.5px; display: inline-flex; align-items: center; gap: 10px; }
.top h1 b { color: var(--accent); font-weight: 800; }
.top .logo { font-size: 26px; line-height: 1; }
.top h1 .ten { line-height: 1.1; text-align: left; } .top h1 .nw { white-space: nowrap; }
.top .thuonghieu { display: inline-flex; align-items: flex-start; gap: 10px; text-align: left; } .top .thuonghieu .sub { margin: 4px 0 0; line-height: 15px; }
.sub { font-size: 12.5px; }
.sub a { color: var(--accent); font-weight: 600; text-decoration: none; margin-left: 6px; }
.sub a:hover { text-decoration: underline; }
.btn.primary:hover { filter: brightness(.95); }
.seg { background: #edf2ee; }
.seg button.on { color: var(--accent); box-shadow: 0 1px 3px rgba(16, 40, 24, .1); }

/* Nền nhận diện Con Ếch Xanh (lá sen, chấm nước, sóng nhẹ) đặt thẳng lên nền gốc: lặp kín cả trang, cuộn quá đầu/cuối cũng không lộ mép */
html {
  background-color: #e8f8ec; min-height: 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cdefs%3E%3Cg id='f'%3E%3Ccircle cx='-12' cy='-9' r='9' fill='%2316a34a'/%3E%3Ccircle cx='12' cy='-9' r='9' fill='%2316a34a'/%3E%3Cellipse cx='0' cy='3' rx='21' ry='14' fill='%2316a34a'/%3E%3Ccircle cx='-12' cy='-10' r='5.5' fill='%23fff'/%3E%3Ccircle cx='12' cy='-10' r='5.5' fill='%23fff'/%3E%3Ccircle cx='-11' cy='-9.5' r='2.8' fill='%2314532d'/%3E%3Ccircle cx='13' cy='-9.5' r='2.8' fill='%2314532d'/%3E%3Ccircle cx='-3' cy='1' r='1.2' fill='%2314532d'/%3E%3Ccircle cx='3' cy='1' r='1.2' fill='%2314532d'/%3E%3Cpath d='M-8 7 q8 6 16 0' fill='none' stroke='%2314532d' stroke-width='1.6' stroke-linecap='round'/%3E%3C/g%3E%3C/defs%3E%3Cg opacity='.13'%3E%3Cuse href='%23f' transform='translate(46 46) rotate(-8)'/%3E%3Cuse href='%23f' transform='translate(134 126) scale(.7) rotate(12)'/%3E%3C/g%3E%3Cg fill='%2316a34a' fill-opacity='.075'%3E%3Ccircle cx='150' cy='40' r='3'/%3E%3Ccircle cx='160' cy='52' r='1.8'/%3E%3Ccircle cx='30' cy='140' r='2.4'/%3E%3Ccircle cx='96' cy='76' r='1.6'/%3E%3C/g%3E%3Cpath d='M70 160 q8 -6 16 0 t16 0' fill='none' stroke='%2316a34a' stroke-opacity='.09' stroke-width='1.6' stroke-linecap='round'/%3E%3Cpath d='M110 22 q6 -5 12 0 t12 0' fill='none' stroke='%2316a34a' stroke-opacity='.08' stroke-width='1.4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}
.top .logo {
  width: 72px; height: 72px; border-radius: 18px; flex: none; display: inline-grid; place-items: center;
  background: var(--accent); font-size: 44px; box-shadow: 0 4px 12px rgba(22, 163, 74, .3);
}
.sub a { background: #14532d; color: #fff; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; }
.sub a:hover { text-decoration: none; background: var(--accent); }

/* Tam hợp khi rê chuột vào cung */
#tamHop { opacity: .4; }
#tamHop polygon { fill: none; stroke: var(--accent); stroke-width: 1.4; stroke-linejoin: round; }
#tamHop line { stroke: var(--accent); stroke-width: 1.2; stroke-dasharray: 4 4; }
#tamHop circle { fill: var(--accent); }

/* Nút liên hệ Zalo nhỏ, nằm ngay bên phải ô nhập của trợ lý AI (ô nhập ở left 4px, rộng 240px) */
.lienhe {
  position: fixed; left: 250px; bottom: 16px; z-index: 50;
  display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 12px;
  border-radius: 999px; background: #0068ff; color: #fff; font-weight: 700; font-size: 12.5px;
  text-decoration: none; box-shadow: 0 3px 10px rgba(0, 104, 255, .3); transition: transform .15s, filter .15s;
}
.lienhe:hover { filter: brightness(1.08); }
.lienhe:active { transform: scale(.96); }
@media print { .lienhe { display: none; } }


/* Vòng lặp đang ẩn các đường ngoài vòng */
.rail-lv button.on.an { background: var(--accent); color: #fff; }

/* Nhãn tự hóa: rê chuột hiện chi tiết */
.co-tip { pointer-events: auto; cursor: help; }
#vong .co-tip text { pointer-events: none; }
.tip-hoa {
  position: fixed; z-index: 100; max-width: 240px; padding: 6px 10px; border-radius: 10px;
  background: #111; color: #fff; font-size: 12px; line-height: 1.45; white-space: pre-line; pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}
.tip-hoa[hidden] { display: none; }

/* Danh sách phi hóa trong cung: nền màu, chữ trắng */
.phihoa > .h0, .phihoa > .h1, .phihoa > .h2, .phihoa > .h3 { display: table; margin: 1px 0; padding: 0 5px; border-radius: var(--r-pill); color: #fff; font-weight: 700; line-height: 1.45; }
.phihoa > .h0 { background: var(--loc); } .phihoa > .h1 { background: var(--quyen); } .phihoa > .h2 { background: var(--khoa); } .phihoa > .h3 { background: var(--ky); }

/* Mũi tên nháy trên nhãn đường phi hóa */
.cv { animation: cvNhay .8s ease-in-out infinite; }
@keyframes cvNhay { 0%, 100% { fill-opacity: 1; } 50% { fill-opacity: .15; } }

/* Vòng lặp đang làm nổi: nền nhãn đục hoàn toàn */
#lopNoi path[id^="nc"] { stroke-opacity: 1; }
#lopNoi text { fill: #fff; }

/* Bảng sao lưu năm nay: hiện khoảng nửa danh sách, cuộn để xem tiếp */
.nn-cuon { max-height: 352px; overflow-y: auto; border-radius: var(--r-md); overscroll-behavior: contain; }
.nn-cuon th { position: sticky; top: 0; z-index: 1; background: #f7faf7; }
.nn-cuon .dv-bang { overflow: visible; }

/* Năm nay: mỗi thông tin chính một ô chữ nhật */
.nn-tag { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; margin-bottom: 10px; }
.nn-o { display: flex; flex-direction: column; gap: 2px; padding: 6px 9px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255, 255, 255, .7); border-left: 4px solid var(--m, var(--accent)); }
.nn-o span { font-size: 10.5px; color: var(--muted); }
.nn-o b { font-size: 12.5px; color: var(--m, var(--ink)); }
.nn-o em { font-style: normal; font-size: 11px; font-weight: 600; color: var(--m); }

/* Vòng lưu hóa năm nay */
.vong-luu { width: 100%; height: auto; display: block; margin: 4px 0 0; overflow: visible; }
.vong-luu .cung rect.o { fill: rgba(255, 255, 255, .95); stroke: rgba(60, 60, 67, .28); stroke-width: 1.3; filter: drop-shadow(0 3px 6px rgba(30, 36, 70, .1)); }
.vong-luu .cung.sel rect.o { fill: #fefce8; stroke: #facc15; stroke-width: 3; }
.vong-luu text { font-family: inherit; }
.nn-o .tt-ds { display: flex; flex-wrap: wrap; gap: 3px; }
.nn-o .tt-chip { white-space: normal; line-height: 1.25; padding: 2px 7px; }
.nn-o .dv-muc { display: inline-block; align-self: flex-start; font-size: 10.5px; line-height: 1.25; padding: 2px 7px; border: 1px solid transparent; }

/* Nút nổi chọn năm xem */
.nam-noi { position: fixed; right: 12px; top: 50%; transform: translateY(-50%); z-index: 50; display: flex; flex-direction: column; width: 58px; border-radius: 14px; overflow: hidden; background: rgba(255, 255, 255, .92); border: 1px solid rgba(22, 163, 74, .35); box-shadow: 0 6px 18px rgba(0, 0, 0, .12); backdrop-filter: blur(8px); }
.nam-noi[hidden] { display: none; }
.nam-noi button { border: 0; border-radius: 0; background: none; color: var(--accent); font-size: 13px; padding: 7px 0; cursor: pointer; box-shadow: none; }
.nam-noi button:hover { background: var(--accent); color: #fff; }
.nam-noi select { border: 0; border-top: 1px solid rgba(22, 163, 74, .25); border-bottom: 1px solid rgba(22, 163, 74, .25); border-radius: 0; padding: 7px 0; text-align: center; text-align-last: center; font-weight: 700; font-size: 13px; color: var(--accent); background: none; appearance: none; -webkit-appearance: none; cursor: pointer; box-shadow: none; }
.nam-noi select:focus { box-shadow: none; }
.nam-noi option { color: #1c1c1e; font-weight: 400; background: #fff; }
.nam-noi option.dau-van { background: rgba(255, 214, 120, .9); font-weight: 700; }
/* Rê chuột xem thử: chỉ hiện đường của hóa đó */
.rail-hoa label.thu { opacity: 1; outline: 1px dashed currentColor; outline-offset: -3px; }
.nam-noi button.nhan { background: var(--accent); color: #fff; }
/* Tình duyên: cột Dấu hiệu hẹp lại, nhãn tự xuống dòng */
#tdBang { table-layout: auto; width: 100%; }
#tdBang th:not(:nth-child(3)), #tdBang td:not(:nth-child(3)) { width: 1%; white-space: nowrap; }
#tdBang td:nth-child(3) .tt-ds { flex-wrap: wrap; }
.td-diem { font-size: 20px; font-weight: 800; color: var(--loc); line-height: 1.2; }

/* Nút Hỏi AI ở phần Thiên thời và bảng câu trả lời nền vàng (chữ hiện dần khi AI đang trả lời) */
.tt-hoi { display: block; margin: 12px auto 2px; padding: 9px 26px; border: 0; border-radius: 999px; background: #db2777; color: #fff; font-family: inherit; font-size: 14px; font-weight: 700; line-height: 1; cursor: pointer; box-shadow: 0 4px 14px rgba(219, 39, 119, .35); transition: transform .15s, filter .15s; }
.tt-hoi:hover { filter: brightness(1.08); }
.tt-hoi:active { transform: scale(.96); }
.tt-hoi:disabled { opacity: .6; cursor: progress; }
.tt-ai { margin-top: 12px; padding: 12px 16px; border-radius: var(--r-md); background: #fef9c3; border: 1px solid #fde047; font-size: 13.5px; line-height: 1.6; color: #3a3a3c; }
.tt-ai h3, .tt-ai h4 { margin: 10px 0 4px; font-size: 14.5px; }
.tt-ai p { margin: 6px 0; }
.tt-ai ul, .tt-ai ol { margin: 4px 0; padding-left: 20px; }
.tt-ai .tt-loi { color: #b91c1c; font-weight: 600; }
.tt-ai .tt-nguon { display: block; margin-top: 8px; font-size: 11px; color: #8e8e93; }
.tt-ai .tt-ghi { font-size: 11.5px; font-style: italic; color: #8e8e93; margin: 0 0 6px; }
.van-tg { height: 26px; margin: 2px 0 0; }
.van-row[hidden] { display: none; }
.tt-ai .tt-tieude { margin: 0 0 6px; font-size: 16px; color: #9d174d; }
.hoi-ai-cho:empty { display: none; }

/* Nút ⚙ cài đặt prompt AI (góc trên bên phải) và hộp danh sách prompt */
.ai-cd-nut { position: fixed; top: 12px; right: 12px; z-index: 60; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255, 255, 255, .92); font-size: 18px; cursor: pointer; box-shadow: 0 3px 10px rgba(0, 0, 0, .12); transition: transform .2s; }
.ai-cd-nut:hover { transform: rotate(45deg); }
.ai-cd { position: fixed; inset: 0; z-index: 100000; background: rgba(0, 0, 0, .35); display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; overflow-y: auto; }
.ai-cd[hidden] { display: none; }
.ai-cd-hop { width: min(720px, 100%); background: #fff; border-radius: 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, .25); padding: 16px 18px; }
.ai-cd-dau { display: flex; align-items: center; justify-content: space-between; font-size: 16px; }
.ai-cd-dau button { border: 0; background: none; font-size: 18px; cursor: pointer; color: #6b6b70; }
.ai-cd-goiy { margin: 4px 0 12px; font-size: 12px; color: #6b6b70; }
.ai-cd-muc { border-top: 1px solid var(--line); padding: 12px 0; }
.ai-cd-ten { font-weight: 700; margin-bottom: 6px; }
.ai-cd-ten small { font-weight: 500; color: #db2777; }
.ai-cd-muc textarea { width: 100%; box-sizing: border-box; font: 13px/1.5 system-ui, sans-serif; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.ai-cd-nutds { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.ai-cd-nutds button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 14px; cursor: pointer; font: inherit; font-size: 13px; }
.ai-cd-nutds .ai-luu { background: #db2777; color: #fff; border-color: #db2777; font-weight: 700; }
/* Khóa mật khẩu trang cài đặt */
.ai-cd-khoa { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 18px 0 8px; border-top: 1px solid var(--line); margin-top: 10px; }
.ai-cd-khoa[hidden] { display: none; }
.ai-cd-khoa > div { width: 100%; font-weight: 600; }
.ai-cd-khoa input { width: 140px; font: 16px/1.2 system-ui, sans-serif; letter-spacing: 4px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; }
.ai-cd-khoa button { border: 1px solid #db2777; background: #db2777; color: #fff; border-radius: 999px; padding: 7px 16px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 700; }
.ai-cd-sai { color: #dc2626; font-size: 13px; }
.ai-bao { font-size: 12px; color: #16a34a; }

/* Mỗi khối nền trắng phủ một lớp màu cầu vồng chuyển màu mượt (7 màu: đỏ, cam, vàng, lục, lam, chàm, tím), khối thứ 8 là hồng.
   Nền phủ kín một lớp màu nhạt (không còn chỗ trắng), trên đó vài vùng đậm nhạt rất rộng chồng lên nhau và tan dần vào nhau cho chuyển màu mượt.
   Đổi màu: sửa --cv ở từng dòng (các mức đậm nhạt tự pha từ màu này). Chỉ áp dụng trên màn hình, khi in vẫn nền trắng */
@media screen {
  .form.glass       { --cv: #fecdd3; }  /* Nhập thông tin: đỏ */
  #vong             { --cv: #fed7aa; }  /* Vòng phi hóa: cam */
  .chart            { --cv: #fef08a; }  /* Lá số: vàng */
  #dvWrap .dv-box   { --cv: #bbf7d0; }  /* Đại vận · Thiên thời: lục */
  #llWrap .dv-box   { --cv: #bfdbfe; }  /* Lưu Lộc Tồn: lam */
  #tdWrap .dv-box   { --cv: #c7d2fe; }  /* Tình duyên: chàm */
  #nnWrap .dv-box   { --cv: #e9d5ff; }  /* Năm xem: tím */
  #ttWrap .dv-box   { --cv: #fbcfe8; }  /* Tam Tai: hồng */
  .form.glass, #vong, .chart, .muc .dv-box {
    --nen: color-mix(in srgb, var(--cv) 11%, #fff);
    --dam: color-mix(in srgb, var(--cv) 29%, transparent);
    --sang: rgba(255, 255, 255, .7);
    background:
      radial-gradient(70% 90% at 10% 10%, var(--dam), transparent 100%),
      radial-gradient(60% 80% at 95% 85%, var(--dam), transparent 100%),
      radial-gradient(55% 70% at 75% 15%, var(--sang), transparent 100%),
      radial-gradient(55% 70% at 25% 90%, var(--sang), transparent 100%),
      var(--nen);
  }
}

/* Màu nền các khối đổi dần liên tục qua 7 màu cầu vồng (mỗi vòng 35 giây, mỗi khối lệch pha một chút nên không cùng màu).
   @property cho phép trình duyệt chuyển mượt giữa hai màu thay vì nhảy. Người dùng bật "giảm chuyển động" thì đứng yên ở màu riêng */
@property --cv { syntax: '<color>'; inherits: true; initial-value: #fff; }
@keyframes doi-mau-cau-vong {
  0%, 100% { --cv: #fecdd3; }   /* đỏ */
  14.3%    { --cv: #fed7aa; }   /* cam */
  28.6%    { --cv: #fef08a; }   /* vàng */
  42.9%    { --cv: #bbf7d0; }   /* lục */
  57.1%    { --cv: #bfdbfe; }   /* lam */
  71.4%    { --cv: #c7d2fe; }   /* chàm */
  85.7%    { --cv: #e9d5ff; }   /* tím */
}
@media screen and (prefers-reduced-motion: no-preference) {
  .form.glass, #vong, .chart, .muc .dv-box { animation: doi-mau-cau-vong 35s linear infinite; }
  .form.glass     { animation-delay: 0s; }
  #vong           { animation-delay: -5s; }
  .chart          { animation-delay: -10s; }
  #dvWrap .dv-box { animation-delay: -15s; }
  #llWrap .dv-box { animation-delay: -20s; }
  #tdWrap .dv-box { animation-delay: -25s; }
  #nnWrap .dv-box { animation-delay: -30s; }
  #ttWrap .dv-box { animation-delay: -2.5s; }
}
