:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e3e3df;
  --accent: #2f6fed;
  --dark: #26262a;
  --bad: #c62828;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
input, select, button { font: inherit; }

.toolbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center;
  padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
#search { flex: 1 1 240px; min-width: 180px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.ctl { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.ctl input[type=number] { width: 76px; }
input[type=number], input[type=text], select { padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
input:disabled { opacity: .45; }
.invalid { border-color: var(--bad) !important; outline: 2px solid rgb(198 40 40 / .3); }

.seg { display: flex; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg label { padding: 5px 10px; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--ink); color: #fff; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }

.swatches { display: flex; gap: 4px; }
.swatch { width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 1px solid #bbb; cursor: pointer; }
.swatch.active { outline: 2px solid var(--accent); outline-offset: 1px; }

button { padding: 5px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .6; cursor: progress; }

.banner { margin: 16px; padding: 12px 16px; border-radius: 8px; background: #fdecea; color: var(--bad); }
.banner[hidden] { display: none; }

main { padding: 12px 16px 96px; }
.count { margin: 0 0 8px; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; padding: 8px; border-radius: 12px; }
.grid.dark { background: var(--dark); }
.cell { position: relative; }
.cell-btn {
  width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 6px 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.grid.dark .cell-btn { background: #333338; border-color: #444; color: #ddd; }
.cell-btn:hover { border-color: var(--accent); }
.cell-btn img { width: 48px; height: 48px; }
.name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--muted); }
.cell input[type=checkbox] { position: absolute; top: 6px; left: 6px; opacity: 0; }
.cell:hover input[type=checkbox], .cell input[type=checkbox]:checked, .cell input[type=checkbox]:focus-visible { opacity: 1; }

.selection-bar {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 3;
  display: flex; gap: 12px; align-items: center; padding: 10px 14px;
  background: var(--ink); color: #fff; border-radius: 12px; box-shadow: 0 6px 24px rgb(0 0 0 / .2);
}
.selection-bar[hidden] { display: none; }

/* Non-modal: sits below the toolbar so the controls stay usable while it is open. */
dialog {
  position: fixed; top: 140px; left: 0; right: 0; z-index: 4; margin: 0 auto;
  padding: 0; border: none; border-radius: 14px;
  max-width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 156px); overflow: auto;
  box-shadow: 0 12px 40px rgb(0 0 0 / .25);
}
dialog::backdrop { background: transparent; }
.detail { position: relative; display: flex; flex-wrap: wrap; gap: 24px; padding: 24px; }
#d-img {
  width: 256px; height: 256px; max-width: 100%; padding: 16px; border-radius: 12px;
  background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0 / 16px 16px;
}
#d-img.dark { background: var(--dark); }
.d-info { flex: 1 1 240px; }
.d-info h2 { margin: 0 0 4px; font-size: 18px; }
.muted { margin: 4px 0; color: var(--muted); }
.d-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.status { min-height: 1.4em; color: var(--muted); }
.close { position: absolute; top: 8px; right: 8px; border: none; background: none; font-size: 20px; }

footer { padding: 16px; text-align: center; font-size: 12px; color: var(--muted); }
