:root {
  --bg: linear-gradient(180deg, #eef4ef 0%, #f7f3ec 100%);
  --panel: rgba(255, 255, 255, 0.96);
  --ink: #1d2733;
  --muted: #5f6e7e;
  --line: #d9e1e7;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #dff4f0;
  --shadow: 0 18px 45px rgba(22, 33, 46, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.title-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.04;
}

h2 {
  font-size: 18px;
}

.subcopy {
  margin-top: 8px;
  color: var(--muted);
  font-size: 15px;
}

.workspace {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel,
.preview-panel {
  background: var(--panel);
  border: 1px solid rgba(217, 225, 231, 0.95);
  border-radius: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.controls-panel {
  position: sticky;
  top: 14px;
  padding: 18px;
}

.upload-box {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 180px;
  padding: 18px;
  border: 2px dashed #b8d0cb;
  border-radius: 12px;
  background: linear-gradient(180deg, #fbfffe 0%, #f3fbf9 100%);
  color: var(--muted);
  text-align: center;
  transition:
    border-color 0.18s ease,
    background 0.18s ease,
    transform 0.18s ease;
}

.upload-box.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.upload-box input {
  width: 100%;
  max-width: 280px;
  min-height: 44px;
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  line-height: 1;
}

.upload-box strong {
  color: var(--ink);
  font-size: 18px;
}

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

.field {
  display: grid;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

.field input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

.switch-row {
  display: grid;
  gap: 10px;
  margin: 18px 0;
  color: var(--ink);
  font-size: 14px;
}

.switch-row label {
  display: flex;
  align-items: center;
  gap: 10px;
}

.switch-row input {
  accent-color: var(--accent);
}

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

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 46px;
  border: 0;
  border-radius: 10px;
  font-weight: 800;
}

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

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  border: 1px solid var(--accent);
  background: #fff;
  color: var(--accent-strong);
}

.secondary-button:disabled {
  cursor: not-allowed;
  border-color: var(--line);
  color: #97a3b1;
}

.ghost-button {
  padding: 0 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  color: var(--muted);
}

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

.stats div {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fcfdfd;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stats strong {
  display: block;
  margin-top: 8px;
  font-size: 18px;
}

.preview-panel {
  min-width: 0;
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.preview-toolbar p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.mobile-tip {
  padding: 10px 18px 0;
  color: var(--muted);
  font-size: 13px;
}

.zoom-tools {
  display: grid;
  grid-template-columns: 40px 68px 40px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
}

.zoom-tools button,
.zoom-tools span {
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  background: #fff;
  color: var(--ink);
}

.zoom-tools span {
  border-inline: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.canvas-stage {
  position: relative;
  min-height: calc(100vh - 210px);
  max-height: calc(100vh - 210px);
  overflow: auto;
  padding: 14px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(45deg, #edf2f7 25%, transparent 25%),
    linear-gradient(-45deg, #edf2f7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf2f7 75%),
    linear-gradient(-45deg, transparent 75%, #edf2f7 75%);
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

#patternCanvas {
  display: block;
  margin: 0 auto;
  max-width: none;
  border: 1px solid #c8d0dc;
  background: #fff;
  transform-origin: top center;
  touch-action: pan-x pan-y;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
  font-size: 22px;
}

.empty-state.hidden {
  display: none;
}

@media (max-width: 980px) {
  .app-shell {
    width: min(100% - 20px, 980px);
    padding-top: 18px;
  }

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

  .controls-panel {
    position: static;
  }

  .canvas-stage {
    min-height: 520px;
    max-height: 72vh;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 14px, 700px);
    padding-bottom: 22px;
  }

  .topbar,
  .preview-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar {
    margin-bottom: 14px;
  }

  .subcopy {
    font-size: 14px;
  }

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

  .controls-panel,
  .preview-panel {
    border-radius: 12px;
  }

  .controls-panel {
    padding: 14px;
  }

  .preview-toolbar {
    padding: 14px;
  }

  .mobile-tip {
    padding: 8px 14px 0;
  }

  .zoom-tools {
    width: 100%;
    grid-template-columns: 1fr 72px 1fr;
  }

  .zoom-tools button,
  .zoom-tools span {
    height: 44px;
  }

  .canvas-stage {
    min-height: 420px;
    max-height: 62vh;
    padding: 10px;
  }

  .upload-box {
    min-height: 160px;
  }

  .upload-box input {
    max-width: 100%;
  }

  .empty-state strong {
    font-size: 20px;
  }
}
