* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 2rem 1rem;
}

main {
  width: 100%;
  max-width: 720px;
}

header { margin-bottom: 2rem; }
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
h1 { margin: 0; font-size: 2.25rem; letter-spacing: -0.02em; }
.subtitle { color: #94a3b8; margin: 0.25rem 0 0; }

.upload-limit {
  margin: 0.6rem 0 0;
  font-size: 0.78rem;
  color: #64748b;
}

.logout-btn {
  background: transparent;
  color: #94a3b8;
  border: 1px solid #334155;
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  border-radius: 0.4rem;
  cursor: pointer;
}
.logout-btn:hover { background: #1e293b; color: #e2e8f0; }

.controls {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  flex-wrap: wrap;
  background: #1e293b;
  padding: 1rem 1.25rem;
  border-radius: 0.75rem;
  margin-bottom: 1rem;
}

.controls label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.controls input[type="range"] { width: 180px; }
.controls .lossless { cursor: pointer; }

.controls select {
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 0.4rem;
  padding: 0.3rem 0.5rem;
  font-size: 0.9rem;
}

.controls .toggle {
  cursor: pointer;
  user-select: none;
  padding: 0.25rem 0.6rem;
  border-radius: 0.4rem;
  background: #0f172a;
  border: 1px solid #334155;
}
.controls .toggle:has(input:checked) {
  border-color: #38bdf8;
  background: #0c4a6e;
}

.controls .disabled { opacity: 0.4; pointer-events: none; }

.model-status {
  background: #0c4a6e;
  border: 1px solid #0284c7;
  color: #bae6fd;
  padding: 0.6rem 0.9rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.trim-options,
.resize-options,
.ratio-options {
  margin-top: -0.5rem;
  margin-bottom: 1rem;
  background: #172033;
}
.trim-options.hidden,
.resize-options.hidden,
.ratio-options .hidden { display: none; }

.trim-options .hint,
.resize-options .hint,
.ratio-options .hint {
  flex-basis: 100%;
  font-size: 0.78rem;
  color: #64748b;
}

.ratio-options.collapsed > *:not(.toggle) { display: none; }

.ratio-options input[type="number"] {
  width: 60px;
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 0.3rem;
  padding: 0.25rem 0.4rem;
  font-size: 0.85rem;
}

.ratio-custom { display: flex; align-items: center; gap: 0.4rem; }

.dropzone {
  border: 2px dashed #475569;
  border-radius: 0.75rem;
  padding: 3rem 1rem;
  text-align: center;
  background: #1e293b;
  transition: all 0.15s ease;
  cursor: pointer;
}

.dropzone.dragover {
  border-color: #38bdf8;
  background: #0c4a6e;
}

.dropzone p { margin: 0.25rem 0; color: #cbd5e1; }
.dropzone .or { color: #64748b; font-size: 0.85rem; }

.browse-btn {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.5rem 1.25rem;
  background: #38bdf8;
  color: #0f172a;
  border-radius: 0.5rem;
  font-weight: 600;
  cursor: pointer;
}
.browse-btn:hover { background: #7dd3fc; }

.url-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.url-row input {
  flex: 1;
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 0.5rem;
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
}
.url-row input:focus {
  outline: none;
  border-color: #38bdf8;
}

.url-row button {
  background: #38bdf8;
  color: #0f172a;
  padding: 0.55rem 1.2rem;
}
.url-row button:hover:not(:disabled) { background: #7dd3fc; }

.url-hint {
  font-size: 0.78rem;
  color: #64748b;
  margin: 0.4rem 0 0;
}

.actions {
  display: flex;
  gap: 0.75rem;
  margin: 1rem 0;
}

button {
  padding: 0.55rem 1.1rem;
  border: none;
  border-radius: 0.5rem;
  background: #334155;
  color: #e2e8f0;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}
button:hover:not(:disabled) { background: #475569; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
#downloadAll { background: #22c55e; color: #052e16; }
#downloadAll:hover:not(:disabled) { background: #4ade80; }

#fileList {
  list-style: none;
  padding: 0;
  margin: 0;
}

.file-item {
  background: #1e293b;
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 1rem;
  align-items: center;
}

.file-item .thumb {
  width: 56px;
  height: 56px;
  border-radius: 0.4rem;
  background: #0f172a center/contain no-repeat;
  background-image:
    linear-gradient(45deg, #1e293b 25%, transparent 25%),
    linear-gradient(-45deg, #1e293b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1e293b 75%),
    linear-gradient(-45deg, transparent 75%, #1e293b 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  cursor: zoom-in;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.file-item .thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.file-item .thumb.placeholder::after {
  content: "";
  position: absolute;
  inset: 0;
  display: flex;
}

.file-item .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item .size {
  font-size: 0.8rem;
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
}

.file-item .savings { color: #4ade80; font-weight: 600; }
.file-item .growth { color: #fbbf24; font-weight: 600; }
.file-item .status { color: #94a3b8; font-size: 0.85rem; }
.file-item .error { color: #f87171; font-size: 0.85rem; }
.file-item .dims {
  color: #64748b;
  font-size: 0.78rem;
  margin-left: 0.4rem;
  font-variant-numeric: tabular-nums;
}

.file-item .actions-cell,
.file-item span:last-child {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.file-item .download,
.file-item .preview-btn {
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border-radius: 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
}

.file-item .download {
  background: #38bdf8;
  color: #0f172a;
}
.file-item .download:hover { background: #7dd3fc; }

.file-item .preview-btn {
  background: #334155;
  color: #e2e8f0;
}
.file-item .preview-btn:hover { background: #475569; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #334155;
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 2rem;
  cursor: zoom-out;
}

.lightbox.open { display: flex; }

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 0.5rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.lightbox .caption {
  position: absolute;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.85);
  color: #e2e8f0;
  padding: 0.5rem 0.9rem;
  border-radius: 0.4rem;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
