:root {
  --bg: #13161c;
  --panel: #1b1f27;
  --panel2: #20252f;
  --line: #2c3340;
  --text: #e6eaf0;
  --muted: #8b93a3;
  --accent: #3c84ff;
  --ok: #5bd38a;
  --err: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--panel); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

* { scrollbar-width: thin; scrollbar-color: var(--line) var(--panel); }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 "Segoe UI", system-ui, sans-serif;
}
header { padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: baseline; gap: 14px; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .4px; }
.brand h1 span { color: var(--accent); }
.brand p { margin: 0; color: var(--muted); font-size: 12px; }
.brand p.err { color: var(--err); }

.layout { display: grid; grid-template-columns: 1fr 360px; gap: 0; height: calc(100vh - 66px); overflow: hidden; }
.browser { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.selection {
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
}

.controls { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; background: var(--panel); }
#q {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font-size: 14px; outline: none;
}
#q:focus { border-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; }
select {
  flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font-size: 13px; outline: none;
}
select optgroup { background: var(--panel); color: var(--text); }
select option { background: var(--panel); }
.count { color: var(--muted); font-size: 12px; }

.grid {
  flex: 1; overflow-y: auto; display: grid; gap: 8px; padding: 16px;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); align-content: start;
}
.cell {
  position: relative; border-radius: 10px; border: 2px solid var(--line);
  background: var(--panel2); cursor: pointer; padding: 4px;
  display: flex; flex-direction: column; gap: 4px; align-items: center;
}
.cell img { width: 100%; border-radius: 6px; display: block; }
.cell .lbl { font-size: 9px; color: var(--muted); word-break: break-all; text-align: center; max-width: 100%; overflow: visible; }
.cell:hover { border-color: var(--accent); }
.cell.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(60,132,255,.35); }
.cell .cat { font-size: 9px; color: var(--muted); }

.more { margin: 0 16px 16px; padding: 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); cursor: pointer; }
.more:hover { border-color: var(--accent); }

.selection h2 { margin: 0; font-size: 13px; flex-shrink: 0; padding-bottom: 4px; }
#selcount { color: var(--muted); font-weight: normal; }
.sellist { display: flex; flex-direction: column; gap: 5px; flex: 1 1 0; min-height: 0; overflow-y: auto; }
.selitem {
  display: flex; align-items: center; gap: 8px; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px;
}
.selitem img { width: 40px; height: 40px; border-radius: 6px; }
.selitem .meta { flex: 1; min-width: 0; }
.selitem .meta .n { font-size: 11px; word-break: break-all; }
.selitem .meta .u { font-size: 10px; color: var(--muted); }
.selitem .x { border: none; background: none; color: var(--muted); font-size: 16px; cursor: pointer; }
.selitem .x:hover { color: var(--err); }

.actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
button {
  padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2);
  color: var(--text); font-size: 13px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.ghost { color: var(--muted); }

.result { border-top: 1px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 5px; flex-shrink: 0; }
.result .ok { color: var(--ok); font-size: 12px; margin: 0; }
.result label { font-size: 11px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
textarea {
  width: 100%; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font-family: Consolas, monospace; font-size: 10px;
  resize: vertical; min-height: 50px;
}

.variant { display: flex; gap: 0; border: none; padding: 0; margin: 0; flex-shrink: 0; }
.vopt { flex: 1; }
.vopt input { position: absolute; opacity: 0; pointer-events: none; }
.vlabel {
  display: block; text-align: center; padding: 8px 10px; background: var(--panel2);
  color: var(--text); border: 1px solid var(--line); cursor: pointer; font-size: 12px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.vopt:first-child .vlabel { border-radius: 6px 0 0 6px; }
.vopt:last-child .vlabel { border-radius: 0 6px 6px 0; }
.vopt:not(:first-child) .vlabel { margin-left: -1px; }
.vopt input:checked + .vlabel { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; position: relative; z-index: 1; }
.vopt:hover .vlabel { border-color: var(--accent); }
.vopt input:focus-visible + .vlabel { outline: 2px solid var(--accent); outline-offset: 2px; }

button:disabled { opacity: 0.45; cursor: not-allowed; }
button:disabled:hover { border-color: var(--line); filter: none; }

.restore { border-top: 1px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 5px; flex-shrink: 0; }
.restore h3 { margin: 0; font-size: 12px; color: var(--muted); }
#restoremsg { font-size: 11px; min-height: 14px; }
#restoremsg.err { color: var(--err); }
#restoremsg.ok { color: var(--ok); }

.foot { color: var(--muted); font-size: 10px; flex-shrink: 0; padding-top: 6px; margin-top: auto; line-height: 1.4; }
.foot a { color: var(--accent); }