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

:root {
  --bg: #0e0e0f;
  --surface: #17171a;
  --surface2: #1f1f24;
  --border: #2e2e36;
  --accent: #eb6f46;
  --accent2: #ff5c5c;
  --text: #e8e8ec;
  --muted: #6b6b7a;
  --radius: 10px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Syne", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px 80px;
}

/* Header */
header {
  width: 100%;
  max-width: 820px;
  margin-bottom: 48px;
  display: flex;
  align-items: baseline;
  gap: 16px;
}

header h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1;
}

header h1 span {
  color: var(--accent);
}

.header-meta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

header p {
  font-family: "Space Mono", monospace;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.header-link {
  font-family: "Space Mono", monospace;
  font-size: 0.68rem;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  transition:
    border-color 0.2s,
    background 0.2s;
}

.header-link:hover {
  border-color: var(--accent);
  background: rgba(200, 255, 87, 0.07);
}

/* Shared layout */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 820px;
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-family: "Space Mono", monospace;
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field input[type="number"],
.field select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-family: "Space Mono", monospace;
  font-size: 0.85rem;
  padding: 10px 12px;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
  appearance: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
}

.bg-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.bg-chip {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition:
    border-color 0.15s,
    transform 0.15s;
  flex-shrink: 0;
}

.bg-chip:hover {
  transform: scale(1.15);
}

.bg-chip.active {
  border-color: var(--accent);
}

.bg-chip.transparent {
  background: repeating-conic-gradient(#555 0% 25%, #222 0% 50%) 0 0/10px 10px;
}

.normalize-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.2s;
}

.normalize-bar:hover {
  border-color: var(--accent);
}

.normalize-bar input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.norm-title {
  font-family: "Space Mono", monospace;
  font-size: 0.74rem;
  color: var(--text);
  flex: 1;
}

.norm-hint {
  font-family: "Space Mono", monospace;
  font-size: 0.65rem;
  color: var(--muted);
}

.normalize-opts {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  margin-top: -12px;
}

.normalize-opts.visible {
  display: grid;
}

.btn-join {
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: #000;
  font-family: "Syne", sans-serif;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.04em;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    opacity 0.2s,
    transform 0.1s;
}

.btn-join:hover {
  opacity: 0.9;
}

.btn-join:active {
  transform: scale(0.99);
}

.btn-join:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

#offscreen {
  display: none;
}

/* Index page */
.drop-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}

.drop-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  height: 170px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    border-color 0.2s,
    background 0.2s;
  position: relative;
  overflow: hidden;
  gap: 8px;
}

.drop-zone:hover {
  border-color: var(--accent);
  background: rgba(200, 255, 87, 0.04);
}

.drop-zone.has-image {
  border-style: solid;
  border-color: var(--accent);
}

.drop-zone img.thumb {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 8px;
  pointer-events: none;
}

.drop-icon {
  font-size: 2rem;
  opacity: 0.4;
}

.drop-label {
  font-family: "Space Mono", monospace;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.drop-tag {
  font-size: 0.62rem;
  font-family: "Space Mono", monospace;
  background: var(--accent);
  color: #000;
  padding: 2px 7px;
  border-radius: 4px;
  position: absolute;
  top: 10px;
  left: 10px;
  font-weight: 700;
  z-index: 2;
}

#preview-wrap {
  display: none;
  flex-direction: column;
  gap: 16px;
}

#preview-wrap.visible {
  display: flex;
}

.preview-header {
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.preview-header span {
  font-family: "Space Mono", monospace;
  font-size: 0.72rem;
  color: var(--muted);
}

#preview-canvas {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: repeating-conic-gradient(#2a2a2a 0% 25%, #1a1a1a 0% 50%) 0 0 /
    20px 20px;
  max-height: 400px;
  object-fit: contain;
  display: block;
}

.btn-dl {
  padding: 12px 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: "Syne", sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition:
    border-color 0.2s,
    background 0.2s;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.btn-dl:hover {
  border-color: var(--accent);
  background: rgba(200, 255, 87, 0.07);
}

#customPxField {
  display: none;
}

.drop-zone.has-image .drop-label,
.drop-zone.has-image .drop-icon {
  display: none;
}

/* Lote page */
.upload-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition:
    border-color 0.2s,
    background 0.2s;
  margin-bottom: 28px;
  text-align: center;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(200, 255, 87, 0.04);
}

.upload-zone .up-icon {
  font-size: 2.2rem;
  opacity: 0.45;
}

.upload-zone .up-title {
  font-weight: 700;
  font-size: 1rem;
}

.upload-zone .up-sub {
  font-family: "Space Mono", monospace;
  font-size: 0.68rem;
  color: var(--muted);
}

#pairs-section {
  margin-bottom: 28px;
  display: none;
}

#pairs-section.visible {
  display: block;
}

.pairs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.pairs-header h3 {
  font-size: 0.8rem;
  font-weight: 700;
  font-family: "Space Mono", monospace;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.btn-clear {
  font-family: "Space Mono", monospace;
  font-size: 0.67rem;
  color: var(--muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  transition:
    border-color 0.2s,
    color 0.2s;
}

.btn-clear:hover {
  border-color: #ff5c5c;
  color: #ff5c5c;
}

.odd-warning {
  display: none;
  font-family: "Space Mono", monospace;
  font-size: 0.68rem;
  color: #ffb347;
  background: rgba(255, 179, 71, 0.08);
  border: 1px solid rgba(255, 179, 71, 0.25);
  border-radius: 7px;
  padding: 8px 12px;
  margin-bottom: 14px;
}

.odd-warning.visible {
  display: block;
}

#image-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}

.img-card {
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  cursor: grab;
  border: 2px solid transparent;
  transition:
    border-color 0.15s,
    transform 0.15s,
    opacity 0.15s;
  background: var(--surface2);
  aspect-ratio: 1;
  user-select: none;
}

.img-card:active {
  cursor: grabbing;
}

.img-card.dragging {
  opacity: 0.35;
  transform: scale(0.96);
}

.img-card.drag-over {
  border-color: var(--accent);
}

.img-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.pair-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  font-family: "Space Mono", monospace;
  font-size: 0.58rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}

.pair-a {
  background: var(--accent);
  color: #000;
}

.pair-b {
  background: #fff;
  color: #000;
}

.pair-odd {
  background: rgba(255, 179, 71, 0.9);
  color: #000;
}

.img-card .fname {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  font-family: "Space Mono", monospace;
  font-size: 0.55rem;
  color: #ccc;
  padding: 3px 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

.img-card:hover .fname {
  opacity: 1;
}

.img-card .rm-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  border: none;
  color: #fff;
  font-size: 0.65rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  line-height: 1;
}

.img-card:hover .rm-btn {
  opacity: 1;
}

.pair-divider {
  grid-column: 1/-1;
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

#progress-wrap {
  display: none;
  margin-top: 20px;
  flex-direction: column;
  gap: 10px;
}

#progress-wrap.visible {
  display: flex;
}

.progress-bar-bg {
  height: 6px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.2s;
  width: 0%;
}

#progress-label {
  font-family: "Space Mono", monospace;
  font-size: 0.7rem;
  color: var(--muted);
}

footer {
  text-align: center;
  padding: 2rem 1rem 2.5rem;
  font-family: "Space Mono", monospace;
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

footer a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.15s;
}

footer a:hover {
  color: #eb6f46;
}

@media (max-width: 520px) {
  .drop-row {
    grid-template-columns: 1fr;
  }

  header {
    flex-direction: column;
    gap: 6px;
  }

  .header-meta {
    margin-left: 0;
    flex-wrap: wrap;
  }

  #image-list {
    grid-template-columns: repeat(3, 1fr);
  }
}
