/* GiaDinhToi — giao diện: giấy dó, đỏ son, vàng kim; chữ to, nút lớn cho người lớn tuổi. */
:root {
  --paper: #fbf6ea; --card: #fffdf7; --ink: #2a1a12; --muted: #6b5a4c; --red: #8b1a1a; --red2: #b3261e;
  --gold: #c9a227; --line: #dfd0ad; --field: #fff; --ok: #1f6b3a; --base: 17px;
}
html.big { --base: 20px; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: var(--base); }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: "GDTSans", "Segoe UI", Roboto, Arial, sans-serif; line-height: 1.5; }
h1, h2 { font-family: "GDTSerif", Georgia, "Times New Roman", serif; font-weight: 700; color: var(--red); margin: 0 0 .4em; text-wrap: balance; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.15rem; }
p { margin: .3em 0 .8em; }
.hint { color: var(--muted); font-size: .9rem; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px; background: var(--red); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand b { font-family: "GDTSerif", Georgia, serif; font-size: 1.2rem; letter-spacing: .3px; display: block; line-height: 1.1; }
.brand small { display: block; color: #f4dfa0; font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.seal { width: 40px; height: 40px; flex: none; display: grid; place-items: center; background: #f4dfa0; color: var(--red); font-family: "GDTSerif", serif; font-weight: 700; border-radius: 6px; border: 2px solid var(--gold); }
.top-actions { display: flex; gap: 8px; align-items: center; }
.lang { display: flex; border: 1px solid #f4dfa0; border-radius: 8px; overflow: hidden; }
.lang button { border: 0; border-radius: 0; background: transparent; color: #fff; min-height: 40px; padding: 0 12px; font-weight: 700; }
.lang button.on { background: #f4dfa0; color: var(--red); }
.top .ghost { background: transparent; color: #fff; border-color: #f4dfa0; min-height: 40px; }

.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 6px 12px 0; background: #f3e8cc; border-bottom: 2px solid var(--gold); position: sticky; top: 0; z-index: 5; }
.tabs button { flex: none; border: 1px solid transparent; border-bottom: 0; border-radius: 10px 10px 0 0; background: transparent; padding: 10px 14px; min-height: 46px; font-weight: 700; color: var(--muted); }
.tabs button.on { background: var(--paper); border-color: var(--gold); color: var(--red); }

main { padding: 16px; max-width: 1500px; margin: 0 auto; }
.view[hidden] { display: none; }
.hero { padding: 6px 0 10px; max-width: 70ch; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.cards3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; align-items: start; }
.stats { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 16px; min-width: 110px; }
.stat b { display: block; font-size: 1.5rem; color: var(--red); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .88rem; }

button, .btn { font: inherit; min-height: 46px; padding: 8px 16px; border-radius: 10px; border: 1px solid #b89c5a; background: #fff8e3; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button:hover, .btn:hover { background: #f7ebc4; }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid #e0a800; outline-offset: 2px; }
button.primary { background: var(--red); color: #fff; border-color: var(--red); font-weight: 700; }
button.primary:hover { background: var(--red2); }
button.danger { color: var(--red2); border-color: var(--red2); background: #fff; margin-top: 12px; }
button.big { font-size: 1.1rem; min-height: 54px; padding: 10px 24px; }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 8px 0; }
.grow { flex: 1; }

input, select, textarea { font: inherit; color: var(--ink); background: var(--field); border: 1px solid #a8956a; border-radius: 8px; padding: 9px 10px; min-height: 46px; max-width: 100%; }
input[type=checkbox] { min-height: 0; width: 22px; height: 22px; vertical-align: -4px; accent-color: var(--red); }
input[type=file] { padding: 6px; width: 100%; }
textarea { width: 100%; min-height: 90px; }
label.field { display: block; margin: 8px 0; flex: 1 1 180px; }
label.field > span, .toolbar label > span { display: block; font-size: .88rem; color: var(--muted); margin-bottom: 2px; }
label.field input, label.field select { width: 100%; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 14px 0 0; padding: 8px 12px 12px; }
fieldset > label { display: block; margin: 6px 0; }
legend { font-weight: 700; color: var(--red); padding: 0 6px; }
.bandrow select { min-height: 40px; padding: 4px 8px; margin-left: 4px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 10px; }
.toolbar input, .toolbar select { min-width: 120px; }
#treeRoot { width: min(320px, 70vw); }
#treeWrap { position: relative; height: calc(100vh - 250px); min-height: 380px; background: #fffaf0 radial-gradient(circle at 50% 40%, #fff, #fbf1d6); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; touch-action: none; }
#treeSvg { width: 100%; height: 100%; display: block; cursor: grab; user-select: none; }
#treeSvg.drag { cursor: grabbing; }
#treeSvg .card { cursor: pointer; }
#treeSvg .card:hover > rect:first-child, #treeSvg .card.sel > rect:first-child { stroke: #e0a800; stroke-width: 4; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); padding: 20px; text-align: center; }

.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #eee2c4; white-space: nowrap; }
th { background: #f3e8cc; position: sticky; top: 0; font-size: .9rem; }
tbody tr { cursor: pointer; } tbody tr:hover { background: #fff3cf; }
td img, td .ph { width: 36px; height: 48px; object-fit: cover; border-radius: 4px; display: block; background: #e8dcc0; }
td.num { font-variant-numeric: tabular-nums; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .8rem; background: #f3e8cc; color: var(--muted); margin-right: 4px; }
.tag.m { background: #d5e5f6; color: #27425f; } .tag.f { background: #f8d3db; color: #6d2b3c; } .tag.d { background: #333; color: #fff; }

.photogrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.pcell { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px; text-align: center; font-size: .78rem; cursor: pointer; }
.pcell img, .pcell .ph { width: 90px; height: 120px; object-fit: cover; display: block; margin: 0 auto 4px; background: #e8dcc0; border-radius: 4px; }
.pcell.none { border-style: dashed; color: var(--muted); }
.progress { position: relative; height: 26px; background: #eee2c4; border-radius: 13px; overflow: hidden; margin-top: 10px; }
.progress div { height: 100%; width: 0; background: var(--gold); transition: width .15s; }
.progress span { position: absolute; inset: 0; display: grid; place-items: center; font-size: .85rem; font-weight: 700; }
.match { background: var(--card); border: 2px solid var(--gold); border-radius: 12px; padding: 14px; margin: 14px 0; }
.mrow { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.mrow .who { flex: 1 1 200px; }
.cands { display: flex; gap: 8px; flex-wrap: wrap; }
.cand { border: 3px solid transparent; border-radius: 8px; padding: 3px; background: #fff; cursor: pointer; text-align: center; font-size: .72rem; min-height: 0; flex-direction: column; max-width: 104px; }
.cand img { width: 84px; height: 112px; object-fit: cover; display: block; border-radius: 4px; }
.cand.on { border-color: var(--ok); background: #e7f5ea; }
.cand.skip { width: 84px; height: 124px; color: var(--muted); }

.day { display: flex; gap: 14px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 8px 0; cursor: pointer; }
.day .when { flex: none; width: 92px; text-align: center; border-right: 1px solid var(--line); padding-right: 12px; }
.day .when b { display: block; font-size: 1.3rem; color: var(--red); font-variant-numeric: tabular-nums; }
.day.soon { border-color: var(--red2); background: #fff3ef; }

.printgrid { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 16px; align-items: start; }
.previewcol { position: sticky; top: 64px; }
.preview { background: #777; padding: 10px; border-radius: 10px; }
.preview svg { width: 100%; height: auto; display: block; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .4); }
.log { font-family: ui-monospace, Consolas, monospace; font-size: .82rem; white-space: pre-wrap; color: var(--muted); margin-top: 14px; }
.shareitem { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-top: 1px solid var(--line); font-size: .9rem; }

dialog { border: 2px solid var(--gold); border-radius: 14px; padding: 0; width: min(760px, 96vw); max-height: 92vh; background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(40, 20, 10, .55); }
#dlgBody { padding: 18px; }
.dlghead { display: flex; gap: 14px; align-items: flex-start; }
.dlghead img, .dlghead .ph { width: 120px; height: 160px; object-fit: cover; border-radius: 8px; background: #e8dcc0; flex: none; border: 1px solid var(--line); }
.dlghead h2 { font-size: 1.4rem; margin-bottom: .2em; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 12px 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.linkbtn { background: none; border: 0; padding: 0 2px; min-height: 0; color: #1d4f91; text-decoration: underline; display: inline; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.formgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 14px; }
.formgrid .wide { grid-column: 1 / -1; }
.close { float: right; min-height: 40px; }
.cropwrap { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
#cropCanvas { width: 270px; height: 360px; border: 1px solid var(--line); background: #f3efe6; touch-action: none; cursor: move; border-radius: 6px; }
.err { color: var(--red2); font-weight: 700; }
.warn { background: #fff3cf; border: 1px solid var(--gold); border-radius: 10px; padding: 10px 14px; margin-top: 14px; }

#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: #2a1a12; color: #fff; padding: 12px 20px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 92vw; z-index: 50; }
#toast.on { opacity: 1; }

@media (max-width: 860px) {
  main { padding: 10px; }
  .printgrid { grid-template-columns: 1fr; }
  .previewcol { position: static; order: -1; }
  #treeWrap { height: calc(100vh - 300px); }
  .dlghead img, .dlghead .ph { width: 90px; height: 120px; }
  dialog { width: 100vw; max-width: 100vw; max-height: 100vh; border-radius: 0; margin: auto 0 0; }
  .kv { grid-template-columns: 1fr; } .kv dt { margin-top: 6px; font-size: .85rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---- bổ sung: Về tôi, cột thông tin, tư liệu, phong tục ---- */
.mebtn { background: #f4dfa0; color: var(--red); border-color: var(--gold); font-weight: 700; }
.top .mebtn { min-height: 40px; }
.treegrid { display: flex; gap: 12px; align-items: stretch; }
.treegrid #treeWrap { flex: 1; min-width: 0; }
#side { width: 360px; flex: none; background: var(--card); border: 2px solid var(--gold); border-radius: 12px; padding: 14px; overflow-y: auto; max-height: calc(100vh - 250px); min-height: 380px; }
#side .dlghead img, #side .dlghead .ph { width: 96px; height: 128px; }
#side .dlghead h2 { font-size: 1.2rem; }
#side .kv { grid-template-columns: 1fr; gap: 0; } #side .kv dt { margin-top: 8px; font-size: .82rem; }
#side .actions button { min-height: 42px; padding: 6px 12px; }
.kin { display: inline-block; background: var(--red); color: #fff; border-radius: 6px; padding: 2px 10px; font-weight: 700; margin: 4px 0; }
.kin small { font-weight: 400; opacity: .85; }
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin: 8px 0; }
.doc { border: 1px solid var(--line); border-radius: 8px; padding: 4px; text-align: center; font-size: .72rem; cursor: pointer; background: #fff; overflow: hidden; min-height: 0; display: block; }
.doc img, .doc .ico { width: 100%; height: 72px; object-fit: cover; display: grid; place-items: center; background: #f3e8cc; border-radius: 4px; font-weight: 700; color: var(--red); }
.doc span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer img { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; }
.viewer iframe { width: 100%; height: 70vh; border: 1px solid var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chips button { min-height: 40px; border-radius: 999px; padding: 4px 16px; }
.chips button.on { background: var(--red); color: #fff; border-color: var(--red); }
.star { background: none; border: 0; font-size: 1.5rem; min-height: 0; padding: 0 6px; color: #b89c5a; }
.star.on { color: #e0a800; }
details { margin-top: 10px; } summary { cursor: pointer; font-weight: 700; color: var(--red); padding: 6px 0; }
.row.six label.field { flex: 1 1 90px; }
.customgrid { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: 16px; align-items: start; }
#customList h3 { margin: 12px 0 4px; font-size: .9rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
#customList button.item { display: block; width: 100%; text-align: left; justify-content: flex-start; margin: 4px 0; min-height: 42px; }
#customList button.item.on { background: var(--red); color: #fff; border-color: var(--red); }
.article { white-space: pre-wrap; font-size: 1.02rem; line-height: 1.7; max-width: 75ch; }
.article mark { background: #fff0b8; padding: 0 2px; border-radius: 3px; }
.blocklabel { font-weight: 700; }
@media (max-width: 860px) {
  .treegrid { display: block; }
  #side { position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-height: 62vh; min-height: 0; z-index: 20; border-radius: 16px 16px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.3); }
  .customgrid { grid-template-columns: 1fr; }
}

/* ---- bản 3: logo, danh mục gia đình, nhạc, thông tin ---- */
.brand .logo { width: 44px; height: 44px; flex: none; display: block; }
#groupSel { min-height: 40px; max-width: 30vw; background: #fff8e3; border-color: var(--gold); font-weight: 700; color: var(--red); }
#btnMusic.on { background: #f4dfa0; color: var(--red); }
.musicbox { position: fixed; right: 12px; top: 64px; z-index: 30; width: min(340px, 94vw); background: var(--card); border: 2px solid var(--gold); border-radius: 12px; padding: 12px 14px; box-shadow: 0 8px 28px rgba(0, 0, 0, .3); }
.musicbox > b { color: var(--red); font-size: 1.05rem; } .musicbox #musicClose { float: right; font-size: 1.2rem; text-decoration: none; }
.musicbox input[type=range] { width: 100%; padding: 0; }
.dirgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.gcard { display: flex; gap: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; align-items: flex-start; text-align: left; }
.gcard.on { border: 2px solid var(--gold); background: #fffaf0; }
.gcard h2 { font-size: 1.25rem; margin-bottom: .2em; overflow-wrap: anywhere; }
.gav { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; flex: none; border: 2px solid var(--gold); display: block; }
.gav.noav svg { width: 100%; height: 100%; display: block; } .gav.noav { border: 0; }
.gbody { flex: 1; min-width: 0; } .gbody .row button { min-height: 42px; padding: 6px 14px; }
.gnew { flex-direction: column; align-items: center; justify-content: center; text-align: center; border: 2px dashed #b89c5a; background: transparent; min-height: 170px; cursor: pointer; }
.gnew .plus { font-size: 2.6rem; line-height: 1; color: var(--red); }
.abouthead { display: flex; gap: 18px; align-items: center; margin-bottom: 16px; }
.biglogo svg { width: 96px; height: 96px; display: block; }
.aboutgrid { display: grid; grid-template-columns: 1fr minmax(300px, 400px); gap: 16px; align-items: start; }
.aboutgrid .panel { margin-bottom: 16px; } .aboutgrid .article { font-size: 1rem; max-width: 70ch; }
.support { text-align: center; border: 2px solid var(--gold); }
.support .qr { width: min(100%, 320px); height: auto; display: block; margin: 8px auto; border-radius: 12px; background: #fff; }
.kv.bank { grid-template-columns: max-content 1fr; text-align: left; align-items: center; } .kv.bank dd b { font-size: 1.15rem; letter-spacing: .5px; }
.kv.bank button { min-height: 40px; padding: 4px 12px; margin-left: 6px; }
@media (max-width: 860px) {
  .top { flex-wrap: wrap; } .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  #groupSel { max-width: 46vw; }
  .aboutgrid { grid-template-columns: 1fr; } .support { order: -1; }
  .gcard { flex-wrap: wrap; } .dirgrid { grid-template-columns: 1fr; }
  .kv.bank { grid-template-columns: max-content 1fr; }
}

/* ----- bản 4.1: Hướng dẫn, Lần đầu dùng, chân trang, PWA ----- */
.top .helpq { min-width: 40px; padding: 0 12px; font-weight: 700; font-size: 1.1rem; }
.firstuse { background: #fff3cf; border: 2px solid var(--gold); border-radius: 12px; padding: 12px 16px; margin: 0 0 14px; max-width: 900px; }
.firstuse b { color: var(--red); font-size: 1.05rem; }
.firstuse .row { margin: 8px 0 0; align-items: center; }
.helpsec { margin: 0 0 12px; max-width: 980px; }
.helpsec > summary { font-size: 1.1rem; font-family: "GDTSerif", Georgia, serif; padding: 2px 0; }
.helpsec .article { font-size: 1rem; }
.helpsec h3 { color: var(--red); margin: 1em 0 .3em; font-size: 1.02rem; }
.helpsec ol, .helpsec ul { padding-left: 1.3em; } .helpsec li { margin: .25em 0; }
.helpsec .kv dt { color: var(--ink); font-weight: 700; } .helpsec .kv dd { white-space: normal; }
.helptable { border-collapse: collapse; width: 100%; } .helptable th, .helptable td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; } .helptable th { background: #f3e8cc; }
.okmsg { color: var(--ok); font-weight: 700; }
.support h3 { color: var(--red); margin: 14px 0 4px; font-size: 1.02rem; } .support hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.sitefoot { display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: center; text-align: center; padding: 18px 16px 28px; border-top: 2px solid var(--gold); background: #f3e8cc; color: var(--muted); font-size: .92rem; margin-top: 24px; }
.sitefoot a, .sitefoot .linkbtn { color: #1d4f91; }
@media (display-mode: standalone) { .top { padding-top: max(8px, env(safe-area-inset-top)); } }
@media (max-width: 600px) { .top { flex-wrap: wrap; } .top-actions { flex-wrap: wrap; justify-content: flex-end; } }
