/* CSS 변수 정의 */
.image-rotate-flip-wrapper {
  --bg-primary: #f5f5f0;
  --bg-secondary: #fff;
  --bg-section: #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;
  --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 */
.image-rotate-flip-wrapper,
.image-rotate-flip-wrapper *,
.image-rotate-flip-wrapper *::before,
.image-rotate-flip-wrapper *::after {
  box-sizing: border-box;
}

/* 메인 컨테이너 */
.image-rotate-flip-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;
}

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

.tool-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;
}

/* 광고 섹션 */
.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;
}

/* 섹션 공통 */
.section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 12px;
  box-shadow: var(--shadow-md);
  margin-bottom: 12px;
}

.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-section {
  width: 100%;
}

/* 메인 그리드 (컨트롤 + 미리보기) */
.main-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

/* 업로드 섹션 */
.upload-area {
  border: 2px dashed var(--border-color);
  background: #fafafa;
  padding: 30px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

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

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

.upload-content svg {
  color: var(--text-light);
  margin-bottom: 12px;
}

.upload-text {
  margin: 0 0 6px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.upload-hint {
  margin: 0;
  font-size: 14px;
  color: var(--text-light);
}

.image-info {
  margin-top: 12px;
  padding: 10px;
  background: #f9f9f9;
  border: 1px solid #ddd;
}

.info-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 14px;
}

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

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

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

/* 컨트롤 섹션 */
.control-group {
  margin-bottom: 12px;
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-label {
  margin: 0 0 8px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
}

.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-control {
  flex: 1;
  min-width: 100px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--border-color);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.15);
  font-family: inherit;
}

.btn-control:hover:not(:disabled) {
  background: #f0f0f0;
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 rgba(0,0,0,0.15);
}

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

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

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

.download-options {
  display: flex;
  align-items: center;
  gap: 10px;
}

.download-options label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

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

.format-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--color-success);
  color: #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;
}

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

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

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

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

.btn-reset {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--color-warning);
  color: #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;
  margin-top: 10px;
}

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

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

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

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

/* 미리보기 섹션 */
.preview-container {
  min-height: 400px;
  background: #f9f9f9;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  position: relative;
}

.preview-placeholder {
  text-align: center;
  color: var(--text-light);
}

.preview-placeholder svg {
  margin-bottom: 12px;
  opacity: 0.5;
}

.preview-placeholder p {
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
}

#canvas {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

/* 정보 섹션 */
.info-content {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.6;
}

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

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

.info-icon {
  font-size: 24px;
  margin-bottom: 6px;
}

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

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

.feature-list {
  margin-bottom: 12px;
}

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

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

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

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

.warning-box {
  padding: 12px;
  background: #fff8e6;
  border: 1px solid var(--color-warning);
  border-left: 4px solid var(--color-warning);
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.warning-box strong {
  color: var(--color-warning);
}

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

/* 반응형: 모바일 */
@media (max-width: 768px) {
  .image-rotate-flip-container {
    margin: 8px 5px;
    padding: 10px;
    width: calc(100% - 10px);
    max-width: 100%;
    box-sizing: border-box;
  }
  
  .tool-header h2 {
    font-size: 24px;
  }
  
  .subtitle {
    font-size: 14px;
  }
  
  .main-grid {
    grid-template-columns: 1fr;
  }
  
  .upload-area {
    padding: 20px;
  }
  
  .button-row {
    flex-direction: column;
  }
  
  .btn-control {
    width: 100%;
  }
  
  .download-options {
    flex-direction: column;
    align-items: stretch;
  }
  
  .download-options label {
    margin-bottom: 4px;
  }
  
  .btn-download {
    width: 100%;
    justify-content: center;
  }
  
  .preview-container {
    min-height: 300px;
  }
  
  .info-grid {
    grid-template-columns: 1fr;
  }
}

/* 반응형: 작은 모바일 */
@media (max-width: 480px) {
  .image-rotate-flip-container {
    margin: 8px 5px;
    padding: 8px;
    width: calc(100% - 10px);
    max-width: 100%;
    box-sizing: border-box;
    border-width: 1px;
  }
  
  .tool-header h2 {
    font-size: 22px;
  }
  
  .upload-area {
    padding: 15px;
  }
  
  .upload-content svg {
    width: 40px;
    height: 40px;
  }
  
  .upload-text {
    font-size: 15px;
  }
  
  .preview-container {
    min-height: 250px;
  }
}