:root {
  --bg-base: #09090b;
  --bg-surface: #18181b;
  --bg-elevated: #27272a;
  --bg-input: #0a0a0a;

  --border: #27272a;
  --border-strong: #3f3f46;

  --text-primary: #f4f4f5;
  --text-secondary: #d4d4d8;
  --text-muted: #71717a;
  --text-faint: #52525b;

  --accent: #7c3aed;
  --accent-hover: #8b4ff0;
  --accent-light: #a78bfa;
  --accent-bg: rgba(124, 58, 237, 0.2);
  --accent-ring: rgba(124, 58, 237, 0.35);
  --accent-glow: rgba(124, 58, 237, 0.12);

  --success: #34d399;
  --success-bg: rgba(16, 185, 129, 0.10);
  --success-border: rgba(16, 185, 129, 0.25);

  --error: #f87171;
  --error-bg: rgba(239, 68, 68, 0.10);
  --error-border: rgba(239, 68, 68, 0.25);

  --warning: #fbbf24;
  --warning-bg: rgba(245, 158, 11, 0.10);
  --warning-border: rgba(245, 158, 11, 0.25);

  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
}

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

/* Author rules like `.row { display: flex }` would otherwise win over the
   user-agent default `[hidden] { display: none }`. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
  line-height: 1.5;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-4);
}

/* ---- Header ---- */
.app-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.app-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}
.app-header .subtitle {
  margin: 2px 0 0 0;
  color: var(--text-muted);
  font-size: 0.8125rem;
}
.logo-dot {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  box-shadow: 0 0 0 4px var(--accent-glow);
  flex-shrink: 0;
}

.app-footer {
  margin-top: var(--space-8);
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-faint);
}
.app-footer a {
  color: var(--text-muted);
  text-decoration: none;
}
.app-footer a:hover { color: var(--accent-light); }

/* ---- Drop zone ---- */
.drop {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 56px 20px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-surface);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  outline: none;
}
.drop:hover,
.drop:focus-visible,
.drop.over {
  border-color: var(--accent);
  background: var(--bg-surface);
  box-shadow: 0 0 0 4px var(--accent-glow);
}
.drop p { margin: 0; color: var(--text-secondary); }
.drop .hint { margin-top: 10px; font-size: 12px; color: var(--text-muted); }

/* ---- Panel ---- */
.panel {
  margin-top: var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  animation: fade-up 0.2s ease both;
}

.section {
  padding: var(--space-4) 0;
  border-top: 1px solid var(--border);
}
.section:first-of-type {
  border-top: none;
  padding-top: 0;
}

.section h3 {
  margin: 0 0 var(--space-3) 0;
  color: var(--text-primary);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ---- Rows / form fields ---- */
.row {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  margin: var(--space-2) 0;
  flex-wrap: wrap;
}
.row label {
  min-width: 110px;
  color: var(--text-muted);
  font-size: 0.8125rem;
}
.dim-x { color: var(--text-faint); }
.ratio-note {
  color: var(--text-faint);
  font-size: 0.75rem;
  font-style: italic;
}
.value-readout {
  color: var(--text-secondary);
  min-width: 50px;
  font-variant-numeric: tabular-nums;
  font-size: 0.8125rem;
}

input[type="number"],
input[type="text"],
select {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 0.8125rem;
  font-family: inherit;
  width: 110px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M3 4.5L6 7.5L9 4.5' stroke='%2371717a' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 26px;
  width: 200px;
}

/* Range slider */
input[type="range"] {
  flex: 1;
  max-width: 240px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 22px;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 999px;
}
input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 999px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: -6px;
  border: 2px solid var(--bg-base);
  box-shadow: 0 0 0 1px var(--accent);
  cursor: pointer;
  transition: transform 0.1s ease;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-base);
  box-shadow: 0 0 0 1px var(--accent);
  cursor: pointer;
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.1); }
input[type="range"]:focus { outline: none; }
input[type="range"]:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--accent-ring);
}

/* ---- Buttons ---- */
button {
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 0.8125rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}
button:disabled {
  background: var(--bg-elevated);
  color: var(--text-faint);
  cursor: not-allowed;
}
button.secondary {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border-color: var(--border);
}
button.secondary:hover:not(:disabled) {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
}
button.small {
  padding: 7px 12px;
  font-size: 0.75rem;
}

/* ---- Pills / badges ---- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}
.pill-success {
  background: var(--success-bg);
  color: var(--success);
  border-color: var(--success-border);
}
.pill-error {
  background: var(--error-bg);
  color: var(--error);
  border-color: var(--error-border);
}
.pill-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border-color: var(--warning-border);
}
.pill-violet {
  background: var(--accent-bg);
  color: var(--accent-light);
  border-color: rgba(124, 58, 237, 0.3);
}

/* ---- Preview / meta ---- */
.preview { margin-top: var(--space-4); }
.preview img {
  max-width: 100%;
  max-height: 460px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  display: block;
  background: #000;
  animation: fade-in 0.15s ease both;
}

.meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: var(--space-3);
  line-height: 1.7;
}
.meta strong { color: var(--text-secondary); font-weight: 600; }
.meta .savings-line { display: inline-flex; gap: 6px; align-items: center; }

.error {
  margin-top: var(--space-3);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error);
  font-size: 0.8125rem;
}

.actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
  flex-wrap: wrap;
}

/* ---- Animations ---- */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@media (max-width: 520px) {
  #app { padding: var(--space-5) var(--space-3); }
  .row label { min-width: 100%; margin-bottom: -2px; }
  select { width: 100%; }
  input[type="number"] { width: 90px; }
}
