/* Token màu và nhịp lấy từ Ops Portal. Font hệ thống: không gọi tài nguyên ngoài. */
:root {
  color-scheme: light dark;
  --ink: #0A0A0A; --text: #171717; --muted: #666; --faint: #707070;
  --paper: #FAFAFA; --surface: #FFF; --surface-2: #F5F5F5;
  --line: #EBEBEB; --line-2: #E1E1E1;
  --accent: #4042FF; --accent-soft: rgba(64,66,255,.09);
  --primary: #0A0A0A; --primary-hover: #333; --primary-fg: #FFF;
  --good: #0B7A46; --warn: #9A6700; --danger: #D93036; --danger-soft: rgba(217,48,54,.08);
  --r-sm: 6px; --r-lg: 12px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  /* Vietnamese needs full horn and tone glyphs: Iowan and Palatino lack them on macOS. */
  --serif: ui-serif, "New York", "Times New Roman", Times, serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --ink: #EDEDED; --text: #E4E4E4; --muted: #A0A0A0; --faint: #8A8A8A;
  --paper: #000; --surface: #0A0A0A; --surface-2: #141414; --line: #232323; --line-2: #2E2E2E;
  --accent: #5B6BFF; --accent-soft: rgba(91,107,255,.14);
  --primary: #EDEDED; --primary-hover: #FFF; --primary-fg: #0A0A0A;
  --good: #3FCF7F; --warn: #E0A106; --danger: #FF5A5F; --danger-soft: rgba(255,90,95,.14);
} }
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #EDEDED; --text: #E4E4E4; --muted: #A0A0A0; --faint: #8A8A8A;
  --paper: #000; --surface: #0A0A0A; --surface-2: #141414; --line: #232323; --line-2: #2E2E2E;
  --accent: #5B6BFF; --accent-soft: rgba(91,107,255,.14);
  --primary: #EDEDED; --primary-hover: #FFF; --primary-fg: #0A0A0A;
  --good: #3FCF7F; --warn: #E0A106; --danger: #FF5A5F; --danger-soft: rgba(255,90,95,.14);
}
:root[data-theme="light"] { color-scheme: light; }
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--sans); background: var(--paper); color: var(--text); -webkit-font-smoothing: antialiased; line-height: 1.5; font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
input[type=text], input[type=email], input[type=number], input:not([type]), select, textarea {
  display: block; width: 100%; min-height: 34px; padding: 6px 10px; border: 1px solid var(--line-2); border-radius: var(--r-sm);
  font-family: var(--sans); font-size: 13px; color: var(--text); background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { line-height: 1.55; resize: vertical; }
input[type=file] { display: block; width: 100%; padding: 8px 10px; border: 1px dashed var(--line-2); border-radius: var(--r-sm); font-size: 12.5px; color: var(--muted); background: var(--surface); }
button.primary { min-height: 34px; padding: 0 14px; background: var(--primary); color: var(--primary-fg); border: 1px solid var(--primary); border-radius: var(--r-sm); font: 500 13px var(--sans); cursor: pointer; }
button.primary:hover { background: var(--primary-hover); }
button.primary:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { min-height: 32px; padding: 0 11px; background: var(--surface); color: var(--text); border: 1px solid var(--line-2); border-radius: var(--r-sm); font: 500 13px var(--sans); cursor: pointer; }
button.ghost:hover { background: var(--surface-2); }
button.danger { color: var(--danger); }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.err { border: 1px solid var(--danger); background: var(--danger-soft); color: var(--danger); border-radius: var(--r-sm); padding: 10px 12px; font-size: 13px; margin-top: 12px; }
.note { border: 1px solid var(--line-2); background: var(--surface-2); color: var(--muted); border-radius: var(--r-sm); padding: 10px 12px; font-size: 13px; margin-top: 12px; }

/* ---------------------------------------------------------------- nav */
nav.top { display: flex; align-items: center; gap: 14px; padding: 0 20px; height: 52px; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 600; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.mark { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; flex: none; }
.navgap { flex: 1; }
.right { display: inline-flex; align-items: center; gap: 12px; }
details.acct { position: relative; }
details.acct > summary { list-style: none; cursor: pointer; }
details.acct > summary::-webkit-details-marker { display: none; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line-2); font-size: 11px; font-weight: 600; color: var(--muted); }
.acct-pop { position: absolute; right: 0; top: 36px; width: 240px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.14); padding: 6px; z-index: 50; }
.aw { padding: 8px 10px; display: flex; flex-direction: column; gap: 1px; }
.aw b { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.ae { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.ahr { height: 1px; background: var(--line); margin: 4px 0; }
.ami { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 6px; padding: 7px 10px; font: 13px var(--sans); color: var(--text); cursor: pointer; }
.ami:hover { background: var(--surface-2); text-decoration: none; }
.athm-w { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; }
.athm-l { font-size: 12.5px; color: var(--muted); }
.athm { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; padding: 2px; gap: 2px; }
.thm { border: 0; background: none; border-radius: 5px; padding: 2px 7px; font: 500 11.5px var(--sans); color: var(--muted); cursor: pointer; }
.thm.on { background: var(--ink); color: var(--paper); }
.fnkeys { display: inline-flex; gap: 4px; margin-left: 14px; }
.fnk { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; background: none; border: 1px solid transparent; border-radius: 6px; color: var(--muted); cursor: pointer; padding: 0; }
.fnk:hover { background: var(--surface-2); color: var(--ink); }
.fnk svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 1.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.aud { display: inline-flex; align-items: center; gap: 8px; margin-right: 14px; font-size: 12px; color: var(--muted); }
.vchips { display: inline-flex; gap: 2px; border: 1px solid var(--line); border-radius: 7px; padding: 2px; background: var(--surface); }
.vchip { border: 0; background: none; border-radius: 5px; padding: 3px 9px; font: 500 11.5px var(--sans); color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.vchip:hover { color: var(--ink); }
.vchip.on { background: var(--ink); color: var(--paper); }
.vchip.on .vd { box-shadow: 0 0 0 1px var(--paper); }

/* ---------------------------------------------------------- explorer */
body.explorer { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.xframe { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--surface); outline: none; }
.xframe.kb:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.xcols { display: flex; flex: 1; min-height: 0; overflow-x: auto; overflow-y: hidden; }
.xcol { width: 236px; flex: none; overflow-y: auto; overflow-x: hidden; padding: 6px 0; border-right: 1px solid var(--line); scrollbar-width: thin; }
.xfill { flex: 1; min-width: 0; background-image: repeating-linear-gradient(to right, transparent 0 235px, var(--line) 235px 236px); }
.xrow { height: 28px; margin: 0 4px; padding: 0 8px; border-radius: var(--r-sm); display: flex; align-items: center; gap: 8px; cursor: default; user-select: none; -webkit-user-select: none; font-size: 13px; color: var(--text); white-space: nowrap; }
.xrow:not(.sel-active):not(.sel-path):hover { background: color-mix(in srgb, var(--surface-2) 65%, transparent); }
.xrow .lbl { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.xrow .chev { flex: none; display: inline-flex; color: var(--faint); }
.xrow .chev svg { width: 8px; height: 8px; stroke: currentColor; stroke-width: 1.5; fill: none; }
.xrow.sel-path { background: var(--surface-2); color: var(--ink); font-weight: 500; }
.xrow.sel-active { background: var(--accent); color: #fff; font-weight: 500; }
.xrow.sel-active .chev, .xrow.sel-active .xico { color: #fff; }
.xrow.dim { opacity: .35; }
.xrow.dragover { box-shadow: inset 0 0 0 1.5px var(--accent); }
.xico { flex: none; display: inline-flex; color: var(--muted); }
.xico svg { width: 15px; height: 15px; stroke: currentColor; stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.xthumb { flex: none; width: 18px; height: 18px; border-radius: 2px; background: var(--surface-2) center/cover no-repeat; border: 1px solid var(--line); overflow: hidden; }
.xthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Chấm khán giả: rỗng là riêng tư, nửa là có link, đặc là công khai. */
.vd { flex: none; width: 7px; height: 7px; border-radius: 50%; border: 1.3px solid currentColor; opacity: .55; }
.vd.link { background: linear-gradient(90deg, currentColor 50%, transparent 50%); opacity: .8; }
.vd.public { background: currentColor; opacity: .9; }
.xrow .vd { color: var(--muted); }
.xrow.sel-active .vd { color: #fff; }
.xsec { margin: 14px 12px 4px; font-size: 11px; font-weight: 500; color: var(--faint); white-space: nowrap; }
.xsec:first-child { margin-top: 6px; }
.xempty { padding: 24px 16px; font-size: 12.5px; color: var(--faint); text-align: center; line-height: 1.6; }
.xrow.xnew { color: var(--accent); }
input[type=text].xnew-input { height: 22px; min-height: 0; padding: 0 6px; font-size: 12.5px; border-radius: 4px; box-shadow: none; }
.xbar { height: 28px; flex: none; border-top: 1px solid var(--line); padding: 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--surface); font-family: var(--mono); font-size: 11px; color: var(--muted); }
.xpath { display: flex; align-items: center; gap: 5px; min-width: 0; overflow: hidden; }
.xpath button { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.xpath button:hover { color: var(--accent); }
.xpath button:last-of-type { color: var(--text); flex: none; }
.xpath .sep { color: var(--faint); }
.xhint { flex: none; color: var(--faint); white-space: nowrap; }
@media (max-width: 1100px) { .xhint { display: none; } }

/* Thẻ chi tiết (thư mục, bộ sưu tập) */
.xdetail { flex: 1 1 auto; min-width: 340px; display: flex; justify-content: center; overflow-y: auto; }
.xdinner { flex: 1 1 auto; min-width: 0; max-width: 460px; padding: 0 24px 28px; }
.dglyph { width: 64px; height: 64px; border-radius: var(--r-lg); background: var(--surface-2); color: var(--muted); display: flex; align-items: center; justify-content: center; margin: 40px auto 0; overflow: hidden; }
.dglyph svg { width: 28px; height: 28px; stroke: currentColor; stroke-width: 1.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.dmosaic { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 32px 0 0; }
.dmosaic span { aspect-ratio: 1; background: var(--surface-2) center/cover no-repeat; border-radius: 2px; }
.dmosaic img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 2px; }
.dtitle { font-size: 15px; font-weight: 600; color: var(--ink); text-align: center; margin-top: 14px; line-height: 1.35; text-wrap: balance; }
.dkind { font-size: 12px; color: var(--muted); text-align: center; margin-top: 4px; }
.dhr { height: 1px; background: var(--line); margin: 20px 0; }
.ddesc { font-size: 13px; color: var(--muted); line-height: 1.6; white-space: pre-wrap; }
.dsec { font-size: 11.5px; font-weight: 500; color: var(--muted); margin: 18px 0 4px; }
.drow { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 7px 0; }
.drow .k { font-size: 12.5px; color: var(--muted); flex: none; }
.drow .v { font-size: 13px; color: var(--text); text-align: right; overflow-wrap: anywhere; min-width: 0; }
.drow .v.mono { font-family: var(--mono); font-size: 12px; }
.dcta { margin-top: 24px; display: flex; flex-direction: column; gap: 8px; }
.dcta :is(a, button) { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 38px; border-radius: var(--r-sm); font: 500 13.5px var(--sans); text-decoration: none; cursor: pointer; }
.dcta .pri { background: var(--primary); color: var(--primary-fg); border: 1px solid var(--primary); }
.dcta .gho { background: var(--surface); color: var(--text); border: 1px solid var(--line-2); }
.dcta .gho:hover { background: var(--surface-2); }

/* Pane xem trước: tác phẩm hoặc trang chữ */
.xpreview { flex: 1 1 auto; min-width: 640px; display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.xphead { flex: none; display: flex; align-items: center; gap: 10px; padding: 0 14px; height: 52px; border-bottom: 1px solid var(--line); }
.xphead .t { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.xphead .t b { font-size: 13.5px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xphead .t span { font-size: 11.5px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xphead .gap { flex: 1; }
.act { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--surface); color: var(--text); font: 500 12px var(--sans); cursor: pointer; text-decoration: none; white-space: nowrap; }
.act:hover { background: var(--surface-2); text-decoration: none; }
.act.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.act svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.act.ico { padding: 0; width: 28px; justify-content: center; }
.xpbody { flex: 1; min-height: 0; position: relative; display: flex; }

/* --------------------------------------------------------- viewer */
/* Nền mặc định là xám trung tính: mắt đánh giá màu của tranh đúng nhất trên
   nền không màu. Ba nền đổi bằng B, nhớ trong localStorage. */
.vw { position: relative; flex: 1; min-width: 0; min-height: 0; overflow: hidden; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; transition: background-color .2s ease; }
.vw.drag { cursor: grabbing; }
.vw[data-bg="grey"] { background: #7a7a7a; --vfg: #f2f2f2; --vfg2: rgba(255,255,255,.72); }
.vw[data-bg="dark"] { background: #121212; --vfg: #e8e8e8; --vfg2: rgba(255,255,255,.55); }
.vw[data-bg="wall"] { background: #f1efea; --vfg: #1c1c1c; --vfg2: rgba(0,0,0,.55); }
.vw img.vimg { position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none; image-rendering: auto; pointer-events: none; will-change: transform; }
.vw.shadow img.vimg { box-shadow: 0 2px 6px rgba(0,0,0,.18), 0 18px 50px rgba(0,0,0,.22); }
.vw .vmsg { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center; color: var(--vfg2); font-size: 13px; text-align: center; padding: 24px; }
.vw .vmsg a { color: var(--vfg); text-decoration: underline; }
.vlabel { position: absolute; left: 22px; bottom: 18px; max-width: min(420px, 60%); color: var(--vfg); font-family: var(--serif); font-size: 14px; line-height: 1.45; pointer-events: none; transition: opacity .2s ease; }
.vlabel b { font-style: italic; font-weight: 400; }
.vlabel span { display: block; color: var(--vfg2); font-size: 13px; }
.vw.nolabel .vlabel { opacity: 0; }
.vhud { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 8px; align-items: center; font: 11px var(--mono); color: var(--vfg2); pointer-events: none; }
.vhud .res { opacity: 0; transition: opacity .3s; }
.vhud .res.on { opacity: 1; }
.vstrip { position: absolute; left: 50%; transform: translateX(-50%); top: 12px; display: flex; gap: 6px; padding: 4px; border-radius: 8px; background: rgba(0,0,0,.28); }
.vstrip button { width: 40px; height: 40px; border: 1.5px solid transparent; border-radius: 4px; padding: 0; background: rgba(255,255,255,.1) center/cover no-repeat; cursor: pointer; overflow: hidden; }
.vstrip button img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vstrip button.on { border-color: #fff; }
.vtools { display: inline-flex; align-items: center; gap: 6px; }
.bgsw { display: inline-flex; gap: 4px; padding: 0 4px; }
.bgsw button { width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line-2); cursor: pointer; padding: 0; }
.bgsw button.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--accent); }
.bgsw .b-grey { background: #7a7a7a; } .bgsw .b-dark { background: #121212; } .bgsw .b-wall { background: #f1efea; }
.zoomv { min-width: 46px; text-align: center; font: 11.5px var(--mono); color: var(--muted); }

/* Xem nhanh toàn màn hình (phím cách, như Quick Look) */
.ql { position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column; background: #000; }
.ql .qlhead { position: absolute; top: 0; left: 0; right: 0; z-index: 2; display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: linear-gradient(rgba(0,0,0,.35), transparent); color: #eee; font-size: 12.5px; opacity: 0; transition: opacity .2s; }
.ql:hover .qlhead { opacity: 1; }
.ql .qlhead .gap { flex: 1; }
.ql .qlhead .act { background: rgba(255,255,255,.12); color: #fff; border-color: transparent; }
.ql .vw { flex: 1; }

/* -------------------------------------------------------- modal, toast */
.xmodal-scrim { position: fixed; inset: 0; z-index: 90; background: color-mix(in srgb, var(--ink) 24%, transparent); display: flex; align-items: flex-start; justify-content: center; padding-top: 11vh; }
.xmodal { width: 440px; max-width: calc(100vw - 48px); max-height: 80vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.22); padding: 18px; }
.xmodal h3 { font-size: 14px; font-weight: 600; color: var(--ink); margin: 0 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xmsub { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.xmodal label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; }
.xmodal .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.xmodal .row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.xmodal .chk { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); margin-top: 14px; }
.xmodal .chk input { width: auto; min-height: 0; }
.xmerr { display: none; font-size: 12px; color: var(--danger); margin-top: 10px; }
.xmnote { font-size: 11.5px; color: var(--faint); margin-top: 12px; line-height: 1.5; }
.xmact { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.fchips { display: flex; flex-direction: column; gap: 4px; max-height: 34vh; overflow-y: auto; }
.fchip { position: relative; display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 6px; padding: 7px 10px; overflow: hidden; }
.fchip .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.fchip .fsize { flex: none; font: 11px var(--mono); color: var(--muted); }
.fchip .fbar { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--accent); width: 0; transition: width .2s; }
.fchip.done .fbar { background: var(--good); }
.fchip.bad { border-color: var(--danger); }
.fchip.bad .fsize { color: var(--danger); }
.pickl { display: flex; flex-direction: column; gap: 1px; max-height: 42vh; overflow-y: auto; margin: 6px -8px 0; }
.pickl button { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: none; border: 0; border-radius: 6px; padding: 8px 10px; font: 13px var(--sans); color: var(--text); cursor: pointer; }
.pickl button:hover, .pickl button:focus-visible { background: var(--surface-2); outline: none; }
.pickl button .sub { margin-left: auto; font: 11px var(--mono); color: var(--faint); }
.pickl button.in { color: var(--accent); }
.audsel { display: flex; flex-direction: column; gap: 6px; }
.audsel label { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 12px; margin: 0; cursor: pointer; color: var(--text); }
.audsel label.on { border-color: var(--accent); background: var(--accent-soft); }
.audsel input { width: auto; min-height: 0; margin-top: 3px; }
.audsel b { font-size: 13px; font-weight: 600; display: block; }
.audsel small { font-size: 12px; color: var(--muted); }
.linkbox { display: flex; gap: 6px; margin-top: 12px; }
.linkbox input { font-family: var(--mono); font-size: 12px; }
.xkeys .krow { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.xkeys kbd { font: 11.5px var(--mono); color: var(--ink); background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 4px; padding: 2px 6px; white-space: nowrap; }
.prow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.prow small { color: var(--faint); }
.xtoast { position: fixed; bottom: 44px; left: 50%; transform: translate(-50%, 4px); background: var(--ink); color: var(--paper); font-size: 12.5px; padding: 9px 14px; border-radius: 6px; z-index: 95; opacity: 0; transition: opacity 140ms, transform 140ms; pointer-events: none; white-space: nowrap; display: flex; gap: 12px; }
.xtoast.on { opacity: 1; transform: translate(-50%, 0); }
.xtoast.has-act.on { pointer-events: auto; }
.xtoast-act { background: none; border: 0; padding: 0; font: 600 12.5px var(--sans); color: var(--accent); cursor: pointer; }
.xdrop { position: fixed; inset: 0; z-index: 85; display: none; align-items: center; justify-content: center; background: color-mix(in srgb, var(--paper) 76%, transparent); }
.xdrop.on { display: flex; }
.xdcard { border: 1.5px dashed var(--accent); border-radius: 12px; background: var(--surface); padding: 30px 44px; text-align: center; pointer-events: none; }
.xdt { font-size: 14.5px; font-weight: 600; color: var(--ink); }
.xds { font-size: 12.5px; color: var(--muted); margin-top: 5px; }

/* ----------------------------------------------------- editor (trang) */
.ed { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.edtools { display: flex; align-items: center; gap: 4px; padding: 6px 14px; border-bottom: 1px solid var(--line); }
.edtools .gap { flex: 1; }
.edtools .st { font-size: 11.5px; color: var(--faint); }
.edtools button { height: 26px; min-width: 26px; padding: 0 7px; border: 0; background: none; border-radius: 5px; font: 600 12.5px var(--sans); color: var(--muted); cursor: pointer; }
.edtools button:hover { background: var(--surface-2); color: var(--ink); }
.edbody { flex: 1; min-height: 0; display: flex; }
.edbody textarea { flex: 1; border: 0; border-radius: 0; box-shadow: none; resize: none; padding: 28px max(24px, calc((100% - 680px) / 2)); font: 15px/1.7 var(--serif); background: var(--surface); }
.edbody textarea:focus { box-shadow: none; }
.edtitle { border: 0 !important; box-shadow: none !important; font: 600 26px var(--serif) !important; padding: 26px max(24px, calc((100% - 680px) / 2)) 0 !important; min-height: 0 !important; background: var(--surface); }
.edprev { flex: 1; overflow-y: auto; padding: 28px max(24px, calc((100% - 680px) / 2)); background: var(--surface); }

/* --------------------------------------------------------- prose */
.prose { font-family: var(--serif); font-size: 17px; line-height: 1.75; color: var(--text); }
.prose h1 { font-size: 34px; font-weight: 500; line-height: 1.2; margin: 0 0 28px; color: var(--ink); letter-spacing: -.01em; }
.prose h2 { font-size: 24px; font-weight: 500; margin: 36px 0 12px; color: var(--ink); }
.prose h3 { font-size: 19px; font-weight: 600; margin: 28px 0 8px; color: var(--ink); }
.prose h4 { font-size: 16px; font-weight: 600; margin: 22px 0 6px; }
.prose p, .prose ul, .prose ol, .prose blockquote { margin: 0 0 16px; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose blockquote { border-left: 2px solid var(--line-2); padding-left: 16px; color: var(--muted); font-style: italic; }
.prose hr { border: 0; height: 1px; background: var(--line); margin: 32px 0; }
.prose a { color: inherit; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-2); }
.prose figure.embed { margin: 32px 0; }
.prose figure.embed img { display: block; max-width: 100%; height: auto; max-height: 80vh; width: auto; margin: 0 auto; }
.prose figcaption { margin-top: 12px; font-size: 14px; line-height: 1.5; color: var(--muted); text-align: center; }
.prose figcaption b { font-style: italic; font-weight: 400; color: var(--text); }
.prose .missing { color: var(--danger); font-size: 14px; }
.prose .noimg { display: block; aspect-ratio: 4/3; background: var(--surface-2); }

/* ------------------------------------------------- login, public */
body.plain { min-height: 100vh; }
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.lcard { width: 380px; max-width: 100%; }
.lhead { display: flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 600; margin-bottom: 40px; }
.lcard h1 { font-size: 24px; font-weight: 600; letter-spacing: -.02em; color: var(--ink); }
.lsub { color: var(--muted); margin-top: 6px; font-size: 13.5px; }
.lform { margin-top: 22px; display: flex; flex-direction: column; gap: 8px; }
.lform label { font-size: 13px; color: var(--muted); }
.lform input { min-height: 40px; font-size: 15px; }
.lform input.otp { font: 600 22px var(--mono); letter-spacing: .35em; text-align: center; }
.lform button { min-height: 40px; margin-top: 6px; font-size: 14px; }
.lalt { margin-top: 16px; font-size: 13px; color: var(--muted); }

.phead { display: flex; align-items: baseline; gap: 24px; padding: 28px clamp(20px, 5vw, 64px); }
.pname { font: 500 20px var(--serif); color: var(--ink); letter-spacing: -.01em; }
.pname:hover { text-decoration: none; }
.plinks { display: flex; gap: 18px; flex-wrap: wrap; flex: 1; }
.plinks a, .pkho { color: var(--muted); font-size: 14px; }
.plinks a:hover, .pkho:hover { color: var(--ink); text-decoration: none; }
.pmain { padding: 8px clamp(20px, 5vw, 64px) 80px; }
.pmain.narrow { max-width: 760px; margin: 0 auto; padding-top: 32px; }
.psec { margin-top: 32px; }
.psec h2 { font: 400 15px var(--serif); color: var(--muted); margin-bottom: 18px; }
.ghead { margin: 24px 0 28px; }
.ghead h1 { font: 500 34px var(--serif); color: var(--ink); letter-spacing: -.01em; }
.gcount { color: var(--faint); font-size: 13px; margin-top: 6px; }
.prose.lead { max-width: 680px; margin-bottom: 40px; font-size: 16px; }
/* Lưới giữ đúng tỉ lệ từng tranh: không cắt khung. */
.grid, .clist { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 56px 40px; align-items: start; }
.gcard, .citem { display: flex; flex-direction: column; gap: 14px; color: inherit; }
.gcard:hover, .citem:hover { text-decoration: none; }
.gimg { display: flex; align-items: flex-end; justify-content: center; aspect-ratio: 1; }
.gimg img { max-width: 100%; max-height: 100%; width: auto; height: auto; display: block; box-shadow: 0 1px 3px rgba(0,0,0,.1); transition: transform .3s ease; }
.gcard:hover .gimg img, .citem:hover .gimg img { transform: translateY(-3px); }
.glabel { font: 14px/1.45 var(--serif); color: var(--muted); }
.glabel b { font-style: italic; font-weight: 400; color: var(--text); }
.gempty { color: var(--faint); padding: 40px 0; }
.pfoot { padding: 0 clamp(20px, 5vw, 64px) 40px; font-size: 12px; }
.pfoot a { color: var(--faint); }
.mnote { display: inline-block; font-size: 12.5px; color: var(--warn); border: 1px solid currentColor; border-radius: 6px; padding: 4px 10px; margin-top: 12px; }
.mtag { font-size: 11.5px; color: var(--warn); border: 1px solid currentColor; border-radius: 999px; padding: 2px 9px; }

/* Trang tác phẩm riêng: viewer chiếm cả cửa sổ */
body.shared { height: 100vh; height: 100dvh; overflow: hidden; }
.sview { height: 100%; display: flex; flex-direction: column; }
.shead { flex: none; display: flex; align-items: center; gap: 10px; height: 50px; padding: 0 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
.sback { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sgap { flex: 1; }
.snav { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border: 1px solid var(--line-2); border-radius: 6px; color: var(--text); font-size: 17px; }
.snav:hover { background: var(--surface-2); text-decoration: none; }
.sbody { flex: 1; min-height: 0; display: flex; }

.xmobile { display: none; }
@media (max-width: 899px) {
  body.explorer { overflow: auto; height: auto; }
  body.explorer .xframe, body.explorer .fnkeys, body.explorer .aud { display: none; }
  .xmobile { display: block; padding: 40px 20px; color: var(--muted); font-size: 14px; line-height: 1.6; }
  .vlabel { left: 14px; bottom: 12px; font-size: 13px; }
  .shead .bgsw, .shead .zoomv { display: none; }
}

/* Work record: wider modal with tabs (Label · Story · Studio · Sharing). */
.xmodal.wide { width: 560px; }
.mtabs { display: flex; gap: 2px; padding: 2px; margin: 4px 0 2px; background: var(--hover, rgba(127,127,127,.1)); border-radius: 8px; }
.mtabs button { flex: 1; height: 28px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 12.5px; cursor: pointer; }
.mtabs button:hover { color: var(--text); }
.mtabs button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.18); }
.mpane[hidden] { display: none; }
.mpane textarea { resize: vertical; }

/* Details panel: the record beside the painting, in the viewer. */
.vinfo { position: absolute; top: 0; right: 0; bottom: 0; width: min(340px, 86%); overflow-y: auto; padding: 22px 22px 40px; background: var(--surface); border-left: 1px solid var(--line-2); color: var(--text); font-family: var(--serif); font-size: 14px; line-height: 1.55; z-index: 3; }
.vinfo[hidden] { display: none; }
.vinfo h4 { font: 500 18px/1.3 var(--serif); color: var(--ink); margin: 0 0 2px; }
.vinfo .yr { color: var(--muted); }
.vinfo dl { margin: 14px 0 0; }
.vinfo dt { font-family: var(--sans, -apple-system, system-ui, sans-serif); font-size: 11px; color: var(--muted); margin: 14px 0 3px; }
.vinfo dd { margin: 0; white-space: pre-line; }
.vinfo .priv { margin-top: 22px; padding-top: 6px; border-top: 1px dashed var(--line-2); }
.vinfo .priv > p { font-family: var(--sans, -apple-system, system-ui, sans-serif); font-size: 11px; color: var(--faint); margin: 10px 0 0; }
.vinfo .x { position: absolute; top: 10px; right: 10px; width: 26px; height: 26px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 16px; cursor: pointer; }
.vinfo .x:hover { background: var(--hover, rgba(127,127,127,.12)); }

/* ===================================================================
   Buttons: three tiers, one shape.
   1 Primary  solid ink pill, one per context (Save, Upload, Sign in).
   2 Secondary  tinted fill, no border (audience, Cancel, secondary CTAs).
   3 Quiet  text or icon only; a fill appears on hover (viewer tools, toolbars).
   Toggle groups share one segmented control: the chosen segment lifts.
   =================================================================== */
:root { --fill: rgba(0,0,0,.045); --fill-2: rgba(0,0,0,.08); --seg-on: #fff; --seg-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 .5px rgba(0,0,0,.06); --r-pill: 999px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --fill: rgba(255,255,255,.07); --fill-2: rgba(255,255,255,.12); --seg-on: #2B2B2B; --seg-shadow: 0 1px 2px rgba(0,0,0,.5); } }
:root[data-theme="dark"] { --fill: rgba(255,255,255,.07); --fill-2: rgba(255,255,255,.12); --seg-on: #2B2B2B; --seg-shadow: 0 1px 2px rgba(0,0,0,.5); }

/* 1 · Primary */
button.primary, .dcta .pri, .lform button {
  min-height: 34px; padding: 0 18px; border: 0; border-radius: var(--r-pill);
  background: var(--primary); color: var(--primary-fg); font: 550 13px var(--sans); letter-spacing: -.005em;
  transition: opacity .15s ease, transform .15s ease;
}
button.primary:hover, .dcta .pri:hover, .lform button:hover { background: var(--primary); opacity: .86; }
button.primary:active, .dcta .pri:active, .lform button:active { transform: scale(.98); }

/* 2 · Secondary */
button.ghost, .act.sec {
  min-height: 32px; padding: 0 14px; border: 0; border-radius: var(--r-pill);
  background: var(--fill); color: var(--ink); font: 500 13px var(--sans); transition: background .15s ease;
}
button.ghost:hover, .act.sec:hover { background: var(--fill-2); }
button.ghost.danger { color: var(--danger); }
.act.sec { height: 28px; min-height: 0; padding: 0 12px; font-size: 12px; }

/* 3 · Quiet */
.act {
  height: 28px; padding: 0 10px; border: 0; border-radius: var(--r-pill);
  background: transparent; color: var(--muted); font: 500 12px var(--sans); transition: background .15s ease, color .15s ease;
}
.act:hover { background: var(--fill); color: var(--ink); }
.act.on { background: var(--fill-2); color: var(--ink); border: 0; }
.act.ico { width: 28px; padding: 0; }
.fnk { border: 0; border-radius: var(--r-pill); width: 30px; height: 30px; transition: background .15s ease, color .15s ease; }
.fnk:hover { background: var(--fill); }
.edtools button { border-radius: var(--r-pill); }
.edtools button:hover { background: var(--fill); }
.dcta { gap: 6px; }
.dcta :is(a, button) { min-height: 36px; border-radius: var(--r-pill); font-weight: 500; }
.dcta .gho { background: transparent; border: 0; color: var(--text); }
.dcta .gho:hover { background: var(--fill); }
.ami { border-radius: 8px; }
.ami:hover { background: var(--fill); }
.xtoast-act { border-radius: var(--r-pill); padding: 3px 10px; background: var(--fill); color: var(--ink); }

/* Segmented control: View as, Gallery/Explorer, Appearance, form tabs */
.vchips, .athm, .mtabs {
  display: inline-flex; gap: 0; padding: 2px; border: 0; border-radius: var(--r-pill); background: var(--fill);
}
.mtabs { display: flex; margin: 8px 0 4px; }
.vchip, .thm, .mtabs button {
  height: 24px; padding: 0 11px; border: 0; border-radius: var(--r-pill); background: transparent;
  color: var(--muted); font: 500 12px var(--sans); cursor: pointer; transition: color .15s ease, background .15s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.mtabs button { height: 28px; }
.vchip:hover, .thm:hover, .mtabs button:hover { color: var(--ink); text-decoration: none; }
.vchip.on, .thm.on, .mtabs button.on { background: var(--seg-on); color: var(--ink); box-shadow: var(--seg-shadow); }
.vchip.on .vd { box-shadow: none; }
.aud { gap: 10px; }
.aud > span:first-child { color: var(--faint); }

/* Viewer: background swatches read as a quiet group */
.bgsw { gap: 6px; padding: 0 6px 0 2px; }
.bgsw button { width: 14px; height: 14px; border: 0; box-shadow: inset 0 0 0 1px rgba(127,127,127,.35); transition: transform .15s ease; }
.bgsw button:hover { transform: scale(1.15); }
.bgsw button.on { box-shadow: inset 0 0 0 1px rgba(127,127,127,.35), 0 0 0 2px var(--surface), 0 0 0 3.5px var(--ink); }
.vtools { display: inline-flex; align-items: center; gap: 2px; }
.ql .qlhead .act { background: transparent; color: rgba(255,255,255,.75); }
.ql .qlhead .act:hover, .ql .qlhead .act.on { background: rgba(255,255,255,.14); color: #fff; }

/* Visitor Explorer header */
.glinks { display: inline-flex; gap: 2px; margin-left: 10px; }
.glinks a, .glink { height: 28px; display: inline-flex; align-items: center; padding: 0 10px; border-radius: var(--r-pill); color: var(--muted); font: 500 13px var(--sans); }
.glinks a:hover, .glink:hover { background: var(--fill); color: var(--ink); text-decoration: none; }
.vswitch { margin-right: 8px; }
.phead .vswitch { align-self: center; }
body.guest .xmobile a { color: var(--ink); text-decoration: underline; }
