/* ============ Mosaic Studio 样式 ============ */
:root {
  --bg: #FAFAFA;
  --bg-canvas: #F1F2F4;
  --surface: #FFFFFF;
  --border: #E4E5E7;
  --border-strong: #D0D2D6;
  --text: #17181C;
  --text-2: #5B5F66;
  --text-3: #9A9EA6;
  --accent: #3B82F6;
  --accent-weak: rgba(59, 130, 246, .12);
  --accent-strong: #2563EB;
  --danger: #DC2626;
  --danger-weak: rgba(220, 38, 38, .08);
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  --font: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  touch-action: manipulation;
}

.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; }
svg { flex-shrink: 0; }

.view { position: fixed; inset: 0; }

/* ============ 上传页 ============ */
.view-upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(59, 130, 246, .08), transparent 60%),
    var(--bg);
  overflow-y: auto;
}

.upload-header {
  width: 100%;
  max-width: 1080px;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo { display: flex; align-items: center; gap: 10px; user-select: none; }
.logo-mark { width: 30px; height: 30px; }
.logo-name { font-size: 17px; font-weight: 650; letter-spacing: -.2px; }
.logo-mini .logo-mark { width: 24px; height: 24px; }
.logo-mini .logo-name { font-size: 15px; }

.link-subtle {
  color: var(--text-3);
  font-size: 13px;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: color .15s, background .15s;
}
.link-subtle:hover { color: var(--text-2); background: rgba(0,0,0,.04); }

.upload-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 720px;
  padding: 12px 24px 14px;
  animation: rise .5s cubic-bezier(.22, .8, .36, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.hero-title {
  font-size: clamp(28px, 4.6vw, 40px);
  font-weight: 700;
  letter-spacing: -.6px;
  line-height: 1.18;
  text-align: center;
  color: var(--text);
}
.hero-title .accent {
  color: var(--accent);
  position: relative;
}
.hero-sub {
  margin-top: 10px;
  color: var(--text-2);
  font-size: 14px;
  text-align: center;
}

.dropzone {
  margin-top: 22px;
  width: 100%;
  max-width: 540px;
  min-height: 188px;
  border: 2px dashed var(--border-strong);
  border-radius: 16px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 26px 24px;
  text-align: center;
  cursor: pointer;
  outline: none;
  transition: border-color .18s, background .18s, box-shadow .18s, transform .18s;
  animation: rise .5s .08s cubic-bezier(.22, .8, .36, 1) both;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-weak);
  transform: translateY(-1px);
  box-shadow: 0 12px 32px rgba(59, 130, 246, .14);
}
.dropzone.dragover { transform: scale(1.012); }

.dz-icon { width: 38px; height: 38px; color: var(--accent); }
.dz-main { font-size: 15px; font-weight: 550; }
.dz-link { color: var(--accent); }
.dz-sub { font-size: 12px; color: var(--text-3); }

.hint-row {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.hint {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-3);
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  animation: rise .5s .18s cubic-bezier(.22, .8, .36, 1) both;
}
.hint svg { width: 15px; height: 15px; }
.hint-row .hint:nth-child(2) { animation-delay: .26s; }
.hint-row .hint:nth-child(3) { animation-delay: .34s; }

.upload-error {
  margin-top: 18px;
  color: var(--danger);
  font-size: 13.5px;
  min-height: 20px;
  text-align: center;
}

.upload-footer {
  padding: 10px 24px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.privacy {
  width: 100%;
  max-width: 540px;
  padding: 12px 16px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
}

.privacy-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.privacy-head svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
}

.privacy-desc {
  margin: 6px 0 4px;
  font-size: 12px;
  color: var(--text-3);
}

.privacy-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.privacy-list li {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-3);
}

.privacy-list b {
  color: var(--text-2);
  font-weight: 600;
}

.privacy-tag {
  margin: 0;
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: .3px;
}

/* ============ 编辑页 ============ */
.view-editor { display: flex; flex-direction: column; background: var(--bg); }

.topbar {
  height: 54px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-actions { display: flex; align-items: center; gap: 2px; }

.btn-icon {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: background .15s, color .15s, opacity .15s;
}
.btn-icon svg { width: 19px; height: 19px; }
.btn-icon:hover:not(:disabled) { background: rgba(0,0,0,.055); color: var(--text); }
.btn-icon:active:not(:disabled) { transform: scale(.94); }
.btn-icon:disabled { opacity: .35; cursor: default; }

.topbar-divider { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }

.btn-export {
  margin-left: 8px;
  height: 34px;
  padding: 0 20px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: .2px;
  box-shadow: 0 2px 8px rgba(59, 130, 246, .3);
  transition: background .15s, transform .15s, box-shadow .15s;
}
.btn-export:hover { background: var(--accent-strong); box-shadow: 0 4px 14px rgba(59, 130, 246, .35); }
.btn-export:active { transform: scale(.97); }

.editor-body {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

/* 左侧工具栏 */
.toolbar {
  width: 88px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  overflow-y: auto;
  z-index: 5;
}
.tool-group { display: flex; flex-direction: column; gap: 4px; width: 100%; align-items: center; }

.tool-btn {
  width: 56px;
  padding: 8px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border-radius: 10px;
  color: var(--text-3);
  transition: background .15s, color .15s;
}
.tool-btn svg { width: 22px; height: 22px; }
.tool-btn span { font-size: 11px; }
.tool-btn:hover { background: rgba(0,0,0,.045); color: var(--text-2); }
.tool-btn.active {
  background: var(--accent-weak);
  color: var(--accent);
}
.tool-btn.active span { font-weight: 600; }

.brush-size-group {
  width: 100%;
  align-items: center;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.brush-size-group svg { width: 16px; height: 16px; color: var(--text-3); }
.brush-size-group input[type="range"] { width: 64px; }
.brush-size-group output {
  font-size: 11px;
  color: var(--text-3);
  font-family: var(--mono);
}

/* 画布区 */
.canvas-wrap {
  flex: 1;
  position: relative;
  background: var(--bg-canvas);
  min-width: 0;
  overflow: hidden;
  touch-action: none;
}
.canvas-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}
.canvas-wrap.panning canvas { cursor: grab; }
.canvas-wrap.dragging canvas { cursor: grabbing; }

.zoom-badge {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-family: var(--mono);
  color: var(--text-2);
  background: rgba(255,255,255,.88);
  border: 1px solid var(--border);
  border-radius: 999px;
  backdrop-filter: blur(4px);
  pointer-events: none;
  user-select: none;
}
.canvas-hint {
  position: absolute;
  right: 12px;
  bottom: 12px;
  font-size: 11.5px;
  color: var(--text-3);
  background: rgba(255,255,255,.8);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  backdrop-filter: blur(4px);
  pointer-events: none;
  user-select: none;
  transition: opacity .3s;
}
.canvas-hint.fade { opacity: 0; }

/* 右侧属性面板 */
.panel {
  width: 264px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 5;
  transition: width .2s, margin .2s;
}
.panel.collapsed { width: 0; border-left: none; margin-right: -1px; }
.panel.collapsed > * { display: none; }

.panel-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-3);
  text-align: center;
  padding: 24px;
  min-height: 200px;
}
.panel-empty svg { width: 40px; height: 40px; }
.panel-empty p { font-size: 14px; color: var(--text-2); font-weight: 550; }
.panel-empty span { font-size: 12.5px; line-height: 1.6; }

.panel-body { padding: 16px 16px 20px; display: flex; flex-direction: column; gap: 16px; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}
.panel-title { font-size: 14px; font-weight: 650; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-head { display: flex; align-items: center; justify-content: space-between; }
.field-label { font-size: 12.5px; font-weight: 550; color: var(--text-2); }
.val {
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text-2);
  background: var(--bg-canvas);
  padding: 1px 7px;
  border-radius: 5px;
  min-width: 34px;
  text-align: center;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 4px rgba(16,24,40,.18);
  cursor: grab;
  transition: transform .12s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-webkit-slider-thumb:active { cursor: grabbing; transform: scale(1.25); }
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent);
  box-shadow: 0 1px 4px rgba(16,24,40,.18);
  cursor: grab;
}

/* 样式卡片 */
.style-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.style-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 9px 2px 7px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text-3);
  transition: border-color .15s, color .15s, background .15s, transform .12s;
}
.style-card svg { width: 19px; height: 19px; }
.style-card span { font-size: 10.5px; }
.style-card:hover { border-color: var(--border-strong); color: var(--text-2); }
.style-card.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-weak);
  transform: translateY(-1px);
}

/* 分段选择器 */
.segmented {
  display: flex;
  background: var(--bg-canvas);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 550;
  color: var(--text-2);
  border-radius: 5px;
  transition: background .15s, color .15s, box-shadow .15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(16,24,40,.12);
}

/* 颜色行 */
.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.color-row input[type="color"] {
  width: 34px;
  height: 30px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}
.color-row input[type="range"] { flex: 1; }

/* 开关 */
.toggle-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: 999px;
  transition: background .18s;
  cursor: pointer;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(16,24,40,.25);
  transition: transform .18s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }

.panel-actions { margin-top: 4px; }
.btn-danger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--danger-weak);
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.btn-danger svg { width: 16px; height: 16px; }
.btn-danger:hover { background: rgba(220,38,38,.14); border-color: rgba(220,38,38,.25); }

/* ============ 弹窗 ============ */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-mask {
  position: absolute; inset: 0;
  background: rgba(17, 18, 21, .42);
  backdrop-filter: blur(3px);
  animation: fade .2s ease both;
}
.modal-mask.dark { background: rgba(10, 10, 12, .88); }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  position: relative;
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px;
  animation: pop .24s cubic-bezier(.22, .8, .36, 1) both;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-head h3 { font-size: 16px; font-weight: 650; }

.export-card { display: flex; flex-direction: column; gap: 16px; }
.export-row { display: flex; flex-direction: column; gap: 8px; }
.export-label { font-size: 12.5px; font-weight: 550; color: var(--text-2); }
.export-label-row { display: flex; align-items: center; justify-content: space-between; }
.export-note { font-size: 12px; color: var(--text-3); }

#customSizeRow { flex-direction: row; align-items: center; gap: 8px; }
#customSizeRow input[type="number"] {
  width: 76px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 8px;
  font-size: 13px;
}
.percent { font-size: 13px; color: var(--text-2); }

.export-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  overflow: hidden;
  position: relative;
  min-height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.export-preview img {
  max-width: 100%;
  max-height: 220px;
  display: block;
}
.preview-note {
  position: absolute;
  right: 8px;
  bottom: 8px;
  font-size: 11.5px;
  font-family: var(--mono);
  color: var(--text-2);
  background: rgba(255,255,255,.9);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 5px;
}

.export-actions {
  display: flex;
  gap: 10px;
}
.export-actions .btn-primary,
.export-actions .btn-secondary {
  flex: 1;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: background .15s, transform .12s, box-shadow .15s;
}
.export-actions svg { width: 17px; height: 17px; }
.export-actions .btn-primary:active, .export-actions .btn-secondary:active { transform: scale(.97); }

.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(59,130,246,.28); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-secondary { background: var(--bg-canvas); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #E9EAEC; }

/* 全屏预览 */
.modal-preview { padding: 24px; }
.preview-stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 20px 80px rgba(0,0,0,.5);
  animation: pop .25s cubic-bezier(.22, .8, .36, 1) both;
}
.preview-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 42px;
  height: 42px;
  background: rgba(255,255,255,.12);
  color: #fff;
  border-radius: 50%;
}
.preview-close:hover { background: rgba(255,255,255,.22); color: #fff; }
.preview-close svg { width: 20px; height: 20px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 36px;
  transform: translateX(-50%);
  z-index: 300;
  background: #1C1E24;
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 28px rgba(0,0,0,.28);
  animation: toastIn .25s cubic-bezier(.22, .8, .36, 1) both;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.error { background: #7F1D1D; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to { opacity: 1; transform: translateX(-50%); }
}

/* ============ 滚动条 ============ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #D6D8DC; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #C2C5CA; }
::-webkit-scrollbar-track { background: transparent; }

/* ============ 响应式：移动端 ============ */
@media (max-width: 900px) {
  .toolbar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 58px;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--border);
    padding: 0 10px;
    gap: 6px;
    justify-content: center;
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(10px);
    overflow-x: auto;
  }
  .tool-group { flex-direction: row; gap: 2px; }
  .tool-btn { width: 52px; padding: 5px 0; }
  .tool-btn svg { width: 20px; height: 20px; }
  .brush-size-group {
    flex-direction: row;
    padding-top: 0;
    border-top: none;
    border-left: 1px solid var(--border);
    padding-left: 10px;
    margin-left: 4px;
  }
  .brush-size-group input[type="range"] { width: 64px; }

  .panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 58px;
    top: auto;
    width: auto;
    height: auto;
    max-height: 46vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -10px 40px rgba(16,24,40,.14);
    z-index: 20;
  }
  .panel.collapsed { height: 0; max-height: 0; border-top: none; }

  .topbar { padding: 0 8px; height: 50px; }
  .logo-mini .logo-name { display: none; }
  .btn-home { display: none; }
  .canvas-hint { display: none; }
  .export-actions { flex-direction: column; }
}

@media (max-width: 420px) {
  .topbar-actions .btn-icon { width: 32px; height: 32px; }
  .btn-export { padding: 0 14px; }
}

[hidden] { display: none !important; }
.logo-mini { cursor: pointer; }
