/* CSS 변수 정의 */
.pixel-art-tool-wrapper {
  --bg-primary: #f5f5f0;
  --bg-secondary: #fff;
  --bg-section: #fff;
  --border-color: #333;
  --border-light: #ddd;
  --text-primary: #222;
  --text-secondary: #555;
  --text-light: #666;
  --color-accent: #3498db;
  --color-success: #27ae60;
  --color-warning: #f39c12;
  --color-danger: #e74c3c;
  --color-purple: #9b59b6;
  --shadow-sm: 2px 2px 0 rgba(0,0,0,0.1);
  --shadow-md: 4px 4px 0 rgba(0,0,0,0.15);
  --shadow-lg: 8px 8px 0 rgba(0,0,0,0.15);
}

/* 전역 box-sizing */
.pixel-art-tool-wrapper,
.pixel-art-tool-wrapper *,
.pixel-art-tool-wrapper *::before,
.pixel-art-tool-wrapper *::after {
  box-sizing: border-box;
}

/* 메인 컨테이너 */
.pixel-art-tool-container {
  max-width: 1180px;
  width: 100%;
  margin: 20px auto;
  padding: 20px;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  font-family: 'Noto Sans KR', 'Malgun Gothic', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  line-height: 1.5;
}

/* 헤더 */
.tool-header {
  text-align: center;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 3px double var(--border-color);
}

.tool-header h2 {
  margin: 0 0 6px 0;
  font-size: 26px;
  font-weight: 700;
  color: #2c3e50;
  text-shadow: 2px 2px 0 rgba(255,255,255,0.5);
  line-height: 1.2;
}

.subtitle {
  margin: 0;
  font-size: 12px;
  color: var(--text-light);
  line-height: 1.4;
}

/* 광고 섹션 */
.ad-section {
  display: block;
  width: 100%;
  min-height: 100px;
  padding: 15px;
  text-align: center;
  background: #fff;
  border: 1px solid var(--border-light);
  overflow: visible;
  margin-bottom: 15px;
}

.ad-label {
  display: block;
  font-size: 10px;
  color: #999;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ad-section .adsbygoogle {
  display: block;
  width: 100%;
  max-width: 100%;
  min-height: 90px;
  text-align: center;
}

/* 메인 그리드 */
.tool-main {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 15px;
  margin-bottom: 15px;
}

/* 섹션 공통 스타일 */
.settings-section,
.preview-section {
  background: var(--bg-section);
  border: 1px solid var(--border-color);
  padding: 15px;
  box-shadow: var(--shadow-md);
}

/* 섹션 타이틀 */
.section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 12px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  font-size: 15px;
  font-weight: 700;
  color: #2c3e50;
  line-height: 1.2;
}

.settings-section .section-title {
  color: var(--color-accent);
}

.preview-section .section-title {
  color: var(--color-purple);
}

.info-section .section-title {
  color: var(--color-success);
}

/* 업로드 박스 */
.upload-box {
  width: 100%;
  min-height: 200px;
  border: 2px dashed var(--border-color);
  margin-bottom: 15px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  background: #fafafa;
  transition: all 0.2s;
}

.upload-box:hover {
  border-color: var(--color-accent);
  background: #f5f9ff;
  transform: scale(1.01);
}

.upload-box.drag-over {
  border-color: var(--color-success);
  background: #f0fff4;
  border-style: solid;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 200px;
  padding: 20px;
  text-align: center;
}

.upload-placeholder svg {
  color: var(--color-accent);
  margin-bottom: 12px;
}

.upload-text {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.4;
}

.upload-text span {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-light);
}

.image-preview-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

.image-preview {
  max-width: 100%;
  max-height: 180px;
  object-fit: contain;
  border: 1px solid var(--border-light);
}

.hidden {
  display: none !important;
}

/* 컨트롤 그룹 */
.control-group {
  margin-bottom: 15px;
}

.control-group.compact {
  margin-bottom: 10px;
}

.control-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.2;
}

/* 슬라이더 그룹 */
.slider-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.value-slider {
  flex: 1;
  height: 8px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background: #ddd;
  border: 1px solid var(--border-color);
  outline: none;
  cursor: pointer;
}

.value-slider:focus-visible {
  outline: 2px solid var(--color-warning);
  outline-offset: 2px;
}

.value-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--color-warning);
  border: 2px solid var(--border-color);
  cursor: pointer;
  transition: transform 0.2s;
}

.value-slider::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

.value-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--color-warning);
  border: 2px solid var(--border-color);
  cursor: pointer;
  transition: transform 0.2s;
}

.value-slider::-moz-range-thumb:hover {
  transform: scale(1.1);
}

/* 숫자 입력 */
.number-input {
  width: 70px;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  font-family: 'Courier New', monospace;
}

.number-input:focus {
  outline: none;
  background: #fffacd;
  border-color: var(--color-warning);
}

/* 셀렉트 입력 */
.select-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: inherit;
  cursor: pointer;
}

.select-input:focus {
  outline: none;
  background: #fffacd;
  border-color: var(--color-warning);
}

/* 변환 버튼 */
.btn-convert {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  background: var(--color-success);
  border: 1px solid var(--border-color);
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-md);
  font-family: inherit;
  margin-bottom: 15px;
}

.btn-convert:hover:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 rgba(0,0,0,0.2);
}

.btn-convert:active:not(:disabled) {
  transform: translate(4px, 4px);
  box-shadow: none;
}

.btn-convert:disabled {
  background: #ccc;
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-convert:focus-visible {
  outline: 3px solid var(--color-warning);
  outline-offset: 2px;
}

/* 유틸리티 버튼 */
.secondary-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  margin-bottom: 15px;
}

.btn-sample,
.btn-reset {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  background: #fff;
  border: 1px solid var(--border-color);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
  font-family: inherit;
}

.btn-sample:hover,
.btn-reset:hover {
  transform: translate(1px, 1px);
  box-shadow: 2px 2px 0 rgba(0,0,0,0.2);
}

.btn-sample:active,
.btn-reset:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.btn-sample:focus-visible,
.btn-reset:focus-visible {
  outline: 2px solid var(--color-warning);
  outline-offset: 2px;
}

.btn-sample {
  background: var(--color-warning);
  color: #fff;
  border-color: var(--border-color);
}

/* 외곽선 섹션 */
.outline-section {
  padding: 12px;
  background: #f9f9f9;
  border: 1px solid var(--border-light);
  margin-bottom: 15px;
}

/* 체크박스 라벨 */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--color-success);
}

.checkmark {
  flex-shrink: 0;
}

/* 외곽선 컨트롤 */
.outline-controls {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-light);
}

/* 컬러 피커 그룹 */
.color-picker-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.color-picker-group input[type="color"] {
  width: 50px;
  height: 32px;
  border: 1px solid var(--border-color);
  cursor: pointer;
  padding: 2px;
}

.color-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
}

/* 추가 옵션 */
.extra-options {
  padding: 12px;
  background: #f9f9f9;
  border: 1px solid var(--border-light);
}

.option-note {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-light);
  font-style: italic;
}

/* 미리보기 정보 */
.preview-info {
  display: flex;
  gap: 15px;
  margin-bottom: 12px;
  padding: 10px;
  background: #f9f9f9;
  border: 1px solid var(--border-light);
}

.info-item {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
}

.info-label {
  font-weight: 600;
  color: var(--text-secondary);
}

.info-value {
  font-weight: 700;
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
}

/* 캔버스 래퍼 */
.canvas-wrapper {
  position: relative;
  width: 100%;
  min-height: 400px;
  background: #fff;
  border: 2px solid var(--border-color);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

#pixelCanvas {
  display: block;
  max-width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

.canvas-placeholder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #999;
}

.canvas-placeholder svg {
  color: #ccc;
  margin-bottom: 12px;
}

.canvas-placeholder p {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
}

/* 액션 버튼 */
.action-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
}

.btn-download,
.btn-copy-canvas {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--border-color);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
  font-family: inherit;
}

.btn-download:hover:not(:disabled),
.btn-copy-canvas:hover:not(:disabled) {
  transform: translate(1px, 1px);
  box-shadow: 2px 2px 0 rgba(0,0,0,0.2);
}

.btn-download:active:not(:disabled),
.btn-copy-canvas:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.btn-download:disabled,
.btn-copy-canvas:disabled {
  background: #f5f5f5;
  cursor: not-allowed;
  opacity: 0.5;
}

.btn-download:focus-visible,
.btn-copy-canvas:focus-visible {
  outline: 2px solid var(--color-warning);
  outline-offset: 2px;
}

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

/* 팔레트 디스플레이 */
.palette-display {
  background: #f9f9f9;
  border: 1px solid var(--border-light);
  padding: 12px;
}

.palette-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.palette-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
}

.btn-copy-palette {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: #fff;
  border: 1px solid var(--border-color);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
  font-family: inherit;
}

.btn-copy-palette:hover:not(:disabled) {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}

.btn-copy-palette:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 8px;
}

.palette-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 20px;
  font-size: 12px;
  color: #999;
}

.palette-color {
  position: relative;
  width: 100%;
  height: 40px;
  border: 2px solid var(--border-color);
  cursor: pointer;
  transition: transform 0.2s;
}

.palette-color:hover {
  transform: scale(1.1);
  z-index: 10;
}

.palette-color::after {
  content: attr(data-hex);
  position: absolute;
  bottom: -26px;
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 4px 8px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid var(--border-color);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  font-family: 'Courier New', monospace;
  z-index: 100;
}

.palette-color:hover::after {
  opacity: 1;
}

/* 정보 섹션 */
.info-section {
  background: var(--bg-section);
  border: 1px solid var(--border-color);
  padding: 15px;
  box-shadow: var(--shadow-md);
}

.info-list {
  margin: 0;
  padding-left: 20px;
  list-style-type: disc;
}

.info-list li {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  line-height: 1.5;
}

.info-list li:last-child {
  margin-bottom: 0;
}

.info-list strong {
  color: var(--text-primary);
}

/* 토스트 */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #27ae60;
  color: #fff;
  padding: 12px 20px;
  border: 2px solid var(--border-color);
  box-shadow: 4px 4px 0 rgba(0,0,0,0.3);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 10000;
  opacity: 0;
  transition: all 0.3s ease;
  max-width: 90%;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-success {
  background: #27ae60;
}

.toast-error {
  background: #e74c3c;
}

.toast-info {
  background: #3498db;
}

.toast-warning {
  background: #f39c12;
}

.toast-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toast-title {
  font-size: 13px;
  font-weight: 700;
}

.toast-value {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.9;
  word-break: break-word;
}

/* 반응형: 태블릿 */
@media (max-width: 1024px) {
  .tool-main {
    grid-template-columns: 1fr;
  }
  
  .palette-grid {
    grid-template-columns: repeat(auto-fill, minmax(35px, 1fr));
  }
}

/* 반응형: 모바일 */
@media (max-width: 768px) {
  .pixel-art-tool-container {
    padding: 15px;
  }
  
  .tool-header h2 {
    font-size: 22px;
  }
  
  .subtitle {
    font-size: 11px;
  }
  
  .secondary-actions {
    flex-direction: column;
  }
  
  .btn-sample,
  .btn-reset {
    width: 100%;
  }
  
  .canvas-wrapper {
    min-height: 300px;
  }
  
  .action-buttons {
    flex-direction: column;
  }
  
  .palette-grid {
    grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
    gap: 6px;
  }
}

/* 반응형: 작은 모바일 */
@media (max-width: 480px) {
  .pixel-art-tool-container {
    padding: 10px;
  }
  
  .tool-header {
    margin-bottom: 12px;
  }
  
  .upload-box {
    min-height: 150px;
  }
  
  .upload-placeholder {
    min-height: 150px;
  }
  
  .canvas-wrapper {
    min-height: 250px;
  }
  
  .slider-group {
    flex-wrap: wrap;
  }
  
  .value-slider {
    width: 100%;
  }
  
  .number-input {
    width: 100%;
  }
}