/* Pixel Studio drawing editor — green game theme */

.draw-editor {
  --gp-bg: #f4faf6;
  --gp-surface: #ffffff;
  --gp-surface-2: #f8fdf9;
  --gp-ink: #1b3a2b;
  --gp-ink-light: #4a6b5a;
  --gp-brand: #2f9e44;
  --gp-brand-dark: #237b34;
  --gp-brand-light: #d3f9d8;
  --gp-accent: #ffd43b;
  --gp-line: #c8e6c9;
  --gp-line-strong: #a5d6a7;
  --gp-danger: #e03131;
  --gp-shadow: 0 6px 20px rgba(47, 158, 68, 0.1);
  --gp-radius: 14px;
  --gp-radius-sm: 10px;

  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--gp-bg);
  border: 2px solid var(--gp-line);
  border-radius: var(--gp-radius);
  color: var(--gp-ink);
  font-family: "Outfit", system-ui, sans-serif;
}

.draw-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.draw-toolbar-inner,
.draw-game-toolbar-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  width: 100%;
}

.draw-tool-btn,
.draw-btn,
.draw-game-btn {
  appearance: none;
  border: 2px solid var(--gp-line);
  background: var(--gp-surface);
  color: var(--gp-ink);
  border-radius: var(--gp-radius-sm);
  padding: 0.45rem 0.7rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 110ms ease, box-shadow 140ms ease, background 140ms ease, border-color 140ms ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 40px;
}

.draw-tool-btn:hover,
.draw-btn:hover,
.draw-game-btn:hover {
  background: var(--gp-brand-light);
  border-color: var(--gp-line-strong);
  transform: translateY(-1px);
}

.draw-tool-btn.active,
.draw-game-btn.active {
  background: var(--gp-brand);
  border-color: var(--gp-brand);
  color: #fff;
  box-shadow: var(--gp-shadow);
}

.draw-game-btn.primary {
  background: var(--gp-brand);
  border-color: var(--gp-brand);
  color: #fff;
}

.draw-game-btn.primary:hover {
  background: var(--gp-brand-dark);
  border-color: var(--gp-brand-dark);
}

.draw-game-btn.cooldown {
  opacity: 0.5;
  pointer-events: none;
  filter: grayscale(0.6);
}

.draw-toolbar-spacer {
  flex: 1;
}

.draw-body {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 0.75rem;
  align-items: start;
}

.draw-canvas-wrap {
  border: 2px solid var(--gp-line);
  border-radius: var(--gp-radius-sm);
  overflow: auto;
  background: var(--gp-surface);
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1px rgba(47, 158, 68, 0.06);

  /* 画布容器：正方形、响应式、带最大/最小边界，避免在 PC 上无限放大或在手机上过小 */
  width: 100%;
  max-width: min(100%, 640px);
  min-width: min(100%, 320px);
  max-height: min(80vh, 640px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
}

.draw-canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: none;
}

.draw-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.draw-sidebar > div,
.draw-panel {
  background: var(--gp-surface);
  border: 2px solid var(--gp-line);
  border-radius: var(--gp-radius-sm);
  padding: 0.75rem;
  box-shadow: var(--gp-shadow);
}

.draw-sidebar h4,
.draw-panel h4 {
  margin: 0 0 0.6rem;
  font-size: 0.95rem;
  color: var(--gp-ink);
}

.draw-status {
  font-size: 0.85rem;
  color: var(--gp-ink-light);
  min-height: 1.4rem;
}

/* Challenge palette */
.draw-challenge-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.draw-color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px var(--gp-line);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
  padding: 0;
}

.draw-color-swatch:hover {
  transform: scale(1.1);
}

.draw-color-swatch.selected {
  box-shadow: 0 0 0 3px var(--gp-brand);
}

/* Result overlay */
.draw-result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(27, 58, 43, 0.55);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 1rem;
  backdrop-filter: blur(4px);
}

.draw-result-card {
  background: var(--gp-surface);
  border: 2px solid var(--gp-line);
  border-radius: var(--gp-radius);
  padding: 1.5rem;
  width: min(420px, 92vw);
  max-width: 100%;
  text-align: center;
  box-shadow: var(--gp-shadow);
}

.draw-result-card h3 {
  margin: 0 0 0.75rem;
  color: var(--gp-brand-dark);
}

.draw-result-score {
  margin-bottom: 1rem;
}

.draw-result-accuracy {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--gp-brand);
  line-height: 1.1;
}

.draw-result-stars {
  font-size: 1.8rem;
  color: var(--gp-accent);
  letter-spacing: 0.1rem;
}

.draw-result-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.draw-result-item {
  background: var(--gp-surface-2);
  border: 2px solid var(--gp-line);
  border-radius: var(--gp-radius-sm);
  padding: 0.5rem;
}

.draw-result-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--gp-ink-light);
  margin-bottom: 0.4rem;
}

.draw-result-canvas-wrap canvas {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  border-radius: 6px;
  border: 1px solid var(--gp-line);
}

.draw-result-close {
  background: var(--gp-brand);
  border: 2px solid var(--gp-brand);
  color: #fff;
  border-radius: var(--gp-radius-sm);
  padding: 0.55rem 1.2rem;
  font-weight: 700;
  cursor: pointer;
}

.draw-result-close:hover {
  background: var(--gp-brand-dark);
}

/* Responsive */
@media (max-width: 800px) {
  .draw-body {
    grid-template-columns: 1fr;
  }
  .draw-sidebar {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .draw-sidebar > div,
  .draw-panel {
    flex: 1 1 240px;
  }
}

@media (max-width: 540px) {
  .draw-editor {
    padding: 0.5rem;
    gap: 0.5rem;
  }
  .draw-tool-label,
  .draw-game-btn-label {
    display: none;
  }
  .draw-tool-btn,
  .draw-game-btn {
    padding: 0.45rem;
    min-width: 44px;
    min-height: 44px;
  }
  .draw-btn {
    padding: 0.4rem 0.55rem;
    font-size: 0.8rem;
  }
  .draw-canvas-wrap {
    min-width: min(100%, 260px);
  }
  .draw-result-compare {
    grid-template-columns: 1fr;
  }
}

/* QuickColorPalette component styles */
.draw-color-source-row {
  margin-bottom: 0.75rem;
}
.draw-color-source-row label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--gp-ink-light);
}
.draw-color-source-row select {
  width: 100%;
  max-width: 220px;
  padding: 0.35rem 0.5rem;
  border: 2px solid var(--gp-line);
  border-radius: var(--gp-radius-sm);
  background: var(--gp-surface);
  color: var(--gp-ink);
  font-size: 0.9rem;
}

.quick-color-palette-v2 {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.quick-color-swatch-v2 {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem;
  border: 2px solid var(--gp-line);
  border-radius: var(--gp-radius-sm);
  background: var(--gp-surface);
  cursor: pointer;
  min-width: 48px;
  transition: border-color 0.15s, background 0.15s;
}
.quick-color-swatch-v2.active {
  border-color: var(--gp-brand);
  background: var(--gp-brand-light);
}
.quick-color-swatch-v2:hover {
  border-color: var(--gp-brand);
  background: var(--gp-brand-light);
}
.quick-color-preview {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.1);
}
.quick-color-label {
  font-size: 0.75rem;
  color: var(--gp-ink-light);
}

/* Layout engine: stage layout and fixed-skeleton fallback */
.draw-editor {
  position: relative;
  min-height: 500px;
  height: 100%;
}

/* 当启用自定义布局时隐藏固定骨架 */
.draw-layout-active .draw-toolbar,
.draw-layout-active .draw-game-toolbar,
.draw-layout-active .draw-body,
.draw-layout-active .draw-status {
  display: none !important;
}

.draw-layout-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: var(--gp-radius);
}

.draw-module {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.draw-module[data-module="canvas"] {
  display: grid;
  place-items: center;
  padding: 0.5rem;
  background: var(--gp-surface);
  border: 2px solid var(--gp-line);
  border-radius: var(--gp-radius-sm);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
}

.draw-module[data-module="canvas"] canvas {
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  max-height: 100%;
}

/* pixel-paint 主题：绿色全屏背景 */
.draw-theme-pixel-paint {
  background: #8bc34a;
}

.draw-theme-pixel-paint .draw-module[data-module="canvas"] {
  background: #ffffff;
  border-color: #ffffff;
}

.draw-theme-pixel-paint .draw-module[data-module="toolbar"],
.draw-theme-pixel-paint .draw-module[data-module="gameToolbar"] {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 999px;
  padding: 0.4rem 0.6rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  flex-direction: row;
  align-items: center;
}

.draw-theme-pixel-paint .draw-module[data-module="palette"] {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 999px;
  padding: 0.6rem 0.9rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  flex-direction: row;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.draw-theme-pixel-paint .draw-module[data-module="status"] {
  display: none;
}

/* pixel-paint 横向圆形调色板 */
.draw-theme-pixel-paint .quick-color-palette-v2 {
  justify-content: center;
  gap: 0.45rem;
}

.draw-theme-pixel-paint .quick-color-swatch-v2 {
  min-width: auto;
  padding: 0.15rem;
  border: none;
  background: transparent;
  border-radius: 50%;
}

.draw-theme-pixel-paint .quick-color-swatch-v2.active {
  background: rgba(0, 0, 0, 0.12);
}

.draw-theme-pixel-paint .quick-color-preview {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.08);
}

.draw-theme-pixel-paint .quick-color-label {
  display: none;
}

/* pixel-paint 工具栏：隐藏文字，只显示图标 */
.draw-theme-pixel-paint .draw-tool-btn {
  background: transparent;
  border: none;
  box-shadow: none;
  color: #4a6b5a;
  padding: 0.35rem;
  font-size: 1.1rem;
}

.draw-theme-pixel-paint .draw-tool-btn.active {
  background: var(--gp-brand-light);
  color: var(--gp-brand);
}

.draw-theme-pixel-paint .draw-tool-btn span:not(.draw-tool-icon) {
  display: none;
}

/* pixel-paint theme refinements */
.draw-theme-pixel-paint .draw-module[data-module="palette"] h4 {
  display: none;
}

.draw-theme-pixel-paint .draw-module[data-module="toolbar"] .draw-btn,
.draw-theme-pixel-paint .draw-module[data-module="gameToolbar"] .draw-game-btn {
  background: transparent;
  border: none;
  box-shadow: none;
  color: #4a6b5a;
  padding: 0.35rem;
  font-size: 0.85rem;
  border-radius: 50%;
  min-width: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.draw-theme-pixel-paint .draw-module[data-module="toolbar"] .draw-btn:hover,
.draw-theme-pixel-paint .draw-module[data-module="gameToolbar"] .draw-game-btn:hover {
  background: rgba(0, 0, 0, 0.06);
}

.draw-theme-pixel-paint .draw-game-btn span.draw-game-btn-label {
  display: none;
}

/* Layout engine responsive overrides for pixel-paint theme */
@media (max-width: 800px) {
  .draw-theme-pixel-paint .draw-module[data-module="canvas"] {
    width: 56% !important;
    max-width: 100% !important;
  }
  .draw-theme-pixel-paint .draw-module[data-module="palette"] {
    width: 90% !important;
  }
}

@media (max-width: 540px) {
  .draw-theme-pixel-paint .draw-module[data-module="canvas"] {
    width: 84% !important;
    max-width: 100% !important;
  }
  .draw-theme-pixel-paint .draw-module[data-module="toolbar"] {
    top: 1% !important;
    left: 2% !important;
  }
  .draw-theme-pixel-paint .draw-module[data-module="gameToolbar"] {
    top: 1% !important;
    right: 2% !important;
  }
  .draw-theme-pixel-paint .draw-module[data-module="palette"] {
    width: 92% !important;
    bottom: 2% !important;
  }
}

/* Floating level picker for challenge mode */
.draw-level-picker-floating {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4rem;
}

.draw-level-picker-toggle {
  appearance: none;
  border: 2px solid var(--gp-line);
  background: var(--gp-surface);
  color: var(--gp-ink);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: var(--gp-shadow);
}

.draw-level-picker-toggle:hover {
  background: var(--gp-brand-light);
  border-color: var(--gp-line-strong);
}

.draw-level-picker-panel {
  background: var(--gp-surface);
  border: 2px solid var(--gp-line);
  border-radius: var(--gp-radius-sm);
  padding: 0.6rem;
  width: min(280px, calc(100vw - 2rem));
  max-height: 70vh;
  overflow: auto;
  box-shadow: var(--gp-shadow);
}

.draw-level-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.draw-level-picker-close {
  border: none;
  background: transparent;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--gp-ink-light);
  cursor: pointer;
}

.draw-level-picker-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 0.5rem;
}

.draw-level-item {
  appearance: none;
  border: 2px solid var(--gp-line);
  background: var(--gp-surface-2);
  border-radius: var(--gp-radius-sm);
  padding: 0.35rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--gp-ink);
}

.draw-level-item:hover {
  border-color: var(--gp-line-strong);
  background: var(--gp-brand-light);
}

.draw-level-item.active {
  border-color: var(--gp-brand);
  background: var(--gp-brand-light);
}

.draw-level-item img {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
  border-radius: 4px;
  border: 1px solid var(--gp-line);
}

.draw-level-placeholder {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  background: var(--gp-line);
  border-radius: 4px;
  font-weight: 700;
}

.draw-level-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.draw-theme-pixel-paint .draw-level-picker-toggle {
  background: rgba(255, 255, 255, 0.95);
  border-color: #fff;
}
