:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #dde1e6;
  --text: #1b1f24;
  --muted: #5f6b78;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --stack: #0f8f84;
  --stack-soft: #dff4f1;
  --pano: #b86e0b;
  --pano-soft: #fbefdc;
  --danger: #c2372b;
  --thumb-bg: #e3e6ea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --thumb: 120px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --surface: #1a1d22;
    --surface-2: #22262c;
    --border: #2e333a;
    --text: #e7e9ec;
    --muted: #9aa4af;
    --accent: #5b8def;
    --accent-ink: #0b1220;
    --stack: #38bdb0;
    --stack-soft: #133632;
    --pano: #f0a43a;
    --pano-soft: #3a2a12;
    --danger: #f2685c;
    --thumb-bg: #0c0e11;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111317; --surface: #1a1d22; --surface-2: #22262c; --border: #2e333a; --text: #e7e9ec; --muted: #9aa4af;
  --accent: #5b8def; --accent-ink: #0b1220; --stack: #38bdb0; --stack-soft: #133632; --pano: #f0a43a; --pano-soft: #3a2a12;
  --danger: #f2685c; --thumb-bg: #0c0e11; --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
button, input, select { font: inherit; color: inherit; }

/* ---------- top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { width: 34px; height: 34px; flex: none; }
.brand .b1 { fill: var(--stack); }
.brand .b2 { fill: var(--pano); opacity: .9; }
.brand h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 12.5px; }
.chip {
  font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}

main { max-width: 1440px; margin: 0 auto; padding: 20px 24px 64px; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px;
}

/* ---------- buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap;
  font-weight: 550;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); min-width: 96px; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); min-width: 96px; }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, input:focus-visible, select:focus-visible, .sum-card:focus-visible, .thumb:focus-visible, .link:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; cursor: pointer; font-size: 16px; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

input[type=text], input[type=search], input[type=number], select {
  height: 36px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding: 0 10px;
}
input[type=number] { width: 76px; }

.field-label { display: block; font-weight: 600; margin-bottom: 6px; }
.path-row { display: flex; gap: 8px; }
.path-row input { flex: 1; min-width: 0; font-family: "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.form-error { color: var(--danger); margin: 10px 0 0; }

.options { margin-top: 12px; }
.options summary { cursor: pointer; color: var(--muted); font-weight: 550; width: max-content; }
.opt-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px 24px; margin-top: 12px;
  padding-top: 12px; border-top: 1px dashed var(--border);
}
.opt { display: flex; flex-direction: column; gap: 4px; }
.opt-title { color: var(--muted); font-size: 12.5px; }
.num { display: inline-flex; align-items: center; gap: 6px; }
.check { display: flex; align-items: center; gap: 8px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; width: max-content; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 6px 14px; border-right: 1px solid var(--border); }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- progress */
.progress-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.phase { font-weight: 650; }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .3s ease; }
.bar.indeterminate .bar-fill { width: 30%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -30%; } 100% { margin-left: 100%; } }
.current {
  margin-top: 8px; font: 12.5px "Cascadia Mono", Consolas, monospace; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: rtl; text-align: left;
}
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 12px 0 0; }
.stats div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.stats dt { color: var(--muted); font-size: 12px; }
.stats dd { margin: 0; font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stats .link { font-weight: 650; }

/* ---------- summary */
.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) 2fr; gap: 12px; margin-bottom: 16px; }
.sum-card {
  text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
  cursor: pointer; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow);
}
.sum-card[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.sum-label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.sum-num { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.sum-sub { color: var(--muted); font-size: 12.5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.stack .dot { background: var(--stack); }
.pano .dot { background: var(--pano); }
.subtypes {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px;
  box-shadow: var(--shadow); min-width: 0;
}
.types-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.types-title { font-size: 12.5px; font-weight: 650; }
.types-hint { font-size: 11.5px; color: var(--muted); }
.type-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.type-chips .empty-note { color: var(--muted); font-size: 12.5px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; cursor: pointer;
  font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: var(--stack-soft); color: var(--stack);
}
.chip-btn.panorama { background: var(--pano-soft); color: var(--pano); }
.chip-btn .n { font-variant-numeric: tabular-nums; opacity: .8; font-weight: 700; }
.chip-btn:hover { border-color: currentColor; }
.chip-btn[aria-pressed="true"] { background: var(--stack); color: var(--surface); }
.chip-btn.panorama[aria-pressed="true"] { background: var(--pano); color: var(--surface); }
.type-chips.filtering .chip-btn[aria-pressed="false"] { opacity: .55; }
.chip-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.showing { display: flex; align-items: center; gap: 12px; margin: -4px 0 14px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.showing strong { color: var(--text); }
.tag.moving { background: var(--surface-2); color: var(--text); text-transform: none; letter-spacing: 0; }

/* ---------- toolbar */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 14px; }
.toolbar input[type=search] { width: 280px; }
.tb-item { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.tb-item select { color: var(--text); }

/* ---------- results */
.folder { margin-bottom: 22px; }
.folder-head {
  display: flex; align-items: baseline; gap: 10px; margin: 0 0 8px; padding: 0 2px;
  font: 600 13px "Cascadia Mono", Consolas, monospace; color: var(--muted);
}
.folder-head .count { font-family: inherit; font-weight: 500; }
.group {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--stack);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px 14px; margin-bottom: 10px;
}
.group.panorama { border-left-color: var(--pano); }
.group.fresh { animation: fresh 1.6s ease-out; }
@keyframes fresh { from { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); } }
.g-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.g-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 240px; }
.g-title h3 { margin: 0; font-size: 15px; font-weight: 650; }
.tag {
  font-size: 11.5px; font-weight: 650; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em;
  background: var(--stack-soft); color: var(--stack);
}
.tag.panorama { background: var(--pano-soft); color: var(--pano); }
.tag.plain { background: var(--surface-2); color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 550; }
.conf { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.conf i { display: inline-block; width: 6px; height: 12px; border-radius: 2px; background: var(--border); }
.conf i.on { background: var(--accent); }
.g-actions { display: flex; gap: 6px; }
.g-meta { color: var(--muted); font-size: 12.5px; margin: 4px 0 10px; display: flex; flex-wrap: wrap; gap: 2px 14px; }
.g-body { display: flex; gap: 14px; align-items: flex-start; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; min-width: 0; }
.thumb {
  position: relative; height: var(--thumb); border-radius: 6px; overflow: hidden; background: var(--thumb-bg);
  border: 0; padding: 0; cursor: zoom-in; flex: none;
}
.thumb img { height: 100%; width: 100%; object-fit: cover; display: block; }
.thumb .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 4px; font-size: 11px; color: #fff; text-align: left;
  background: linear-gradient(transparent, rgba(0,0,0,.72)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thumb .badge {
  position: absolute; top: 5px; left: 5px; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px;
  background: rgba(0,0,0,.6); color: #fff; letter-spacing: .03em;
}
.thumb .pos {
  position: absolute; top: 5px; right: 5px; font-size: 10px; font-weight: 700; min-width: 18px; text-align: center; padding: 1px 5px;
  border-radius: 4px; background: var(--pano); color: #1b1203;
}
.thumbs .pos-sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 2px; }

.layout {
  flex: none; width: 280px; background: var(--thumb-bg); border-radius: 8px; padding: 10px; position: relative;
}
.layout-title { font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.layout-canvas { position: relative; margin: 0 auto; }
.layout-canvas img {
  position: absolute; object-fit: cover; border: 1px solid rgba(255,255,255,.7); border-radius: 2px; opacity: .85;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.layout-canvas img:hover { opacity: 1; z-index: 5; outline: 2px solid var(--pano); }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

/* ---------- dialogs */
.modal {
  border: 1px solid var(--border); border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.modal::backdrop { background: rgba(0,0,0,.45); }
.modal-inner { display: flex; flex-direction: column; max-height: min(80vh, 720px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; }
.modal-head h2 { margin: 0; font-size: 16px; }
.crumbs { padding: 0 16px 10px; display: flex; flex-wrap: wrap; gap: 2px; font: 12.5px "Cascadia Mono", Consolas, monospace; }
.crumbs button { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.crumbs button:hover { background: var(--surface-2); }
.crumbs span { color: var(--muted); }
.dir-list, .err-list { list-style: none; margin: 0; padding: 4px 8px; overflow: auto; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); flex: 1; min-height: 200px; }
.dir-list button {
  width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 6px; cursor: pointer;
  display: flex; gap: 8px; align-items: center;
}
.dir-list button:hover, .dir-list button:focus-visible { background: var(--surface-2); outline: none; }
.dir-list .ico { color: var(--pano); }
.err-list li { padding: 8px 8px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.err-list code { display: block; font: 12px "Cascadia Mono", Consolas, monospace; color: var(--muted); word-break: break-all; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; }

/* ---------- lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(8, 9, 11, .97); color: #e7e9ec;
  display: grid; grid-template-columns: 64px 1fr 64px; grid-template-rows: auto 1fr auto auto;
}
.lb-top { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; gap: 12px; }
.lb-title { display: flex; gap: 10px; align-items: baseline; min-width: 0; }
.lb-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lightbox .muted { color: #9aa4af; }
.lightbox .btn { background: transparent; color: #e7e9ec; border-color: #3a4048; }
.lightbox .icon-btn { color: #c9ced4; }
.lightbox .icon-btn:hover { background: #22262c; color: #fff; }
.lb-actions { display: flex; gap: 8px; align-items: center; }
.lb-stage { margin: 0; grid-column: 2; display: flex; align-items: center; justify-content: center; min-height: 0; position: relative; }
.lb-stage img { max-width: 100%; max-height: calc(100vh - 230px); object-fit: contain; box-shadow: 0 6px 30px rgba(0,0,0,.6); }
.lb-spinner {
  position: absolute; width: 36px; height: 36px; border-radius: 50%; border: 3px solid #3a4048; border-top-color: #e7e9ec;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.lb-nav { background: none; border: 0; color: #c9ced4; font-size: 44px; cursor: pointer; align-self: center; height: 120px; border-radius: 10px; }
.lb-nav:hover { background: #1a1d22; color: #fff; }
.lb-nav.prev { grid-column: 1; grid-row: 2; }
.lb-nav.next { grid-column: 3; grid-row: 2; }
.lb-meta { grid-column: 1 / -1; text-align: center; font-size: 13px; color: #c9ced4; padding: 8px 16px 4px; }
.lb-meta code { font: 12px "Cascadia Mono", Consolas, monospace; color: #9aa4af; }
.lb-strip { grid-column: 1 / -1; display: flex; gap: 6px; justify-content: safe center; padding: 8px 16px 16px; overflow-x: auto; }
.lb-strip img { height: 54px; border-radius: 4px; opacity: .5; cursor: pointer; border: 2px solid transparent; }
.lb-strip img.active { opacity: 1; border-color: #e7e9ec; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 60; box-shadow: var(--shadow);
}

/* ---------- narrow screens */
@media (max-width: 860px) {
  .summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .subtypes { grid-column: 1 / -1; }
  .g-body { flex-direction: column; }
  .layout { width: 100%; }
}
@media (max-width: 560px) {
  main { padding: 16px 16px 48px; }
  .topbar { padding: 12px 16px; }
  .brand p { display: none; }
  .path-row { flex-wrap: wrap; }
  .path-row input { flex-basis: 100%; }
  .toolbar input[type=search] { width: 100%; }
  .sum-num { font-size: 21px; }
  .lightbox { grid-template-columns: 36px 1fr 36px; }
}
