:root {
  --bg: #f7f2e6;
  --paper: #fffdf7;
  --paper-2: #fbf6ea;
  --ink: #2b2419;
  --ink-2: #4c4231;
  --muted: #776b58;
  --line: #e3d7c0;
  --line-2: #d3c3a4;
  --gold: #a77f2c;
  --gold-2: #d8b463;
  --gold-3: #f3e3b8;
  --red: #a3392a;
  --jade: #2f6b57;
  --shadow: 0 1px 2px rgba(70, 50, 10, .06), 0 16px 40px rgba(70, 50, 10, .08);
  --radius: 16px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background:
    radial-gradient(900px 460px at 50% -12%, rgba(216, 180, 99, .18), transparent 70%),
    var(--bg);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--serif); color: var(--ink); font-weight: 600; line-height: 1.2; margin: 0; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code { background: var(--paper-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-size: .88em; }
.muted { color: var(--muted); font-weight: 400; }
.wrap { width: min(1180px, 100% - 40px); margin-inline: auto; }
.center { text-align: center; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: 999px;
  padding: 11px 20px; font-weight: 600; font-size: 14.5px; line-height: 1.2;
  transition: background .18s, border-color .18s, color .18s, transform .1s, box-shadow .18s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-gold {
  background: linear-gradient(135deg, #f0d99a, var(--gold-2));
  color: #33240a;
  box-shadow: 0 8px 22px rgba(167, 127, 44, .22);
}
.btn-gold:hover { filter: brightness(1.04); }
.btn-ghost { background: var(--paper); border-color: var(--line-2); color: var(--ink); }
.btn-ghost:hover { border-color: var(--gold); background: var(--paper-2); }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- Thanh đầu ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(247, 242, 230, .88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-in { display: flex; align-items: center; gap: 22px; height: 64px; }
.brand { display: inline-flex; align-items: center; gap: 9px; flex: none; }
.brand-mark {
  width: 30px; height: 30px; display: grid; place-items: center;
  border-radius: 50%; color: var(--gold);
  border: 1px solid var(--line-2); background: var(--paper);
  font-size: 14px;
}
.brand-text { font-family: var(--serif); font-size: 19px; color: var(--ink); font-weight: 600; }
.brand-text small { font-family: var(--sans); font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); margin-left: 4px; }
.nav { display: flex; gap: 18px; font-size: 13.5px; color: var(--muted); }
.nav a { padding: 4px 0; border-bottom: 1px solid transparent; }
.nav a:hover { color: var(--ink); border-color: var(--gold-2); }
.account { margin-left: auto; display: flex; align-items: center; gap: 9px; min-width: 0; }
.user-name { font-size: 13px; color: var(--ink); font-weight: 600; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Hero ---------- */
.hero { padding: 56px 0 30px; }
.hero-in { display: grid; grid-template-columns: 1.02fr .98fr; gap: 44px; align-items: start; }
.eyebrow {
  font-size: 11px; letter-spacing: .24em; text-transform: uppercase;
  color: var(--gold); font-weight: 700; margin-bottom: 10px;
}
.hero h1 { font-size: clamp(32px, 4.3vw, 52px); letter-spacing: -.015em; margin-bottom: 18px; }
.hero h1 em { font-style: italic; color: var(--gold); }
.lead { color: var(--muted); font-size: 16px; max-width: 54ch; }
.lead.small { font-size: 14px; }
.hero-points { list-style: none; padding: 0; margin: 22px 0 0; display: grid; gap: 8px; }
.hero-points li { position: relative; padding-left: 20px; font-size: 13.5px; color: var(--ink-2); }
.hero-points li::before { content: "✦"; position: absolute; left: 0; top: 0; color: var(--gold); font-size: 10px; }
.hero-points b { color: var(--ink); }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.form-card { padding: 22px; }
.form-card h2 { font-size: 22px; margin-bottom: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; margin-bottom: 12px; }
.field label, .label { font-size: 12px; font-weight: 700; letter-spacing: .02em; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea {
  width: 100%; height: 42px; padding: 0 11px;
  border: 1px solid var(--line-2); border-radius: 9px;
  background: var(--paper); color: var(--ink);
  outline: none; transition: border-color .16s, box-shadow .16s;
}
textarea { height: auto; padding: 10px 11px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(216, 180, 99, .22); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { grid-template-columns: .8fr .8fr 1.1fr; }
.seg { display: flex; background: var(--paper-2); border: 1px solid var(--line-2); border-radius: 9px; padding: 3px; height: 42px; }
.seg-btn { flex: 1; border: 0; background: transparent; border-radius: 7px; font-size: 13px; color: var(--muted); font-weight: 500; }
.seg-btn.is-on { background: var(--paper); color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgba(70, 50, 10, .14); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.check input { width: 17px; height: 17px; accent-color: var(--gold); }
.hint { font-size: 12.5px; color: var(--muted); margin: 4px 0 12px; }
.fineprint { font-size: 11.5px; color: var(--muted); line-height: 1.55; margin-top: 10px; }
.error {
  background: #fbece5; border: 1px solid #ecc7b8; color: #8a2f21;
  padding: 8px 11px; border-radius: 8px; font-size: 13px; margin: 8px 0 12px;
}

/* ---------- Section ---------- */
.section { padding: 64px 0; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.section-head.center { justify-content: center; text-align: center; }
.section-head h2 { font-size: clamp(26px, 3vw, 36px); }
.section-head .lead { margin-top: 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.eyebrow + h2 { margin-top: 2px; }

.results { padding-top: 24px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1.42fr) minmax(360px, 1fr); gap: 20px; align-items: start; }
.chart-column { min-width: 0; }
.scroll-hint { display: none; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.chart-scroll { overflow-x: auto; padding-bottom: 4px; }

.chart {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(148px, auto));
  gap: 6px;
  min-width: 640px;
  background: var(--line-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 6px;
}
.cell {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
  display: flex; flex-direction: column; gap: 3px;
  font-size: 11.5px; line-height: 1.34;
  min-width: 0; text-align: left;
  transition: border-color .16s, box-shadow .16s, background .16s;
}
.cell:hover { border-color: var(--gold-2); box-shadow: 0 6px 16px rgba(70, 50, 10, .09); }
.cell.is-selected { border-color: var(--gold); box-shadow: inset 0 0 0 2px rgba(216, 180, 99, .4); background: #fffdf3; }
.cell.is-menh { background: linear-gradient(180deg, #fffdf4, #fbf1d7); }
.cell-head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.cell-name { font-family: var(--serif); font-size: 15.5px; color: var(--ink); font-weight: 600; white-space: nowrap; }
.cell-name .body-tag {
  font-family: var(--sans); font-size: 8px; letter-spacing: .08em; text-transform: uppercase;
  background: var(--ink); color: var(--gold-3); border-radius: 999px; padding: 1px 5px;
  vertical-align: 2px; margin-left: 3px;
}
.cell-branch { color: var(--muted); font-size: 10.5px; white-space: nowrap; }
.stars { display: flex; flex-direction: column; gap: 1px; }
.star { display: block; overflow-wrap: anywhere; }
.star.major { color: var(--red); font-weight: 700; }
.star.minor { color: var(--ink-2); }
.star.adjective { color: var(--muted); font-size: 10.5px; }
.star .bright { font-size: .82em; color: var(--muted); font-weight: 400; margin-left: 2px; }
.star .mut {
  font-size: .78em; font-weight: 700; color: #7a5310;
  background: var(--gold-3); border-radius: 4px; padding: 0 3px; margin-left: 3px;
}
.cell-foot {
  margin-top: auto; padding-top: 3px; border-top: 1px dashed var(--line);
  color: var(--muted); font-size: 10.5px; display: flex; justify-content: space-between; gap: 6px;
}
.center-cell {
  grid-row: 2 / 4; grid-column: 2 / 4;
  background: linear-gradient(180deg, #fffdf6, #f8efda);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: 5px; min-width: 0;
}
.center-cell h3 { font-size: clamp(18px, 2.4vw, 26px); }
.center-cell .c-name { font-size: 12px; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); font-weight: 700; }
.center-cell .c-line { font-size: 11.5px; color: var(--ink-2); }
.center-cell .c-line b { color: var(--ink); }
.center-cell .c-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; margin-top: 4px; font-size: 11px; color: var(--muted); }
.center-cell .c-grid b { color: var(--ink-2); font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.major { background: var(--red); }
.dot.minor { background: var(--ink-2); }
.dot.adjective { background: var(--line-2); }
.dot.mutagen { background: var(--gold-2); }

/* ---------- Panel luận giải ---------- */
.panel { padding: 16px; position: sticky; top: 84px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.panel-head h3 { font-size: 21px; }
.badge { font-size: 11px; font-weight: 700; color: var(--gold); background: var(--gold-3); border-radius: 999px; padding: 3px 9px; white-space: nowrap; }
.palace-info { font-size: 13px; color: var(--ink-2); background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; min-height: 72px; }
.palace-info .pi-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.palace-info .pi-head b { font-family: var(--serif); font-size: 17px; color: var(--ink); }
.palace-info .pi-row { margin: 2px 0; }
.palace-info .pi-row span { color: var(--muted); }
.palace-info .tag { display: inline-block; font-size: 10.5px; padding: 1px 6px; border-radius: 999px; background: var(--gold-3); color: #7a5310; margin-left: 4px; font-weight: 700; }
.panel-actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.panel-actions .btn-gold { flex: 1; }
.ai-out {
  margin-top: 14px; padding: 14px; border-radius: 10px;
  background: var(--paper-2); border: 1px solid var(--line);
  font-size: 13.5px; line-height: 1.75; max-height: 520px; overflow-y: auto;
}
.ai-out h2 { font-size: 18px; margin: 16px 0 6px; }
.ai-out h2:first-child { margin-top: 0; }
.ai-out p { margin: 0 0 10px; }
.ai-out ul { margin: 0 0 10px; padding-left: 20px; }
.ai-out li { margin: 2px 0; }
.ai-out .ai-error { color: var(--red); }
.ai-out .cursor { display: inline-block; width: 7px; height: 1em; background: var(--gold); animation: blink 1s steps(2) infinite; vertical-align: -2px; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Bảng giá ---------- */
.pricing { border-top: 1px solid var(--line); background: rgba(255, 253, 247, .5); }
.plans { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: stretch; }
.plan {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; display: flex; flex-direction: column; gap: 8px; position: relative;
}
.plan.is-hot { border-color: var(--gold-2); box-shadow: 0 18px 46px rgba(167, 127, 44, .16); }
.plan .tag-hot {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  background: var(--gold); color: #fff; font-size: 10px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; border-radius: 999px; padding: 3px 10px;
  white-space: nowrap;
}
.plan h3 { font-size: 21px; }
.plan .price { font-family: var(--serif); font-size: 30px; color: var(--gold); line-height: 1.1; }
.plan .price small { font-size: 13px; color: var(--muted); font-family: var(--sans); }
.plan ul { list-style: none; margin: 8px 0 14px; padding: 0; display: grid; gap: 5px; font-size: 13px; }
.plan li { position: relative; padding-left: 17px; }
.plan li::before { content: "✦"; position: absolute; left: 0; top: 0; color: var(--gold); font-size: 9px; }
.plan .btn { margin-top: auto; }

/* ---------- Hướng dẫn ---------- */
.guide { background: var(--paper-2); border-top: 1px solid var(--line); }
.guide-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.guide-grid .card { padding: 18px; box-shadow: none; }
.guide-grid h3 { font-size: 17px; margin-bottom: 6px; }
.guide-grid p { font-size: 13px; color: var(--muted); }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--line); padding: 28px 0; background: var(--bg); }
.footer-in { display: flex; justify-content: space-between; gap: 24px; font-size: 12.5px; color: var(--muted); }
.footer-in b { font-family: var(--serif); font-size: 17px; color: var(--ink); }
.footer-in p { max-width: 64ch; margin-top: 4px; }
.footer-links { display: flex; gap: 14px; flex-wrap: wrap; align-content: flex-start; }
.footer-links a:hover { color: var(--gold); }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center; padding: 18px;
  background: rgba(43, 36, 25, .42);
  backdrop-filter: blur(3px);
}
.modal-card {
  width: min(440px, 100%); max-height: 92vh; overflow-y: auto;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 18px; padding: 22px; position: relative;
  box-shadow: 0 24px 70px rgba(30, 20, 5, .3);
}
.modal-card h3 { font-size: 23px; padding-right: 30px; }
.modal-x {
  position: absolute; top: 10px; right: 10px; width: 34px; height: 34px;
  border: 0; border-radius: 50%; background: transparent; font-size: 24px; color: var(--muted);
}
.modal-x:hover { background: var(--paper-2); color: var(--ink); }
.tabs { display: flex; gap: 4px; background: var(--paper-2); border-radius: 999px; padding: 3px; margin: 14px 0 16px; }
.tab { flex: 1; border: 0; background: transparent; border-radius: 999px; padding: 8px; font-size: 13px; color: var(--muted); }
.tab.is-on { background: var(--paper); color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgba(70, 50, 10, .12); }
.auth-form .field { margin-bottom: 10px; }

/* Thanh toán */
.pay-box { display: grid; place-items: center; gap: 10px; margin: 12px 0; }
.pay-qr { width: min(260px, 80vw); height: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 8px; }
.pay-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 15px; font-weight: 700; letter-spacing: .06em; background: var(--gold-3); border-radius: 8px; padding: 5px 10px; }
.pay-meta { font-size: 13px; color: var(--muted); text-align: center; }
.pay-status { text-align: center; font-size: 13.5px; font-weight: 600; margin-top: 8px; }
.pay-status.ok { color: var(--jade); }
.pay-status.warn { color: var(--gold); }

/* ---------- Responsive ---------- */
@media (max-width: 1020px) {
  .hero-in { grid-template-columns: 1fr; gap: 28px; }
  .hero-copy { max-width: 720px; }
  .workspace { grid-template-columns: 1fr; }
  .panel { position: static; }
  .plans { grid-template-columns: 1fr; max-width: 520px; margin-inline: auto; }
  .scroll-hint { display: block; }
  .guide-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .wrap { width: min(100% - 28px, 1180px); }
  .nav { display: none; }
  .hero { padding-top: 34px; }
  .section { padding: 46px 0; }
  .section-head { flex-direction: column; align-items: flex-start; }
  .row-3 { grid-template-columns: 1fr 1fr; }
  .row-3 .field:last-child { grid-column: 1 / -1; }
  .guide-grid { grid-template-columns: 1fr; }
  .footer-in { flex-direction: column; }
  .chart { min-width: 600px; }
}
@media (max-width: 480px) {
  .topbar-in { gap: 10px; }
  .brand-text { font-size: 17px; }
  .form-card { padding: 16px; }
  .center-cell .c-grid { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation: none !important; transition: none !important; }
}

/* ---------- In / lưu PDF ---------- */
@media print {
  .topbar, .hero-copy, #bang-gia, #huong-dan, .footer, .panel, .actions, .scroll-hint, .fineprint { display: none !important; }
  body { background: #fff; }
  .section, .results { padding: 0; }
  .workspace { display: block; }
  .chart { min-width: 0; border-color: #999; box-shadow: none; }
  .cell { break-inside: avoid; font-size: 9px; }
  .chart-column { width: 100%; }
}
