/* View Gallery — lưới level của cả bộ (thay Level Overview Gallery của Level Studio). Token màu lấy từ app.css. */
:root {
  --d-easy: #15803d; --d-medium: #d97706; --d-hard: #dc2626; --d-superhard: #9333ea;   /* xanh lá · vàng cam · đỏ · tím */
  --thumb-bg: #0b1a2c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --d-easy: #4ade80; --d-medium: #f59e0b; --d-hard: #f87171; --d-superhard: #c084fc; --thumb-bg: #08131f; }
}
:root[data-theme="dark"] { --d-easy: #4ade80; --d-medium: #f59e0b; --d-hard: #f87171; --d-superhard: #c084fc; --thumb-bg: #08131f; }

.view.gallery { overflow: hidden; }
.gal { display: grid; grid-template-rows: auto 1fr; height: 100%; min-height: 0; }

/* ---------- thanh công cụ ---------- */
.gal-bar { background: var(--fl-header); border-bottom: 1px solid var(--line); padding: 8px 12px; display: grid; gap: 7px; }
.gal-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.gal-row > select { max-width: 170px; }
.gal-q { width: 250px; min-width: 160px; flex: 0 1 250px; }
.gal-sub { font-size: 12px; }
.gal-summary b { font-variant-numeric: tabular-nums; }
.gal-summary .gc-err { color: var(--bad); font-weight: 600; }
.gal-summary .gc-warn { color: var(--warn); font-weight: 600; }
.gal-selinfo { font-weight: 600; color: var(--accent); }
.gal-hint { white-space: nowrap; }
@media (max-width: 1320px) { .gal-hint { display: none; } }

/* lọc độ khó: chữ màu theo mức (thang chung difficulty.mjs) */
.gal-diffsel option { color: var(--ink); }
.gal-diffsel option.d-easy, .gal-diffsel.d-easy { color: var(--d-easy); font-weight: 600; }
.gal-diffsel option.d-medium, .gal-diffsel.d-medium { color: var(--d-medium); font-weight: 600; }
.gal-diffsel option.d-hard, .gal-diffsel.d-hard { color: var(--d-hard); font-weight: 600; }
.gal-diffsel option.d-superhard, .gal-diffsel.d-superhard { color: var(--d-superhard); font-weight: 600; }
/* sắp xếp: ô dạng combo (giống <select>), chọn lại mục đang dùng để đổi chiều */
.gal-sort { display: inline-flex; align-items: center; height: var(--ctl); min-width: 130px; padding: 0 26px 0 9px; border: 1px solid var(--line-2);
  border-radius: var(--r-md); background: var(--surface); color: var(--ink); cursor: pointer; text-align: left; white-space: nowrap;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 52%, calc(100% - 8.5px) 52%; background-size: 4.5px 4.5px, 4.5px 4.5px; background-repeat: no-repeat; }
.gal-sort:hover { border-color: var(--line-3); }
.gal-sort:focus-visible, .gal-sort[aria-expanded="true"] { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
#gal-sortmenu .pm-item.cur { color: var(--accent); font-weight: 600; }
#gal-sortmenu .pm-ic { font-weight: 700; }

/* nút bật / tắt đang bật: kiểu "soft" — nền accent nhạt, lún nhẹ */
.btn[aria-pressed="true"], .gal-toggle[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); font-weight: 600; box-shadow: inset 0 1px 2px color-mix(in srgb, var(--accent) 20%, transparent); }
/* segmented control: rãnh chìm + nút đang chọn nổi lên (cùng kiểu với chọn ngôn ngữ ở thanh trên) */
.seg { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--sunken); }
.seg button { border: 0; background: none; height: calc(var(--ctl) - 6px); padding: 0 10px; border-radius: var(--r-sm); font-size: 12px; font-weight: 500; cursor: pointer; color: var(--muted);
  transition: background-color .15s var(--ease), color .15s var(--ease); }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: var(--shadow-xs); }
.seg button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

/* dropdown lọc cơ chế (giữ UI chip + AND/OR của Studio) */
.gal-mech { position: relative; }
.gal-mechbtn .caret { color: var(--muted); font-size: 10px; }
.gal-mechbtn.on { border-color: var(--accent-line); color: var(--accent); background: var(--accent-soft); font-weight: 600; box-shadow: inset 0 1px 2px color-mix(in srgb, var(--accent) 20%, transparent); }
.gal-mechmenu { position: absolute; top: calc(100% + 4px); left: 0; z-index: 30; width: 380px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 12px; animation: dlg-in .14s var(--ease); }
.gal-mechhead { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.gal-mechlogic { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12px; padding: 6px 0 8px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.gal-chips { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; max-height: 320px; overflow: auto; }
.gal-chip { display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 9px; border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface-2); cursor: pointer; font-size: 12px; text-align: left; }
.gal-chip:hover { border-color: var(--accent-line); }
.gal-chip img, .gal-chip i { width: 18px; height: 18px; object-fit: contain; flex: none; border-radius: 4px; }
.gal-chip span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.gal-chip small { color: var(--muted); font-variant-numeric: tabular-nums; }
.gal-chip .ck { visibility: hidden; color: var(--accent); }
.gal-chip.active { border-color: var(--accent); background: var(--accent-soft); }
.gal-chip.active .ck { visibility: visible; }

.gal-progress { display: flex; align-items: center; gap: 8px; }
.gal-progress .progress { flex: 0 1 360px; }

/* ---------- lưới ---------- */
.gal-grid { overflow-y: auto; display: grid; gap: 12px; padding: 12px; align-content: start; min-height: 0; background: var(--bg); outline: none; }
.gal-grid > .empty { grid-column: 1 / -1; }
.gal-grid.size-s { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 8px; }
.gal-grid.size-m { grid-template-columns: repeat(auto-fill, minmax(195px, 1fr)); }
.gal-grid.size-l { grid-template-columns: repeat(auto-fill, minmax(265px, 1fr)); }

.gc { position: relative; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-xs);
  cursor: pointer; min-width: 0; transition: border-color .15s, box-shadow .15s, transform .15s;
  content-visibility: auto; contain-intrinsic-size: auto 300px; }
.size-s .gc { contain-intrinsic-size: auto 110px; }
.size-l .gc { contain-intrinsic-size: auto 390px; }
.gc:hover { border-color: var(--accent-line); box-shadow: var(--shadow-sm); transform: translateY(-2px); }
.gc:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); border-color: var(--accent); }
.gc.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.gc.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.gc.ping { animation: gc-ping 1.2s ease-out 2; }
@keyframes gc-ping { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 70%, transparent); } 100% { box-shadow: 0 0 0 12px transparent; } }

.gc-thumb { position: relative; aspect-ratio: var(--thumb-ar, 400 / 560); flex: none; background: var(--thumb-bg); border-radius: 11px 11px 0 0; overflow: hidden; }
.size-s .gc-thumb { display: none; }
.gc-ph { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 2px; color: #7890a8;
  background: radial-gradient(circle at 50% 45%, #16304c 0%, var(--thumb-bg) 75%); transition: opacity .2s; }
.gc-ph span { font-size: 28px; opacity: .7; }
.gc-ph b { font-size: 12px; }
.gc-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity .2s; }
.gc.has-img .gc-img { opacity: 1; }
.gc.has-img .gc-ph { opacity: 0; }

.gc-sel { position: absolute; top: 6px; left: 6px; z-index: 2; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 5px;
  background: rgba(8, 19, 31, .72); opacity: 0; transition: opacity .12s; cursor: pointer; }
.gc-sel input { margin: 0; width: 14px; height: 14px; cursor: pointer; accent-color: var(--accent); }
.gc:hover .gc-sel, .gc.sel .gc-sel, .gc:focus-visible .gc-sel { opacity: 1; }
.size-s .gc-sel { position: static; float: right; opacity: 1; background: none; width: auto; height: auto; }
.gc-open { position: absolute; top: 6px; right: 6px; z-index: 2; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 2px 6px rgba(0, 0, 0, .45); }
.gc-open:empty { display: none; }

.gc-body { display: flex; flex-direction: column; gap: 3px; padding: 7px 9px 8px; min-width: 0; flex: 1 1 auto; }
.size-s .gc-body { padding: 7px 9px; }
.gc-head { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.gc-num { font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }
.gc-openpill { display: none; font-size: 10px; font-weight: 700; color: var(--accent); }
.size-s .gc-openpill { display: inline; }
/* độ khó (chữ màu .diff-tag) + cơ chế (tag .obs-tag) (app.css, ui/obstags.mjs) — ở đây chỉ chỉnh cỡ trên thẻ */
.gc-diff { margin-left: auto; font-size: 11px; }
.gc-stats { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.gc-mechs { display: flex; flex-wrap: wrap; gap: 3px; margin: 2px 0 3px; }
.gc-m { height: 18px; padding: 0 5px 0 3px; font-size: 10px; border-radius: 4px; }
.size-s .gc-m { height: 16px; font-size: 9.5px; }
.size-s .gc-m img { width: 12px; height: 12px; }
.gc-state { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 4px; margin-top: auto; padding-top: 5px; border-top: 1px solid var(--line); min-width: 0; }
.gc-state .pill { height: 17px; font-size: 10.5px; padding: 0 5px; }
.gc-rev { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; margin-right: auto; }
.gc-flag { color: var(--warn); font-size: 11px; }

/* mobile: ô tìm / chọn giãn hết hàng, lưới 2 cột thẻ nhỏ */
@media (max-width: 640px) {
  .gal-bar { padding: 8px 10px; }
  .gal-q { flex: 1 1 100%; width: auto; }
  .gal-row > select, .gal-row > .pp { max-width: none; flex: 1 1 40%; }
  .gal-grid { padding: 10px; gap: 8px; }
  .gal-grid.size-s, .gal-grid.size-m, .gal-grid.size-l { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .gal-chips { grid-template-columns: 1fr; }
}
/* ảnh game (tabs/gallery.mjs — ui/gamecapture.mjs, ui/gameshots.mjs): dải đếm + nút chụp, 🔍 trên thẻ, hộp ảnh lớn */
.gal-shots { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.gal-shots[hidden] { display: none; }
.gal-shots [data-r=shotcount] { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.gc-zoom { position: absolute; bottom: 6px; right: 6px; z-index: 2; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 5px;
  background: rgba(0, 0, 0, .45); color: #fff; font-size: 12px; line-height: 24px; cursor: pointer; opacity: 0; transition: opacity .15s; }
.gc:hover .gc-zoom, .gc:focus-visible .gc-zoom, .gc-zoom:focus-visible { opacity: 1; }
.size-s .gc-zoom { display: none; }
.gal-detail { display: grid; place-items: center; background: var(--thumb-bg, #0b0d12); border-radius: 10px; min-height: 200px; }
.gal-detail img { display: block; max-width: 100%; max-height: 70vh; object-fit: contain; }
