/* CSS 변수 정의 */
.color-inverter-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 */
.color-inverter-wrapper,
.color-inverter-wrapper *,
.color-inverter-wrapper *::before,
.color-inverter-wrapper *::after {
  box-sizing: border-box;
}

/* 메인 컨테이너 */
.color-inverter-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;
}

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

.calculator-header h2 {
  margin: 0 0 10px 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: 15px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-sample,
.btn-reset {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  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: 3px 3px 0 rgba(0,0,0,0.2);
  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(3px, 3px);
  box-shadow: none;
}

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

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

/* 광고 섹션 */
.ad-section {
  display: block;
  width: 100%;
  min-height: 100px;
  padding: 15px;
  text-align: center;
  background: #fff;
  border: 1px solid #ddd;
  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;
}

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

.input-section,
.result-section {
  background: var(--bg-secondary);
  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 15px 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
  font-size: 16px;
  font-weight: 700;
  color: #2c3e50;
  line-height: 1.2;
}

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

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

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

.history-section .section-title {
  color: var(--color-danger);
}

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

/* 입력 그룹 */
.input-group {
  margin-bottom: 15px;
}

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

/* 컬러 피커 */
.color-picker-input {
  width: 100%;
  height: 60px;
  border: 1px solid var(--border-color);
  cursor: pointer;
  padding: 4px;
}

/* 텍스트 입력 */
.text-input {
  width: 100%;
  max-width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  background: #fff;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
  transition: all 0.2s;
}

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

.text-input.error {
  border-color: var(--color-danger);
  background: #ffe6e6;
}

/* 입력 + 버튼 */
.input-with-btn {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-with-btn .text-input {
  flex: 1;
}

/* 계산 버튼 */
.btn-calculate {
  flex-shrink: 0;
  padding: 10px 18px;
  background: var(--color-success);
  color: #fff;
  border: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.2);
  font-weight: 600;
  font-size: 14px;
  font-family: inherit;
}

.btn-calculate:hover {
  background: #229954;
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}

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

/* 에러 메시지 */
.error-message {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-danger);
  min-height: 16px;
}

/* RGB 입력 */
.rgb-inputs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.rgb-input-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rgb-input-item label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
}

.number-input {
  width: 100%;
  max-width: 100%;
  padding: 10px 8px;
  border: 1px solid var(--border-color);
  background: #fff;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
  text-align: center;
  transition: all 0.2s;
}

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

/* 미리보기 섹션 */
.preview-section {
  margin-top: 20px;
}

.preview-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 8px 0;
}

.preview-box {
  position: relative;
  width: 100%;
  height: 180px;
  border: 2px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease;
}

.preview-hex {
  padding: 12px 24px;
  font-size: 20px;
  font-weight: 700;
  font-family: 'Courier New', monospace;
  border: 2px solid rgba(0,0,0,0.2);
  background: rgba(255,255,255,0.9);
  color: var(--text-primary);
  transition: all 0.2s;
}

.preview-hex.light-bg {
  background: rgba(0,0,0,0.9);
  color: #fff;
  border-color: rgba(255,255,255,0.2);
}

/* 색상 상세 정보 섹션 */
.color-details-section {
  padding-top: 15px;
  border-top: 2px dashed #ddd;
  margin-top: 15px;
}

.details-subtitle {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 12px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.details-subtitle::before {
  content: '📊';
  font-size: 16px;
}

.color-detail-item {
  margin-bottom: 10px;
}

.color-detail-item label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.detail-value-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #f9f9f9;
  border: 1px solid #ddd;
}

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

.btn-copy-small {
  flex-shrink: 0;
  padding: 6px 8px;
  background: #fff;
  border: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 1px 1px 0 rgba(0,0,0,0.1);
}

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

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

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

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

.color-info-card .info-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 6px;
}

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

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

.comparison-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 20px;
  align-items: center;
}

.comparison-card {
  text-align: center;
}

.comparison-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.comparison-preview {
  width: 100%;
  height: 120px;
  border: 2px solid var(--border-color);
  margin-bottom: 10px;
}

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

.comparison-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-success);
}

/* 히스토리 섹션 */
.history-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 15px;
  box-shadow: var(--shadow-md);
  margin-bottom: 15px;
}

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

.history-header .section-title {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

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

.btn-clear-history:hover {
  background: #ffe6e6;
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}

.history-colors {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 10px;
}

.history-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 30px;
  font-size: 14px;
  color: #999;
}

.history-color-pair {
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.2s;
}

.history-color-pair:hover {
  transform: scale(1.05);
  z-index: 10;
}

.history-color {
  width: 100%;
  height: 50px;
  border: 2px solid var(--border-color);
  position: relative;
}

.history-label {
  font-size: 10px;
  text-align: center;
  color: var(--text-secondary);
  font-weight: 600;
}

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

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

.info-content li {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 8px;
  line-height: 1.6;
}

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

/* 반응형: 태블릿 */
@media (max-width: 768px) {
  .calculator-main {
    grid-template-columns: 1fr;
  }

  .color-inverter-container {
    margin: 10px 5px;
    padding: 15px;
    width: calc(100% - 10px);
    max-width: 100%;
    box-sizing: border-box;
  }

  .comparison-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  .comparison-arrow {
    transform: rotate(90deg);
  }

  .history-colors {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* 반응형: 모바일 */
@media (max-width: 480px) {
  .color-inverter-container {
    margin: 10px 5px;
    padding: 10px;
    width: calc(100% - 10px);
    max-width: 100%;
    box-sizing: border-box;
    border-width: 1px;
  }

  .calculator-header h2 {
    font-size: 22px;
  }

  .subtitle {
    font-size: 13px;
  }

  .quick-actions {
    flex-direction: column;
  }

  .btn-sample,
  .btn-reset {
    width: 100%;
    justify-content: center;
  }

  .rgb-inputs {
    grid-template-columns: 1fr;
  }

  .preview-box {
    height: 140px;
  }

  .preview-hex {
    font-size: 16px;
    padding: 10px 18px;
  }

  .comparison-preview {
    height: 100px;
  }

  .history-colors {
    grid-template-columns: repeat(4, 1fr);
  }

  .color-info-grid {
    grid-template-columns: 1fr;
  }

  .section-title {
    font-size: 15px;
  }

  .info-content li {
    font-size: 13px;
  }
}