:root {
  --bg: #1a1a1a;
  --bg-panel: #252525;
  --text: #e8e8e8;
  --text-muted: #a0a0a0;
  --accent: #6b9bd1;
  --accent-hover: #8ab4e8;
  --border: #3a3a3a;
  --error: #c75c5c;
}
* { box-sizing: border-box; }
/* .control-row sets display:flex, which would otherwise out-specify the UA's
   [hidden] { display: none } and leave hidden rows visible. */
[hidden] { display: none !important; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  min-height: 100vh;
  padding: 1rem;
}
.container { max-width: 900px; margin: 0 auto; }
h1 { font-size: 1.5rem; margin: 0; font-weight: 600; }
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0 0 1.5rem;
}
#targetBtn { font-variant-numeric: tabular-nums; }
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  background: var(--bg-panel);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--accent); background: #2a2a2a; }
.drop-zone input[type="file"] { display: none; }
.drop-zone label { cursor: pointer; color: var(--accent); }
.preview-section { margin-top: 1.5rem; }
.preview-section h2 { font-size: 1.1rem; margin: 0 0 0.75rem; font-weight: 600; }
.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 1rem;
}
.preview-item {
  background: var(--bg-panel);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: grab;
  position: relative;
}
.preview-item:active { cursor: grabbing; }
.preview-item.dragging { opacity: 0.5; }
.preview-item .thumb-wrap {
  aspect-ratio: 63/88;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a1a1a;
}
.preview-item .thumb-wrap img { width: 100%; height: 100%; object-fit: contain; display: block; }
.preview-item .num { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,0.7); color: #fff; padding: 2px 6px; border-radius: 4px; font-size: 0.75rem; }
.preview-item .remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 1.4rem;
  height: 1.4rem;
  padding: 0;
  line-height: 1;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
  /* Always visible: a hover-only control is unreachable on a touch screen. */
  opacity: 0.75;
  transition: opacity 0.15s, background 0.15s;
}
.preview-item:hover .remove { opacity: 1; }
.preview-item .remove:hover { background: var(--error); }
.preview-item .name { padding: 0.4rem 0.5rem; font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.controls {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: center;
}
.control-row { display: flex; align-items: center; gap: 0.5rem; }
.control-row label { font-size: 0.9rem; color: var(--text-muted); }
.control-row .base { font-size: 0.8rem; color: var(--text-muted); }
.control-row .value { min-width: 2.5rem; text-align: center; font-weight: 600; }
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s;
}
.btn:hover:not(:disabled) { background: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 0.35rem 0.6rem; font-size: 0.85rem; }
.btn-ghost { background: var(--bg-panel); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: #333; }
.actions { margin-top: 1.5rem; display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.message { margin-top: 1rem; padding: 0.75rem; border-radius: 8px; font-size: 0.9rem; }
.message.error { background: rgba(199,92,92,0.2); color: var(--error); }
.message.success { background: rgba(100,160,100,0.2); color: #8bc98b; }
.message.hidden { display: none; }
.command-section { margin-top: 2rem; }
.command-section h2 { font-size: 1.1rem; margin: 0 0 0.75rem; font-weight: 600; }
.command {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  text-align: left;
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font: inherit;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.command:hover { border-color: var(--accent); background: #2a2a2a; }
.command code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}
.command-hint { flex: none; font-size: 0.75rem; color: var(--text-muted); }
.command.copied { border-color: #8bc98b; }
.command.copied .command-hint { color: #8bc98b; }

#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
#lightbox.show { display: flex; }
#lightbox img { max-width: 100%; max-height: 90vh; object-fit: contain; border-radius: 8px; }
#lightbox .close { position: absolute; top: 1rem; right: 1rem; background: var(--bg-panel); color: var(--text); border: 1px solid var(--border); width: 2.5rem; height: 2.5rem; border-radius: 8px; cursor: pointer; font-size: 1.2rem; }
@media (max-width: 600px) {
  .controls { flex-direction: column; align-items: flex-start; }
  .actions { flex-direction: column; align-items: stretch; }
}
