:root {
  color-scheme: light;
  --blue: #2439b7;
  --blue-dark: #152783;
  --blue-soft: #eef0ff;
  --ink: #171b2e;
  --muted: #6d7182;
  --line: #dcdfe9;
  --paper: #f6f5f1;
  --card: #ffffff;
  --success: #087d55;
  --danger: #b42a37;
  --shadow: 0 24px 80px rgba(31, 39, 88, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(36, 57, 183, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(36, 57, 183, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 24px 24px;
}

button,
input,
select {
  font: inherit;
}

button,
label,
select,
input[type="range"] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
label:has(input:focus-visible) {
  outline: 3px solid rgba(36, 57, 183, 0.28);
  outline-offset: 3px;
}

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

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(20px, 4vw, 64px);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--blue);
  font-size: 28px;
  font-weight: 300;
  border-radius: 12px 12px 12px 3px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  letter-spacing: -0.02em;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.privacy-pill,
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #3f465b;
  font-size: 13px;
}

.privacy-pill {
  padding: 9px 13px;
  background: #eef8f3;
  border: 1px solid #c7eadc;
  border-radius: 999px;
}

.privacy-pill span,
.status span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(8, 125, 85, 0.1);
}

.workspace {
  max-width: 1600px;
  margin: 0 auto;
  padding: 42px clamp(18px, 4vw, 60px) 56px;
  display: grid;
  grid-template-columns: 330px minmax(480px, 1fr) 300px;
  grid-template-areas:
    "intro preview palette"
    "controls preview palette";
  align-items: start;
  gap: 24px;
}

.intro {
  grid-area: intro;
  padding: 14px 8px 14px 2px;
}

.intro h1 {
  margin: 7px 0 14px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(35px, 3vw, 50px);
  line-height: 1.03;
  letter-spacing: -0.05em;
  font-weight: 500;
}

.intro > p:last-child {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
  font-size: 14px;
}

.eyebrow {
  margin: 0;
  color: var(--blue);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.19em;
}

.control-panel,
.preview-panel,
.palette-panel {
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(210, 214, 227, 0.95);
  box-shadow: var(--shadow);
}

.control-panel {
  grid-area: controls;
  padding: 24px;
  border-radius: 20px;
}

.step-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 15px;
}

.step-heading > span {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  color: var(--blue);
  background: var(--blue-soft);
  border: 1px solid #cfd4ff;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 800;
}

.step-heading h2,
.preview-toolbar h2,
.palette-heading h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.upload-zone {
  min-height: 137px;
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  text-align: center;
  cursor: pointer;
  border: 1.5px dashed #aeb5d6;
  border-radius: 14px;
  background: linear-gradient(145deg, #fafaff, #f2f4ff);
  transition: border-color 0.2s, transform 0.2s, background 0.2s;
}

.upload-zone:hover {
  border-color: var(--blue);
  background: #f0f2ff;
  transform: translateY(-1px);
}

.upload-zone input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.upload-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
  color: var(--blue);
  background: white;
  border: 1px solid #d6dafa;
  border-radius: 10px;
  font-size: 21px;
}

.upload-zone strong {
  font-size: 14px;
}

.upload-zone small,
.segmented small,
.palette-note,
.empty-palette {
  color: var(--muted);
  font-size: 11px;
}

.text-button {
  width: 100%;
  margin-top: 9px;
  padding: 7px;
  color: var(--blue);
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.divider {
  height: 1px;
  margin: 22px -24px;
  background: var(--line);
}

fieldset {
  padding: 0;
  margin: 0;
  border: 0;
}

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

.segmented label {
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label > span {
  min-height: 55px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: white;
  font-size: 12px;
  font-weight: 800;
  transition: 0.2s ease;
}

.segmented input:checked + span {
  color: white;
  border-color: var(--blue);
  background: var(--blue);
  box-shadow: 0 7px 18px rgba(36, 57, 183, 0.2);
}

.segmented input:checked + span small {
  color: rgba(255, 255, 255, 0.74);
}

.size-table {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}

.size-table-head,
.size-table label > span {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 58px;
  align-items: center;
  gap: 8px;
}

.size-table-head {
  min-height: 34px;
  padding: 0 11px;
  color: var(--muted);
  background: #f6f7fb;
  border-bottom: 1px solid var(--line);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.size-table-head span:last-child {
  text-align: right;
}

.size-table label {
  display: block;
  cursor: pointer;
}

.size-table input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.size-table label > span {
  min-height: 42px;
  padding: 0 11px;
  border-bottom: 1px solid #ececf1;
  transition: color 0.18s, background 0.18s;
}

.size-table label:last-child > span {
  border-bottom: 0;
}

.size-table strong {
  font-size: 12px;
}

.size-table small {
  color: var(--muted);
  font-size: 11px;
}

.size-table em {
  color: var(--blue);
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
  text-align: right;
}

.size-table input:checked + span {
  color: white;
  background: var(--blue);
}

.size-table input:checked + span small,
.size-table input:checked + span em {
  color: rgba(255, 255, 255, 0.82);
}

.fabric-options {
  grid-template-columns: repeat(4, 1fr);
}

.fabric-options label > span {
  min-height: 42px;
  padding: 6px 2px;
}

.control-label small,
.preset-note {
  color: var(--muted);
  font-size: 9px;
  font-weight: 500;
}

.preset-note {
  margin: 10px 1px 0;
  line-height: 1.55;
}

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 18px 0 9px;
  font-size: 12px;
  font-weight: 750;
}

.control-label output {
  color: var(--blue);
  font-size: 14px;
}

input[type="range"] {
  width: 100%;
  height: 4px;
  appearance: none;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--blue), #cdd2ef);
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  appearance: none;
  background: white;
  border: 5px solid var(--blue);
  border-radius: 50%;
  box-shadow: 0 2px 7px rgba(23, 27, 46, 0.2);
}

.range-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  color: var(--muted);
  font-size: 9px;
}

select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12px;
}

.preview-panel {
  grid-area: preview;
  min-width: 0;
  max-height: calc(100vh - 118px);
  padding: 25px;
  border-radius: 24px;
  position: sticky;
  top: 96px;
  align-self: start;
  overflow-y: auto;
  scrollbar-width: thin;
}

.preview-toolbar,
.palette-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.preview-toolbar h2,
.palette-heading h2 {
  margin-top: 4px;
  font-size: 19px;
}

.status {
  white-space: nowrap;
}

.status[data-state="busy"] span {
  background: #e79d21;
  box-shadow: 0 0 0 4px rgba(231, 157, 33, 0.12);
  animation: pulse 1s infinite alternate;
}

.status[data-state="error"] {
  color: var(--danger);
}

.status[data-state="error"] span {
  background: var(--danger);
}

@keyframes pulse {
  to { opacity: 0.35; transform: scale(0.72); }
}

.image-stage {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 22px;
}

figure {
  min-width: 0;
  margin: 0;
}

figcaption {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.image-frame {
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  background-color: #eeeee9;
  border: 1px solid #e0e0da;
  border-radius: 16px;
  position: relative;
}

.stitched-frame {
  background:
    linear-gradient(45deg, #e5e3db 25%, transparent 25%),
    linear-gradient(-45deg, #e5e3db 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e3db 75%),
    linear-gradient(-45deg, transparent 75%, #e5e3db 75%),
    #f1f0eb;
  background-position: 0 0, 0 2px, 2px -2px, -2px 0;
  background-size: 4px 4px;
}

.image-frame img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.placeholder {
  max-width: 190px;
  padding: 18px;
  text-align: center;
  color: #888b97;
  font-size: 12px;
  line-height: 1.55;
}

.mini-stitch {
  display: block;
  margin-bottom: 9px;
  color: var(--blue);
  font-size: 30px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  margin-top: 18px;
  overflow: hidden;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.metrics > div {
  min-width: 0;
  padding: 12px 10px;
  background: #fafafa;
}

.metrics small,
.metrics strong {
  display: block;
}

.metrics small {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 9px;
}

.metrics strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.primary-button,
.secondary-button {
  min-height: 45px;
  padding: 10px 16px;
  border-radius: 11px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  transition: opacity 0.2s, transform 0.2s;
}

.primary-button {
  color: white;
  background: var(--blue);
  border: 1px solid var(--blue);
}

.secondary-button {
  color: var(--blue);
  background: white;
  border: 1px solid #bcc4f2;
}

.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.palette-panel {
  grid-area: palette;
  max-height: calc(100vh - 118px);
  padding: 22px;
  border-radius: 20px;
  position: sticky;
  top: 96px;
  overflow: hidden;
}

.palette-heading > span {
  min-width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--blue);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
}

.palette-note {
  margin: 13px 0 15px;
  line-height: 1.55;
}

.palette-list {
  max-height: calc(100vh - 245px);
  overflow: auto;
  scrollbar-width: thin;
}

.palette-row {
  display: grid;
  grid-template-columns: 31px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 2px;
  border-top: 1px solid #ececf1;
}

.swatch {
  width: 29px;
  height: 29px;
  display: block;
  background: var(--swatch);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 9px 9px 9px 2px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.25);
}

.thread-copy,
.thread-count {
  min-width: 0;
}

.thread-copy strong,
.thread-copy small,
.thread-count strong,
.thread-count small {
  display: block;
}

.thread-copy strong,
.thread-count strong {
  font-size: 11px;
}

.thread-copy small {
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-count {
  text-align: right;
}

.thread-count small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 8px;
}

.empty-palette {
  padding: 50px 20px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 12px;
}

footer {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 clamp(20px, 4vw, 60px) 34px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  color: var(--muted);
  font-size: 10px;
}

footer p {
  margin: 0;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 320px minmax(0, 1fr);
    grid-template-areas:
      "intro preview"
      "controls preview"
      "palette palette";
  }

  .palette-panel {
    position: static;
    max-height: none;
  }

  .palette-list {
    max-height: 360px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 24px;
  }
}

@media (max-width: 780px) {
  .topbar {
    height: 68px;
  }

  .privacy-pill {
    display: none;
  }

  .workspace {
    padding-top: 24px;
    grid-template-columns: 1fr;
    grid-template-areas: "intro" "controls" "preview" "palette";
  }

  .intro h1 {
    font-size: 38px;
  }

  .preview-panel {
    padding: 18px;
    position: static;
    max-height: none;
    overflow: visible;
  }

  .image-stage {
    grid-template-columns: 1fr;
  }

  .image-frame {
    aspect-ratio: 4 / 3;
  }

  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .metrics > div:last-child {
    grid-column: 1 / -1;
  }

  .palette-list {
    display: block;
  }

  footer {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}
