/*=============================================================================
  1. CSS 변수 (커스텀 프로퍼티)
=============================================================================*/

:root {
  /* 폰트 */
  --font-pixel: var(--font-title);

  /* 색상 */
  --color-primary: #2a8af1;
  --color-primary-light: #e9f3fd;
  --color-warning: #ef2b48;
  --color-text: #484c61;
  --color-bg: #fcfcfc;

  /* 전환 타이밍 */
  --transition-fast: 0.1s;
  --transition-normal: 0.25s;
  --transition-slow: 0.3s;
  --easing: ease;
}

/*=============================================================================
  2. 유틸리티 클래스
=============================================================================*/

.pixel-font {
  font-family: var(--font-pixel);
  image-rendering: pixelated;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: grayscale;
  contain: paint;
}

.dn {
  display: none !important;
}

.u-transition {
  transition: all var(--transition-normal) var(--easing);
}
.u-overflow-hidden {
  overflow: hidden;
}

/*=============================================================================
  3. 애니메이션 모음
=============================================================================*/

/* 태그 클릭 시 bump + glow */
@keyframes tagBump {
  0%,
  100% {
    transform: scale(1);
  }
  60% {
    transform: scale(0.95);
  }
}
@keyframes tagGlow {
  0%,
  100% {
    box-shadow: 0 0 0 transparent;
  }
  50% {
    box-shadow: 0 0 8px 2px var(--glow-color);
  }
}
.tag-btn.glowing {
  animation: tagBump var(--transition-fast) ease-out, tagGlow 360ms ease-out;
}

/* 검색 아이콘 흔들기 */
@keyframes shake {
  0%,
  100% {
    transform: translateY(-50%) translateX(0);
  }
  25% {
    transform: translateY(-50%) translateX(-2px);
  }
  75% {
    transform: translateY(-50%) translateX(2px);
  }
}
.search-icon.shake {
  animation: shake 0.3s;
}

/* 인풋 타이핑 시 펄스 */
@keyframes inputPulse {
  0%,
  100% {
    box-shadow: 0 0 0 transparent;
  }
  50% {
    box-shadow: 0 0 6px var(--color-primary);
  }
}
#search-input.typing {
  animation: inputPulse 1s ease-in-out infinite;
}

@keyframes rotate360 {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes changeResetColor {
  0% {
    background-color: var(--color-warning);
    color: #fcfcfc;
  }
  100% {
    background-color: var(--color-bg);
    color: var(--color-warning);
  }
}

.reset-btn.spin .icon {
  animation: rotate360 0.6s ease;
}

.reset-btn.spin {
  animation: changeResetColor 0.6s ease-in-out;
}

.reset-btn {
  cursor: pointer;
  font-size: 12px;
  min-width: 28px;
  height: 28px;
  font-size: 12px;
  border-radius: 4px;
  background-color: var(--color-bg);
  padding: 0 4px;
  color: #999;
  border: 1px solid currentColor;
  transition: color var(--transition-slow) var(--easing),
    background-color var(--transition-slow) var(--easing);
}

.reset-btn .icon {
  display: inline-block;
}

.reset-btn:hover {
  color: var(--color-warning);
}

.reset-btn:active {
  color: #fcfcfc;
  background: var(--color-warning);
}

@keyframes pulseTagGlow {
  0%,
  100% {
    box-shadow: 0 0 15px 0px var(--glow-color);
  }
  50% {
    box-shadow: 0 0 35px 2px var(--glow-color);
  }
}

.tag-glow {
  animation: pulseTagGlow 2s ease-in-out infinite;
}

/*=============================================================================
  4. 컴포넌트별 스타일
=============================================================================*/

/* 4-1 공통 Collapsible */

.collapsible {
  margin-bottom: 10px;
}
.collapsible-header {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 6px;
}

.collapsible-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.collapsible-title:hover {
  background-color: rgba(0, 0, 0, 0.07);
  border-radius: 4px;
}
.collapsible-content {
  height: 0;
  overflow: hidden;
  transition: height var(--transition-slow) var(--easing);
}
.collapsible.open .collapsible-content {
  height: auto; /* JS에서 scrollHeight로 세팅 */
}
.collapsible.collapsed .toggle-icon {
  transform: rotate(-90deg);
}

/* 검색 필터 바디 커스터마이징 */
.tag-filter {
  padding: 5px;
}

.tag-filter-title {
  margin-bottom: 8px;
}

.tag-filter-title .collapsible-title {
  font-size: 24px;
  line-height: 1.2;
  color: #484c61;
  padding: 8px;
  text-shadow: -1px 0 #fcfcfc, 1px 0 #fcfcfc, 0 -1px #fcfcfc, 0 1px #fcfcfc,
    -2px 0 #fcfcfc, 2px 0 #fcfcfc, 0 -2px #fcfcfc, 0 2px #fcfcfc;
}

.tag-filter-body {
  overflow: visible;
  transition: height var(--transition-slow) var(--easing),
    transform var(--transition-slow) var(--easing),
    opacity var(--transition-slow) var(--easing);
  will-change: height, transform, opacity;
}

.tag-filter.collapsed .tag-filter-body {
  overflow: hidden;
  padding-top: 0;
  padding-bottom: 0;
  transform: translateY(-10px);
  opacity: 0;
}

/* 태그 목록 커스터마이징 */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.tag-list .tag-btn {
  /* 기본 숨김 상태 (닫힐 때) */
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.3s ease var(--delay-in),
    transform 0.3s ease var(--delay-in);
}

.tag-group.open .tag-list .tag-btn {
  --delay-in: calc(var(--index) * 50ms);
  opacity: 1;
  transform: translateY(0);
}

.tag-group.collapsed .tag-list .tag-btn {
  --delay-in: calc((var(--btn-count) - var(--index) - 1) * 25ms);
  opacity: 0;
  transform: translateY(6px);
}

/* 태그 목록 크게 닫기 */

.tag-subsection {
  margin-top: 12px;
  padding-left: 12px;
}

.tag-subsection-header {
  font-size: 20px;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 10px;
}

.tag-subsection-header .collapsible-title {
  padding: 6px;
  color: #484c61;
  text-shadow: -1px 0 #fcfcfc, 1px 0 #fcfcfc, 0 -1px #fcfcfc, 0 1px #fcfcfc,
    -2px 0 #fcfcfc, 2px 0 #fcfcfc, 0 -2px #fcfcfc, 0 2px #fcfcfc;
}

.tag-subsection-body {
  padding-top: 4px;
}

/* ============================================================================= */
/* 4-2. 태그 버튼 */

.tag-btn {
  position: relative;
  display: inline-block;
  margin: 0;
  padding: 4px 12px;
  border-radius: 2px;
  font-size: 12px;
  text-decoration: none;
  background-color: var(--color-bg);
  border: 1px solid currentColor;
  color: var(--color-text);

  transition: transform var(--transition-fast) steps(1),
    box-shadow var(--transition-fast) steps(1),
    background-color var(--transition-normal),
    border-color var(--transition-normal), color var(--transition-normal);
}

.tag-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 3px var(--glow-color);
}

.tag-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0);
}

.tag-btn.selected {
  outline: none;
}

/* 태그 group */

.tag-group {
  position: relative;
  margin-bottom: 10px;
  padding-bottom: 8px;
  margin-left: 12px;
  border-bottom: 1px solid #fcfcfc;
  box-shadow: inset 0 -1px 0 #484c61, inset 0 -2px 0 #fcfcfc;
}

.tag-group-name {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 6px;
  user-select: none;
  padding: 4px 4px;
  font-size: 16px;
  color: #484c61;
  text-shadow: -1px 0 #fcfcfc, 1px 0 #fcfcfc, 0 -1px #fcfcfc, 0 1px #fcfcfc;
}

.tag-group-name .toggle-icon {
  transition: transform 0.2s ease;
  display: inline-block;
}

.tag-group:not(.open) .toggle-icon {
  transform: rotate(-90deg);
}

#gallery-area .gall_row,
#gallery-area .gall_row > * {
  will-change: transform, opacity;
}

.fade-in {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 200ms ease, transform 200ms ease;
}
.fade-in.show {
  opacity: 1;
  transform: translateY(0);
}

.empty-state {
  text-align: center;
  padding: 40px 0;
}

.empty-state img {
  max-width: 192px;
  width: 50%;
  height: auto;
  display: block;
  margin: 0 auto 16px;
}

.empty-state p {
  font-family: var(--font-title);
  font-size: 24px;
  color: #484c61;
  white-space: pre-line;
  margin: 0;

  text-shadow: -1px 0 #fcfcfc, 1px 0 #fcfcfc, 0 -1px #fcfcfc, 0 1px #fcfcfc,
    -2px 0 #fcfcfc, 2px 0 #fcfcfc, 0 -2px #fcfcfc, 0 2px #fcfcfc;
}

.search-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  overflow: visible;
  margin-bottom: 12px;
}

.search-wrap {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  padding: 3px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  width: 24px;
  height: 24px;
  transform: translateY(-50%);
  pointer-events: none;
}

#search-input {
  font-family: var(--font-title);
  width: 100%;
  min-width: 0;
  padding: 10px 20px 10px 44px; /* 왼쪽 패딩 조정 */
  font-size: 12px;
  box-sizing: border-box;

  border: 1px solid currentColor;
  border-radius: 999px;

  background-color: #fcfcfc;
  color: #484c61;

  outline: 1px solid #fcfcfc;
  transition: all ease 0.2s;
}

#search-input:focus {
  outline: none;
  box-shadow: 0 0 3px rgba(42, 138, 241, 1);
}

.mode-box {
  flex-shrink: 0;
  background: #fcfcfc;
  border-radius: 4px;
  padding: 5px 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: #484c61;
  border: 1px solid #484c61;
  outline: 1px solid #fcfcfc;
  white-space: nowrap;
}

#toggle-mode {
  outline: none;
  border: 1px solid currentColor;
}

#toggle-mode.flip {
  outline: none;
  color: #fcfcfc;
}

.mode-label {
  font-size: 12px;
  color: #484c61;
  user-select: none;
}

.mode-flip {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: auto;
  min-width: 120px;
  height: 26px;
  border-radius: 25px;
  font-size: 12px;
  background-color: #e9f3fd;
  color: #2a8af1;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.1s steps(1), box-shadow 0.1s steps(1);
  outline: none;
}

.mode-flip.hover-flash,
.mode-flip:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 0 #2a8af1;
}

.mode-flip:active {
  transform: translateY(0);
  box-shadow: 0 2px 0 transparent;
}

.mode-flip span {
  position: absolute;
  width: 100%;
  text-align: center;
  transition: opacity 0.25s ease;
  backface-visibility: hidden;
  padding: 0 10px;
  line-height: 26px;
}

.mode-flip .flip-front {
  opacity: 1;
  background-color: #e9f3fd;
  color: #2a8af1;
}

.mode-flip.flip .flip-front {
  opacity: 0;
}

.mode-flip .flip-back {
  opacity: 0;
  background-color: #2a8af1;
  color: #fcfcfc;
}

.mode-flip.flip .flip-back {
  opacity: 1;
}

/* #filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  width: fit-content;
  user-select: none;
} */

.toggle-icon {
  display: inline-block;
  transition: transform 0.2s ease;
}

.tag-filter.collapsed .toggle-icon {
  transform: rotate(-90deg);
}

#order-box {
  flex-shrink: 0;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

#order-box,
#toggle-order {
  overflow: visible;
}

.order-square {
  font-family: var(--font-title);
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-width: 40px;
  height: 38px;
  font-size: 12px;
  padding: 0 8px;
  border-radius: 4px;
  background-color: #fcfcfc;
  color: #2a8af1;
  border: 1px solid currentColor;
  cursor: pointer;

  transition: transform 0.2s ease;
}

.order-label {
  display: inline-block;
  transform-origin: center;
  backface-visibility: hidden;
}

/* 마이크로 인터랙션 부분 */

/* 검색 시 */
@keyframes shake {
  0%,
  100% {
    transform: translateY(-50%) translateX(0);
  }
  25% {
    transform: translateY(-50%) translateX(-2px);
  }
  75% {
    transform: translateY(-50%) translateX(2px);
  }
}

.search-icon.shake {
  animation: shake 0.3s;
}

/* 검색 결과가 없을 때 */

/* 이미지용 애니메이션 */
.fade-in-stage1 {
  opacity: 0;
  transform: translateY(10px) scale(0.5);
  transition: opacity 500ms ease, transform 500ms ease;
}
.fade-in-stage1.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* 텍스트용 애니메이션 */
.fade-in-stage2 {
  opacity: 0;
  transform: translateY(10px);
  backface-visibility: hidden;
  transition: opacity 500ms ease, transform 500ms ease;
}
.fade-in-stage2.show {
  opacity: 1;
  transform: translateY(0);
}

/* 모드 바꿀때 */
.mode-flip {
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.25s ease, background-color 0.25s ease,
    transform 0.25s ease;
}

.mode-flip::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(42, 138, 241, 0.15);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.mode-flip.flip::after {
  opacity: 1;
}

.mode-flip:active {
  transform: scale(0.96);
  box-shadow: 0 0 10px rgba(42, 138, 241, 0.5);
}

/* 타이핑 시 */
@keyframes inputPulse {
  0% {
    box-shadow: 0 0 0 rgba(42, 138, 241, 0);
  }
  50% {
    box-shadow: 0 0 6px rgba(42, 138, 241, 1);
  }
  100% {
    box-shadow: 0 0 0 rgba(42, 138, 241, 0);
  }
}

#search-input.typing {
  animation: inputPulse 1s ease-in-out infinite;
}

/* order에 마우스 올렸을 때 */
#order-box.hover-flash,
#order-box.hover-enabled:hover {
  transform: rotateZ(-8deg);
}

#order-box.hover-enabled:active {
  transform: rotateZ(2deg);
}
