:root {
  --bg: #0c0d10;
  --panel: #14161c;
  --panel-2: #1a1d26;
  --border: #2a2f3a;
  --text: #e8eaef;
  --muted: #8b93a7;
  --accent: #ff4d8d;
  --accent-2: #7c5cff;
  --ok: #3dd68c;
  --warn: #f5a524;
  --radius: 14px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(124, 92, 255, 0.18), transparent),
    radial-gradient(ellipse 60% 40% at 90% 10%, rgba(255, 77, 141, 0.12), transparent),
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: auto, auto, 40px 40px, 40px 40px;
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(255, 77, 141, 0.2), rgba(124, 92, 255, 0.2));
  border: 1px solid var(--border);
  color: var(--accent);
}

h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 18px;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(8px);
}

.dropzone {
  position: relative;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  min-height: 160px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: var(--panel-2);
  overflow: hidden;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--panel-2));
  outline: none;
}

.drop-inner {
  text-align: center;
  padding: 24px;
  pointer-events: none;
}

.drop-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 10px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 77, 141, 0.15);
  color: var(--accent);
  font-weight: 700;
}

.drop-inner strong {
  display: block;
  margin-bottom: 4px;
}

.drop-inner span {
  color: var(--muted);
  font-size: 0.85rem;
}

.file-preview {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px;
  background: var(--panel-2);
}

.file-preview img,
.file-preview object {
  max-width: 45%;
  max-height: 130px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}

.file-preview .meta {
  text-align: left;
  font-size: 0.85rem;
}

.file-preview .meta strong {
  display: block;
  margin-bottom: 4px;
  word-break: break-all;
}

.file-preview .meta span {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.samples {
  margin-top: 18px;
}

.samples h2,
.options h2,
.result-header h2 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.samples-hint {
  margin: 0 0 10px;
  font-size: 0.8rem;
  color: var(--muted);
}

.sample-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.sample-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.72rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.sample-card:hover,
.sample-card:focus-visible {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel-2));
  color: var(--text);
  outline: none;
}

.sample-card:active {
  transform: scale(0.97);
}

.sample-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
}

.sample-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent);
}

.options {
  margin-top: 18px;
}

.options h2 {
  margin-bottom: 14px;
}

.result-header h2 {
  margin: 0 0 14px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

label {
  display: block;
  margin-bottom: 14px;
  font-size: 0.88rem;
  color: var(--muted);
}

input[type="number"],
select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.range-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
}

.range-row output {
  font-family: var(--mono);
  font-size: 0.85rem;
  min-width: 2.5rem;
  text-align: right;
  color: var(--text);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--text);
}

.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.1s, opacity 0.15s, filter 0.15s;
}

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

.btn.primary {
  margin-top: 4px;
  background: linear-gradient(135deg, var(--accent), #ff7a5c 55%, var(--accent-2));
  color: #fff;
  box-shadow: 0 8px 24px rgba(255, 77, 141, 0.25);
}

.btn.primary:not(:disabled):hover {
  filter: brightness(1.06);
}

.btn.primary:not(:disabled):active {
  transform: scale(0.98);
}

.btn.download {
  background: var(--ok);
  color: #062016;
}

.btn.download:hover {
  filter: brightness(1.05);
}

.result {
  display: flex;
  flex-direction: column;
  min-height: 480px;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stat {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.stat strong {
  color: var(--text);
  font-weight: 500;
}

.preview-box {
  flex: 1;
  min-height: 320px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #2a2a2e;
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
  padding: 10px;
}

.preview-box svg {
  width: 100%;
  height: 100%;
  max-height: 420px;
  padding: 12px;
}

.preview-box img.stitch-sim {
  width: 100%;
  height: 100%;
  max-height: 440px;
  object-fit: contain;
  background: #b0b0b4;
  border-radius: 8px;
  display: block;
}

.placeholder {
  padding: 28px;
  color: var(--muted);
  max-width: 360px;
}

.placeholder p {
  margin: 0 0 12px;
  color: var(--text);
  font-weight: 500;
}

.placeholder ul {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.88rem;
}

.placeholder li {
  margin-bottom: 4px;
}

.color-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  min-height: 8px;
}

.swatch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.swatch i {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.actions {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.status {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--muted);
}

.status.error {
  color: #ff6b7a;
}

.status.ok {
  color: var(--ok);
}

.status.loading {
  color: var(--warn);
}

.footer {
  margin-top: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.footer p {
  margin: 0;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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