/* CSS 변수 정의 */
.css-beautifier-wrapper {
  --bg-primary: #f5f5f0;
  --bg-secondary: #fff;
  --border-color: #333;
  --text-primary: #222;
  --text-secondary: #555;
  --text-light: #666;
  --color-accent: #3498db;
  --color-success: #27ae60;
  --color-warning: #f39c12;
  --color-danger: #e74c3c;
  --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 */
.css-beautifier-wrapper,
.css-beautifier-wrapper *,
.css-beautifier-wrapper *::before,
.css-beautifier-wrapper *::after {
  box-sizing: border-box;
}

/* 메인 컨테이너 */
.css-beautifier-container {
  max-width: 1180px;
  width: 100%;
  margin: 15px auto;
  padding: 15px;
  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;
}

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

.beautifier-header h2 {
  margin: 0 0 6px 0;
  font-size: 28px;
  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: 15px;
  color: var(--text-light);
  line-height: 1.4;
}

/* 빠른 액션 */
.quick-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-example,
.btn-reset {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #fff;
  border: 1px solid var(--border-color);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.2);
  font-family: inherit;
  color: var(--text-primary);
}

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

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

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

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

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

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

.ad-label {
  display: block;
  font-size: 12px;
  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;
}

/* 메인 레이아웃 */
.beautifier-main {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.beautifier-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 12px;
  box-shadow: var(--shadow-md);
}

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

/* 파일 업로드 */
.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #f9f9f9;
  border: 2px dashed var(--border-color);
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 12px;
  min-height: 100px;
}

.upload-area:hover {
  background: #f0f0f0;
  border-color: var(--color-accent);
}

.upload-area.dragover {
  background: #e8f5e9;
  border-color: var(--color-success);
}

.upload-icon {
  color: var(--color-accent);
  margin-bottom: 8px;
}

.upload-text {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
}

/* 코드 영역 */
.code-area {
  margin-bottom: 12px;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #f0f0f0;
  border: 1px solid var(--border-color);
  border-bottom: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.code-actions {
  display: flex;
  gap: 6px;
}

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

.btn-clear:hover,
.btn-action:hover {
  background: #f0f0f0;
  transform: translate(0.5px, 0.5px);
  box-shadow: 0.5px 0.5px 0 rgba(0,0,0,0.1);
}

.btn-clear:active,
.btn-action:active {
  transform: translate(1px, 1px);
  box-shadow: none;
}

.code-textarea {
  width: 100%;
  max-width: 100%;
  min-height: 300px;
  padding: 10px;
  border: 1px solid var(--border-color);
  background: #fff;
  font-size: 14px;
  font-family: 'Courier New', monospace;
  color: var(--text-primary);
  resize: vertical;
  line-height: 1.5;
}

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

.code-textarea::placeholder {
  color: #999;
}

.output-section .code-textarea {
  background: #f9f9f9;
}

/* 옵션 영역 */
.options-area {
  margin-bottom: 12px;
}

.mode-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.mode-btn {
  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: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.1);
  font-family: inherit;
  color: var(--text-primary);
}

.mode-btn:hover {
  transform: translate(0.5px, 0.5px);
  box-shadow: 1.5px 1.5px 0 rgba(0,0,0,0.1);
}

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

.mode-btn.active {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--border-color);
}

.option-group {
  padding: 12px;
  background: #f9f9f9;
  border: 1px solid #ddd;
}

.option-group.hidden {
  display: none;
}

.option-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}

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

.option-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  user-select: none;
}

.option-item input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.checkbox-custom {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-color);
  background: #fff;
  position: relative;
  flex-shrink: 0;
}

.option-item input[type="checkbox"]:checked + .checkbox-custom {
  background: var(--color-success);
  border-color: var(--color-success);
}

.option-item input[type="checkbox"]:checked + .checkbox-custom::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.indent-control {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid #ddd;
  font-size: 14px;
  color: var(--text-secondary);
}

.indent-control label {
  font-weight: 600;
}

.indent-select {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-primary);
  cursor: pointer;
}

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

/* 처리 버튼 */
.btn-process {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--color-success);
  color: #fff;
  border: 2px solid var(--border-color);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.3);
  font-family: inherit;
}

.btn-process:hover {
  transform: translate(1px, 1px);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.3);
}

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

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

/* 통계 영역 */
.stats-area {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.stat-item {
  padding: 10px;
  background: #f9f9f9;
  border: 1px solid #ddd;
  text-align: center;
}

.stat-label {
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 4px;
}

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

.stat-value.success {
  color: var(--color-success);
}

/* 정보 영역 */
.info-area {
  display: flex;
  gap: 15px;
  padding: 10px;
  background: #f0f0f0;
  border: 1px solid #ddd;
  justify-content: center;
}

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

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

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

/* 사용 안내 */
.guide-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 12px;
  box-shadow: var(--shadow-md);
}

.guide-content {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.guide-card {
  padding: 12px;
  background: #f9f9f9;
  border: 1px solid #ddd;
  text-align: center;
}

.guide-icon {
  font-size: 28px;
  margin-bottom: 6px;
}

.guide-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.guide-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.guide-tips {
  margin-bottom: 0;
}

.guide-tips p {
  margin: 0 0 8px 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

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

.guide-tips li {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  line-height: 1.5;
}

.guide-tips li:last-child {
  margin-bottom: 0;
}

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

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

.toast.error {
  background: var(--color-danger);
}

.toast-icon {
  flex-shrink: 0;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 2px;
}

.toast-message {
  font-size: 14px;
  opacity: 0.9;
}

/* 반응형: 태블릿 */
@media (max-width: 1024px) {
  .beautifier-main {
    grid-template-columns: 1fr;
  }
  
  .guide-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* 반응형: 모바일 */
@media (max-width: 768px) {
  .css-beautifier-container {
    margin: 8px 5px;
    padding: 10px;
    width: calc(100% - 10px);
    max-width: 100%;
  }
  
  .beautifier-header h2 {
    font-size: 24px;
  }
  
  .subtitle {
    font-size: 14px;
  }
  
  .quick-actions {
    flex-direction: column;
  }
  
  .btn-example,
  .btn-reset {
    width: 100%;
    justify-content: center;
  }
  
  .code-textarea {
    min-height: 250px;
    font-size: 13px;
  }
  
  .stats-area {
    grid-template-columns: 1fr;
  }
  
  .guide-grid {
    grid-template-columns: 1fr;
  }
  
  .info-area {
    flex-direction: column;
    gap: 8px;
  }
  
  .option-row {
    grid-template-columns: 1fr;
  }
  
  .toast {
    min-width: 250px;
  }
}

/* 반응형: 작은 모바일 */
@media (max-width: 480px) {
  .css-beautifier-container {
    margin: 8px 5px;
    padding: 8px;
    width: calc(100% - 10px);
    border-width: 1px;
  }
  
  .beautifier-header h2 {
    font-size: 22px;
  }
  
  .code-textarea {
    min-height: 200px;
    font-size: 12px;
  }
  
  .mode-toggle {
    flex-direction: column;
  }
  
  .toast {
    min-width: 200px;
    padding: 10px 16px;
  }
}