*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #141414;
  color: #d4d4d4;
  height: 100vh;
  overflow: hidden;
}

/* ─── Two-pane shell ─────────────────────────────────────────────────────── */

#app {
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: auto 1fr;
  height: 100vh;
}

header {
  grid-column: 1 / -1;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid #1f1f1f;
  display: flex;
  align-items: center;
}

header h1 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #e8e8e8;
  letter-spacing: -0.01em;
}

/* ─── Left pane ──────────────────────────────────────────────────────────── */

#left-pane {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  overflow-y: auto;
  border-right: 1px solid #1f1f1f;
  background: #181818;
}

/* ─── Drop zone ──────────────────────────────────────────────────────────── */

#drop-zone {
  border: 1.5px dashed #303030;
  border-radius: 10px;
  padding: 1.4rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s;
  color: #555;
  user-select: none;
  flex-shrink: 0;
}

#drop-zone:hover {
  border-color: #4a7cf5;
  background: rgba(74, 124, 245, 0.04);
  color: #888;
}

#drop-zone.drag-over {
  border-color: #4a7cf5;
  background: rgba(74, 124, 245, 0.08);
  color: #aaa;
}

#drop-zone p {
  font-size: 0.82rem;
  margin-bottom: 0.65rem;
  color: inherit;
}

#drop-zone kbd {
  font-family: monospace;
  font-size: 0.78em;
  background: #242424;
  border: 1px solid #383838;
  border-radius: 3px;
  padding: 0 4px;
  color: #777;
}

#browse-label {
  display: inline-block;
  padding: 0.28rem 0.9rem;
  border: 1px solid #353535;
  border-radius: 6px;
  color: #888;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

#browse-label:hover {
  border-color: #4a7cf5;
  color: #4a7cf5;
  background: rgba(74, 124, 245, 0.06);
}

#file-input {
  display: none;
}

/* ─── Thumbnails ─────────────────────────────────────────────────────────── */

#thumbnails-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

#thumbnails {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

#clear-all-btn {
  align-self: flex-start;
  background: none;
  border: none;
  padding: 0;
  font-size: 0.72rem;
  color: #444;
  cursor: pointer;
  border-radius: 0;
  transition: color 0.13s;
}

#clear-all-btn:hover {
  background: none;
  border: none;
  color: #c0392b;
}

#batch-summary {
  font-size: 0.72rem;
  color: #444;
}

.thumbnail {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #2a2a2a;
  flex-shrink: 0;
}

.thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-delete {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.75);
  color: #ccc;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.12s, background 0.12s;
}

.thumbnail:hover .thumb-delete {
  opacity: 1;
}

.thumb-delete:hover {
  background: #c0392b;
  color: #fff;
}

/* ─── Controls ───────────────────────────────────────────────────────────── */

#controls {
  display: flex;
  flex-direction: column;
  border-top: 1px solid #222;
  padding-top: 1.1rem;
  gap: 0;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding-bottom: 1.1rem;
}

.control-group:last-child {
  padding-bottom: 0;
}

/* Section header — small caps label */
.control-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #4a4a4a;
}

/* Row of buttons (orientation, etc.) */
.btn-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

/* ─── Generic buttons ────────────────────────────────────────────────────── */

button {
  padding: 0.35rem 0.85rem;
  border: 1px solid #2e2e2e;
  border-radius: 6px;
  background: #212121;
  color: #aaa;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.13s, border-color 0.13s, color 0.13s;
  line-height: 1.4;
  white-space: nowrap;
}

button:hover {
  background: #282828;
  border-color: #3a3a3a;
  color: #d0d0d0;
}

button.active {
  background: #4a7cf5;
  border-color: #4a7cf5;
  color: #fff;
}

#grid-presets {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

/* ─── Toggle switch ──────────────────────────────────────────────────────── */

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  user-select: none;
}

.toggle input[type="checkbox"] {
  display: none;
}

.toggle-track {
  width: 34px;
  height: 19px;
  border-radius: 10px;
  background: #242424;
  border: 1px solid #333;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}

.toggle input:checked+.toggle-track {
  background: #4a7cf5;
  border-color: #4a7cf5;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #4a4a4a;
  transition: transform 0.18s, background 0.18s;
}

.toggle input:checked+.toggle-track .toggle-thumb {
  transform: translateX(15px);
  background: #fff;
}

.toggle-hint {
  font-size: 0.76rem;
  color: #555;
}

/* ─── Slider ─────────────────────────────────────────────────────────────── */

.slider-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
}

.slider-row input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: #4a7cf5;
  cursor: pointer;
}

#threshold-value {
  font-size: 0.78rem;
  color: #777;
  min-width: 18px;
  text-align: right;
}

/* ─── Right pane ─────────────────────────────────────────────────────────── */

#right-pane {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  overflow: hidden;
  min-height: 0;
}

/* ─── Preview ────────────────────────────────────────────────────────────── */

#preview-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  min-height: 0;
}

#preview-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #111;
  border-radius: 10px;
  padding: 1rem;
  overflow: hidden;
  min-height: 0;
}

#preview-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 6px 32px rgba(0, 0, 0, 0.6);
  border-radius: 2px;
}

#page-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

#page-nav button {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#page-indicator {
  font-size: 0.78rem;
  color: #555;
  min-width: 90px;
  text-align: center;
}

/* ─── Export ─────────────────────────────────────────────────────────────── */

#export {
  display: flex;
  justify-content: center;
  gap: 0.65rem;
  flex-shrink: 0;
}

#download-btn,
#print-btn {
  padding: 0.55rem 1.6rem;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: 7px;
}

#download-btn {
  background: #4a7cf5;
  border-color: #4a7cf5;
  color: #fff;
}

#download-btn:hover {
  background: #3a6de0;
  border-color: #3a6de0;
  color: #fff;
}

#download-btn:active {
  background: #2f5ec9;
}

#print-btn {
  background: #212121;
  border-color: #2e2e2e;
  color: #aaa;
}

#print-btn:hover {
  background: #282828;
  border-color: #3a3a3a;
  color: #d0d0d0;
}

/* ─── Mobile ─────────────────────────────────────────────────────────────── */

/* Delete buttons always visible on touch devices */
@media (hover: none) {
  .thumb-delete {
    opacity: 1;
  }
}

@media (max-width: 680px) {
  body {
    height: auto;
    overflow: auto;
  }

  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    height: auto;
    min-height: 100vh;
  }

  header {
    grid-column: 1;
    padding: 0.75rem 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
    background: #141414;
  }

  header h1 {
    font-size: 1rem;
  }

  #left-pane {
    border-right: none;
    border-bottom: 1px solid #1f1f1f;
    padding: 1rem;
    gap: 0.85rem;
    overflow-y: visible;
  }

  #drop-zone {
    padding: 1.5rem 1rem;
  }

  #drop-zone p {
    font-size: 0.85rem;
  }

  #browse-label {
    padding: 0.5rem 1.4rem;
    font-size: 0.88rem;
  }

  /* Larger thumbnails on mobile */
  .thumbnail {
    width: 72px;
    height: 72px;
  }

  /* Larger touch target for delete */
  .thumb-delete {
    width: 22px;
    height: 22px;
    font-size: 13px;
  }

  /* Bigger control buttons */
  button {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
  }

  #right-pane {
    padding: 0.85rem 1rem 1.25rem;
    overflow: visible;
    min-height: 0;
  }

  #preview-section {
    min-height: 0;
  }

  #preview-wrap {
    height: 60vw;
    min-height: 220px;
    max-height: 420px;
    flex: none;
    padding: 0.6rem;
  }

  #export {
    flex-direction: column;
    gap: 0.5rem;
  }

  #download-btn,
  #print-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    text-align: center;
  }

  /* Bigger page nav buttons */
  #page-nav button {
    width: 40px;
    height: 40px;
    font-size: 1.6rem;
    line-height: 1;
  }

  #page-indicator {
    font-size: 0.85rem;
  }

  .control-label {
    font-size: 0.7rem;
  }

  .toggle-hint {
    font-size: 0.82rem;
  }

  /* Toggle track slightly larger */
  .toggle-track {
    width: 40px;
    height: 23px;
  }

  .toggle-thumb {
    width: 17px;
    height: 17px;
  }

  .toggle input:checked+.toggle-track .toggle-thumb {
    transform: translateX(17px);
  }
}

/* ─── Print ──────────────────────────────────────────────────────────────── */

#print-area {
  display: none;
}

@media print {
  body {
    margin: 0;
    background: #fff;
    overflow: visible;
  }

  #app {
    display: none !important;
  }

  #print-area {
    display: block !important;
  }

  .print-page {
    display: block;
    object-fit: fill;
    page-break-after: always;
    break-after: page;
  }

  .print-page:last-child {
    page-break-after: avoid;
    break-after: avoid;
  }
}