/* 移动端马赛克应用 - 纯色、无渐变 */
:root {
  --bg: #1a1a1a;
  --surface: #2d2d2d;
  --surface-alt: #3d3d3d;
  --text: #f5f5f5;
  --text-muted: #999;
  --accent: #4a9eff;
  --accent-press: #3a7ed9;
  --danger: #e55c5c;
  --danger-press: #c94a4a;
  --safe-area: env(safe-area-inset-bottom, 0);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  touch-action: manipulation;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
}

/* 顶部操作栏 */
.top-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface);
  min-height: 48px;
}

.title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.btn {
  min-height: 44px;
  min-width: 44px;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.98);
}

.btn-save {
  background: var(--accent);
  color: #fff;
}

.btn-save:active:not(:disabled) {
  background: var(--accent-press);
}

.btn-save:disabled {
  background: var(--surface-alt);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* 操作提示区 */
.hint-area {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--bg);
}

.hint-area.hidden {
  display: none;
}

.hint-text {
  margin: 0;
  flex: 1;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.hint-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hint-close:active {
  color: var(--text);
}

/* 中间编辑区 */
.edit-area {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}

.canvas-wrap {
  display: inline-block;
  min-width: 100%;
  min-height: 200px;
  padding: 8px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.canvas-wrap.has-image {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}

.placeholder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  white-space: nowrap;
  pointer-events: none;
}

.canvas-wrap.has-image .placeholder {
  display: none;
}

#canvas {
  display: block;
  touch-action: none;
}

.canvas-inner {
  display: inline-block;
  transform-origin: 0 0;
  will-change: transform;
}

.canvas-wrap.has-image #canvas {
  margin: 0 auto;
  display: block;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.loading-overlay[hidden] {
  display: none;
}

.loading-text {
  color: #fff;
  font-size: 0.9375rem;
}

/* 底部功能栏 */
.bottom-bar {
  flex-shrink: 0;
  padding: 12px 16px;
  padding-bottom: max(12px, calc(12px + var(--safe-area)));
  background: var(--surface);
  border-top: 1px solid var(--bg);
}

.btn-upload {
  width: 100%;
  margin-bottom: 12px;
  background: var(--accent);
  color: #fff;
}

.btn-upload:active {
  background: var(--accent-press);
}

.params {
  margin-bottom: 12px;
}

.param-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.param-row:last-child {
  margin-bottom: 0;
}

.param-row label {
  flex: 0 0 72px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.param-row input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 28px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--surface-alt);
  border-radius: 4px;
}

.param-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.param-row input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.param-value {
  flex: 0 0 36px;
  font-size: 0.875rem;
  color: var(--text);
  text-align: right;
}

.btn-clear {
  width: 100%;
  background: var(--surface-alt);
  color: var(--text);
}

.btn-clear:active:not(:disabled) {
  background: var(--danger);
  color: #fff;
}

.btn-clear:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
}

/* 适配 320px 小屏 */
@media (max-width: 360px) {
  .top-bar, .bottom-bar {
    padding-left: 12px;
    padding-right: 12px;
  }

  .param-row label {
    flex: 0 0 60px;
    font-size: 0.8125rem;
  }
}
