/* Gia Phả — Vietnamese lacquer art (sơn mài): lacquer black, cinnabar, gold leaf, ivory cards. */
:root {
    --lacquer: #140e0c;
    --lacquer-2: #1f1512;
    --lacquer-3: #2b1d18;
    --cinnabar: #9b2a1f;
    --gold: #d9b56c;
    --gold-hi: #f4dfa3;
    --gold-lo: #a97c35;
    --ivory: #fbf5e8;
    --ivory-2: #f2e5c9;
    --ink: #2a1d17;
    --muted: #8b7663;
    --jade: #5f8f7c;
    --rose: #b9667a;
    --danger: #a3322a;
    --radius: 16px;
    --display: 'Cormorant Garamond', 'Times New Roman', serif;
    --text: 'Be Vietnam Pro', system-ui, sans-serif;
    --lotus: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cg fill='none' stroke='%23d9b56c' stroke-width='2.2' stroke-linejoin='round'%3E%3Cpath d='M32 14c5 6 7 12 0 22c-7-10-5-16 0-22z'/%3E%3Cpath d='M32 36c-6-4-13-4-18-1c4 6 11 8 18 1z'/%3E%3Cpath d='M32 36c6-4 13-4 18-1c-4 6-11 8-18 1z'/%3E%3Cpath d='M14 46h36'/%3E%3C/g%3E%3C/svg%3E");
    --pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='none' stroke='%23d9b56c' stroke-opacity='.07' stroke-width='1.2'%3E%3Cpath d='M60 34c5 6 7 12 0 22c-7-10-5-16 0-22zM60 56c-6-4-13-4-18-1c4 6 11 8 18 1zM60 56c6-4 13-4 18-1c-4 6-11 8-18 1z'/%3E%3Ccircle cx='0' cy='0' r='18'/%3E%3Ccircle cx='120' cy='0' r='18'/%3E%3Ccircle cx='0' cy='120' r='18'/%3E%3Ccircle cx='120' cy='120' r='18'/%3E%3C/g%3E%3C/svg%3E");
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
html { touch-action: manipulation; }
body {
    background-color: var(--lacquer);
    background-image:
        radial-gradient(ellipse at 15% 0%, rgba(155, 42, 31, .28), transparent 55%),
        radial-gradient(ellipse at 90% 100%, rgba(217, 181, 108, .12), transparent 55%),
        var(--pattern);
    color: var(--ivory);
    font: 15px/1.5 var(--text);
    -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: var(--gold); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; }

/* ---------- Buttons & fields ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 18px; border-radius: 999px; border: 1px solid rgba(169, 124, 53, .55);
    background: rgba(255, 255, 255, .55); color: var(--ink); font-weight: 600; text-decoration: none;
    transition: transform .12s, box-shadow .2s, background .2s;
}
.btn:hover { box-shadow: 0 4px 14px rgba(169, 124, 53, .25); }
.btn:active { transform: translateY(1px); }
.btn.gold {
    border-color: transparent; color: #2a1606;
    background: linear-gradient(135deg, var(--gold-lo), var(--gold-hi) 45%, var(--gold) 70%, var(--gold-lo));
    box-shadow: 0 6px 18px rgba(217, 181, 108, .35), inset 0 1px 0 rgba(255, 255, 255, .5);
}
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(163, 50, 42, .35); background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.wide { width: 100%; }
.icon-btn {
    width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(217, 181, 108, .35);
    background: rgba(20, 14, 12, .55); color: var(--gold-hi); font-size: 18px; line-height: 1;
}
.icon-btn:hover { border-color: var(--gold); }
.field { display: block; margin: 0 0 12px; }
.field > span { display: block; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea, .inline input, .ask-name input, .share input {
    width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid #e4d3ae;
    background: #fffdf7; color: var(--ink); outline: none; transition: border-color .2s, box-shadow .2s;
}
.field textarea { resize: vertical; min-height: 90px; }
.field input:focus, .field select:focus, .field textarea:focus, .inline input:focus, .ask-name input:focus {
    border-color: var(--gold); box-shadow: 0 0 0 3px rgba(217, 181, 108, .25);
}
.row { display: flex; gap: 12px; }
.row > .field { flex: 1; min-width: 0; }
.row > .field.narrow { flex: 0 0 96px; }
.inline { display: flex; gap: 8px; }
.form-error { color: var(--danger); min-height: 1.3em; margin: 4px 0 8px; font-size: 14px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.seg { display: flex; gap: 6px; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 9px 6px; border-radius: 12px; border: 1px solid #e4d3ae; background: #fffdf7; color: var(--ink); cursor: pointer; }
.seg input:checked + span { background: linear-gradient(135deg, #f7e7bf, #eed49a); border-color: var(--gold); font-weight: 600; }
.seg input:focus-visible + span { box-shadow: 0 0 0 3px rgba(217, 181, 108, .35); }
.switch { display: flex; align-items: center; gap: 10px; margin: 6px 0 14px; cursor: pointer; color: var(--ink); font-weight: 500; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 44px; height: 26px; border-radius: 13px; background: #e4d3ae; position: relative; transition: background .2s; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s; }
.switch input:checked + .track { background: var(--muted); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px rgba(217, 181, 108, .35); }
.death-fields { border-left: 2px solid var(--gold); padding-left: 14px; margin: 0 0 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 10px 16px; border-radius: 999px; border: 1px solid var(--gold); background: #fffaf0; color: var(--ink); font-weight: 600; }
.chip:hover { background: #f7e7bf; }
.chip.ghost { border-style: dashed; font-weight: 500; }

/* ---------- Emblem ---------- */
.emblem { width: 92px; height: 92px; margin: 0 auto; background: var(--lotus) center / 70% no-repeat; border-radius: 50%; border: 1px solid rgba(217, 181, 108, .55); box-shadow: 0 0 0 6px rgba(217, 181, 108, .08), 0 0 40px rgba(217, 181, 108, .25); }
.emblem.small { width: 58px; height: 58px; margin-bottom: 8px; }
.emblem.tiny { width: 30px; height: 30px; margin: 0; box-shadow: none; }

/* ---------- Landing ---------- */
.landing { min-height: 100%; max-width: 1040px; margin: 0 auto; padding: 56px 20px 64px; position: relative; }
.landing.center { display: grid; place-items: center; }
.landing .lang { position: absolute; top: 18px; right: 20px; }
.lang { background: none; border: 1px solid rgba(217, 181, 108, .35); color: var(--gold-hi); border-radius: 999px; padding: 6px 14px; font-size: 13px; }
.hero { text-align: center; margin-bottom: 40px; animation: rise .8s ease both; }
.hero h1 {
    font: 700 clamp(56px, 11vw, 104px)/1 var(--display); margin: 22px 0 8px; letter-spacing: .02em;
    background: linear-gradient(180deg, var(--gold-hi), var(--gold) 55%, var(--gold-lo));
    -webkit-background-clip: text; background-clip: text; color: transparent;
    filter: drop-shadow(0 4px 24px rgba(217, 181, 108, .25));
}
.tagline { font: italic 500 22px/1.3 var(--display); color: #e9d8b4; margin: 0; }
.panels { display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px; align-items: start; }
.panel {
    background: linear-gradient(160deg, var(--ivory), var(--ivory-2)); color: var(--ink);
    border-radius: 22px; padding: 28px; position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .45), inset 0 0 0 1px rgba(255, 255, 255, .7), 0 0 0 1px rgba(217, 181, 108, .6);
    animation: rise .8s .1s ease both;
}
.panel::before { content: ''; position: absolute; inset: 7px; border-radius: 16px; border: 1px solid rgba(217, 181, 108, .45); pointer-events: none; }
.panel.narrow { width: min(420px, 100%); text-align: center; }
.panel.narrow .field { text-align: left; }
.panel h2 { font: 700 30px/1.15 var(--display); margin: 0 0 6px; }
.panel .muted { margin: 0 0 18px; }
.recent { margin-top: 22px; }
.recent h4 { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.recent-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; color: var(--ink); text-decoration: none; font: 600 19px var(--display); }
.recent-item:hover { background: rgba(217, 181, 108, .18); }
.lotus-dot { width: 22px; height: 22px; background: var(--lotus) center / contain no-repeat; filter: brightness(.7); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@media (max-width: 760px) {
    .landing { padding-top: 40px; }
    .panels { grid-template-columns: 1fr; }
    .row { flex-wrap: wrap; }
}

/* ---------- Tree page ---------- */
body.tree-page { overflow: hidden; overscroll-behavior: none; }
.stage { position: fixed; inset: 0; overflow: hidden; touch-action: none; cursor: grab; outline: none; -webkit-user-select: none; user-select: none; }
.stage.panning { cursor: grabbing; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.world.animate { transition: transform .45s cubic-bezier(.2, .8, .2, 1); }
.lines { position: absolute; overflow: visible; pointer-events: none; }
.lines .edge { fill: none; stroke: url(#gold); stroke-width: 2; opacity: .8; }
.lines .couple { fill: none; stroke: var(--gold); stroke-width: 2.4; }
.lines .couple.divorced { stroke-dasharray: 5 6; opacity: .7; }
.lines .couple.widowed { opacity: .55; }
.lines .couple.cross { stroke-dasharray: 2 7; stroke-linecap: round; }
.lines .ring { fill: var(--lacquer); stroke: var(--gold-hi); stroke-width: 2; }
.lines .ring.divorced { stroke-dasharray: 3 3; }
.lines .siblings { fill: none; stroke: var(--gold); stroke-width: 1.6; stroke-dasharray: 2 5; stroke-linecap: round; opacity: .7; }
.gen-label {
    position: absolute; top: -72px; text-align: center; font: italic 600 24px var(--display); color: var(--gold);
    letter-spacing: .03em; pointer-events: none;
}
.gen-label::after { content: ''; display: block; margin: 6px auto 0; width: 60%; height: 1px; background: linear-gradient(90deg, transparent, var(--gold), transparent); }

.card {
    position: absolute; width: 230px; height: 96px; display: flex; align-items: center; gap: 12px; padding: 0 14px 0 12px;
    border-radius: 18px; color: var(--ink); cursor: pointer; outline: none;
    background: linear-gradient(150deg, #fffbf1 0%, var(--ivory-2) 100%);
    box-shadow: 0 10px 26px rgba(0, 0, 0, .45), 0 0 0 1px rgba(217, 181, 108, .9), inset 0 0 0 4px rgba(255, 255, 255, .45);
    transition: transform .2s, box-shadow .25s;
}
.card::before { content: ''; position: absolute; inset: 5px; border-radius: 14px; border: 1px solid rgba(217, 181, 108, .4); pointer-events: none; }
.card:hover, .card:focus-visible { transform: translateY(-3px); box-shadow: 0 16px 34px rgba(0, 0, 0, .5), 0 0 0 1.5px var(--gold-hi), 0 0 30px rgba(217, 181, 108, .35); }
.card.selected { box-shadow: 0 16px 34px rgba(0, 0, 0, .5), 0 0 0 2.5px var(--gold-hi), 0 0 44px rgba(244, 223, 163, .55); }
.portrait {
    flex: none; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; overflow: hidden;
    font: 700 22px var(--display); color: #fffaf0; letter-spacing: .02em;
    background: linear-gradient(140deg, #a08a73, #6d5a49);
    box-shadow: 0 0 0 2px #fffaf0, 0 0 0 3.5px var(--gold), 0 4px 10px rgba(0, 0, 0, .25);
}
.card.m .portrait, .portrait.m { background: linear-gradient(140deg, #7fb09c, var(--jade) 60%, #3f6b5a); }
.card.f .portrait, .portrait.f { background: linear-gradient(140deg, #dc93a3, var(--rose) 60%, #8d4357); }
.portrait img { width: 100%; height: 100%; object-fit: cover; }
.card .info { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.card .name { font: 700 19px/1.12 var(--display); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .nick { font: italic 500 15px/1.15 var(--display); color: var(--cinnabar); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .years { font-size: 12px; letter-spacing: .06em; color: var(--muted); }
.card.passed { background: linear-gradient(150deg, #f6f0e4 0%, #e3d8c3 100%); }
.card.passed .portrait { filter: saturate(.55); }
.card.passed .info { padding-right: 14px; }
.card .lotus { position: absolute; right: 10px; top: 9px; width: 20px; height: 20px; background: var(--lotus) center / contain no-repeat; filter: brightness(.75) sepia(.3); opacity: .85; }
.card .plus {
    position: absolute; right: -13px; top: 50%; width: 28px; height: 28px; margin-top: -14px; border-radius: 50%;
    border: none; background: linear-gradient(135deg, var(--gold-lo), var(--gold-hi)); color: #2a1606; font: 700 19px/28px var(--text); padding: 0;
    box-shadow: 0 3px 10px rgba(0, 0, 0, .4); opacity: 0; transform: scale(.6); transition: opacity .2s, transform .2s;
}
.card:hover .plus, .card:focus-within .plus, .card.selected .plus { opacity: 1; transform: scale(1); }
@media (hover: none) { .card.selected .plus { opacity: 1; transform: scale(1); } }
.card.bloom { animation: bloom 1.1s cubic-bezier(.2, .9, .2, 1.2) both; }
.card.bloom::after { content: ''; position: absolute; inset: -2px; border-radius: 20px; pointer-events: none; animation: shimmer 1.4s ease-out both;
    background: linear-gradient(110deg, transparent 30%, rgba(255, 245, 210, .85) 50%, transparent 70%) 0 0 / 250% 100% no-repeat; }
@keyframes bloom { 0% { transform: scale(.4); opacity: 0; } 60% { opacity: 1; } 100% { transform: scale(1); } }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -100% 0; } }
.stage.far .card .nick, .stage.far .card .years { display: none; }

/* Top bar, zoom, empty state */
.topbar {
    position: fixed; top: max(10px, env(safe-area-inset-top)); left: 12px; right: 12px; z-index: 5;
    display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 12px; border-radius: 18px;
    background: rgba(20, 14, 12, .72); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(217, 181, 108, .28); box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.tree-name { font: 700 23px var(--display); color: var(--gold-hi); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-pill { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; padding: 3px 9px; border-radius: 999px; border: 1px solid rgba(217, 181, 108, .4); color: #cdb98e; white-space: nowrap; }
.role-pill.edit { color: #2a1606; background: linear-gradient(135deg, var(--gold), var(--gold-hi)); border-color: transparent; }
.topbar .btn.small { color: var(--gold-hi); background: transparent; border-color: rgba(217, 181, 108, .5); }
.search-wrap { position: relative; }
.search { width: 220px; padding: 9px 14px; border-radius: 999px; border: 1px solid rgba(217, 181, 108, .35); background: rgba(255, 255, 255, .06); color: var(--ivory); outline: none; }
.search::placeholder { color: #a8957a; }
.search:focus { border-color: var(--gold); }
.search-results { position: absolute; right: 0; top: 46px; width: 260px; padding: 6px; border-radius: 14px; background: var(--ivory); box-shadow: 0 14px 40px rgba(0, 0, 0, .45); }
.search-results button { display: block; width: 100%; text-align: left; padding: 9px 12px; border: none; border-radius: 10px; background: none; color: var(--ink); font: 600 18px var(--display); }
.search-results button:hover { background: #f3e5c3; }
.zoom { position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 5; display: flex; flex-direction: column; gap: 8px; }
@media (min-width: 761px) { body.sheet-open .zoom, body.sheet-open .topbar { right: 446px; } }
.topbar { transition: right .38s cubic-bezier(.2, .8, .2, 1); }
.zoom { transition: right .38s cubic-bezier(.2, .8, .2, 1); }
.zoom button { width: 46px; height: 46px; border-radius: 50%; border: 1px solid rgba(217, 181, 108, .45); background: rgba(20, 14, 12, .75); color: var(--gold-hi); font-size: 22px; backdrop-filter: blur(10px); }
.empty { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 4; text-align: center; padding: 34px 38px; border-radius: 24px;
    background: rgba(20, 14, 12, .65); border: 1px solid rgba(217, 181, 108, .35); backdrop-filter: blur(8px); }
.empty h2 { font: 700 34px var(--display); color: var(--gold-hi); margin: 0 0 6px; }
.empty .muted { color: #bca88a; margin: 0 0 20px; }
@media (max-width: 760px) {
    .topbar { flex-wrap: wrap; gap: 8px; }
    .search-wrap { order: 9; flex: 1 1 100%; }
    .search { width: 100%; }
    .search-results { left: 0; right: auto; width: 100%; }
    .tree-name { font-size: 20px; max-width: 46vw; }
    .topbar .role-pill { display: none; }
    .topbar .lang { padding: 6px 10px; font-size: 12px; }
}

/* ---------- Person sheet ---------- */
.sheet {
    position: fixed; z-index: 8; top: 10px; right: 10px; bottom: 10px; width: 420px; max-width: calc(100vw - 20px);
    background: linear-gradient(170deg, var(--ivory), #f4ead3); color: var(--ink); border-radius: 24px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .55), 0 0 0 1px rgba(217, 181, 108, .7);
    transform: translateX(calc(100% + 30px)); transition: transform .38s cubic-bezier(.2, .8, .2, 1); display: flex; flex-direction: column;
}
.sheet.open { transform: none; }
.sheet::before { content: ''; position: absolute; inset: 7px; border-radius: 18px; border: 1px solid rgba(217, 181, 108, .4); pointer-events: none; }
.sheet-grip { display: none; }
.sheet-close { position: absolute; top: 14px; right: 14px; z-index: 2; width: 36px; height: 36px; border-radius: 50%; border: 1px solid rgba(169, 124, 53, .4); background: rgba(255, 255, 255, .6); font-size: 22px; line-height: 1; }
.sheet-body { overflow-y: auto; padding: 28px 26px 30px; flex: 1; overscroll-behavior: contain; -webkit-user-select: text; user-select: text; }
.person-head { text-align: center; padding-bottom: 14px; }
.portrait.big { width: 132px; height: 132px; margin: 6px auto 14px; font-size: 44px; box-shadow: 0 0 0 4px #fffaf0, 0 0 0 6px var(--gold), 0 12px 30px rgba(0, 0, 0, .25); }
.person-head h2 { font: 700 32px/1.1 var(--display); margin: 0 0 4px; }
.person-head .nick { font: italic 500 21px var(--display); color: var(--cinnabar); margin: 0 0 4px; }
.person-head .span { font-size: 15px; letter-spacing: .05em; margin: 0 0 2px; }
.person-head .muted { margin: 0; font-size: 13px; }
.person-head.passed .portrait.big { filter: saturate(.6); }
.actions { display: flex; gap: 10px; justify-content: center; margin: 4px 0 18px; }
.memorial { margin: 0 0 18px; padding: 16px 18px 14px 56px; border-radius: 16px; position: relative;
    background: linear-gradient(140deg, #efe4cc, #e6d6b5); border: 1px solid rgba(169, 124, 53, .35); }
.memorial::before { content: ''; position: absolute; left: 16px; top: 16px; width: 28px; height: 28px; background: var(--lotus) center / contain no-repeat; filter: brightness(.6) sepia(.4); }
.memorial h4 { margin: 0 0 4px; }
.memorial p { margin: 0 0 4px; }
.sheet h4 { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.bio { margin: 0 0 18px; font: 500 18px/1.5 var(--display); }
.bio p { margin: 0 0 10px; }
.rel { margin: 0 0 18px; }
.rel > .person-chip { margin: 0 8px 8px 0; }
.kid-group { margin-bottom: 10px; }
.kid-group > p { margin: 0 0 6px; }
.person-chip { display: inline-flex; align-items: center; gap: 10px; padding: 6px 14px 6px 6px; border-radius: 999px; border: 1px solid rgba(169, 124, 53, .35); background: rgba(255, 255, 255, .6); text-align: left; }
.person-chip:hover { border-color: var(--gold); background: #fff; }
.person-chip b { display: block; font: 700 17px/1.1 var(--display); }
.person-chip small { display: block; font-size: 11px; color: var(--muted); }
.person-chip.passed { opacity: .82; }
.portrait.mini { width: 34px; height: 34px; font-size: 13px; box-shadow: 0 0 0 1.5px #fffaf0, 0 0 0 2.5px var(--gold); }
.sheet footer { display: flex; flex-direction: column; gap: 2px; margin: 10px 0 0; }
.danger-zone { margin-top: 18px; padding-top: 14px; border-top: 1px dashed rgba(169, 124, 53, .35); text-align: right; }
.person-form h2 { font: 700 28px var(--display); margin: 4px 40px 16px 0; }
@media (max-width: 760px) {
    .sheet { top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-width: none; height: 86vh; height: 86dvh; border-radius: 24px 24px 0 0; transform: translateY(102%); }
    .sheet::before { inset: 7px 7px 0; border-bottom: none; border-radius: 18px 18px 0 0; }
    .sheet-grip { display: block; width: 44px; height: 5px; border-radius: 3px; background: rgba(169, 124, 53, .4); margin: 9px auto 0; }
    .sheet-body { padding: 18px 20px calc(30px + env(safe-area-inset-bottom)); }
}

/* ---------- Modals, radial menu, toast ---------- */
.modal { border: none; padding: 0; border-radius: 22px; background: linear-gradient(160deg, var(--ivory), var(--ivory-2)); color: var(--ink);
    width: min(440px, calc(100vw - 32px)); box-shadow: 0 30px 80px rgba(0, 0, 0, .6), 0 0 0 1px rgba(217, 181, 108, .7); }
.modal::backdrop { background: rgba(10, 6, 5, .62); backdrop-filter: blur(3px); }
.modal[open] { animation: pop .28s cubic-bezier(.2, .9, .2, 1.15); }
.modal > * { padding: 24px; }
.modal h3 { font: 700 26px/1.15 var(--display); margin: 0 0 10px; }
.modal .chips { margin: 14px 0 16px; }
.modal .muted { margin: 0 0 12px; }
.share-row { margin-bottom: 12px; }
.share-row .muted { display: block; margin-bottom: 4px; }
@keyframes pop { from { transform: scale(.92); opacity: 0; } }

.radial-layer { position: fixed; inset: 0; z-index: 20; background: rgba(10, 6, 5, .35); animation: fade .15s; }
.radial-layer.closing { opacity: 0; transition: opacity .15s; }
.radial { position: absolute; width: 0; height: 0; }
.radial-btn {
    position: absolute; left: 0; top: 0; width: 84px; height: 84px; margin: -42px 0 0 -42px; border-radius: 50%; padding: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    border: none; color: #2a1606; background: radial-gradient(circle at 35% 30%, var(--gold-hi), var(--gold) 55%, var(--gold-lo));
    box-shadow: 0 10px 26px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .6);
    transform: translate(var(--dx), var(--dy)); animation: fan .32s calc(var(--i) * 35ms) cubic-bezier(.2, .9, .2, 1.3) both;
}
.radial-btn:focus-visible { outline: 3px solid #fff; }
.radial-icon { font-size: 22px; line-height: 1; }
.radial-label { font-size: 11.5px; font-weight: 600; line-height: 1.1; max-width: 76px; text-align: center; }
.radial-close { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; border: 1px solid var(--gold); background: var(--lacquer); color: var(--gold-hi); font-size: 24px; line-height: 1; }
@media (max-width: 500px) {
    .radial-btn { width: 72px; height: 72px; margin: -36px 0 0 -36px; }
    .radial-label { font-size: 10.5px; max-width: 64px; }
}
@keyframes fan { from { transform: translate(0, 0) scale(.3); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: max(26px, env(safe-area-inset-bottom)); z-index: 30; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
    padding: 12px 22px; border-radius: 999px; background: var(--lacquer-3); color: var(--gold-hi); font-weight: 600;
    border: 1px solid rgba(217, 181, 108, .5); box-shadow: 0 14px 40px rgba(0, 0, 0, .5); transition: opacity .25s, transform .25s; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.sparkle { background: linear-gradient(135deg, var(--gold-lo), var(--gold-hi) 50%, var(--gold)); color: #2a1606; border-color: transparent; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Stage 2: photos, resting places, maps ---------- */
.portrait-btn { position: relative; display: block; margin: 0 auto; padding: 0; border: none; background: none; border-radius: 50%; }
.portrait-btn .portrait.big { margin-bottom: 14px; }
.portrait-btn .cam { position: absolute; right: 2px; bottom: 16px; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-size: 17px;
    background: linear-gradient(135deg, var(--gold-lo), var(--gold-hi)); box-shadow: 0 4px 12px rgba(0, 0, 0, .3); transition: transform .2s; }
.portrait-btn:hover .cam { transform: scale(1.1); }
.gallery { margin: 0 0 18px; }
.gallery .grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb { aspect-ratio: 1; padding: 0; border: none; border-radius: 12px; overflow: hidden; background: #e9dcc0; box-shadow: 0 0 0 1px rgba(169, 124, 53, .35); }
.thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s; }
.thumb:hover img { transform: scale(1.06); }
.thumb.add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 1.5px dashed var(--gold); background: rgba(255, 255, 255, .5); color: var(--gold-lo); box-shadow: none; }
.thumb.add span { font-size: 28px; line-height: 1; }
.thumb.add small { font-size: 11px; font-weight: 600; }
.modal.wide { width: min(760px, calc(100vw - 24px)); }
.modal.dark { background: #0f0a09; color: var(--ivory); box-shadow: 0 30px 80px rgba(0, 0, 0, .7), 0 0 0 1px rgba(217, 181, 108, .45); }
.lightbox { outline: none; }
.lb-stage { position: relative; display: grid; place-items: center; min-height: 240px; }
.lb-stage img { max-width: 100%; max-height: 68vh; max-height: 68dvh; border-radius: 12px; box-shadow: 0 0 0 1px rgba(217, 181, 108, .4); touch-action: pan-y; -webkit-user-drag: none; }
.lb-nav { position: absolute; top: 50%; margin-top: -24px; width: 48px; height: 48px; border-radius: 50%; border: 1px solid rgba(217, 181, 108, .5); background: rgba(15, 10, 9, .7); color: var(--gold-hi); font-size: 30px; line-height: 1; }
.lb-nav.prev { left: 6px; } .lb-nav.next { right: 6px; }
.lb-meta { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin: 12px 2px 4px; }
.caption { margin: 0; font: italic 500 19px var(--display); }
.lb-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.modal.dark .btn:not(.gold) { color: var(--gold-hi); background: transparent; border-color: rgba(217, 181, 108, .45); }
.modal.dark .btn.danger { color: #e08a7f; border-color: rgba(224, 138, 127, .45); }
.resting { margin-top: 12px; padding-top: 12px; border-top: 1px dashed rgba(169, 124, 53, .4); }
.resting p { margin: 0 0 4px; }
.resting-kind { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--gold-lo); }
.resting-name { font: 700 21px/1.2 var(--display); }
.resting-photo { display: block; width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; margin: 10px 0; box-shadow: 0 0 0 1px rgba(169, 124, 53, .35); }
.resting .btn { margin-top: 10px; }
.mini-map { height: 150px; border-radius: 12px; overflow: hidden; margin: 10px 0 0; box-shadow: 0 0 0 1px rgba(169, 124, 53, .35); }
.companions { margin-top: 12px; }
.chip.small { padding: 6px 12px; font-size: 14px; font-family: var(--display); font-weight: 700; }
.resting-fields { border: 1px solid rgba(169, 124, 53, .35); border-radius: 14px; padding: 12px 14px 4px; margin: 0 0 12px; }
.resting-fields legend { padding: 0 6px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.seg.four { flex-wrap: wrap; margin-bottom: 12px; }
.seg.four label { flex: 1 1 calc(50% - 6px); }
.location { margin-bottom: 4px; }
.pin-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 12px; flex-wrap: wrap; }
.photo-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; box-shadow: 0 0 0 1px rgba(169, 124, 53, .4); display: block; }
.map-dialog .inline { margin-bottom: 10px; }
.map-pick { height: min(52vh, 440px); border-radius: 14px; overflow: hidden; box-shadow: 0 0 0 1px rgba(169, 124, 53, .45); }
.map-dialog .form-actions { flex-wrap: wrap; align-items: center; }
.place-form textarea { min-height: 60px; }
.pin span { display: block; width: 30px; height: 30px; margin: 0 auto; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
    background: radial-gradient(circle at 50% 50%, var(--lacquer) 0 5px, transparent 6px), linear-gradient(135deg, var(--gold-hi), var(--gold-lo));
    box-shadow: 0 4px 10px rgba(0, 0, 0, .4), 0 0 0 2px #fffaf0; }
.leaflet-container { font: 12px var(--text); }

/* ---------- Stage 3: giỗ, changes ---------- */
.gio-line { margin-top: 6px; }
.gio-line p { margin: 0 0 2px; }
.gio-lunar { font: 700 19px var(--display); color: var(--cinnabar); }
.gio-list ol, .changes ul { list-style: none; margin: 0 0 12px; padding: 0; max-height: 60vh; overflow-y: auto; }
.gio-item, .change-item { width: 100%; display: flex; align-items: center; gap: 14px; text-align: left; padding: 10px 8px; border: none; border-bottom: 1px solid rgba(169, 124, 53, .2); background: none; color: var(--ink); border-radius: 10px; }
.gio-item:hover, .change-item:not(:disabled):hover { background: rgba(217, 181, 108, .16); }
.change-item { justify-content: space-between; }
.change-item:disabled { cursor: default; }
.gio-date { flex: none; width: 54px; height: 58px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: linear-gradient(160deg, #fffaf0, #efdfbb); box-shadow: 0 0 0 1px rgba(169, 124, 53, .5); }
.gio-date b { font: 700 24px/1 var(--display); color: var(--cinnabar); }
.gio-date small { white-space: nowrap; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.gio-who { flex: 1; min-width: 0; }
.gio-who b { display: block; font: 700 19px/1.15 var(--display); }
.gio-who small { color: var(--muted); }
.gio-when { flex: none; font-size: 13px; font-weight: 600; color: var(--gold-lo); }
.gio-item.soon .gio-when { color: var(--cinnabar); }
.gio-banner { position: fixed; z-index: 6; left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + 70px); transform: translateX(-50%);
    display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 24px); padding: 8px 8px 8px 14px; border-radius: 999px;
    background: linear-gradient(135deg, #3a1a14, #22120e); border: 1px solid rgba(217, 181, 108, .55); box-shadow: 0 12px 30px rgba(0, 0, 0, .45); animation: rise .6s ease both; }
.gio-banner .link { background: none; border: none; color: var(--gold-hi); font: italic 600 18px var(--display); text-align: left; padding: 0; }
.gio-banner .x { width: 28px; height: 28px; border-radius: 50%; border: none; background: rgba(255, 255, 255, .08); color: var(--gold-hi); font-size: 18px; line-height: 1; }
.incense { width: 18px; height: 22px; flex: none; background: radial-gradient(circle at 50% 22%, #ffb35c 0 3px, transparent 4px), linear-gradient(var(--gold), var(--gold)) 50% 60% / 2px 60% no-repeat; animation: flicker 2.4s ease-in-out infinite; }
@keyframes flicker { 50% { opacity: .65; } }
@media (max-width: 760px) {
    .topbar .icon-btn { width: 36px; height: 36px; font-size: 16px; }
    .tree-name { max-width: 30vw; }
    .gio-banner { top: calc(max(10px, env(safe-area-inset-top)) + 112px); }
    .gio-banner .link { font-size: 16px; }
}
