:root {
  --bg: #f5f3ed;
  --surface: #fffefb;
  --ink: #161616;
  --muted: #77736a;
  --line: #d8d4ca;
  --soft: #ece9e0;
  --accent: #bbff3c;
  --danger: #c44b39;
  --mono: "DM Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  --sans: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

body {
  overflow: hidden;
}

button, input { font: inherit; }
button { color: inherit; }

button:focus-visible,
label:focus-within {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: 62px minmax(0, 1fr);
}

.topbar {
  height: 62px;
  padding: 0 clamp(16px, 2.5vw, 36px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: rgba(245, 243, 237, .95);
}

.brand {
  color: inherit;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.logo {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--accent);
  display: grid;
  place-items: center;
  font: 600 16px/1 var(--sans);
  flex: 0 0 auto;
}

.brand-copy {
  display: grid;
  line-height: 1;
  gap: 4px;
}

.brand-copy strong {
  font-size: 14px;
  letter-spacing: .08em;
}

.brand-copy small {
  color: var(--muted);
  font: 500 8px/1 var(--mono);
  letter-spacing: .14em;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ghost-button,
.icon-button,
.generate-button,
.restart-button,
.retry-button,
.download-button,
.remove-button {
  border: 0;
  cursor: pointer;
}

.ghost-button {
  min-height: 36px;
  padding: 0 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}

.ghost-button:hover:not(:disabled) {
  border-color: var(--ink);
}

.ghost-button:disabled {
  opacity: .35;
  cursor: default;
}

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
}

.icon-button:hover { border-color: var(--ink); }

.icon-button svg,
.upload-icon svg,
.generate-button svg,
.download-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  gap: 0;
}

.input-panel,
.output-panel {
  min-height: 0;
  padding: clamp(18px, 2.4vw, 32px);
}

.input-panel {
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto minmax(170px, 1fr) auto auto;
  gap: 14px;
  overflow: hidden;
}

.output-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.overline {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font: 500 9px/1 var(--mono);
  letter-spacing: .14em;
}

h1, h2, p { margin: 0; }

h1, h2 {
  font-size: clamp(20px, 2vw, 28px);
  line-height: 1.08;
  letter-spacing: -.035em;
}

.count-badge {
  min-width: 27px;
  height: 27px;
  border: 1px solid var(--line);
  border-radius: 99px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font: 500 10px/1 var(--mono);
}

.result-summary {
  color: var(--muted);
  font: 500 10px/1 var(--mono);
  white-space: nowrap;
}

.dropzone {
  min-height: 170px;
  border: 1px dashed #aaa69b;
  border-radius: 14px;
  background: rgba(255, 254, 251, .55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}

.dropzone:hover,
.dropzone.is-dragging {
  border-color: var(--ink);
  background: var(--surface);
}

.dropzone.is-dragging { transform: scale(.994); }

.upload-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--accent);
  display: grid;
  place-items: center;
  margin-bottom: 12px;
}

.dropzone strong {
  font-size: 14px;
  font-weight: 600;
}

.dropzone small {
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
}

.queue {
  max-height: 154px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  scrollbar-width: thin;
}

.queue-item {
  height: 50px;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 28px;
  gap: 10px;
  align-items: center;
  padding: 6px 8px;
  border-top: 1px solid var(--line);
}

.queue-item:first-child { border-top: 0; }

.queue-thumb {
  width: 36px;
  height: 36px;
  border-radius: 7px;
  object-fit: cover;
  background: var(--soft);
}

.queue-info { min-width: 0; }

.queue-name {
  font-size: 11px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-meta {
  margin-top: 2px;
  color: var(--muted);
  font: 400 8px/1.2 var(--mono);
}

.remove-button {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.remove-button:hover { background: var(--soft); color: var(--ink); }

.generate-button {
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  border-radius: 11px;
  background: var(--ink);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
}

.generate-button svg { color: var(--accent); }
.generate-button:disabled { opacity: .35; cursor: default; }

.restart-button {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 9px;
  background: transparent;
  border: 1px solid var(--ink);
  color: var(--ink);
  font-size: 11px;
  font-weight: 600;
}

.restart-button:hover:not(:disabled) {
  background: var(--surface);
}

.restart-button:disabled {
  opacity: .5;
  cursor: default;
}

.restart-button[hidden] {
  display: none;
}

.empty-state {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 15px;
  color: var(--muted);
}

.empty-state p { font-size: 12px; }

.empty-watch {
  width: min(180px, 30vw);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  position: relative;
}

.empty-watch::before,
.empty-watch::after {
  content: "";
  position: absolute;
  width: 38%;
  height: 16%;
  left: 31%;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.empty-watch::before { top: -16%; }
.empty-watch::after { bottom: -16%; }

.empty-watch span {
  width: 55%;
  height: 55%;
  border-radius: 50%;
  border: 1px solid var(--line);
}

.results {
  min-height: 0;
  height: 100%;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 12px;
  scrollbar-width: thin;
}

.results[data-count="1"] {
  grid-template-columns: minmax(0, 1fr);
}

.result-card {
  min-height: 250px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
  display: grid;
  grid-template-rows: minmax(0, 1fr) 46px;
}

.result-visual {
  min-height: 0;
  background: #eeece5;
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}

.result-visual img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  background: var(--surface);
}

.result-loading {
  display: grid;
  place-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
}

.spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #d8d4ca;
  border-top-color: var(--ink);
  animation: spin .75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.result-error {
  width: min(320px, 80%);
  text-align: center;
  color: var(--danger);
  font-size: 11px;
  line-height: 1.45;
  display: grid;
  justify-items: center;
  gap: 10px;
}

.retry-button {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-size: 10px;
  font-weight: 600;
}

.retry-button:hover {
  opacity: .85;
}

.result-foot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 7px 8px 7px 12px;
  border-top: 1px solid var(--line);
}

.result-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 600;
}

.result-meta {
  margin-top: 2px;
  color: var(--muted);
  font: 400 8px/1 var(--mono);
}

.download-button {
  height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  display: inline-flex;
  gap: 7px;
  align-items: center;
  font-size: 10px;
  font-weight: 600;
}

.download-button svg { width: 14px; height: 14px; }
.download-button:disabled { opacity: .28; cursor: default; }

.toast {
  position: fixed;
  z-index: 20;
  right: 18px;
  bottom: 18px;
  max-width: min(380px, calc(100vw - 36px));
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--ink);
  color: white;
  font-size: 11px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: .16s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 901px) {
  .results[data-count="1"] .result-card {
    height: 100%;
  }

  .results[data-count="2"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .app {
    grid-template-rows: 56px minmax(0, 1fr);
  }

  .topbar { height: 56px; padding-inline: 14px; }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(255px, 40%) minmax(0, 60%);
  }

  .input-panel,
  .output-panel {
    padding: 14px;
  }

  .input-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(110px, 1fr) auto;
    gap: 10px;
  }

  .input-panel .panel-head { grid-column: 1 / -1; }

  .input-panel:has(.queue[hidden]) .dropzone {
    grid-column: 1 / -1;
  }

  .dropzone {
    min-height: 110px;
    padding: 12px;
  }

  .upload-icon {
    width: 32px;
    height: 32px;
    margin-bottom: 7px;
  }

  .dropzone small {
    display: none;
  }

  .queue {
    max-height: none;
    height: 100%;
  }

  .generate-button {
    grid-column: 1 / -1;
    min-height: 42px;
  }

  .output-panel { gap: 10px; }
  h1, h2 { font-size: 19px; }

  .results {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    grid-auto-rows: minmax(210px, 1fr);
  }

  .empty-watch {
    width: 92px;
  }
}

@media (max-width: 540px) {
  .brand-copy small { display: none; }
  .ghost-button { min-height: 34px; padding-inline: 9px; font-size: 10px; }
  .icon-button { width: 34px; height: 34px; }

  .workspace {
    grid-template-rows: minmax(230px, 42%) minmax(0, 58%);
  }

  .input-panel {
    padding: 11px;
    grid-template-columns: minmax(0, 1fr) 42%;
    grid-template-rows: auto minmax(92px, 1fr) 40px;
    gap: 8px;
  }

  .output-panel { padding: 11px; }
  .panel-head { align-items: center; }
  .overline { display: none; }
  h1, h2 { font-size: 17px; }

  .dropzone {
    min-height: 92px;
    border-radius: 11px;
  }

  .dropzone strong { font-size: 11px; }
  .upload-icon { width: 28px; height: 28px; margin-bottom: 6px; }
  .upload-icon svg { width: 15px; height: 15px; }

  .queue-item {
    height: 42px;
    grid-template-columns: 30px minmax(0, 1fr) 24px;
    gap: 7px;
    padding: 5px 6px;
  }

  .queue-thumb { width: 30px; height: 30px; }
  .queue-meta { display: none; }
  .remove-button { width: 24px; height: 24px; }

  .generate-button {
    min-height: 40px;
    border-radius: 9px;
  }

  .results {
    grid-auto-rows: minmax(190px, 1fr);
  }

  .result-card {
    min-height: 190px;
    grid-template-rows: minmax(0, 1fr) 42px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}