/* Layout: ba cột như một bàn học — hồ sơ bên trái, cuốn vở ô ly ghi nhật ký ở giữa, ngăn kéo menu bên phải */
:root {
  --bg: #eef1f7;
  --surface: #ffffff;
  --paper: #fdfdff;
  --rule: #dce3f2;
  --margin: #eba9a9;
  --ink: #1d2140;
  --muted: #646b8b;
  --tim: #4b2fa0;          /* mực tím học trò */
  --line: #dde1ec;
  --good: #1d7a47;
  --bad: #b8323a;
  --accent: #4b2fa0;
  --accent-fg: #ffffff;
  --c-health: #2f9e5c;
  --c-happy: #d99a00;
  --c-smarts: #3a6fd8;
  --c-looks: #d4508c;
  --shadow: 0 1px 2px rgba(29,33,64,.06), 0 10px 30px rgba(29,33,64,.10);
  --f-hand: "Patrick Hand", "Comic Sans MS", cursive;
  --f-ui: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f111d; --surface: #171a2b; --paper: #161929; --rule: #242a44; --margin: #6a3440;
    --ink: #e4e6f5; --muted: #9aa0c0; --tim: #b9a6ff; --line: #2a2f4a;
    --good: #5fd394; --bad: #ff8088; --accent: #a58bff; --accent-fg: #15102b;
    --c-health: #4fc97f; --c-happy: #f2c037; --c-smarts: #6f9bff; --c-looks: #f27bb0;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f111d; --surface: #171a2b; --paper: #161929; --rule: #242a44; --margin: #6a3440;
  --ink: #e4e6f5; --muted: #9aa0c0; --tim: #b9a6ff; --line: #2a2f4a;
  --good: #5fd394; --bad: #ff8088; --accent: #a58bff; --accent-fg: #15102b;
  --c-health: #4fc97f; --c-happy: #f2c037; --c-smarts: #6f9bff; --c-looks: #f27bb0;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--f-ui); font-size: 14px; line-height: 1.5;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { max-width: 1320px; margin: 0 auto; height: 100%; display: flex; flex-direction: column; padding-block: 14px; gap: 14px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand h1 { font-family: var(--f-hand); font-weight: 400; font-size: 32px; line-height: 1; margin: 0; color: var(--tim); }
.brand span { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 500;
}
.btn:hover { border-color: var(--accent); }
.topbtns { display: flex; gap: 8px; }
.bugtext { width: 100%; min-height: 70px; font: inherit; padding: 8px; border-radius: 8px; border: 1px solid var(--line, #ccc); background: var(--card, transparent); color: inherit; box-sizing: border-box; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

.grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 290px minmax(0, 1fr) 340px; gap: 14px; }
.col { min-height: 0; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }

/* Hồ sơ */
.profile { padding: 18px; display: flex; flex-direction: column; gap: 16px; overflow: auto; }
.who { display: flex; gap: 12px; align-items: center; }
.avatar {
  flex: none; width: 56px; height: 56px; border-radius: 50%; overflow: hidden; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 14%, transparent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}
.avatar svg, .avprev svg, .obit-av svg { display: block; }
.face { display: inline-block; flex: none; border-radius: 50%; overflow: hidden; vertical-align: middle; background-color: color-mix(in srgb, var(--accent) 14%, transparent); background-repeat: no-repeat; background-size: 500% 100%; }
.face svg { display: block; width: 100%; height: 100%; }
.face.dead { filter: grayscale(1); opacity: .8; }
.item .ic-av { flex: none; display: grid; place-items: center; margin-right: 2px; }
.dhead { display: flex; align-items: center; gap: 14px; }
.actimg { display: block; width: 100%; max-height: 42vh; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; margin: 0 0 12px; background: #f6efe0; }
.dhead h3 { margin-top: 2px; }
.facegrid { flex: 1; min-width: 180px; display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; max-height: 196px; overflow-y: auto; padding: 2px; }
.facegrid button { border: 2px solid transparent; border-radius: 50%; padding: 0; background: none; cursor: pointer; width: 44px; height: 44px; }
.facegrid button[aria-pressed="true"] { border-color: var(--accent); }
.facegrid .face { width: 40px; height: 40px; }
.avpick { display: flex; gap: 14px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.avprev { flex: none; width: 84px; height: 84px; border-radius: 50%; overflow: hidden; box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.avfields { flex: 1; min-width: 180px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.goals { margin: 4px 0 10px; padding-left: 18px; font-size: 13.5px; line-height: 1.55; }
.goals .muted { color: var(--muted); font-size: 12px; }
.goals.miss { opacity: .55; text-decoration: line-through; }
.obit-av { width: 76px; height: 76px; border-radius: 50%; overflow: hidden; margin: 0 auto 8px; }
.who h2 { margin: 0; font-size: 17px; line-height: 1.3; text-wrap: balance; }
.who p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; min-width: 0; }
.facts dd.neg { color: var(--bad); }
.facts dd.sick { color: var(--bad); }
.stats { display: flex; flex-direction: column; gap: 12px; padding-top: 14px; border-top: 1px solid var(--line); }
.stat-h { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.stat-h b { font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 99px; background: color-mix(in srgb, var(--ink) 8%, transparent); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; transition: width .4s ease; }

/* Cuốn vở */
.book { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.log {
  flex: 1; min-height: 0; overflow-y: auto; padding: 28px 18px 28px 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(90deg, transparent 66px, var(--margin) 66px, var(--margin) 67px, transparent 67px),
    linear-gradient(var(--rule) 1px, transparent 1px);
  background-size: 100% 100%, 100% 28px;
  background-attachment: local;
  font-family: var(--f-hand); font-size: 19px; line-height: 28px; color: var(--tim);
}
.yr { display: grid; grid-template-columns: 66px minmax(0, 1fr); }
.yr-age { text-align: right; padding-right: 12px; color: var(--muted); font-size: 19px; }
.yr-age small { font-size: 13px; margin-left: 2px; }
.yr-lines { padding-left: 14px; min-width: 0; }
.ln { margin: 0; }
.ln.q { color: var(--ink); }
.ln.good { color: var(--good); }
.ln.bad { color: var(--bad); }
.ln.muted { color: var(--muted); }
.agebar { display: flex; align-items: center; gap: 12px; padding: 12px; border-top: 1px solid var(--line); background: var(--surface); }
.agebtn {
  flex: 1; border: 0; border-radius: 12px; padding: 12px 18px; background: var(--accent); color: var(--accent-fg); cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 14px; transition: transform .12s ease, filter .12s;
}
.agebtn:hover { filter: brightness(1.08); }
.agebtn:active { transform: scale(.98); }
.agebtn b { font-family: var(--f-hand); font-weight: 400; font-size: 28px; line-height: 1; }
.agebtn span { font-size: 13px; opacity: .85; }
.kbd { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* Ngăn kéo */
.drawer { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.tabs { display: flex; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 1 0 auto; border: 0; background: none; padding: 12px 2px; font-size: 12px; white-space: nowrap; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--tim); border-bottom-color: var(--accent); }
.tabbody { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.sec { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin: 8px 0 2px; }
.sec:first-child { margin-top: 0; }
.item {
  width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 10px 12px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.item:hover:not(:disabled) { border-color: var(--accent); }
.item .main { flex: 1; min-width: 0; }
.item .ic { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; margin-right: 2px; background: color-mix(in srgb, var(--ic) 14%, transparent); color: var(--ic); }
.item .ic svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.item .ic-none { background: none; }
.g-health { --ic: #2f9e6b } .g-study { --ic: #3a6fd8 } .g-fun { --ic: #8a5cd6 } .g-money { --ic: #b07a0e } .g-love { --ic: #d6457a } .g-looks { --ic: #c8577b } .g-risk { --ic: #d64545 } .g-shop { --ic: var(--accent) }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .g-health { --ic: #5fd394 } :root:not([data-theme="light"]) .g-study { --ic: #7ea6ff } :root:not([data-theme="light"]) .g-fun { --ic: #b79bff } :root:not([data-theme="light"]) .g-money { --ic: #f2c14e } :root:not([data-theme="light"]) .g-love { --ic: #ff7fae } :root:not([data-theme="light"]) .g-looks { --ic: #ff8fb0 } :root:not([data-theme="light"]) .g-risk { --ic: #ff8088 } }
:root[data-theme="dark"] .g-health { --ic: #5fd394 } :root[data-theme="dark"] .g-study { --ic: #7ea6ff } :root[data-theme="dark"] .g-fun { --ic: #b79bff } :root[data-theme="dark"] .g-money { --ic: #f2c14e } :root[data-theme="dark"] .g-love { --ic: #ff7fae } :root[data-theme="dark"] .g-looks { --ic: #ff8fb0 } :root[data-theme="dark"] .g-risk { --ic: #ff8088 }
.item:disabled { cursor: default; opacity: .5; }
.item .t { font-weight: 600; display: block; }
.item .d { color: var(--muted); font-size: 12.5px; display: block; margin-top: 1px; }
.item .r { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; }
.item .mini { width: 70px; margin-top: 4px; height: 5px; }
.note { color: var(--muted); font-size: 13px; margin: 0; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 8px; }
.note.neg { color: var(--bad); border-color: var(--bad); }
.jobcard { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.jobcard h3 { margin: 0; font-size: 15px; }
.jobcard p { margin: 0; color: var(--muted); font-size: 13px; }
.dead { text-decoration: line-through; }

/* Hộp thoại */
.scrim { position: fixed; inset: 0; background: rgba(12, 14, 30, .5); display: grid; place-items: center; padding: 16px; z-index: 20; }
.dialog {
  width: min(460px, 100%); max-height: calc(100% - 32px); overflow: auto; background: var(--surface); border-radius: 14px;
  box-shadow: var(--shadow); padding: 22px; display: flex; flex-direction: column; gap: 14px; animation: pop .18s ease;
}
@keyframes pop { from { transform: translateY(6px) scale(.98); opacity: .6; } to { transform: none; opacity: 1; } }
.dialog .kicker { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.dialog h3 { margin: -8px 0 0; font-family: var(--f-hand); font-weight: 400; font-size: 28px; line-height: 1.15; color: var(--tim); text-wrap: balance; }
.dialog .body { font-size: 15px; line-height: 1.6; }
.dialog .body p { margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12.5px; font-weight: 600; padding: 3px 9px; border-radius: 99px; font-variant-numeric: tabular-nums; }
.chip.up { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.chip.down { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 11px 14px; cursor: pointer; text-align: left; font-weight: 500; }
.choice:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.choice.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); text-align: center; }
.choice.ghost { text-align: center; color: var(--muted); }
.choice:disabled { opacity: .45; cursor: default; }
.choice:disabled:hover { border-color: var(--line); background: var(--surface); }
.skills { display: flex; flex-direction: column; gap: 6px; padding-top: 14px; border-top: 1px solid var(--line); }
.skills .sec { margin: 0 0 2px; }
.sk { display: grid; grid-template-columns: 82px minmax(0, 1fr) 26px; gap: 8px; align-items: center; font-size: 12.5px; }
.sk .bar { height: 5px; }
.sk b { text-align: right; font-variant-numeric: tabular-nums; }
.dialog .body .hint { color: var(--muted); font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.field input, .field select { font: inherit; font-size: 15px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.obit { border-top: 1px solid var(--line); padding-top: 12px; }
.epitaph { font-family: var(--f-hand); font-size: 20px; color: var(--tim); text-align: center; margin: 4px 0 0; }

@media (max-width: 1080px) {
  html, body { height: auto; }
  .app { height: auto; }
  .grid { grid-template-columns: 270px minmax(0, 1fr); }
  .book { height: 70vh; flex: none; }
  .col.right { grid-column: 1 / -1; }
  .drawer { min-height: 420px; }
}
@media (max-width: 720px) {
  .grid { display: flex; flex-direction: column; }
  .book { height: 62vh; flex: none; }
  .agebar { position: sticky; bottom: env(safe-area-inset-bottom, 0px); }
  .kbd { display: none; }
  .log { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) { .dialog { animation: none; } .bar i { transition: none; } }
.lnk{background:none;border:0;padding:0;margin:0;font:inherit;color:inherit;cursor:pointer;text-decoration:underline dotted;text-underline-offset:3px;text-align:inherit}.lnk:hover{color:var(--accent)}

/* ---------- Tờ báo tử theo nấc (js/33b-ket-cuoc-doi.js). Màu giấy cố định ở cả sáng lẫn tối: giấy là giấy ---------- */
.ketdoi { --giay: #fdfcf8; --giay-bao: #f2efe6; --giay-so: #eef1e7; --giay-so-ke: #c7d2bd; --muc: #1a1a1a; --muc-nhat: #55554f; --tuong: #d6d2c8; --go: #6b4423; --vang: #c9a35a; --bang-tang: #0d0d0d; --bang-dinh: rgba(232, 222, 170, .82); --do-son: #a3262b; --f-trang: "Noto Serif", "Times New Roman", Georgia, serif; }
.ketdoi > div:first-child { border-radius: 10px; overflow: hidden; margin: 0 0 12px; }
.ketdoi .vat { padding: 16px 14px; }
.ketdoi .dianh { position: relative; overflow: hidden; flex: none; line-height: 0; }
.ketdoi .dianh .face { border-radius: 0; display: block; }
.ketdoi .dianh.bang::after { content: ""; position: absolute; top: 15%; right: -32%; width: 90%; height: 13%; background: var(--bang-tang); transform: rotate(45deg); box-shadow: 0 1px 2px rgba(0,0,0,.4); }
.ketdoi .khung-go { border: 9px solid var(--go); box-shadow: inset 0 0 0 2px var(--vang), 0 4px 10px rgba(0,0,0,.25); }
.ketdoi .khung-den { border: 6px solid var(--muc); box-shadow: 0 3px 8px rgba(0,0,0,.2); }
.ketdoi .khung-don { border: 4px solid #3b3b38; box-shadow: 0 2px 6px rgba(0,0,0,.18); }
.ketdoi .phac { border: 1px dashed var(--muc-nhat); }
.ketdoi .phac .face { filter: grayscale(1) contrast(.75) brightness(1.15); opacity: .38; }
.ketdoi .bao-nho { border: 1px solid var(--muc-nhat); }
.ketdoi .trang-bao { background: var(--giay-bao); color: var(--muc); font-family: var(--f-trang); }
.ketdoi .bao-ten { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; border-bottom: 3px double var(--muc); padding-bottom: 6px; }
.ketdoi .bao-ten b { font-weight: 900; font-size: 22px; letter-spacing: .02em; }
.ketdoi .bao-ten span { font-size: 11px; color: var(--muc-nhat); }
.ketdoi .tin-buon { text-align: center; font-weight: 900; font-size: 28px; letter-spacing: .14em; margin: 10px 0 8px; }
.ketdoi .bao-than, .ketdoi .manh-bao .than, .ketdoi .so-dong { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; }
.ketdoi .bao-than p, .ketdoi .manh-bao p { margin: 0; font-size: 14px; line-height: 1.5; min-width: 0; }
.ketdoi .cao-pho { color: var(--muc); font-family: var(--f-trang); text-align: center; }
.ketdoi .cao-pho h3 { font-family: var(--f-trang); color: var(--muc); margin: 4px 0 6px; font-weight: 900; font-size: 26px; letter-spacing: .2em; }
.ketdoi .cao-pho .bao-tin { font-style: italic; font-size: 14px; margin: 0 0 8px; }
.ketdoi .cao-pho .dianh { margin: 0 auto 8px; width: max-content; }
.ketdoi .cao-pho .ten-mat { font-weight: 900; font-size: 19px; margin: 6px 0 2px; }
.ketdoi .cao-pho .chuc { font-size: 14px; margin: 0 0 8px; }
.ketdoi .cao-pho .kinh-bao { font-weight: 900; letter-spacing: .12em; font-size: 13px; margin: 8px 0 0; }
.ketdoi .co-quan { background: var(--giay); outline: 7px solid var(--muc); outline-offset: -14px; padding: 26px 24px; }
.ketdoi .co-quan .ten-cq { font-family: var(--f-ui, inherit); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.ketdoi .tuong { background: var(--tuong); padding: 24px 16px 18px; }
.ketdoi .to-dan { position: relative; background: var(--giay); border: 2px solid var(--muc); padding: 16px 12px 12px; box-shadow: 0 6px 14px rgba(0,0,0,.18); transform: rotate(-1.2deg); }
.ketdoi .to-dan::before, .ketdoi .to-dan::after { content: ""; position: absolute; top: -12px; width: 70px; height: 22px; background: var(--bang-dinh); }
.ketdoi .to-dan::before { left: 14px; transform: rotate(-8deg); }
.ketdoi .to-dan::after { right: 14px; transform: rotate(7deg); }
.ketdoi .gia-dinh { font-size: 13px; margin: 6px 0 0; border-top: 1px solid var(--muc); padding-top: 6px; }
.ketdoi .so { background: var(--giay-so); color: var(--muc); background-image: repeating-linear-gradient(to bottom, transparent 0 27px, var(--giay-so-ke) 27px 28px); }
.ketdoi .khong-cao-pho { font-weight: 700; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--do-son); margin: 0 0 8px; }
.ketdoi .so-dau { font-size: 11.5px; font-weight: 700; color: var(--muc-nhat); text-transform: uppercase; letter-spacing: .05em; margin: 0 0 6px; }
.ketdoi .so-dong p { margin: 0; font-family: var(--f-hand); font-size: 18px; line-height: 28px; min-width: 0; }
.ketdoi .manh-bao-nen { background: var(--tuong); padding: 16px; }
.ketdoi .manh-bao { background: var(--giay-bao); color: var(--muc); font-family: var(--f-trang); padding: 14px; clip-path: polygon(0 2%, 6% 0, 14% 2%, 24% 0, 35% 1.5%, 47% 0, 58% 2%, 69% 0, 81% 1.5%, 92% 0, 100% 2%, 99% 30%, 100% 62%, 98.5% 100%, 86% 98%, 73% 100%, 60% 98.5%, 46% 100%, 33% 98%, 20% 100%, 8% 98.5%, 0 100%, 1.5% 64%, 0 33%); }
.ketdoi .manh-bao h4 { margin: 0 0 8px; font-weight: 700; font-size: 17px; line-height: 1.3; }
.ketdoi .binh-luan { margin-top: 10px; border-top: 1px solid var(--muc-nhat); padding-top: 8px; font-size: 12px; display: grid; gap: 4px; color: var(--muc-nhat); }
.ketdoi .binh-luan i { color: var(--muc); font-style: normal; }
.ketdoi .ket-nhan { display: grid; gap: 2px; margin: 0 0 6px; }
.ketdoi .ket-nhan span { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--tim); }
.ketdoi .ket-nhan b { font-size: 18px; }
