:root {
  --bg: #eef1f6; --bg2: #e6eaf2; --panel: #ffffff; --ink: #0f172a; --muted: #64748b; --line: #e4e8ef;
  --accent: #1f4e79; --accent2: #2f78b8; --ring: rgba(47,120,184,.28);
  --r-sm: 9px; --r-md: 13px; --r-lg: 18px;
  --sh-1: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.05);
  --sh-2: 0 6px 18px rgba(15,23,42,.08); --sh-3: 0 18px 50px rgba(15,23,42,.16);
  --t: .2s cubic-bezier(.4,0,.2,1);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Inter", "Segoe UI", system-ui, Arial, sans-serif; color: var(--ink); background: radial-gradient(1200px 600px at 70% -10%, #f7f9fc 0%, var(--bg) 45%, var(--bg2) 100%); display: flex; flex-direction: column; -webkit-font-smoothing: antialiased; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px; padding: 12px 22px; background: rgba(255,255,255,.78); backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px); border-bottom: 1px solid var(--line); }
.brand-back { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; color: var(--accent); text-decoration: none; font-size: 22px; font-weight: 700; background: #fff; box-shadow: var(--sh-1); transition: var(--t); }
.brand-back:hover { transform: translateX(-2px); box-shadow: var(--sh-2); }
.brand { display: flex; flex-direction: column; line-height: 1.15; }
.brand-eyebrow { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.brand h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.live-pill { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 600; color: #15692f; background: #e8f7ee; border: 1px solid #c7ebd4; }
.live-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; animation: pulse 2s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(34,197,94,.5);} 70%{box-shadow:0 0 0 7px rgba(34,197,94,0);} 100%{box-shadow:0 0 0 0 rgba(34,197,94,0);} }

.layout { flex: 1; display: flex; min-height: 0; }
.rail { width: 300px; flex: 0 0 300px; overflow-y: auto; padding: 18px 16px 36px; display: flex; flex-direction: column; gap: 14px; }
.rail::-webkit-scrollbar { width: 9px; } .rail::-webkit-scrollbar-thumb { background: #cdd5e1; border-radius: 9px; border: 2px solid transparent; background-clip: content-box; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--sh-1); transition: var(--t); }
.panel:hover { box-shadow: var(--sh-2); }
.panel h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 0 0 13px; font-weight: 700; }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.preset { display: flex; flex-direction: column; align-items: center; gap: 7px; padding: 11px 8px; border: 1.5px solid var(--line); border-radius: var(--r-md); background: #fff; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--muted); transition: var(--t); }
.preset:hover { border-color: #c4d2e2; transform: translateY(-1px); box-shadow: var(--sh-1); }
.preset.active { border-color: var(--accent2); color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.pv { width: 44px; height: 34px; border-radius: 7px; padding: 4px; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 3px; background: #eef2f7; }
.pv i { display: block; background: #9fb6cf; border-radius: 2px; }
.pv-classic i { border-radius: 3px; }
.pv-cards { background: #e8edf4; } .pv-cards i { border-radius: 5px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.pv-circles i { border-radius: 50%; }
.pv-dark { background: #0b1220; } .pv-dark i { border-radius: 4px; background: #33415c; }
.ctl { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; margin: 11px 0; }
.ctl.row { flex-direction: row; align-items: center; justify-content: space-between; }
.ctl input[type=text] { font: inherit; font-weight: 500; font-size: 14px; color: var(--ink); padding: 9px 11px; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: #fbfcfe; transition: var(--t); }
.ctl input[type=file] { font-size: 12px; color: var(--muted); }
.ctl input[type=text]:focus { outline: none; border-color: var(--accent2); box-shadow: 0 0 0 3px var(--ring); background: #fff; }
.ctl input[type=color] { width: 42px; height: 30px; padding: 2px; border: 1.5px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.sel { position: relative; display: block; }
.sel::after { content: ""; position: absolute; right: 12px; top: 50%; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-65%) rotate(45deg); pointer-events: none; }
.sel select { appearance: none; -webkit-appearance: none; width: 100%; font: inherit; font-weight: 600; font-size: 14px; color: var(--ink); padding: 9px 30px 9px 11px; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: #fbfcfe; cursor: pointer; transition: var(--t); }
.sel select:focus { outline: none; border-color: var(--accent2); box-shadow: 0 0 0 3px var(--ring); background: #fff; }
.switch { display: flex; align-items: center; gap: 11px; font-size: 13.5px; font-weight: 500; color: var(--ink); cursor: pointer; margin: 11px 0; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { position: relative; flex: 0 0 auto; width: 38px; height: 22px; border-radius: 999px; background: #cbd5e1; transition: var(--t); }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: var(--t); }
.switch input:checked + .track { background: linear-gradient(180deg, var(--accent2), var(--accent)); }
.switch input:checked + .track::after { transform: translateX(16px); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; width: 100%; margin-top: 9px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: #fff; color: var(--ink); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; transition: var(--t); }
.btn:hover { border-color: #c4d2e2; transform: translateY(-1px); box-shadow: var(--sh-1); }
.btn.primary { border: 0; color: #fff; background: linear-gradient(180deg, var(--accent2), var(--accent)); box-shadow: 0 6px 16px rgba(31,78,121,.3); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn-link { background: none; border: 0; color: var(--accent); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; padding: 6px 0 0; }
.hint { font-size: 11px; color: var(--muted); line-height: 1.45; margin: 10px 0 0; }

/* ---------- board: top header + centered wall ---------- */
.stage { flex: 1; min-width: 0; overflow: auto; padding: 30px; display: flex; align-items: flex-start; justify-content: center; position: relative; }
.canvas-wrap { width: 100%; max-width: 1480px; border-radius: var(--r-lg); box-shadow: var(--sh-3); overflow: hidden; transition: var(--t); }
.board {
  --cols: 12; --gap: 8px; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: var(--gap);
  background: #fff; container-type: inline-size; padding: 30px;
}
.face { min-width: 0; }
.face .nm { max-width: 100%; }
@keyframes faceIn { from { opacity: 0; transform: translateY(16px) scale(.94); } to { opacity: 1; transform: none; } }
.board.cascade .face, .board.cascade .title-tile { opacity: 0; animation: faceIn .55s cubic-bezier(.2,.7,.2,1) both; }
.face { display: flex; flex-direction: column; }
.face .ph { position: relative; width: 100%; aspect-ratio: 1; border-radius: 9px; overflow: hidden; background: #e2e8f0; transition: transform .2s cubic-bezier(.2,.7,.2,1), box-shadow .2s ease; }
.face .ph img { width: 100%; height: 100%; object-fit: cover; object-position: center; display: block; }
.face .ph::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px rgba(15,23,42,.09); pointer-events: none; }
.board.style-dark .face .ph::after { box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); }
.face .nm { text-align: center; padding: 5px 2px 2px; font-size: 11px; font-weight: 600; color: var(--ink); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.face .nm .tt { display: block; font-size: 10px; font-weight: 400; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.face:hover .ph { transform: translateY(-3px); box-shadow: 0 12px 26px rgba(15,23,42,.20); z-index: 2; }

/* logo wrapped by photos (centered tile) */
.title-tile { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; padding: 10px; }
.title-tile img.logo { width: 94%; max-height: 70%; object-fit: contain; }
.title-tile h2 { margin: 0; font-weight: 800; letter-spacing: -.02em; color: var(--ink); line-height: 1.04; font-size: clamp(20px, 4cqw, 58px); }
.title-tile p { margin: 0; color: var(--muted); font-weight: 500; font-size: clamp(10px, 1.25cqw, 16px); }

.board.style-classic { --gap: 7px; }
.board.style-cards { --gap: 16px; }
.board.style-cards .face .ph { border-radius: 16px; box-shadow: 0 2px 6px rgba(15,23,42,.08), 0 10px 24px rgba(15,23,42,.10); }
.board.style-circles { --gap: 12px; }
.board.style-circles .face .ph { border-radius: 50%; box-shadow: 0 2px 6px rgba(15,23,42,.08), 0 10px 22px rgba(15,23,42,.10); }
.board.style-dark { background: #0b1220; }
.board.style-dark .face .nm { color: #f1f5f9; }
.board.style-dark .face .nm .tt { color: #9fb0c7; }
.board.style-dark .face .ph { box-shadow: 0 2px 6px rgba(0,0,0,.4), 0 10px 24px rgba(0,0,0,.45); }
.board.style-dark .title-tile h2 { color: #fff; } .board.style-dark .title-tile p { color: #9fb0c7; }
.board.style-dark .title-tile img.logo { filter: brightness(0) invert(1); }

.loader { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--muted); font-size: 14px; font-weight: 500; background: rgba(238,241,246,.6); backdrop-filter: blur(2px); }
.loader[hidden] { display: none; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid #d4dce6; border-top-color: var(--accent2); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { color: var(--muted); font-size: 15px; text-align: center; margin-top: 90px; max-width: 460px; }

/* ---------- search ---------- */
.search { position: relative; margin-left: 20px; flex: 1 1 280px; max-width: 380px; display: flex; align-items: center; }
.search-ico { position: absolute; left: 12px; width: 17px; height: 17px; color: var(--muted); pointer-events: none; }
.search input { width: 100%; font: inherit; font-size: 14px; font-weight: 500; color: var(--ink); padding: 9px 34px 9px 36px; border: 1.5px solid var(--line); border-radius: 999px; background: #fbfcfe; transition: var(--t); }
.search input:focus { outline: none; border-color: var(--accent2); box-shadow: 0 0 0 3px var(--ring); background: #fff; }
.search-clear { position: absolute; right: 8px; width: 22px; height: 22px; border: 0; border-radius: 50%; background: #e2e8f0; color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer; display: grid; place-items: center; transition: var(--t); }
.search-clear:hover { background: #cbd5e1; color: var(--ink); }
.search-results { position: absolute; top: calc(100% + 8px); left: 0; right: 0; max-height: 340px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--sh-3); z-index: 60; padding: 6px; }
.search-results[hidden] { display: none; }
.search-res { display: flex; align-items: center; gap: 11px; width: 100%; padding: 7px 9px; border: 0; border-radius: var(--r-sm); background: none; cursor: pointer; text-align: left; font: inherit; transition: background .12s; }
.search-res:hover, .search-res.active { background: #eef4fb; }
.search-res img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: #e2e8f0; flex: 0 0 auto; }
.search-res .sr-name { font-size: 13.5px; font-weight: 600; color: var(--ink); line-height: 1.2; }
.search-res .sr-title { font-size: 11.5px; color: var(--muted); line-height: 1.2; }
.search-res .sr-none { padding: 12px; color: var(--muted); font-size: 13px; text-align: center; }

/* clickable faces + search highlight */
.face .ph { cursor: pointer; }
.board.searching .face:not(.match) { opacity: .22; filter: grayscale(.4); }
.board .face.match .ph { box-shadow: 0 0 0 3px var(--accent2), 0 10px 24px rgba(31,78,121,.28); }

/* ---------- profile popup ---------- */
.profile-overlay { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(15,23,42,.46); backdrop-filter: blur(3px); animation: poFade .18s ease; }
.profile-overlay[hidden] { display: none; }
@keyframes poFade { from { opacity: 0; } to { opacity: 1; } }
.profile-card { position: relative; width: 100%; max-width: 460px; background: #fff; border-radius: var(--r-lg); box-shadow: var(--sh-3); overflow: hidden; animation: poPop .22s cubic-bezier(.2,.7,.2,1); }
@keyframes poPop { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: none; } }
.profile-close { position: absolute; top: 12px; right: 12px; z-index: 2; width: 32px; height: 32px; border: 0; border-radius: 50%; background: rgba(255,255,255,.85); color: #475569; font-size: 20px; line-height: 1; cursor: pointer; display: grid; place-items: center; box-shadow: var(--sh-1); transition: var(--t); }
.profile-close:hover { background: #fff; color: var(--ink); transform: rotate(90deg); }
.po-hero { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 30px 26px 18px; background: linear-gradient(180deg, #f3f7fc, #fff); }
.po-photo { width: 104px; height: 104px; border-radius: 50%; object-fit: cover; background: #e2e8f0; box-shadow: 0 8px 22px rgba(15,23,42,.18), 0 0 0 4px #fff; }
.po-name { font-size: 21px; font-weight: 800; letter-spacing: -.01em; color: var(--ink); margin: 10px 0 0; }
.po-title { font-size: 13.5px; color: var(--muted); font-weight: 600; }
.po-badge { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; padding: 4px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 700; text-transform: capitalize; }
.po-badge.active { color: #15692f; background: #e8f7ee; border: 1px solid #c7ebd4; }
.po-badge.gone { color: #9a3412; background: #fff1e6; border: 1px solid #fcd9b6; }
.po-badge.other { color: #475569; background: #eef2f7; border: 1px solid var(--line); }
.po-fields { padding: 6px 26px 8px; }
.po-row { display: flex; align-items: flex-start; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.po-row:last-child { border-bottom: 0; }
.po-row .po-k { flex: 0 0 96px; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; padding-top: 2px; }
.po-row .po-v { flex: 1; font-size: 14px; color: var(--ink); font-weight: 500; word-break: break-word; }
.po-row .po-v a { color: var(--accent); text-decoration: none; }
.po-row .po-v a:hover { text-decoration: underline; }
.po-actions { display: flex; gap: 10px; padding: 16px 26px 22px; }
.po-btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 11px 14px; border-radius: var(--r-sm); font: inherit; font-size: 13.5px; font-weight: 700; cursor: pointer; transition: var(--t); border: 1.5px solid var(--line); background: #fff; color: var(--ink); }
.po-btn:hover { border-color: #c4d2e2; box-shadow: var(--sh-1); }
.po-btn.danger { border: 0; color: #fff; background: linear-gradient(180deg, #ef4444, #dc2626); box-shadow: 0 6px 16px rgba(220,38,38,.28); }
.po-btn.danger:hover { filter: brightness(1.06); }
.po-btn.success { border: 0; color: #fff; background: linear-gradient(180deg, #22c55e, #16a34a); box-shadow: 0 6px 16px rgba(22,163,74,.28); }
.po-btn:disabled { opacity: .6; cursor: default; box-shadow: none; filter: none; }
.po-loading { padding: 60px 26px; text-align: center; color: var(--muted); font-size: 14px; }
.po-confirm { padding: 0 26px 8px; }
.po-confirm p { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0 0 12px; background: #fff7ed; border: 1px solid #fed7aa; border-radius: var(--r-sm); padding: 11px 13px; }

/* ---------- toast ---------- */
.toast-host { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { padding: 11px 18px; border-radius: 999px; font-size: 13.5px; font-weight: 600; color: #fff; background: #0f172a; box-shadow: var(--sh-3); animation: toastIn .25s cubic-bezier(.2,.7,.2,1); }
.toast.ok { background: linear-gradient(180deg, #16a34a, #15803d); }
.toast.err { background: linear-gradient(180deg, #dc2626, #b91c1c); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

@media (max-width: 860px) { .layout { flex-direction: column; } .rail { width: 100%; flex: none; flex-direction: row; flex-wrap: wrap; } .panel { flex: 1 1 240px; } .search { order: 3; flex-basis: 100%; max-width: none; margin-left: 0; } }
@media print { .topbar, .rail, .loader, .profile-overlay, .toast-host { display: none !important; } .stage { padding: 0; overflow: visible; } .canvas-wrap { box-shadow: none; max-width: none; } }
