:root {
  color-scheme: light;
  --ink: #17181f;
  --muted: #69707d;
  --line: #d9dee8;
  --surface: #f4f6f9;
  --panel: #ffffff;
  --accent: #f35b5b;
  --accent-dark: #cb3f45;
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100svh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(23, 24, 31, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(23, 24, 31, 0.035) 1px, transparent 1px),
    var(--surface);
  background-size: 28px 28px;
}

body.is-busy {
  cursor: wait;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
select,
textarea,
.upload-zone {
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

button {
  min-height: 44px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(23, 24, 31, 0.3);
}

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

a {
  color: var(--accent-dark);
  text-underline-offset: 3px;
}

.primary {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  min-height: 100svh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(18px);
}

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

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 18px);
  gap: 5px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.brand-mark span {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.44);
}

.brand-mark span:nth-child(1) {
  background: #f35b5b;
}

.brand-mark span:nth-child(2) {
  background: #ffbf47;
}

.brand-mark span:nth-child(3) {
  background: #35b77d;
}

.brand-mark span:nth-child(4) {
  background: #3f8cff;
}

.flow-nav {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.flow-nav button {
  display: grid;
  place-items: center;
  min-height: 34px;
  padding: 0 6px;
  border: 0;
  border-bottom: 2px solid var(--line);
  border-radius: 0;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

.flow-nav button:hover:not(:disabled) {
  transform: none;
  border-color: rgba(23, 24, 31, 0.28);
}

.flow-nav button:disabled {
  cursor: default;
  opacity: 0.48;
}

.flow-nav button.active {
  border-color: var(--accent);
  color: var(--ink);
  opacity: 1;
}

.flow-nav button.done {
  border-color: #35b77d;
  color: var(--ink);
}

.flow-message {
  min-height: 22px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.05;
}

h2 {
  font-size: 14px;
  line-height: 1.2;
}

h3 {
  font-size: 16px;
  line-height: 1.2;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0;
}

.tool-section,
.status-panel {
  display: grid;
  gap: 12px;
}

.step-card {
  position: relative;
  padding: 16px;
  border: 1px solid rgba(23, 24, 31, 0.08);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.82);
  overflow: hidden;
}

.step-card.active {
  border-color: rgba(243, 91, 91, 0.34);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 3px rgba(243, 91, 91, 0.08);
}

.step-card.done .step-number {
  color: #fff;
  background: #35b77d;
}

.step-card.disabled-step {
  opacity: 0.64;
}

.step-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  text-align: left;
}

.step-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.step-body {
  display: grid;
  gap: 12px;
  padding-top: 12px;
}

.step-number {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: var(--accent-dark);
  background: rgba(243, 91, 91, 0.12);
  font-size: 13px;
  font-weight: 800;
}

.action-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.upload-zone {
  display: grid;
  place-items: center;
  min-height: 76px;
  padding: 14px;
  color: var(--muted);
  background:
    linear-gradient(135deg, rgba(243, 91, 91, 0.08), transparent 46%),
    var(--panel);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background:
    linear-gradient(135deg, rgba(243, 91, 91, 0.14), transparent 48%),
    var(--panel);
}

.upload-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

textarea,
select {
  width: 100%;
  color: var(--ink);
  background: var(--panel);
}

textarea {
  min-height: 108px;
  padding: 11px 12px;
  resize: vertical;
}

select {
  min-height: 42px;
  padding: 0 10px;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.control-grid .field:first-child {
  grid-column: 1 / -1;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

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

.status-panel {
  margin-top: 0;
}

.status-panel p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.download-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.download-row a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(220px, 32vh) 1fr;
  gap: 24px;
  min-width: 0;
  padding: 32px;
}

.workspace-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.workspace-header h2 {
  max-width: 760px;
  font-size: 26px;
  line-height: 1.18;
  letter-spacing: 0;
}

.workspace-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.workspace-meta span,
.section-title span {
  padding: 7px 10px;
  border: 1px solid rgba(23, 24, 31, 0.1);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  font-size: 13px;
}

.preview-band,
.pattern-area {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.candidate-strip {
  display: grid;
  grid-template-columns: minmax(220px, 420px);
  gap: 14px;
  min-height: 100%;
  padding-bottom: 4px;
}

.candidate {
  position: relative;
  min-height: 210px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
}

.candidate.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(243, 91, 91, 0.12);
}

.candidate img {
  width: 100%;
  height: 100%;
  min-height: 210px;
  object-fit: cover;
  display: block;
}

.candidate span {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 5px 8px;
  border-radius: 999px;
  color: #fff;
  background: rgba(23, 24, 31, 0.72);
  font-size: 12px;
}

.pattern-layout {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(210px, 300px);
  gap: 18px;
  min-height: 0;
}

.pattern-board {
  display: grid;
  place-items: center;
  min-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    repeating-linear-gradient(90deg, rgba(23, 24, 31, 0.035) 0 1px, transparent 1px 24px),
    repeating-linear-gradient(0deg, rgba(23, 24, 31, 0.035) 0 1px, transparent 1px 24px),
    rgba(255, 255, 255, 0.78);
}

.pixel-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-size), var(--cell-size));
  padding: 14px;
}

.pixel {
  width: var(--cell-size);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.66) 0 16%, transparent 17%),
    var(--pixel-color);
  box-shadow: inset -1px -2px 3px rgba(23, 24, 31, 0.14);
}

.pixel.empty {
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.color-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 420px;
  max-height: 56vh;
  overflow: auto;
  border-left: 1px solid var(--line);
  padding-left: 16px;
}

.color-item {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.color-item span:nth-child(2) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip {
  width: 24px;
  height: 24px;
  border: 1px solid rgba(23, 24, 31, 0.12);
  border-radius: 50%;
  background: var(--chip-color);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 160px;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.62);
  text-align: center;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(244, 246, 249, 0.58);
  backdrop-filter: blur(8px);
}

.loading-panel {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  max-width: min(320px, 100%);
  padding: 0 16px;
  border: 1px solid rgba(23, 24, 31, 0.1);
  border-radius: var(--radius);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 18px 50px rgba(23, 24, 31, 0.14);
  font-size: 14px;
  font-weight: 700;
}

.loading-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(243, 91, 91, 0.22);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: loading-spin 720ms linear infinite;
}

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

@media (max-width: 980px) {
  body {
    background-size: 22px 22px;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .pattern-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 16px;
    padding: 20px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand,
  .flow-nav,
  .flow-message,
  .status-panel {
    grid-column: 1 / -1;
  }

  .tool-section {
    align-self: stretch;
  }

  .step-card.active {
    background: rgba(255, 255, 255, 0.84);
  }

  .workspace {
    grid-template-rows: auto auto auto;
    padding: 24px 18px;
  }

  .workspace-header {
    display: grid;
  }

  .workspace-header h2 {
    font-size: 24px;
  }

  .workspace-meta {
    justify-content: flex-start;
  }

  .candidate-strip {
    grid-template-columns: minmax(220px, 420px);
  }

  .color-list {
    min-height: 0;
    max-height: none;
    border-left: 0;
    padding-left: 0;
  }
}

@media (max-width: 720px) {
  button,
  select,
  .download-row a {
    min-height: 48px;
  }

  .app-shell {
    min-height: auto;
  }

  .sidebar {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.96);
  }

  .brand {
    position: sticky;
    top: 0;
    z-index: 8;
    margin: -14px -14px 0;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
  }

  .flow-nav {
    position: sticky;
    top: 58px;
    z-index: 7;
    margin: 0 -14px;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
  }

  .brand-mark {
    grid-template-columns: repeat(2, 14px);
    gap: 4px;
    padding: 6px;
  }

  .brand-mark span {
    width: 14px;
    height: 14px;
  }

  h1 {
    font-size: 22px;
  }

  .tool-section {
    padding: 12px;
  }

  .step-card {
    border-color: rgba(23, 24, 31, 0.08);
    background: rgba(255, 255, 255, 0.72);
  }

  .step-head {
    align-items: center;
  }

  .step-head p {
    font-size: 12px;
  }

  .action-pair {
    grid-template-columns: 1fr;
  }

  .upload-zone {
    min-height: 62px;
  }

  textarea {
    min-height: 82px;
  }

  .control-grid {
    grid-template-columns: 1fr;
  }

  .control-grid .field:first-child {
    grid-column: auto;
  }

  .check-field {
    min-height: 44px;
  }

  .status-panel {
    gap: 10px;
    margin-top: 0;
    padding-top: 12px;
  }

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

  .download-row a {
    padding: 0 8px;
    font-size: 12px;
    white-space: nowrap;
  }

  .workspace {
    gap: 18px;
    padding: 18px 12px 28px;
  }

  .workspace-header h2 {
    font-size: 21px;
    line-height: 1.02;
  }

  .workspace-meta span,
  .section-title span {
    font-size: 12px;
  }

  .candidate-strip {
    grid-template-columns: 1fr;
    gap: 10px;
    margin: 0;
    padding: 0 0 6px;
  }

  .candidate,
  .candidate img {
    min-height: 180px;
  }

  .pattern-board {
    justify-content: start;
    min-height: 320px;
    max-height: 68svh;
    -webkit-overflow-scrolling: touch;
  }

  .pixel-grid {
    padding: 10px;
  }

  .color-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    max-height: 260px;
    overflow: auto;
    padding: 0;
    -webkit-overflow-scrolling: touch;
  }

  .color-item {
    min-height: 38px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(23, 24, 31, 0.07);
  }

  .empty-state {
    min-height: 130px;
    padding: 18px;
  }
}

@media (max-width: 390px) {
  .download-row {
    grid-template-columns: 1fr;
  }

  .workspace-header h2 {
    font-size: 20px;
  }

  .candidate-strip {
    grid-template-columns: 1fr;
  }
}
