:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #eef3fb;
  --canvas: #f9fbff;
  --border: #cfd8e6;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: #dbeafe;
  --success: #16a34a;
  --danger: #dc2626;
  --text: #1f2937;
  --text-dim: #6b7280;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --input-bg: #fff;
  --input-color: #1f2937;
  --btn-text: #fff;
}
[data-theme="dark"] {
  --bg: #0d0f14;
  --panel: #151820;
  --panel-2: #1a1e28;
  --canvas: #111520;
  --border: #252a35;
  --accent: #4e9eff;
  --accent-hover: #6db3ff;
  --accent-soft: #1a2540;
  --success: #34d399;
  --danger: #f87171;
  --text: #c8cdd8;
  --text-dim: #5a6070;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  --input-bg: #111520;
  --input-color: #c8cdd8;
  --btn-text: #0d0f14;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Microsoft YaHei UI", "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 100vh;
  padding: 12px;
  gap: 12px;
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.status-group {
  min-width: 320px;
  text-align: right;
}

.status-head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}

.status-line {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-line.muted {
  color: var(--text-dim);
}

.main-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr) 160px;
  gap: 12px;
  min-height: 0;
  flex: 1;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: auto;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 15px;
}

.field-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.field-row.compact {
  align-items: end;
}

.field-row label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-dim);
}

input[type="number"] {
  width: 100px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--input-bg);
  color: var(--input-color);
}

.btn,
.icon-btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--text);
  cursor: pointer;
  transition: 0.15s ease;
}

.btn {
  padding: 10px 16px;
}

.btn.small {
  padding: 9px 12px;
}

.btn.primary {
  background: var(--accent);
  color: var(--btn-text);
}

.btn.success {
  background: var(--success);
  color: var(--btn-text);
}

.lang-toggle {
  min-width: 58px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  font-weight: 700;
}

.btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.check-row input:disabled + span {
  color: var(--text-dim);
}

.check-row.inline {
  display: inline-flex;
}

.fill-bg-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 10px 0 0 24px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel-2);
}

.fill-bg-controls.hidden {
  display: none;
}

.color-field {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

input[type="color"] {
  width: 44px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
}

.hint {
  margin: 0;
  color: var(--text-dim);
  font-size: 12px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.preset-item {
  display: flex;
  gap: 6px;
  min-width: 0;
}

.preset-main {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preset-main.active {
  background: #bfdbfe;
}

.preset-remove {
  width: 32px;
  min-width: 32px;
  padding: 8px 0;
  font-size: 12px;
  background: #f8fafc;
  color: var(--text-dim);
}

.info-box {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-dim);
  font: 12px/1.6 Consolas, "Courier New", monospace;
}

.canvas-panel {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.canvas-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.canvas-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

#previewCanvas {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 0;
  display: block;
  border-radius: 14px;
  background: var(--canvas);
}

.image-scale-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  flex-shrink: 0;
}

.image-scale-bar.hidden {
  display: none;
}

.scale-bar-label {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  min-width: 28px;
  text-align: center;
}

.scale-bar-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  min-width: 44px;
  text-align: right;
}

#imageScaleSlider {
  flex: 1;
  min-width: 0;
  height: 4px;
  appearance: none;
  -webkit-appearance: none;
  background: linear-gradient(to right, var(--accent) 0%, var(--accent) 50%, var(--border) 50%, var(--border) 100%);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
  border: none;
  padding: 0;
}

#imageScaleSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(59, 130, 246, 0.4);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

#imageScaleSlider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.6);
}

#imageScaleSlider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(59, 130, 246, 0.4);
}

.thumbnail-strip {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.thumbnail-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  flex: 1;
}

.thumbnail-item {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  background: var(--canvas);
  flex-shrink: 0;
  transition: border-color 0.15s ease;
}

.thumbnail-item:hover {
  border-color: var(--border);
}

.thumbnail-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.thumbnail-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

@media (max-width: 1100px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .thumbnail-strip {
    display: none;
  }

  .status-group {
    min-width: 0;
    text-align: left;
  }

  .status-head {
    justify-content: flex-start;
  }

  .topbar {
    flex-direction: column;
  }

  .canvas-panel {
    grid-template-columns: 1fr;
  }

  .canvas-toolbar {
    flex-direction: row;
    justify-content: center;
  }
}

/* ---- Doodle mode styles ---- */

.doodle-mode .topbar #doodleModeBtn {
  background: var(--accent);
  color: var(--btn-text);
}

.doodle-mode .topbar #doodleModeBtn:hover {
  background: var(--accent-hover);
}

#doodleModeBtn.active {
  background: var(--accent);
  color: var(--btn-text);
}

#doodleModeBtn.active:hover {
  background: var(--accent-hover);
}

#doodlePanel {
  overflow: visible;
}

#brushSizeSlider {
  flex: 1;
  min-width: 80px;
  height: 4px;
  appearance: none;
  -webkit-appearance: none;
  background: linear-gradient(to right, var(--accent) 0%, var(--accent) 10%, var(--border) 10%, var(--border) 100%);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
  border: none;
  padding: 0;
  margin: 6px 0;
}

#brushSizeSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(59, 130, 246, 0.4);
}

#brushSizeSlider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(59, 130, 246, 0.4);
}

.brush-size-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  min-width: 36px;
  text-align: right;
}

.color-palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-top: 2px;
}

.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.12s ease, border-color 0.12s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.color-swatch:hover {
  transform: scale(1.12);
}

.color-swatch.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--accent);
}

.doodle-mode .card.crop-only {
  display: none;
}
