/* StitchFont design system — clean SaaS with a sage accent. */

:root {
  /* Brand */
  --sage:        rgb(146, 163, 140);
  --sage-dark:   rgb(118, 138, 110);
  --sage-darker: rgb(96, 116, 88);
  --sage-tint:   rgb(232, 237, 229);
  --sage-tint-2: rgb(244, 247, 242);

  /* Neutrals */
  --ink:    rgb(28, 32, 28);
  --text:   rgb(50, 56, 50);
  --muted:  rgb(110, 116, 110);
  --hairline: rgb(225, 228, 222);
  --surface:    rgb(255, 255, 255);
  --surface-2:  rgb(250, 251, 248);
  --bg:         rgb(247, 248, 245);

  /* Semantic */
  --error:   rgb(180, 60, 50);
  --warning: rgb(180, 130, 40);

  /* Typography */
  --font-display: "Newsreader", ui-serif, Georgia, serif;
  --font-body:    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono:    ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Sizing */
  --radius:   8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(50, 56, 50, 0.04), 0 1px 1px rgba(50, 56, 50, 0.04);
  --shadow:    0 2px 6px rgba(50, 56, 50, 0.05), 0 1px 2px rgba(50, 56, 50, 0.06);

  /* Inline SVG dropdown chevron — replaces the native <select> arrow so we can
     control its right margin. Color is `--muted` (rgb 110,116,110 → #6e746e). */
  --select-arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' stroke='%236e746e' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin: 0 0 0.5em;
}

h1 { font-size: 2.4rem; font-weight: 450; letter-spacing: -0.02em; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.15rem; font-weight: 500; }

p { margin: 0 0 0.75em; }
p:last-child { margin-bottom: 0; }

a { color: var(--sage-darker); text-decoration: none; }
a:hover { color: var(--ink); text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--error); }

/* ---------- Layout ---------- */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  border-bottom: 1px solid var(--hairline);
  background: var(--surface);
}
.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.logo {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.logo:hover { text-decoration: none; }
.logo-mark {
  display: inline-block;
  width: 18px;
  height: 18px;
  background: var(--sage);
  border-radius: 4px;
  vertical-align: -3px;
  margin-right: 8px;
  position: relative;
}
.logo-mark::after {
  content: "";
  position: absolute;
  inset: 4px;
  background: var(--surface);
  border-radius: 1px;
  transform: rotate(45deg);
}

.privacy-badge {
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.privacy-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sage);
  display: inline-block;
}

main {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 48px 24px;
}

.footer {
  border-top: 1px solid var(--hairline);
  padding: 24px 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  background: var(--surface);
}
.footer a { color: var(--muted); margin: 0 8px; }
.footer p { margin: 0; }
.footer p + p { margin-top: 6px; }
.footer-credit { font-size: 12px; }
.footer-credit a { margin: 0 0 0 4px; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Legal pages (terms, privacy) ---------- */

.legal {
  max-width: 720px;
}
.legal h1 {
  font-size: 2rem;
  margin-bottom: 0.25em;
}
.legal h2 {
  font-size: 1.15rem;
  margin-top: 1.8em;
  margin-bottom: 0.4em;
}
.legal p { margin: 0 0 1em; }
.legal ul {
  margin: 0 0 1em;
  padding-left: 1.5em;
}
.legal ul li { margin-bottom: 0.4em; }
.legal code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 1px 4px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 3px;
}

/* ---------- Hero ---------- */

.hero {
  text-align: center;
  margin-bottom: 32px;
}
.hero h1 {
  max-width: 18ch;
  margin: 0 auto 16px;
}
.hero .lede {
  font-size: 1.05rem;
  color: var(--muted);
  max-width: 56ch;
  margin: 0 auto 28px;
}

/* ---------- Drop zone ---------- */

.dropzone {
  border: 2px dashed rgb(200, 207, 197);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 56px 24px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
  max-width: 640px;
  margin: 0 auto;
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--sage);
  background: var(--sage-tint-2);
}
.dropzone-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--ink);
  margin: 0 0 6px;
}
.dropzone-sub { color: var(--muted); font-size: 14px; margin: 0; }

.sample-row {
  text-align: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--muted);
}
.sample-row .link {
  background: none;
  border: none;
  color: var(--sage-darker);
  cursor: pointer;
  font: inherit;
  padding: 0 4px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.sample-row .link:hover { color: var(--ink); }

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 28px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.card h2 { margin-bottom: 6px; }
.card-sub { color: var(--muted); margin-bottom: 24px; font-size: 14px; }

/* ---------- Form rows ---------- */

.form-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}
.form-row label {
  min-width: 90px;
  color: var(--muted);
  font-size: 14px;
}
.form-row select, .form-row input[type="text"] {
  flex: 1;
  font: inherit;
  /* 10px vertical padding so the box matches the .btn height alongside it
     (Convert button, modal action buttons). */
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
}
.form-row select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.form-row select:focus, .form-row input:focus {
  outline: none;
  border-color: var(--sage);
  box-shadow: 0 0 0 3px var(--sage-tint);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}
.checkbox-row input[type="checkbox"] {
  accent-color: var(--sage);
  width: 16px;
  height: 16px;
}
.checkbox-row .hint { color: var(--muted); font-size: 13px; }

/* ---------- Chips ---------- */

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 16px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--sage-tint);
  color: var(--sage-darker);
  font-size: 12px;
  font-weight: 500;
}
/* Chips carry hover tooltips (title attr); the help cursor signals that. */
.chip[title] { cursor: help; }

/* Fine-tune row inside the preview card. */
.finetune-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.finetune-row label { color: var(--muted); font-size: 14px; min-width: 50px; }
.finetune-row select {
  font: inherit;
  padding: 7px 26px 7px 10px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 8px center;
  min-width: 5em;
}
.finetune-nudge {
  font-family: var(--font-mono);
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 600;
}
.finetune-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  font-size: 12px;
}
.finetune-list:empty { display: none; }

.colors-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.color-swatch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
}
.color-swatch input[type="color"] {
  appearance: none;
  -webkit-appearance: none;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}
.color-swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.color-swatch input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }
.color-swatch:hover input[type="color"] { border-color: var(--sage); }
.colors-list:empty::before {
  content: "no thread colors detected";
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}
.finetune-list .override {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  font-family: var(--font-mono);
  color: var(--text);
}
.finetune-list .override button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
}
.finetune-list .override button:hover { color: var(--error); }
.chip.warn { background: rgb(255, 244, 219); color: rgb(132, 95, 14); }
.chip.muted { background: rgb(238, 240, 234); color: var(--muted); }

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.05s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--sage);
  color: white;
  border-color: var(--sage);
}
.btn-primary:hover:not(:disabled) {
  background: var(--sage-dark);
  border-color: var(--sage-dark);
}

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--hairline);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: rgb(200, 205, 195);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: transparent;
  padding: 10px 12px;
}
.btn-ghost:hover { background: var(--surface-2); }

/* Back-to-configure button at top of preview card; pull left a touch so the
   text aligns with the card's content padding rather than the button padding. */
.btn-back {
  margin: -8px 0 12px -12px;
  font-size: 14px;
  color: var(--muted);
}
.btn-back:hover { color: var(--ink); }

/* ---------- Advanced expander ---------- */

.advanced {
  margin: 18px 0;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.advanced summary {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  user-select: none;
  list-style: none;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::before {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  border: 5px solid transparent;
  border-left-color: var(--muted);
  margin-right: 10px;
  vertical-align: middle;
  position: relative;
  top: -1px;
  transition: transform 0.15s;
}
.advanced[open] summary::before { transform: rotate(90deg); }
.advanced-body { padding: 4px 14px 14px; }

/* ---------- Convert action row ---------- */

/* Modal action rows: simple horizontal flex of buttons. */
.actions {
  display: flex;
  gap: 12px;
  align-items: stretch;
  margin-top: 24px;
}
.actions input[type="text"] { flex: 1; }

/* Build row: a form-row that also hosts the Convert button on the right. The
   form-row class handles label + input alignment so the Name field lines up
   with Font/Size/etc. above it; this just lifts the row off the chip cluster. */
.build-row {
  margin-top: 24px;
  margin-bottom: 0;
}

/* ---------- Status / progress ---------- */

.status {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
}
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--hairline);
  border-top-color: var(--sage);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress-bar {
  height: 4px;
  background: var(--hairline);
  border-radius: 99px;
  overflow: hidden;
  margin: 12px 0;
}
.progress-bar-fill {
  height: 100%;
  background: var(--sage);
  width: 0%;
  transition: width 0.2s;
}

/* ---------- Live preview ---------- */

.preview-input {
  width: 100%;
  font: inherit;
  font-size: 1.1rem;
  padding: 12px 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-bottom: 14px;
}
.preview-input:focus {
  outline: none;
  border-color: var(--sage);
  box-shadow: 0 0 0 3px var(--sage-tint);
}

.preview-canvas-wrap {
  position: relative;
}
.preview-canvas {
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 24px;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}
.preview-canvas svg {
  width: 100%;
  height: 220px;
  display: block;
  cursor: grab;
}
.preview-canvas svg:active { cursor: grabbing; }
.preview-canvas .placeholder {
  color: var(--muted);
  font-size: 14px;
}
.preview-reset-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 12px;
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--hairline);
}
.preview-zoom-buttons {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 4px;
}
.zoom-btn {
  font: inherit;
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.zoom-btn:hover { background: var(--surface-2); border-color: rgb(200, 205, 195); }
.zoom-btn:active { transform: translateY(0.5px); }
.preview-hint {
  margin: 6px 2px 0;
  font-size: 11px;
  color: var(--muted);
}

.preview-output-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}
.preview-output-row select {
  font: inherit;
  font-size: 13px;
  padding: 5px 26px 5px 8px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--surface);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 8px center;
}

/* ---------- Download + tip ---------- */

.download {
  background: var(--sage-tint-2);
  border: 1px solid var(--sage-tint);
  border-radius: var(--radius);
  margin-top: 24px;
  padding: 22px 24px;
}
.download-state {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.download-state[hidden] { display: none; }
.download-info { flex: 1; }
.download-info h3 { margin: 0 0 4px; }
.download-info p { margin: 0; font-size: 13px; color: var(--muted); }
.download-actions { display: flex; gap: 8px; }

.tip-row {
  margin: 18px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.design-or {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin: 20px 0 12px;
}

.design-export {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 24px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}
.design-export[hidden] { display: none; }
.design-export .download-info h3 { margin: 0 0 4px; font-size: 1rem; }
.design-export .download-info p { margin: 0; font-size: 13px; color: var(--muted); }
.btn-link {
  background: none;
  border: none;
  color: var(--sage-darker);
  cursor: pointer;
  font: inherit;
  padding: 0 0 0 4px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn-link:hover { color: var(--ink); }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 32, 28, 0.4);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px rgba(28, 32, 28, 0.18);
  padding: 28px;
  max-width: 460px;
  width: 100%;
}
.modal-card h3 { margin-top: 0; }
.modal-card .actions { margin-top: 22px; }
.dev-link {
  display: block;
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}
.dev-link button {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.dev-link button:hover { color: var(--ink); }

/* ---------- Selected file pill (shown after upload) ---------- */

.file-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 99px;
  font-size: 13px;
}
.file-pill button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 16px;
  padding: 0;
  line-height: 1;
}
.file-pill button:hover { color: var(--error); }

@media (max-width: 700px) {
  .hero h1 { font-size: 1.8rem; }
  .form-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .form-row label { min-width: 0; }
  .actions { flex-direction: column; }
  .purchase { flex-direction: column; align-items: stretch; text-align: center; }
}
