:root {
  --ink: #17342d;
  --muted: #64746f;
  --paper: #fbf8ef;
  --card: #fffdf7;
  --green: #1f6b55;
  --green-dark: #124b3b;
  --mint: #dcecdf;
  --gold: #e6a83c;
  --coral: #d96b52;
  --line: #d7ddd4;
  --shadow: 0 16px 45px rgba(23, 52, 45, .11);
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 20% 0%, #f2e7c9 0, transparent 30%), var(--paper); }
button, input { font: inherit; }
button { cursor: pointer; }
.topbar { height: 68px; display: flex; align-items: center; justify-content: space-between; padding: 0 max(20px, calc((100vw - 1120px)/2)); border-bottom: 1px solid rgba(23,52,45,.08); background: rgba(251,248,239,.92); backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; border: 0; background: none; color: var(--ink); font-weight: 800; font-size: 18px; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50% 50% 45% 55%; color: white; background: var(--green); font-family: Georgia, serif; font-size: 24px; }
.profile-button { border: 0; background: transparent; display: flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 700; }
.profile-button img { width: 38px; height: 38px; object-fit: cover; border-radius: 50%; border: 2px solid white; box-shadow: 0 0 0 2px var(--green); }
.desktop-nav { display: flex; align-items: center; gap: 4px; margin: 0 auto; padding: 0 18px; }
.desktop-nav button { min-height: 40px; padding: 0 14px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 800; }
.desktop-nav button:hover { color: var(--green); background: var(--mint); }
.desktop-nav button.active { color: white; background: var(--green); }
.hidden { display: none !important; }
main { width: min(1120px, 100%); margin: auto; padding: 28px 20px 110px; }
.loading-screen { min-height: 65vh; display: grid; place-content: center; text-align: center; color: var(--muted); }
.loader { width: 48px; height: 48px; margin: auto; border: 4px solid var(--mint); border-top-color: var(--green); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.eyebrow { color: var(--green); text-transform: uppercase; letter-spacing: .15em; font-weight: 800; font-size: 12px; }
h1 { font: 700 clamp(38px, 7vw, 72px)/.98 Georgia, serif; letter-spacing: -.035em; margin: 12px 0 18px; }
h2 { font: 700 clamp(30px, 5vw, 48px)/1.05 Georgia, serif; margin: 8px 0 14px; }
h3 { margin: 0 0 8px; }
p { line-height: 1.55; }
.hero { display: grid; grid-template-columns: 1.1fr .9fr; min-height: 68vh; align-items: center; gap: 55px; }
.hero p { font-size: 19px; color: var(--muted); max-width: 620px; }
.hero-art { position: relative; min-height: 430px; }
.portrait-stack img { width: 150px; height: 190px; object-fit: cover; border: 7px solid white; border-radius: 18px; box-shadow: var(--shadow); position: absolute; }
.portrait-stack img:nth-child(1) { left: 4%; top: 70px; transform: rotate(-8deg); }
.portrait-stack img:nth-child(2) { left: 36%; top: 0; transform: rotate(5deg); }
.portrait-stack img:nth-child(3) { left: 52%; top: 190px; transform: rotate(9deg); }
.portrait-stack img:nth-child(4) { left: 8%; top: 245px; transform: rotate(-3deg); }
.button-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 25px; }
.primary, .secondary, .danger { min-height: 48px; padding: 0 22px; border-radius: 999px; border: 1px solid transparent; font-weight: 800; }
.primary { background: var(--green); color: white; box-shadow: 0 8px 20px rgba(31,107,85,.22); }
.primary:hover { background: var(--green-dark); }
.secondary { background: transparent; color: var(--green); border-color: var(--green); }
.danger { background: #fff1ed; color: #a6412e; }
.onboarding { max-width: 760px; margin: 35px auto; }
.step { color: var(--muted); font-weight: 700; }
.notice { background: #fff7df; border-left: 4px solid var(--gold); padding: 14px 17px; border-radius: 8px; color: #66542c; font-size: 14px; }
.search { width: 100%; height: 54px; border: 1px solid var(--line); background: white; border-radius: 14px; padding: 0 18px; outline: none; font-size: 17px; }
.search:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(31,107,85,.12); }
.login-card { max-width: 560px; }
.login-card h1 { font-size: clamp(42px, 9vw, 68px); }
.login-card label { display: block; margin-bottom: 9px; }
.wide-button { width: 100%; margin-top: 16px; }
.form-error { margin-top: 10px; color: #a6412e; font-weight: 700; }
.upload-panel { display: grid; justify-items: center; gap: 16px; }
.upload-panel img { width: min(240px,70vw); aspect-ratio: 1; object-fit: cover; border-radius: 24px; }
.file-button { display: inline-grid; place-items: center; }
.qr-panel { text-align: center; }
.qr-panel img { width: min(320px,80vw); height: auto; image-rendering: pixelated; border: 12px solid white; border-radius: 18px; }
.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(225px, 1fr)); gap: 14px; margin-top: 20px; }
.person-card { display: grid; grid-template-columns: 70px 1fr; gap: 13px; text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 11px; color: var(--ink); min-height: 94px; transition: .18s ease; }
.person-card:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(23,52,45,.1); border-color: #a9c3b7; }
.person-card img, .avatar { width: 70px; height: 70px; object-fit: cover; border-radius: 12px; background: var(--mint); }
.person-card strong { display: block; line-height: 1.15; margin: 4px 0 6px; }
.person-card small { color: var(--muted); }
.person-card small { display: block; }
.person-card .alias { margin-bottom: 4px; color: var(--green); font-weight: 700; }
.life-facts { display: grid; grid-template-columns: repeat(auto-fit,minmax(190px,1fr)); gap: 10px; }
.life-facts .fact-card { margin: 0; }
.dashboard-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 22px 0 30px; }
.stat { background: var(--card); padding: 20px; border-radius: 18px; border: 1px solid var(--line); }
.stat b { display: block; font: 700 36px Georgia, serif; color: var(--green); }
.stat span { color: var(--muted); font-size: 14px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 22px; box-shadow: 0 8px 30px rgba(23,52,45,.05); margin: 18px 0; }
.encounter-list, .leader-list { display: grid; gap: 10px; }
.encounter, .leader { display: flex; align-items: center; gap: 14px; padding: 10px; border-radius: 14px; background: #f5f5ec; }
.encounter img, .leader img { width: 50px; height: 50px; object-fit: cover; border-radius: 50%; }
.encounter .grow, .leader .grow { flex: 1; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(180px,1fr)); gap: 14px; margin-top: 22px; }
.gallery-card { padding: 0 0 14px; overflow: hidden; text-align: left; border: 1px solid var(--line); border-radius: 18px; color: var(--ink); background: var(--card); }
.gallery-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; margin-bottom: 12px; }
.gallery-card strong,.gallery-card span { display: block; padding: 0 12px; }
.gallery-card span { margin-top: 4px; color: var(--green); font-size: 12px; font-weight: 700; }
.gallery-upload { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.gallery-upload h3, .gallery-upload p { margin: 0; }
.gallery-upload p { margin-top: 5px; color: var(--muted); }
.gallery-preview { width: 100%; max-height: 55vh; object-fit: contain; border-radius: 18px; background: var(--mint); }
.caption-label { display: block; margin: 18px 0 8px; font-weight: 800; }
.caption-label span { color: var(--muted); font-weight: 500; }
.relation { color: var(--green); font-size: 13px; font-weight: 700; }
.camera-shell { max-width: 680px; margin: 20px auto; text-align: center; }
.camera-frame { position: relative; overflow: hidden; aspect-ratio: 4/3; background: #10231e; border-radius: 24px; box-shadow: var(--shadow); }
.camera-frame video, .camera-frame canvas { width: 100%; height: 100%; object-fit: cover; }
.camera-guide { position: absolute; inset: 12%; border: 2px dashed rgba(255,255,255,.65); border-radius: 46% 46% 42% 42%; pointer-events: none; }
.camera-error { color: white; display: grid; place-content: center; height: 100%; padding: 25px; }
.camera-retry { margin-top: 8px; color: white; border-color: white; }
.recognition-ready { display: inline-flex; align-items: center; margin: 0 auto 14px; padding: 8px 12px; border-radius: 999px; color: var(--green-dark); background: var(--mint); font-size: 13px; font-weight: 800; }
.generation-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin: 18px 0; }
.chip { white-space: nowrap; border: 1px solid var(--line); border-radius: 999px; padding: 9px 14px; background: white; color: var(--muted); }
.chip.active { background: var(--green); border-color: var(--green); color: white; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(11,28,23,.7); z-index: 50; display: grid; place-items: center; padding: 18px; }
.modal { width: min(560px, 100%); max-height: 90vh; overflow: auto; background: var(--paper); border-radius: 24px; padding: 24px; box-shadow: var(--shadow); }
.gallery-upload-modal { position: relative; }
.gallery-photo-modal { position: relative; width: min(760px,100%); }
.gallery-full-photo { display: block; width: 100%; max-height: 62vh; object-fit: contain; border-radius: 18px; background: #10231e; }
.gallery-photo-modal h2 { margin-top: 18px; font-size: clamp(26px,5vw,38px); }
.text-button { padding: 0; border: 0; color: var(--green); background: transparent; font-weight: 800; }
.download-button { display: inline-grid; place-items: center; text-decoration: none; }
.admin-list { display: grid; gap: 10px; margin-top: 14px; }
.admin-row { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 14px; background: #f5f5ec; }
.admin-row img { width: 58px; height: 58px; object-fit: cover; border-radius: 10px; }
.admin-row small { display: block; margin-top: 4px; color: var(--muted); }
.compact { min-height: 40px; padding: 0 14px; }
.modal:has(.profile-tree) { width: min(820px, 100%); }
.modal-person { display: flex; gap: 18px; align-items: center; }
.modal-person img { width: 105px; height: 125px; object-fit: cover; border-radius: 16px; }
.profile-tree { display: grid; gap: 15px; }
.profile-middle { display: grid; grid-template-columns: minmax(0, .9fr) minmax(280px, 1.5fr); gap: 16px; align-items: stretch; }
.focus-person { min-height: 170px; display: flex; align-items: center; gap: 20px; padding: 18px; border-radius: 20px; background: var(--green-dark); color: white; }
.focus-person img { width: 112px; height: 135px; flex: 0 0 auto; object-fit: cover; border-radius: 16px; border: 4px solid rgba(255,255,255,.8); }
.focus-person h2 { margin: 5px 0 9px; font-size: clamp(27px, 4vw, 38px); }
.focus-person .eyebrow { color: #bfe1ce; }
.focus-person .relation { color: #f5d28f; }
.relation-branch { padding: 13px; border-radius: 18px; border: 1px solid var(--line); background: rgba(255,255,255,.6); }
.relation-branch.side { height: 100%; }
.branch-label { margin-bottom: 10px; color: var(--muted); font-size: 12px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.relative-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 9px; }
.side .relative-cards { grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); }
.relative-card { min-width: 0; border: 1px solid #ccd9d0; border-radius: 14px; background: white; color: var(--ink); padding: 9px; display: flex; align-items: center; gap: 10px; text-align: left; font-size: 13px; font-weight: 800; line-height: 1.15; transition: .16s ease; }
.relative-card:hover, .relative-card:focus-visible { transform: translateY(-2px); border-color: var(--green); box-shadow: 0 7px 17px rgba(23,52,45,.12); outline: none; }
.relative-card img { width: 47px; height: 54px; flex: 0 0 auto; object-fit: cover; border-radius: 9px; background: var(--mint); }
.fact-card { margin: 18px 0; background: var(--mint); border-radius: 16px; padding: 18px; }
.rank { font: 700 22px Georgia, serif; width: 34px; text-align: center; }
.you { outline: 2px solid var(--gold); }
.empty { text-align: center; padding: 35px 15px; color: var(--muted); }
.progress-track { height: 12px; margin: 18px 0 4px; overflow: hidden; border-radius: 999px; background: #dbe3dc; }
.progress-track > div { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--green), #5eac78); transition: width .25s ease; }
.loading-inline { min-height: 220px; display: grid; place-content: center; text-align: center; }
.candidate-list { display: grid; gap: 10px; margin: 20px 0; }
.candidate-card { width: 100%; min-height: 84px; display: grid; grid-template-columns: 28px 62px minmax(0,1fr) auto; align-items: center; gap: 10px; padding: 10px; text-align: left; border: 1px solid var(--line); border-radius: 17px; color: var(--ink); background: white; transition: .16s ease; }
.candidate-card:hover, .candidate-card:focus-visible { border-color: var(--green); box-shadow: 0 7px 18px rgba(23,52,45,.12); transform: translateY(-1px); outline: none; }
.candidate-card img { width: 62px; height: 62px; object-fit: cover; border-radius: 12px; }
.candidate-rank { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 50%; background: var(--mint); color: var(--green); font-weight: 900; }
.candidate-name { min-width: 0; }
.candidate-name strong, .candidate-name small, .similarity small { display: block; }
.candidate-name small, .similarity small { color: var(--muted); font-size: 11px; }
.similarity { text-align: right; color: var(--green); }
.similarity b { font-size: 19px; }
.toast { position: fixed; left: 50%; bottom: 92px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--ink); color: white; padding: 12px 18px; border-radius: 999px; z-index: 80; transition: .2s; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.bottom-nav { display: none; }
@media (max-width: 760px) {
  .gallery-upload { align-items: stretch; flex-direction: column; }
  .gallery-upload .file-button { width: 100%; }
  main { padding: 18px 14px 95px; }
  .hero { grid-template-columns: 1fr; min-height: auto; gap: 10px; }
  .hero-art { min-height: 355px; }
  .portrait-stack img { width: 125px; height: 158px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stats .stat:last-child { grid-column: 1/-1; }
  .dashboard-head { align-items: start; flex-direction: column; }
  .bottom-nav { position: fixed; display: grid; grid-template-columns: repeat(5,1fr); left: 0; right: 0; bottom: 0; z-index: 30; min-height: 72px; padding-bottom: env(safe-area-inset-bottom); background: rgba(255,253,247,.96); border-top: 1px solid var(--line); backdrop-filter: blur(12px); }
  .bottom-nav { gap: 7px; min-height: 82px; padding: 8px 8px max(8px, env(safe-area-inset-bottom)); background: rgba(250,247,237,.98); box-shadow: 0 -10px 30px rgba(23,52,45,.12); }
  .bottom-nav button { min-width: 0; border: 1px solid #d4ddd5; border-radius: 15px; background: white; color: #52645e; font-size: 11px; font-weight: 800; box-shadow: 0 2px 5px rgba(23,52,45,.06); transition: transform .15s ease, background .15s ease, color .15s ease; }
  .bottom-nav button:active { transform: scale(.96); }
  .bottom-nav span { display: block; font-size: 23px; line-height: 1; margin-bottom: 5px; }
  .bottom-nav button.active { color: white; border-color: var(--green); background: var(--green); box-shadow: 0 7px 16px rgba(31,107,85,.28); transform: translateY(-3px); }
  .profile-button span { display: none; }
  .desktop-nav { display: none !important; }
  .generation-tabs { flex-wrap: wrap; overflow-x: visible; gap: 7px; padding: 0; margin: 16px 0 18px; }
  .generation-tabs .chip { flex: 0 0 auto; min-height: 42px; padding: 9px 13px; text-align: center; }
  .profile-middle { grid-template-columns: 1fr; }
  .focus-person { order: -1; min-height: 145px; }
  .focus-person img { width: 90px; height: 110px; }
  .relative-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .relative-card { align-items: center; flex-direction: row; min-height: 70px; }
  .relative-card img { width: 47px; height: 54px; }
  .face-lab .panel { padding: 17px; }
  .candidate-card { grid-template-columns: 24px 54px minmax(0,1fr) auto; gap: 8px; padding: 8px; }
  .candidate-card img { width: 54px; height: 58px; }
  .candidate-name strong { font-size: 13px; line-height: 1.15; }
  .similarity b { font-size: 16px; }
}
