/* Base resets */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: #0f172a;
  background: #f8fafc;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.skip-link:focus {
  position: static;
  width: auto;
  height: auto;
  padding: .5rem .75rem;
  background: #111827;
  color: #fff;
}

.app-header {
  padding: 2rem 1rem 1rem;
  text-align: center;
}

.app-title {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: .2px;
}

.app-tagline {
  margin: .5rem 0 0;
  color: #475569;
}

.app-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  gap: 1.5rem;
}

.dropzone {
  border: 2px dashed #94a3b8;
  border-radius: 12px;
  padding: 2rem;
  background: #fff;
  display: grid;
  place-items: center;
  text-align: center;
  outline: none;
  transition: border-color .2s ease, background .2s ease, transform .06s ease;
}

.dropzone:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .15);
}

.dropzone.is-dragover {
  border-color: #16a34a;
  background: #f0fdf4;
  transform: scale(0.998);
}

.dropzone__content {
  display: grid;
  gap: .25rem;
}

.dz-title {
  font-weight: 600;
}

.dz-subtitle {
  color: #475569;
  margin: 0;
}

.dz-hint {
  color: #64748b;
  font-size: .9rem;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.button {
  appearance: none;
  border: 1px solid #1e293b;
  background: #111827;
  font-size: 14px;
  color: #fff;
  padding: .6rem;
  border-radius: 8px;
  cursor: pointer;
}

.button:hover {
  background: #0b1220;
}

.button:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.button--ghost {
  background: #fff;
  color: #111827;
  border-color: #cbd5e1;
}

.button--ghost:hover {
  background: #f8fafc;
}

.section-title {
  margin: 0 0 1.1rem 0;
  font-size: 1.1rem;
}

.counter {
  display: inline-block;
  margin-left: .5rem;
  background: #e2e8f0;
  color: #0f172a;
  padding: .1rem .5rem;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.pending {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem;
}

.pending-list {
  list-style: none;
  margin: .75rem 0 0;
  padding: 0;
  display: grid;
  gap: .5rem;
}

.pending-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: .6rem .75rem;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  gap: .75rem;
}

.pending-item__left {
  display: grid;
  gap: .8rem;
}

.pending-item__info {
  display: flex;
  gap: .5rem;
  align-items: baseline;
  min-width: 0;
}

.pending-item__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pending-item__meta {
  color: #475569;
  font-variant-numeric: tabular-nums;
}

.pending-item__right {
  display: grid;
  gap: .4rem;
  align-items: center;
  justify-items: end;
}

.pending-item__outputs {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .5rem;
}

.output-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .2rem .5rem;
  border-radius: 999px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: #0f172a;
  font-size: .85rem;
}

.output-chip--ready {
  cursor: pointer;
  position: relative;
}

.output-chip--ready::before {
  content: "";
  display: inline-block;
  width: .9rem;
  height: .9rem;
  margin-right: .25rem;
  background-image: url('data:image/svg+xml,<%3Fxml version="1.0" encoding="utf-8"%3F><svg width="24px" height="24px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M22 20.8201C15.426 22.392 8.574 22.392 2 20.8201" stroke="%23000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M11.9492 2V16" stroke="%23000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M16.8996 11.8L13.3796 15.4099C13.2011 15.5978 12.9863 15.7476 12.7482 15.8499C12.5101 15.9521 12.2538 16.0046 11.9946 16.0046C11.7355 16.0046 11.4791 15.9521 11.241 15.8499C11.0029 15.7476 10.7881 15.5978 10.6096 15.4099L7.09961 11.8" stroke="%23000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
}

.output-chip--pending {
  opacity: .65;
}

.output-chip--best {
  background: #ecfdf5;
  border-color: #34d399;
}

.output-chip--skipped {
  background: #f1f5f9;
  border-color: #e2e8f0;
  color: #64748b;
}

.output-chip__size {
  color: #475569;
  font-variant-numeric: tabular-nums;
}

.msg {
  margin: 0.25rem 0;
  padding: .6rem .8rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: #eef2ff;
  color: #1e293b;
}

.msg--error {
  background: #fef2f2;
  color: #7f1d1d;
  border-color: #fecaca;
}

.msg--warn {
  background: #fffbeb;
  color: #7c2d12;
  border-color: #fde68a;
}

.progress {
  position: relative;
  height: 10px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress--sm {
  height: 8px;
}

.progress__bar {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, #22c55e, #16a34a);
}

.overall__row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .75rem;
  align-items: center;
}

.overall__summary {
  color: #475569;
  font-variant-numeric: tabular-nums;
}

.formats {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem;
}

.format-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1rem;
  margin-top: .5rem;
}

.format-toggle {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .35rem .5rem;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  background: #f8fafc;
}

.formats-hint {
  color: #64748b;
  margin: .5rem 0 0;
  font-size: .9rem;
}

.controls {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem;
}

.controls-grid {
  display: grid;
  gap: 2rem;
  grid-template-columns: 1fr;
}

.quality__row {
  display: grid;
  grid-template-columns: 120px 40px auto;
  gap: .75rem;
  align-items: center;
  margin-bottom: .5rem;
}

.quality__row input[type="range"] {
  width: 100%;
}

.resize__modes {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.resize__inputs {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: .5rem 1rem;
}

.resize__input {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: .5rem;
  align-items: center;
}

.resize__hint {
  color: #64748b;
  font-size: .9rem;
  margin-top: .5rem;
}

@media (min-width: 820px) {
  .controls-grid {
    grid-template-columns: 1fr 1fr;
    gap: 2rem 4rem;
  }
}

.metadata {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem;
}

.metadata__options {
  display: grid;
  gap: .5rem;
}

.metadata__toggle {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}

.metadata__preserve {
  display: none;
  gap: .5rem 1rem;
  flex-wrap: wrap;
  margin-top: .25rem;
}

.metadata__field {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .2rem .5rem;
  border-radius: 999px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
}

.metadata__hint {
  color: #64748b;
  font-size: .9rem;
  margin-top: .25rem;
}

.skip-small {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem;
}

.skip-small__toggle {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}

.skip-small__input {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  margin-left: 1rem;
}

.skip-small__hint {
  color: #64748b;
  font-size: .9rem;
  margin-top: .5rem;
}

.naming {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem;
}

.naming__options {
  display: grid;
  gap: .5rem;
}

.naming__toggle {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}

.app-footer {
  text-align: center;
  color: #475569;
  padding: 2rem 1rem 3rem;
}

@media (min-width: 768px) {
  .app-main {
    grid-template-columns: 1fr;
  }
}

/* Minimal toast styles */
.toast-container {
  position: fixed;
  right: 12px;
  bottom: 12px;
  display: grid;
  gap: 8px;
  z-index: 9999;
}

.toast-item {
  background: #0f172a;
  color: #fff;
  border-radius: 10px;
  padding: .6rem .8rem;
  border: 1px solid #111827;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
  box-shadow: 0 10px 20px rgba(2, 6, 23, .18);
  max-width: 300px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.toast-item--error {
  background: #991b1b;
  border-color: #7f1d1d;
}

.toast-item.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Preview overlay */
.preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, .7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9998;
}

.preview-overlay.is-open {
  display: flex;
}

.preview-panel {
  background: #fff;
  color: #0f172a;
  width: min(100vw - 24px, 980px);
  max-height: calc(100vh - 24px);
  border-radius: 12px;
  box-shadow: 0 15px 50px rgba(2, 6, 23, .3);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid #e2e8f0;
}

.preview-title {
  margin: 0;
  font-size: 1rem;
}

.preview-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  overflow: auto;
}

.preview-canvas {
  display: grid;
  place-items: center;
  padding: .75rem;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  position: relative;
}

.preview-canvas:last-child {
  border-bottom: none;
}

/* Ensure canvases scale down to container width for vertical layout */
.preview-canvas > canvas {
  max-width: 100%;
  height: auto;
}

.preview-label {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(15, 23, 42, .75);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  padding: .25rem .4rem;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,.2);
}

.preview-label--uncompressed { background: rgba(15, 23, 42, .75); }
.preview-label--compressed { background: rgba(22, 163, 74, .85); }

.preview-meta {
  font-size: .9rem;
  color: #475569;
  padding: .5rem 1rem;
  border-top: 1px solid #e2e8f0;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
}

.preview-meta__sizes {
  font-variant-numeric: tabular-nums;
}

.preview-close {
  margin-left: auto;
}

/* How it works section */
.how-it-works {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem;
}

.how-steps {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: .5rem;
}

.how-steps li {
  color: #0f172a;
}

.how-note {
  color: #64748b;
  font-size: .9rem;
  margin-top: .5rem;
}