:root {
  --bg: #faf7f2; --surface: #ffffff; --surface-2: #f3eee6; --text: #1f1a17; --muted: #6b625a;
  --line: #e4dcd0; --accent: #9a3412; --accent-ink: #ffffff; --accent-soft: #fdebdc;
  --ok: #166534; --err: #b91c1c; --err-bg: #fef2f2; --focus: #c2410c;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(60,30,10,.06);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #15120f; --surface: #1f1b17; --surface-2: #29231e; --text: #f3ede6; --muted: #b3a89c;
  --line: #3a322b; --accent: #f59e5b; --accent-ink: #1b120b; --accent-soft: #3a2518;
  --ok: #4ade80; --err: #fca5a5; --err-bg: #3b1414; --focus: #fb923c;
  --shadow: none; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15120f; --surface: #1f1b17; --surface-2: #29231e; --text: #f3ede6; --muted: #b3a89c;
    --line: #3a322b; --accent: #f59e5b; --accent-ink: #1b120b; --accent-soft: #3a2518;
    --ok: #4ade80; --err: #fca5a5; --err-bg: #3b1414; --focus: #fb923c;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { font-size: 19px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", "Malgun Gothic", sans-serif;
  line-height: 1.55; padding-top: 64px;
}
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Header cố định */
.top {
  position: fixed; inset: 0 0 auto 0; height: 64px; z-index: 10;
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px); -webkit-backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 1.1rem; margin-right: auto; white-space: nowrap; }
.brand svg { width: 34px; height: 34px; flex: none; }
.brand .lg-bg { fill: var(--accent); } .brand .lg-fg { stroke: var(--accent-ink); } .brand .lg-fill { fill: var(--accent-ink); }
.top select, .icon-btn {
  height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-size: .85rem; padding: 0 10px; cursor: pointer;
}
.icon-btn { width: 44px; padding: 0; display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; }

main { max-width: 760px; margin: 0 auto; padding: 20px 16px 40px; }
h1 { font-size: 1.9rem; line-height: 1.2; margin: 12px 0 6px; text-wrap: balance; }
h2 { font-size: 1.3rem; margin: 0 0 12px; }
.lead { color: var(--muted); margin: 0 0 18px; font-size: 1.05rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }

/* Form chữ to */
.field { margin-bottom: 18px; }
.field > label, .label { display: block; font-weight: 650; margin-bottom: 6px; }
input[type=text], input[type=number], input[type=date], select.big {
  width: 100%; min-height: 56px; font: inherit; font-size: 1.1rem; padding: 10px 14px;
  border: 2px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text);
}
input:focus, select:focus { border-color: var(--accent); outline: none; }
.row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 12px; min-height: 48px; margin-top: 10px; cursor: pointer; font-size: 1.05rem; }
.check input { width: 28px; height: 28px; accent-color: var(--accent); flex: none; }
.hint { color: var(--muted); font-size: .88rem; margin: 6px 0 0; }
.linkbtn { background: none; border: 0; padding: 8px 0; color: var(--accent); font: inherit; font-size: .95rem; text-decoration: underline; cursor: pointer; min-height: 44px; }
.conv { color: var(--ok); font-weight: 600; margin: 8px 0 0; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 60px;
  border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-ink);
  font: inherit; font-size: 1.15rem; font-weight: 700; cursor: pointer; padding: 10px 18px; text-align: center;
}
.btn:hover { filter: brightness(1.06); }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); font-weight: 650; font-size: 1.02rem; }
.btn svg { width: 24px; height: 24px; flex: none; }
.actions { display: grid; gap: 10px; }
.actions .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

details.rules { border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px; margin-bottom: 18px; background: var(--surface-2); }
details.rules summary { cursor: pointer; font-weight: 650; min-height: 48px; display: flex; align-items: center; }
fieldset { border: 0; margin: 0 0 12px; padding: 0; }
legend { font-weight: 650; margin-bottom: 4px; font-size: .95rem; }
.radio { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: .95rem; cursor: pointer; }
.radio input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.alert { background: var(--err-bg); color: var(--err); border-radius: 12px; padding: 14px 16px; font-weight: 600; margin-bottom: 18px; }
.ok { color: var(--ok); font-weight: 600; margin: 10px 0 0; }

/* Kết quả */
.next { text-align: center; background: var(--accent-soft); border-color: transparent; }
.next .who { font-weight: 700; color: var(--muted); }
.next .date { font-size: 1.7rem; font-weight: 800; line-height: 1.25; margin: 6px 0; text-wrap: balance; }
.next .left { display: inline-block; background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 4px 16px; font-weight: 700; font-size: 1.05rem; }
.next .lunar { margin: 10px 0 0; }
.tag { display: inline-block; border-radius: 8px; padding: 1px 8px; font-size: .82rem; font-weight: 700; background: var(--accent); color: var(--accent-ink); }
.tag-het { background: var(--text); color: var(--bg); }
.next .tag { margin-top: 8px; font-size: .95rem; }
.note { font-size: .85rem; color: var(--muted); }
.muted { color: var(--muted); font-size: .88rem; }
.big { font-size: 1.08rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { white-space: nowrap; font-size: .85rem; color: var(--muted); font-weight: 650; }
tr.is-next td { background: var(--accent-soft); }
tr.is-past td { opacity: .55; }
.mem ul { list-style: none; padding: 0; margin: 0; }
.mem li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.mem li:last-child { border: 0; }
.mem b { display: block; }

details.faq { border-bottom: 1px solid var(--line); padding: 4px 0; }
details.faq summary { cursor: pointer; font-weight: 650; min-height: 48px; display: flex; align-items: center; }
details.faq p { margin: 0 0 14px; color: var(--muted); }
.howto ul { padding-left: 20px; margin: 0; }
.howto li { margin-bottom: 8px; }

footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px 40px; border-top: 1px solid var(--line); }

@media (max-width: 600px) {
  html { font-size: 18px; }
  h1 { font-size: 1.6rem; }
  .card { padding: 16px; }
  .actions .pair { grid-template-columns: 1fr; }
  .brand span { display: none; }
  /* bảng → thẻ gọn */
  thead { display: none; }
  table, tbody { display: block; width: 100%; }
  tr { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "year left" "solar solar" "lunar note";
       column-gap: 10px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; padding: 10px 14px; }
  tr.is-next { border: 2px solid var(--accent); background: var(--accent-soft); }
  td { border: 0; padding: 0; background: none !important; }
  .c-year { grid-area: year; } .c-left { grid-area: left; text-align: right; font-weight: 650; }
  .c-solar { grid-area: solar; padding: 2px 0; } .c-solar br { display: none; } .c-solar .muted { margin-left: 6px; }
  .c-lunar { grid-area: lunar; color: var(--muted); font-size: .9rem; } .c-note { grid-area: note; text-align: right; }
}
@media (max-width: 600px) { .row.stack { grid-template-columns: 1fr; gap: 0; } }
@media (max-width: 380px) { .row { grid-template-columns: 1fr; } }

@media print {
  .top, form, .actions, .howto, .faq-sec, footer, #icsDone, .lead, h1 { display: none !important; }
  body { padding: 0; background: #fff; color: #000; }
  .card { box-shadow: none; border: 0; }
  tr.is-past td { opacity: 1; }
}

.leapnote { margin: 0 0 10px; color: var(--muted); font-size: .92rem; }
:lang(ko), :lang(zh-Hant), :lang(zh-Hans) { word-break: keep-all; overflow-wrap: anywhere; }
