:root {
  --bg: #f5efe5;
  --panel: rgba(255, 251, 245, 0.9);
  --ink: #28211a;
  --muted: #6e6154;
  --line: rgba(40, 33, 26, 0.1);
  --primary: #0f766e;
  --primary-strong: #115e59;
  --secondary: #f0e0c9;
  --accent: #cf5c36;
  --shadow: 0 18px 48px rgba(62, 39, 19, 0.12);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(207, 92, 54, 0.16), transparent 26%),
    radial-gradient(circle at top right, rgba(15, 118, 110, 0.18), transparent 30%),
    linear-gradient(180deg, #f8f3eb 0%, var(--bg) 100%);
}

body {
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
}

button,
input {
  font: inherit;
}

.shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 16px 16px 108px;
}

.hero {
  padding: 8px 4px 14px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-size: clamp(30px, 8vw, 48px);
  line-height: 1;
}

.lead {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.layout {
  display: grid;
  gap: 14px;
}

.panel {
  background: var(--panel);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.panel-accent {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.82), rgba(255, 248, 240, 0.92)),
    linear-gradient(135deg, rgba(207, 92, 54, 0.08), rgba(15, 118, 110, 0.08));
}

.section-head,
.preview-meta,
.sheet-head,
.sheet-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-head {
  margin-bottom: 12px;
}

.section-head h2,
.sheet-head h3 {
  margin: 0;
  font-size: 18px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: #f2e5d5;
  color: #684d38;
  font-size: 13px;
  font-weight: 700;
}

.badge-soft {
  background: rgba(15, 118, 110, 0.12);
  color: var(--primary-strong);
}

.upload-card {
  display: block;
  border: 1.5px dashed rgba(15, 118, 110, 0.34);
  border-radius: 20px;
  padding: 18px 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(244, 250, 249, 0.9));
}

.upload-card input[type="file"] {
  display: block;
  width: 100%;
  margin-bottom: 10px;
}

.upload-title {
  display: block;
  font-weight: 700;
}

.upload-subtitle,
.muted,
.sheet-kicker,
.preview-kicker,
.compat-note {
  color: var(--muted);
  font-size: 13px;
}

.thumb-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 80px;
  gap: 10px;
  margin-top: 12px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.thumb-strip.empty {
  display: none;
}

.thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 18px;
  background: #e9dfd0;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.thumb.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.13);
}

.thumb img,
.result-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.field label {
  font-size: 14px;
  font-weight: 600;
}

.field input[type="text"],
.field input[type="file"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px 14px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

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

.color-chip {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 999px;
  border: 2px solid rgba(40, 33, 26, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55);
}

.color-chip[data-color="#ffffff"] { background: #ffffff; }
.color-chip[data-color="#111111"] { background: #111111; }
.color-chip[data-color="#d7263d"] { background: #d7263d; }
.color-chip[data-color="#f4b400"] { background: #f4b400; }
.color-chip[data-color="#2563eb"] { background: #2563eb; }
.color-chip[data-color="#16a34a"] { background: #16a34a; }
.color-chip[data-color="#6b7280"] { background: #6b7280; }
.color-chip[data-color="#ea580c"] { background: #ea580c; }

.color-chip.active {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  border-color: var(--primary);
  transform: scale(1.06);
}

.inline-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.preview-meta {
  margin-bottom: 12px;
}

.preview-kicker,
.sheet-kicker {
  margin: 0 0 4px;
}

.current-file {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  word-break: break-all;
}

.compact-btn {
  flex: none;
}

.preview-stage {
  position: relative;
  min-height: 156px;
  border-radius: 22px;
  overflow: hidden;
  background:
    linear-gradient(45deg, rgba(40, 33, 26, 0.06) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(40, 33, 26, 0.06) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(40, 33, 26, 0.06) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(40, 33, 26, 0.06) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

.preview-stage.compact {
  max-height: 210px;
}

.preview-stage.expanded {
  min-height: 320px;
  max-height: none;
}

#previewCanvas {
  width: 100%;
  display: block;
}

.preview-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  line-height: 1.6;
}

.primary-btn,
.secondary-btn,
.ghost-btn {
  border: 0;
  border-radius: 18px;
  min-height: 48px;
  padding: 0 16px;
  font-weight: 700;
}

.primary-btn {
  background: linear-gradient(135deg, var(--primary), #0b8f85);
  color: #fff;
}

.secondary-btn {
  background: var(--secondary);
  color: var(--ink);
}

.ghost-btn {
  min-height: 36px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.progress-block {
  margin-top: 14px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(40, 33, 26, 0.08);
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  transition: width 0.2s ease;
}

.compat-note {
  margin: 14px 0 0;
  line-height: 1.6;
}

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1.15fr;
  gap: 8px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0));
  background: rgba(248, 243, 235, 0.94);
  backdrop-filter: blur(18px);
  border-top: 1px solid rgba(40, 33, 26, 0.08);
  z-index: 20;
}

.site-credit {
  position: fixed;
  right: 12px;
  bottom: calc(78px + env(safe-area-inset-bottom, 0));
  z-index: 15;
  color: rgba(40, 33, 26, 0.62);
  font-size: 11px;
  line-height: 1.5;
  text-align: right;
  pointer-events: none;
}

.sheet.hidden {
  display: none;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 20, 16, 0.44);
}

.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 82vh;
  overflow: auto;
  background: #fffaf5;
  border-radius: 24px 24px 0 0;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom, 0));
  box-shadow: 0 -18px 42px rgba(0, 0, 0, 0.14);
}

.sheet-head {
  align-items: flex-start;
  margin-bottom: 14px;
}

.sheet-actions {
  margin-bottom: 14px;
}

.results-list {
  display: grid;
  gap: 12px;
}

.result-card {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 12px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(40, 33, 26, 0.08);
  border-radius: 18px;
  padding: 10px;
}

.result-thumb {
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  overflow: hidden;
  background: #ece2d3;
}

.result-body {
  min-width: 0;
}

.result-name {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
  word-break: break-all;
}

.result-status {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.result-actions {
  display: flex;
  gap: 8px;
}

.result-actions button {
  min-height: 38px;
  border-radius: 14px;
  padding: 0 12px;
}

@media (min-width: 760px) {
  .shell {
    padding: 24px 22px 34px;
  }

  .layout {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }

  .bottom-bar {
    position: static;
    width: min(100%, 760px);
    margin: 0 auto 24px;
    border: 1px solid rgba(40, 33, 26, 0.08);
    border-radius: 22px;
  }

  .site-credit {
    right: 18px;
    bottom: 18px;
  }

  .sheet-panel {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(760px, 100%);
    border-radius: 24px 24px 0 0;
  }
}

@media (max-width: 420px) {
  .grid.two,
  .sheet-actions {
    grid-template-columns: 1fr;
  }

  .bottom-bar {
    grid-template-columns: 1fr 1fr;
  }

  .primary-btn {
    grid-column: 1 / -1;
  }

  .result-card {
    grid-template-columns: 1fr;
  }

  .site-credit {
    bottom: calc(128px + env(safe-area-inset-bottom, 0));
    max-width: 70vw;
  }
}
