/* Level Gallery plugin - uses the site's own CSS variables so light/dark theme and look stay consistent. */
:root { --lg-panel-w: 392px; --lg-rail-w: 52px; --lg-gold: #e8890c; }
:root[data-theme="dark"], :root:not([data-theme="light"]) { --lg-gold: #ffb454; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) { --lg-gold: #c26a00; } }
:root[data-theme="light"] { --lg-gold: #c26a00; }

body.lg-pad { padding-right: var(--lg-panel-w); transition: padding-right .2s ease; }
body.lg-pad-rail { padding-right: var(--lg-rail-w); transition: padding-right .2s ease; }

/* header additions */
.lg-panelbtn { display: inline-flex; align-items: center; gap: 6px; background: var(--accent) !important; color: var(--accent-ink) !important; border-color: var(--accent) !important; font-weight: 600; }
.lg-badge { display: inline-grid; place-items: center; min-width: 20px; height: 18px; padding: 0 6px; border-radius: 99px; background: rgba(0,0,0,.28); color: #fff; font-size: 12px; font-weight: 700; }
#lgImgMode { max-width: 210px; }

/* grid / table decoration */
.thumb .lg-pick { position: absolute; right: 6px; bottom: 6px; width: 28px; height: 28px; padding: 0; border-radius: 50%; border: 1px solid rgba(255,255,255,.5); background: rgba(0,0,0,.62); color: #fff; font-size: 18px; line-height: 1; display: grid; place-items: center; cursor: pointer; }
.thumb .lg-pick:hover, .lg-pick.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.lg-pick.on { font-size: 14px; font-weight: 800; }
.card.lg-picked { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.lg-demotag { position: absolute; left: 6px; bottom: 6px; padding: 1px 7px; border-radius: 6px; background: var(--new); color: #fff; font-size: 11px; font-weight: 700; line-height: 16px; }
.lg-line { margin-top: 2px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lg-line b { color: var(--lg-gold); font-weight: 700; }
.lg-pick-row { position: static !important; width: 24px; height: 24px; font-size: 16px; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 50%; padding: 0; cursor: pointer; display: grid; place-items: center; }
.lg-pick-row.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* side panel */
.lg-panel { position: fixed; top: 0; right: 0; bottom: 0; width: var(--lg-panel-w); z-index: 30; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; transition: width .2s ease; overflow: hidden; }
.lg-panel .lg-rail { display: none; }
.lg-panel.collapsed { width: var(--lg-rail-w); }
.lg-panel.collapsed .lg-inner { display: none; }
.lg-panel.collapsed .lg-rail { display: flex; }
.lg-rail { flex-direction: column; align-items: center; gap: 12px; padding: 14px 0; width: 100%; height: 100%; background: transparent; border: 0; color: var(--muted); cursor: pointer; font: inherit; }
.lg-rail:hover { background: var(--panel2); color: var(--text); }
.lg-rail-arrow { font-size: 20px; line-height: 1; }
.lg-rail-count { display: grid; place-items: center; min-width: 28px; height: 24px; padding: 0 7px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 13px; }
.lg-rail-text { writing-mode: vertical-rl; transform: rotate(180deg); letter-spacing: 3px; font-size: 12px; font-weight: 700; }
.lg-inner { display: flex; flex-direction: column; min-height: 0; flex: 1; width: var(--lg-panel-w); }
.lg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 14px 16px 8px; }
.lg-head h2 { margin: 0; font-size: 15px; }
.lg-head p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.lg-head p b { color: var(--lg-gold); }
.lg-icon { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 18px; line-height: 1; cursor: pointer; display: inline-grid; place-items: center; flex: none; padding: 0 0 2px; }
.lg-icon:hover { border-color: var(--accent); }
.lg-tools { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 8px; }
.lg-tools .btn[disabled], .lg-primary[disabled] { opacity: .45; cursor: default; pointer-events: none; }
.lg-primary { background: var(--accent) !important; color: var(--accent-ink) !important; border-color: var(--accent) !important; }
.lg-danger { color: var(--ee) !important; }
.lg-psearch { padding: 0 16px 8px; }
.lg-psearch input { width: 100%; }
.lg-list { list-style: none; margin: 0; padding: 4px 10px 16px; overflow: auto; flex: 1; min-height: 0; border-top: 1px solid var(--line); }
.lg-row { position: relative; display: grid; grid-template-columns: 14px 30px 46px 1fr auto; align-items: center; gap: 8px; padding: 7px 7px; margin-top: 6px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.lg-row:hover { border-color: var(--accent); }
.lg-row[hidden] { display: none; }
.lg-row.dragging { opacity: .4; }
.lg-row.drop-before::before, .lg-row.drop-after::after { content: ""; position: absolute; left: 6px; right: 6px; height: 3px; border-radius: 3px; background: var(--accent); }
.lg-row.drop-before::before { top: -5px; } .lg-row.drop-after::after { bottom: -5px; }
.lg-row.flash { animation: lgflash 1.2s ease; }
@keyframes lgflash { 0% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }
.lg-grip { color: var(--muted); cursor: grab; font-size: 14px; letter-spacing: -2px; user-select: none; text-align: center; }
.lg-pos { height: 28px; min-width: 28px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-weight: 700; font-size: 13px; padding: 0 4px; cursor: pointer; }
.lg-pos:hover { border-color: var(--accent); color: var(--accent); }
.lg-posin { width: 42px; height: 28px; padding: 0 2px; text-align: center; font-weight: 700; border-color: var(--accent) !important; }
.lg-pthumb { width: 46px; height: 58px; border-radius: 7px; overflow: hidden; background: var(--panel); display: grid; place-items: center; }
.lg-pthumb img { width: 100%; height: 100%; object-fit: contain; }
.lg-pinfo { min-width: 0; }
.lg-pid { display: flex; align-items: center; gap: 6px; }
.lg-pid b { font-variant-numeric: tabular-nums; }
.lg-pname { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lg-pmeta { display: flex; gap: 10px; font-size: 12px; color: var(--lg-gold); font-weight: 600; margin-top: 1px; }
.lg-ph { color: var(--accent); } .lg-nd { color: var(--muted); font-weight: 400; }
.lg-acts { display: flex; flex-direction: column; gap: 2px; }
.lg-acts button { width: 24px; height: 22px; border-radius: 6px; border: 1px solid transparent; background: transparent; color: var(--muted); font: inherit; font-size: 13px; line-height: 1; padding: 0; cursor: pointer; }
.lg-acts button:hover { background: var(--panel); color: var(--text); border-color: var(--line); }
.lg-acts .lg-del:hover { color: var(--ee); }
.lg-empty { display: none; flex-direction: column; align-items: center; gap: 6px; padding: 40px 28px; text-align: center; color: var(--muted); border-top: 1px solid var(--line); flex: 1; }
.lg-plus { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: var(--panel2); color: var(--accent); font-size: 26px; margin-bottom: 6px; }
.lg-empty b { color: var(--text); font-size: 15px; }
.lg-panel.is-empty .lg-list, .lg-panel.is-empty .lg-psearch { display: none; }
.lg-panel.is-empty .lg-empty { display: flex; }

/* detail dialog */
#lgDlg { max-width: min(1180px, 96vw); width: 100%; height: min(860px, 94vh); overflow: hidden; }
#lgDlg[open] { display: flex; flex-direction: column; }
.lg-dhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 14px 18px 10px; border-bottom: 1px solid var(--line); }
.lg-dtitle h2 { margin: 0; font-size: 19px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.lg-dtitle p { margin: 4px 0 0; }
.lg-dnav { display: flex; align-items: center; gap: 8px; flex: none; }
.lg-dbody { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); }
.lg-viewer { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--panel2); border-right: 1px solid var(--line); }
.lg-stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 14px; overflow: hidden; }
.lg-stage img { max-width: 100%; max-height: 100%; min-width: 0; min-height: 0; object-fit: contain; border-radius: 8px; cursor: zoom-in; box-shadow: 0 6px 24px rgba(0,0,0,.28); background: var(--panel); }
.lg-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 38px; height: 54px; border-radius: 10px; border: 1px solid rgba(255,255,255,.3); background: rgba(0,0,0,.55); color: #fff; font-size: 26px; display: grid; place-items: center; z-index: 2; cursor: pointer; padding: 0 0 3px; }
.lg-nav:hover { background: var(--accent); }
.lg-nav.left { left: 10px; } .lg-nav.right { right: 10px; }
.lg-viewer.single .lg-stage .lg-nav { display: none; }
.lg-note { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: rgba(255,170,60,.18); border: 1px solid rgba(255,170,60,.55); color: var(--text); border-radius: 99px; padding: 4px 14px; font-size: 12.5px; z-index: 2; white-space: nowrap; max-width: calc(100% - 24px); overflow: hidden; text-overflow: ellipsis; }
.lg-cap { display: flex; justify-content: space-between; gap: 10px; padding: 7px 14px; font-size: 13px; border-top: 1px solid var(--line); }
.lg-cap #lgCap { font-weight: 600; }
.lg-thumbs { display: flex; gap: 8px; padding: 8px 14px 12px; overflow-x: auto; }
.lg-thumbs button { flex: none; width: 70px; padding: 0; border-radius: 8px; border: 2px solid transparent; background: var(--panel); overflow: hidden; cursor: pointer; font: inherit; color: var(--muted); }
.lg-thumbs button.on { border-color: var(--accent); color: var(--accent); }
.lg-thumbs img { width: 100%; height: 86px; object-fit: contain; display: block; background: var(--panel2); }
.lg-thumbs span { display: block; padding: 3px 2px 4px; font-size: 11px; text-align: center; }
.lg-dinfo { overflow: auto; padding: 16px 18px 22px; display: flex; flex-direction: column; gap: 12px; }
.lg-hero { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--lg-gold); background: var(--panel2); }
.lg-hnum { display: flex; align-items: baseline; gap: 8px; }
.lg-hnum span { font-size: 38px; font-weight: 750; line-height: 1; color: var(--lg-gold); font-variant-numeric: tabular-nums; }
.lg-hnum small { color: var(--muted); font-size: 14px; }
.lg-hsub { margin-top: 4px; color: var(--muted); font-size: 12.5px; }
.lg-wide { width: 100%; height: 38px; font-weight: 600; cursor: pointer; }
.lg-desc { margin: 0; color: var(--muted); }
.lg-sheetname { margin: 0; font-size: 13px; }
.lg-facts { margin: 0; display: grid; grid-template-columns: auto 1fr; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.lg-facts dt, .lg-facts dd { margin: 0; padding: 7px 12px; border-bottom: 1px solid var(--line); }
.lg-facts dt { background: var(--panel2); color: var(--muted); font-size: 13px; }
.lg-facts dd { font-weight: 600; }
.lg-facts dd small { color: var(--muted); font-weight: 400; }
.lg-facts dt:last-of-type, .lg-facts dd:last-of-type { border-bottom: 0; }
.lg-member { margin: 0; padding-left: 18px; font-size: 13px; }
.lg-member li { margin: 3px 0; }
.lg-gd { border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); }
.lg-gd summary { padding: 8px 12px; cursor: pointer; color: var(--muted); font-weight: 600; }
.lg-gd p { margin: 0; padding: 0 12px 10px; font-size: 13px; white-space: pre-wrap; }
.lg-path { margin: 0; font-size: 12px; }

/* lightbox (inside the dialog so it shares the top layer) */
.lg-lb { position: absolute; inset: 0; z-index: 10; background: rgba(0,0,0,.94); display: grid; }
.lg-lb[hidden] { display: none; }
.lg-lbscroll { overflow: auto; display: grid; place-items: center; padding: 16px; }
.lg-lbscroll img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; }
.lg-lbscroll.zoomed { place-items: start center; }
.lg-lbscroll.zoomed img { max-width: none; max-height: none; cursor: zoom-out; }
.lg-lbclose { position: absolute; right: 12px; top: 10px; z-index: 3; }
.lg-lbcap { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); background: rgba(20,24,34,.88); color: #fff; padding: 4px 14px; border-radius: 99px; font-size: 13px; }

/* import dialog */
#lgImp { max-width: min(560px, 96vw); width: 100%; }
.lg-impbody { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 10px; }
.lg-impbody h2 { margin: 0; font-size: 17px; }
.lg-impbody p { margin: 0; font-size: 13px; }
.lg-impbody textarea { width: 100%; resize: vertical; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font: 13px Consolas, "Cascadia Mono", monospace; }
.lg-improw { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lg-spacer { flex: 1; }

.lg-toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 16px); background: var(--panel); color: var(--text); border: 1px solid var(--line); padding: 8px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 200; font-size: 13.5px; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.lg-toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  body.lg-pad, body.lg-pad-rail { padding-right: 0; }
  .lg-panel { box-shadow: -10px 0 28px rgba(0,0,0,.35); max-width: 100%; }
  .lg-panel.collapsed { box-shadow: none; }
  body.lg-pad-rail main { padding-right: calc(var(--lg-rail-w) + 8px); }
  .lg-dbody { grid-template-columns: 1fr; overflow: auto; display: block; }
  .lg-viewer { border-right: 0; border-bottom: 1px solid var(--line); }
  .lg-stage { height: 60vh; flex: none; }
  .lg-dinfo { overflow: visible; }
  #lgDlg { height: 100%; max-height: 100%; }
}
@media (max-width: 640px) { :root { --lg-panel-w: min(392px, 100vw); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
