/* mobile-optimized.css - 모든 화면의 모바일 최적화 */

/* ===========================
   기본 설정 및 변수
   =========================== */
:root {
  --primary-color: #e63946;
  --primary-dark: #c1121f;
  --secondary-color: #457b9d;
  --light-bg: #f1faee;
  --dark-text: #1d3557;
  --gray-text: #6c757d;
  --accent-color: #ffb703;
  --success-color: #2a9d8f;
  --box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  --box-shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.12);
  --border-radius: 12px;
  --mobile-padding: 1rem;
  --touch-target-size: 44px;
  --header-height: 60px;
}

/* ===========================
   모바일 우선 기본 스타일
   =========================== */
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

body {
  margin: 0;
  padding: 0;
  padding-top: var(--header-height);
  overscroll-behavior-y: contain;
}

/* ===========================
   헤더 모바일 최적화
   =========================== */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--mobile-padding);
  margin: 0 !important;
  border-radius: 0 !important;
}

.logo {
  font-size: 1.3rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.logo::before {
  width: 20px;
  height: 20px;
}

/* 데스크톱 네비게이션 숨기기 */
@media (max-width: 768px) {
  .header nav {
    display: none !important;
  }
  
  .auth-box {
    display: none !important;
  }
}

/* ===========================
   햄버거 메뉴 개선
   =========================== */
.hamburger-menu {
  width: var(--touch-target-size);
  height: var(--touch-target-size);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: transparent;
  border: none;
  padding: 10px;
  cursor: pointer;
  position: relative;
}

@media (min-width: 769px) {
  .hamburger-menu {
    display: none;
  }
}

.hamburger-menu span {
  width: 24px;
  height: 2px;
  background: var(--dark-text);
  margin: 3px 0;
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  border-radius: 2px;
}

.hamburger-menu.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.hamburger-menu.active span:nth-child(2) {
  opacity: 0;
  transform: scale(0);
}

.hamburger-menu.active span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -6px);
}

/* ===========================
   모바일 네비게이션 개선
   =========================== */
.mobile-nav {
  position: fixed;
  top: 0;
  right: -100%;
  width: 85%;
  max-width: 320px;
  height: 100vh;
  background: white;
  box-shadow: -5px 0 15px rgba(0, 0, 0, 0.1);
  transition: right 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  z-index: 2000;
  display: flex;
  flex-direction: column;
}

.mobile-nav.active {
  right: 0;
}

.mobile-nav-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.2rem var(--mobile-padding);
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: white;
}

.mobile-nav-title {
  font-weight: 600;
  font-size: 1.2rem;
}

.close-mobile-nav {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.3s ease;
}

.close-mobile-nav::before {
  content: '×';
  font-size: 28px;
  color: white;
  line-height: 1;
}

.mobile-nav-menu {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0;
}

.mobile-nav-menu a {
  display: flex;
  align-items: center;
  min-height: var(--touch-target-size);
  padding: 0.875rem 1.5rem;
  color: var(--dark-text);
  text-decoration: none;
  transition: all 0.2s ease;
  font-size: 1rem;
  position: relative;
  gap: 12px;
}

.mobile-nav-menu a::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  background: var(--primary-color);
  transition: height 0.3s ease;
}

.mobile-nav-menu a.active::before,
.mobile-nav-menu a:active::before {
  height: 60%;
}

.mobile-nav-menu a:active {
  background: rgba(230, 57, 70, 0.05);
}

.mobile-nav-menu a.active {
  background: rgba(230, 57, 70, 0.1);
  color: var(--primary-color);
  font-weight: 600;
}

/* ===========================
   컨테이너 모바일 최적화
   =========================== */
.container {
  max-width: 100%;
  margin: 0;
  padding: var(--mobile-padding);
  background: white;
  border-radius: 0;
  min-height: calc(100vh - var(--header-height));
  overflow: visible !important;
}

@media (min-width: 769px) {
  .container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    overflow: visible !important;
  }
  
  .filter-section {
    overflow: visible !important;
    position: relative;
    z-index: 100;
  }
}

/* ===========================
   필터 섹션 모바일 최적화
   =========================== */
.filter-section {
  position: relative;
  background: #f8f9fa;
  z-index: 5;
  padding: 1rem;
  margin: 0 0 1rem 0;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  overflow: visible !important;
  -webkit-overflow-scrolling: touch;
}

/* 카테고리 필터 스크롤 가능하게 */
#categoryFilter {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

#categoryFilter::-webkit-scrollbar {
  display: none;
}

.category-btn {
  flex-shrink: 0;
  min-height: var(--touch-target-size);
  padding: 0.6rem 1.2rem;
  white-space: nowrap;
}

/* 국가 필터 드롭다운으로 변경 */
#countryFilter {
  margin-bottom: 0.5rem;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

#countryFilter::-webkit-scrollbar {
  display: none;
}


/* 도시 필터 개선 */
.city-filter-container {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.city-filter-input {
  flex: 1;
  min-height: var(--touch-target-size);
  padding: 0.75rem;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  font-size: 16px;
}

.city-filter-container button {
  min-width: 80px;
  min-height: var(--touch-target-size);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  white-space: nowrap;
}

/* ===========================
   검색 바 모바일 최적화
   =========================== */
.filter-bar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1rem 0;
}

.search-box {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

#searchInput {
  flex: 1 1 auto;
  min-width: 100px;
  max-width: none;
  height: var(--touch-target-size);
  padding: 0.75rem;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  font-size: 16px;
  width: auto;
}

#searchBtn {
  flex: 0 0 auto;
  flex-shrink: 0;
  width: auto;
  min-width: auto;
  height: var(--touch-target-size);
  padding: 0.75rem 0.75rem;
  background: var(--secondary-color);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.85rem;
  white-space: nowrap;
}

.refresh-btn {
  flex-shrink: 0;
  width: var(--touch-target-size) !important;
  height: var(--touch-target-size) !important;
  min-width: var(--touch-target-size);
  min-height: var(--touch-target-size);
  padding: 0.6rem !important;
}

.filter-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.filter-options select {
  min-height: var(--touch-target-size);
  padding: 0.75rem;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  font-size: 16px;
  background: white;
}

/* ===========================
   도전 카드 모바일 최적화
   =========================== */
#challengeList {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

@media (min-width: 576px) {
  #challengeList {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
  }
}

.card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  padding: 1.2rem;
  position: relative;
  transition: all 0.3s ease;
  cursor: pointer;
  overflow: hidden;
}

.card:active {
  transform: scale(0.98);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

@media (hover: hover) {
  .card:hover {
    transform: translateY(-3px);
    box-shadow: var(--box-shadow-hover);
  }
}

.card h3 {
  font-size: 1.1rem;
  margin: 0 0 0.75rem 0;
  color: var(--dark-text);
  line-height: 1.3;
}

.card p {
  font-size: 0.9rem;
  margin: 0.5rem 0;
  color: var(--gray-text);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 카드 내 배지 스타일 */
.category-badge,
.country-badge,
.city-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.7rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  margin: 0 0.25rem 0.5rem 0;
  gap: 4px;
}

.category-badge {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.country-badge {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
}

.city-badge {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  color: white;
}

/* 카드 내 액션 버튼 */
.card a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0.6rem 1.2rem;
  background: var(--primary-color);
  color: white;
  text-decoration: none;
  border-radius: 20px;
  font-weight: 500;
  margin-top: 1rem;
  gap: 6px;
  transition: all 0.3s ease;
}

.card a:active {
  transform: scale(0.95);
}

/* ===========================
   빈 상태 UI 모바일 최적화
   =========================== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
}

.empty-state img {
  width: 80px;
  height: 80px;
  margin-bottom: 1.5rem;
  opacity: 0.6;
}

.empty-state p {
  font-size: 1.1rem;
  color: var(--gray-text);
  margin-bottom: 1.5rem;
}

#createFirstChallenge {
  min-height: var(--touch-target-size);
  padding: 0.875rem 2rem;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: white;
  border: none;
  border-radius: 25px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(230, 57, 70, 0.3);
  transition: all 0.3s ease;
}

#createFirstChallenge:active {
  transform: scale(0.95);
}

/* ===========================
   푸터 모바일 최적화
   =========================== */
footer {
  background: var(--dark-text);
  color: white;
  padding: 2rem var(--mobile-padding);
  text-align: center;
  margin-top: 3rem;
  border-radius: 0;
}

footer .copyright {
  font-size: 0.75rem;
  opacity: 0.8;
  line-height: 1.5;
  margin-top: 1rem;
}

.social-links {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin: 1rem 0;
}

.social-icon {
  width: var(--touch-target-size);
  height: var(--touch-target-size);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  transition: all 0.3s ease;
}

.social-icon:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.2);
}

.social-icon img {
  width: 20px;
  height: 20px;
  filter: invert(1);
}

.mobile-lang-section {
  padding: 1rem;
  border-top: 1px solid #eee;
  margin-top: auto;
}

.mobile-lang-toggle {
  width: 100%;
  min-height: var(--touch-target-size);
  padding: 0.875rem;
  background: linear-gradient(135deg, var(--secondary-color), #3a6186);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.3s ease;
}

.mobile-lang-toggle:active {
  transform: scale(0.98);
}

/* ===========================
   인증 섹션 모바일 최적화
   =========================== */
.mobile-auth-section {
  padding: 1rem;
  background: #f8f9fa;
  border-top: 1px solid #eee;
}

.mobile-user-info {
  text-align: center;
  padding: 0.75rem;
  background: white;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: var(--dark-text);
}

.mobile-login-btn,
.mobile-logout-btn {
  width: 100%;
  min-height: var(--touch-target-size);
  padding: 0.875rem;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.mobile-login-btn {
  background: var(--primary-color);
  color: white;
}

.mobile-logout-btn {
  background: #e9ecef;
  color: var(--dark-text);
}

.mobile-login-btn:active,
.mobile-logout-btn:active {
  transform: scale(0.98);
}

/* ===========================
   오버레이 개선
   =========================== */
.mobile-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1999;
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.mobile-overlay.active {
  display: block;
  opacity: 1;
}

/* ===========================
   Safe Area 대응 (iPhone)
   =========================== */
@supports (padding: max(0px)) {
  .header {
    padding-top: max(0, env(safe-area-inset-top));
    height: calc(var(--header-height) + env(safe-area-inset-top));
  }
  
  body {
    padding-top: calc(var(--header-height) + env(safe-area-inset-top));
  }
  
  .filter-section {
    top: calc(var(--header-height) + env(safe-area-inset-top));
  }
  
  .mobile-nav {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  
  .container {
    padding-bottom: calc(var(--mobile-padding) + env(safe-area-inset-bottom));
  }
  
  footer {
    padding-bottom: calc(2rem + env(safe-area-inset-bottom));
  }
}

/* ===========================
   가로 모드 대응
   =========================== */
@media (max-height: 500px) and (orientation: landscape) {
  .header {
    height: 50px;
  }
  
  body {
    padding-top: 50px;
  }
  
  .filter-section {
    top: 50px;
    padding: 0.5rem var(--mobile-padding);
  }
  
  .container {
    padding: 0.75rem;
  }
  
  .card {
    padding: 0.75rem;
  }
  
  .empty-state {
    min-height: 30vh;
    padding: 2rem 1rem;
  }
}

/* ===========================
   성능 최적화
   =========================== */
@media (max-width: 768px) {
  /* GPU 가속 */
  .card,
  .mobile-nav,
  .hamburger-menu span,
  button {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
  }
  
  /* 스크롤 성능 */
  .container,
  .mobile-nav-menu,
  #challengeList {
    -webkit-overflow-scrolling: touch;
  }
  
  /* 애니메이션 단순화 */
  * {
    animation-duration: 0.3s !important;
  }
}

/* ===========================
   접근성 개선
   =========================== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* 포커스 스타일 개선 */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--primary-color);
  outline-offset: 2px;
}

/* 다크 모드 지원 */
@media (prefers-color-scheme: dark) {
  :root {
    --light-bg: #1a1a1a;
    --dark-text: #f0f0f0;
    --gray-text: #b0b0b0;
  }
  
  body {
    background: #0d0d0d;
    color: var(--dark-text);
  }
  
  .header,
  .container,
  .card,
  .mobile-nav {
    background: #1a1a1a;
  }
  
  .mobile-nav-header {
    background: linear-gradient(135deg, #2d2d2d, #1a1a1a);
  }
  
  input,
  select,
  textarea {
    background: #2d2d2d;
    color: var(--dark-text);
    border-color: #404040;
  }
}

/* ===========================
   폼 요소 모바일 최적화 (create.html)
   =========================== */
#challengeForm {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group label {
  font-weight: 600;
  color: var(--dark-text);
  font-size: 0.95rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  min-height: var(--touch-target-size);
  padding: 0.875rem;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  font-size: 16px;
  background: white;
  transition: all 0.3s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(230, 57, 70, 0.1);
}

.form-group textarea {
  min-height: 120px;
  resize: vertical;
}

/* 카테고리 선택기 모바일 최적화 */
#categorySelector {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#mainCategory,
#subCategory {
  width: 100%;
  min-height: var(--touch-target-size);
  padding: 0.875rem;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  font-size: 16px;
  background: white;
}

/* 미리보기 섹션 모바일 최적화 */
.preview-section {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 1.2rem;
  margin: 1.5rem 0;
}

.preview-title {
  font-weight: 600;
  color: var(--dark-text);
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

.preview-card {
  background: white;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.preview-card h3 {
  font-size: 1.1rem;
  margin: 0 0 0.75rem 0;
  color: var(--dark-text);
}

.preview-card p {
  font-size: 0.9rem;
  margin: 0.5rem 0;
  color: var(--gray-text);
}

/* 제출 버튼 모바일 최적화 */
#challengeForm button[type="submit"] {
  min-height: calc(var(--touch-target-size) + 8px);
  padding: 1rem;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 1.5rem;
  box-shadow: 0 4px 15px rgba(230, 57, 70, 0.3);
  transition: all 0.3s ease;
}

#challengeForm button[type="submit"]:active {
  transform: scale(0.98);
}

/* 팁 섹션 모바일 최적화 */
.form-tip {
  background: linear-gradient(135deg, #ffeaa7, #fdcb6e);
  padding: 1rem;
  border-radius: 8px;
  margin: 1rem 0;
  font-size: 0.9rem;
  line-height: 1.5;
}

.form-tip strong {
  color: var(--dark-text);
}