:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --accent: #111827;
  --accent-soft: #eef2ff;
  --accent-blue: #2563eb;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "SF Pro Display", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

body.mobile-panel-open {
  overflow: hidden;
}

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

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.upload-tile small {
  color: var(--muted);
}

.topbar-button {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
}

.topbar-button {
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
}

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

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  min-height: calc(100vh - 72px);
  padding: 18px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.tool-card,
.canvas-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.tool-card {
  padding: 18px;
}

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

.section-title span {
  font-size: 14px;
  font-weight: 600;
}

.section-title strong {
  font-size: 13px;
}

.section-title.compact {
  margin-top: 16px;
}

.upload-tile {
  display: block;
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  background: var(--surface-soft);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease;
}

.upload-tile:hover,
.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.layer-item:hover {
  transform: translateY(-1px);
}

.upload-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  height: 24px;
  padding: 0 10px;
  margin-bottom: 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #3730a3;
  font-size: 12px;
  font-weight: 600;
}

.upload-tile strong,
.upload-tile small {
  display: block;
}

.upload-tile strong {
  margin-bottom: 6px;
  font-size: 15px;
}

.layer-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 280px;
  overflow: auto;
}

.layer-empty {
  margin: 0;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.layer-item {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-soft);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.layer-item.is-active {
  border-color: rgba(37, 99, 235, 0.35);
  background: rgba(239, 246, 255, 0.9);
}

.layer-thumb {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  object-fit: cover;
  background: #fff;
  border: 1px solid var(--line);
}

.layer-meta {
  min-width: 0;
}

.layer-meta strong,
.layer-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-meta strong {
  margin-bottom: 4px;
  font-size: 14px;
}

.layer-meta span,
.layer-index {
  color: var(--muted);
  font-size: 12px;
}

.button-pair,
.button-stack,
.nudge-grid {
  display: grid;
  gap: 10px;
}

.button-pair,
.nudge-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.button-pair {
  margin-top: 14px;
}

.nudge-grid {
  margin-top: 12px;
}

.primary-button,
.secondary-button,
.ghost-button,
.bottom-tool-button,
.mobile-sheet-close {
  appearance: none;
  min-height: 42px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

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

.secondary-button,
.ghost-button,
.bottom-tool-button,
.mobile-sheet-close {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
}

.button-stack {
  margin-top: 14px;
}

.status-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.side-meta {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
}

.canvas-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.canvas-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100vh - 108px);
  padding: 0;
  background:
    linear-gradient(45deg, rgba(15, 23, 42, 0.03) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(15, 23, 42, 0.03) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(15, 23, 42, 0.03) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(15, 23, 42, 0.03) 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
}

#previewCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.canvas-placeholder {
  position: absolute;
  inset: 24px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: center;
  pointer-events: none;
}

.mobile-layer-sheet,
.bottom-toolbar {
  display: none;
}

.canvas-placeholder[hidden] {
  display: none;
}

.canvas-placeholder strong {
  font-size: 18px;
}

.canvas-placeholder span {
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .canvas-stage {
    height: calc(100vh - 108px);
  }
}

@media (max-width: 720px) {
  .topbar {
    height: 64px;
    padding: 0 14px;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0;
    min-height: calc(100vh - 64px);
  }

  .topbar-meta {
    margin-left: auto;
    gap: 6px;
  }

  .template-chip {
    min-height: 32px;
    padding: 0 10px;
    font-size: 12px;
  }

  .sidebar {
    display: none;
  }

  .canvas-panel {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }

  .canvas-stage {
    height: calc(100vh - 64px - 64px);
    padding: 0 0 86px;
    background-size: 18px 18px;
    background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  }

  .canvas-placeholder {
    inset: 0 0 86px;
    border-radius: 0;
  }

  #previewCanvas {
    width: 100%;
    height: 100%;
  }

  .mobile-layer-sheet {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 72px;
    z-index: 40;
    display: block;
    max-height: 0;
    overflow: hidden;
    border: 1px solid rgba(209, 213, 219, 0.9);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 18px 60px rgba(15, 23, 42, 0.12);
    transition: max-height 180ms ease, padding 180ms ease;
  }

  body.layer-sheet-open .mobile-layer-sheet {
    max-height: min(28vh, 220px);
    padding: 10px;
  }

  .mobile-layer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
  }

  .mobile-sheet-close {
    min-height: 34px;
    padding: 0 12px;
  }

  .mobile-layer-list {
    max-height: calc(min(28vh, 220px) - 44px);
  }

  .bottom-toolbar {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    padding: 8px;
    border: 1px solid rgba(209, 213, 219, 0.9);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 18px 60px rgba(15, 23, 42, 0.12);
    backdrop-filter: blur(14px);
  }

  .topbar-button,
  .topbar-upload {
    min-height: 36px;
    padding: 0 12px;
    font-size: 12px;
  }

  .bottom-tool-button {
    width: 100%;
    min-height: 42px;
    border-radius: 14px;
    background: #f3f4f6;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
  }

  .bottom-tool-button.danger {
    color: #b91c1c;
  }

  .bottom-tool-button:disabled {
    opacity: 0.42;
  }
}
