/* 완전히 수정된 반응형 CSS - 토글 사이드바 포함 */

/* ===== 기본 설정 강화 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Arial", sans-serif;
  background: linear-gradient(135deg, #1a1a2e, #16213e, #0f3460);
  color: white;
  overflow-x: hidden;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===== 헤더 고정 및 겹침 방지 (모든 화면 크기) ===== */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(15px);
  border-bottom: 1px solid rgba(0, 255, 136, 0.3);
  padding: 15px 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
}

/* ===== 메인 컨테이너 - 헤더 높이에 따른 적응형 마진 ===== */
.main-container {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100vh;
}

/* ===== 홈페이지 레이아웃 ===== */
.home-layout {
  display: flex;
  gap: 20px;
  width: 100%;
}

.home-content {
  flex: 1;
  min-width: 0;
}

/* ===== 사이드바 - 기본 스타일 ===== */
.sidebar {
  background: rgba(0, 0, 0, 0.9);
  border: 1px solid rgba(0, 255, 136, 0.3);
  position: relative;
  z-index: 200;
  flex-shrink: 0;
  transition: all 0.3s ease;
}

/* ===== 토글 버튼 스타일 ===== */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 90px; /* 헤더 아래쪽으로 이동 */
  left: 20px;
  z-index: 10002; /* 사이드바보다 높게 설정 */
  width: 50px;
  height: 50px;
  background: rgba(0, 255, 136, 0.9);
  border: none;
  border-radius: 25px;
  cursor: pointer;
  font-size: 20px;
  color: #1a1a2e;
  box-shadow: 0 4px 15px rgba(0, 255, 136, 0.3);
  transition: all 0.3s ease;
  pointer-events: auto; /* 클릭 이벤트 보장 */
}

.sidebar-toggle:hover {
  background: #00ff88;
  transform: scale(1.1);
}

.sidebar-toggle.active {
  left: 270px;
}

/* ===== 모바일/태블릿 토글 사이드바 ===== */
.sidebar-mobile {
  display: none;
  position: fixed;
  top: 0;
  left: -300px;
  width: 280px;
  height: 100vh;
  background: rgba(0, 0, 0, 0.95);
  border-right: 1px solid rgba(0, 255, 136, 0.3);
  padding: 80px 20px 20px 20px;
  z-index: 10001; /* 헤더보다 높게 설정 */
  transition: left 0.3s ease;
  overflow-y: auto;
  backdrop-filter: blur(15px);
  pointer-events: auto; /* 클릭 이벤트 보장 */
}

.sidebar-mobile.open {
  left: 0;
}

.sidebar-mobile h3 {
  color: #00ff88;
  margin-bottom: 20px;
  font-size: 18px;
}

.sidebar-mobile .game-list,
.sidebar-mobile .tool-list {
  list-style: none;
  display: block;
}

.sidebar-mobile .game-item,
.sidebar-mobile .tool-item {
  padding: 15px 20px;
  margin-bottom: 10px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  border-left: 3px solid transparent;
  color: white;
  text-decoration: none;
  display: block;
  border: 1px solid rgba(0, 255, 136, 0.2);
  font-size: 14px;
  min-height: 50px;
  display: flex;
  align-items: center;
  pointer-events: auto; /* 클릭 이벤트 보장 */
}

.sidebar-mobile .game-item:hover,
.sidebar-mobile .tool-item:hover,
.sidebar-mobile .game-item.active,
.sidebar-mobile .tool-item.active {
  background: rgba(0, 255, 136, 0.2);
  border-left-color: #00ff88;
  border-color: #00ff88;
  color: #00ff88;
}

/* ===== 모바일 오버레이 ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999; /* 헤더보다 낮게, 사이드바보다 낮게 */
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none; /* 기본적으로 클릭 차단 */
}

.sidebar-overlay.open {
  opacity: 1;
  pointer-events: auto; /* 열릴 때만 클릭 허용 */
}

/* ===== 광고 영역 기본 설정 ===== */

.ad-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 0px 20px;
  position: relative;
}

/*
.ad-sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 0px 20px;
  position: relative;
}
*/

.ad-sidebar .ad-slot {
  border: 1px dashed rgba(0, 255, 136, 0.3);
  border-radius: 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 140px;
  height: 450px;
}

.mobile-ads {
  display: none;
  position: relative;
  z-index: 5;
  clear: both;
  margin: 40px 0;
  width: 100%;
}

.mobile-ads .ad-container {
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  padding: 0 20px;
  max-width: 1200px;
}

.mobile-ads .ad-slot {
  border: 1px dashed rgba(0, 255, 136, 0.3);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 5px;
  width: 100%;
  max-width: 728px;
  height: 100px;
}

.ads-hide {
  display: none !important;
}

.about-container .ad-section {
  display: none !important;
}

.about-container .ad-sidebar {
  display: none !important;
}

/* ===== 푸터 그리드 레이아웃 ===== */
.footer-info {
  background: rgba(0, 0, 0, 0.9);
  padding: 30px 20px;
  border-top: 1px solid rgba(0, 255, 136, 0.3);
  position: relative;
  z-index: 10;
  clear: both;
  margin-top: 40px;
}

.footer-section {
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
}

.footer-title {
  font-size: 20px;
  color: #00ff88;
  margin-bottom: 20px;
}

.footer-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
  max-width: 800px;
  margin: 0 auto 30px auto;
}

.footer-item {
  color: #aaa;
  cursor: pointer;
  transition: color 0.3s ease;
  padding: 12px;

  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: none;
}

.footer-item:hover {
  color: #00ff88;
  border-color: rgba(0, 255, 136, 0.5);
}

/* ===== 언어 선택기 ===== */
.footer-language {
  display: block;
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid rgba(0, 255, 136, 0.3);
  text-align: center;
}

.footer-language h4 {
  color: #00ff88;
  margin-bottom: 15px;
  font-size: 16px;
}

.footer-lang-buttons {
  display: flex;
  gap: 15px;
  justify-content: center;
}

.lang-btn {
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(0, 255, 136, 0.3);
  color: white;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 14px;
  min-height: 44px;
}

.lang-btn.active {
  background: #00ff88;
  color: #1a1a2e;
  border-color: #00ff88;
}

.lang-btn:hover {
  border-color: #00ff88;
  background: rgba(0, 255, 136, 0.2);
}

.footer-biz-grid {
  display: flex;
  flex-direction: column;
  gap: 15px;
  max-width: 800px;
  margin: 0 auto 30px auto;
}

/* ===== PC 전용 (1200px 이상) ===== */
@media (min-width: 1200px) {
  .desktop-only {
    display: block !important;
  }
  .tablet-only,
  .mobile-only {
    display: none !important;
  }
  .mobile-ads {
    display: none !important;
  }

  /* 토글 버튼 숨김 */
  .sidebar-toggle {
    display: none !important;
  }

  .sidebar-mobile,
  .sidebar-overlay {
    display: none !important;
  }

  /* 헤더 아래 마진 */
  .main-container {
    padding: 0 40px;
  }

  /* 홈 레이아웃 */
  .home-layout {
    display: flex;
    gap: 20px;
  }

  /* 게임/도구 컨테이너 */
  .games-container,
  .tools-container {
    display: flex !important;
    flex-direction: row !important;
    gap: 30px;
  }

  .sidebar {
    display: block !important;
    width: 250px;
    padding: 20px;
    border-right: 1px solid rgba(0, 255, 136, 0.3);
    border-bottom: none;
    order: 1 !important;
    flex-shrink: 0;
    position: relative;
    left: 0;
  }

  .game-content,
  .tool-content {
    flex: 1;
    min-width: 0;
    order: 2 !important;
  }

  .about-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 40px 20px;
  }

  /* 광고 사이드바 */
  .ad-section {
    display: flex !important;
    flex-direction: column;
    gap: 20px;
    padding: 20px;
    width: 200px;
    order: 3 !important;
    flex-shrink: 0;
  }
  /* 
  .ad-sidebar {
    display: flex !important;
    flex-direction: column;
    gap: 20px;
    padding: 20px;
    width: 200px;
    order: 3 !important;
    flex-shrink: 0;
  }
*/
  /* 게임/도구 사이드바 - 세로 목록 */
  .game-list,
  .tool-list {
    display: block;
    list-style: none;
  }

  .game-item,
  .tool-item {
    margin-bottom: 8px;
    padding: 12px 16px;
    border-radius: 8px;
    min-height: 44px;
    display: flex;
    align-items: center;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(0, 255, 136, 0.2);
    cursor: pointer;
    transition: all 0.3s ease;
    border-left: 3px solid transparent;
  }

  .game-item:hover,
  .tool-item:hover,
  .game-item.active,
  .tool-item.active {
    background: rgba(0, 255, 136, 0.1);
    border-left-color: #00ff88;
  }

  /* About 컨테이너 */
  .about-container {
    display: flex !important;
    gap: 20px;
    margin: 0 auto;
    align-items: flex-start;
  }

  .about-content {
    flex: 1;
    min-width: 0;
    max-width: 800px;
    margin: 0;
    padding: 40px 20px;
    order: 2;
  }

  .home-content {
    flex: 1;
    min-width: 0;
    order: 2;
  }

  .home-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
  }

  /* 푸터 그리드는 4x1 유지 */
  .footer-grid {
    grid-template-columns: repeat(4, 1fr);
    max-width: 800px;
  }

  .ads-hide {
    display: none !important;
  }
}

/* ===== 태블릿 (768px ~ 1199px) ===== */
@media (max-width: 1199px) and (min-width: 768px) {
  .desktop-only {
    display: none !important;
  }
  .tablet-only {
    display: block !important;
  }
  .mobile-only {
    display: none !important;
  }

  /* 광고 사이드바 숨김, 모바일 광고 표시 */

  .ad-section {
    width: 100%;
  }

  .ad-sidebar {
    display: none !important;
  }

  .mobile-ads {
    display: block !important;
  }

  .about-container {
    display: block !important;
  }

  .about-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 40px 20px;
  }

  /* 토글 버튼 표시 */
  .sidebar-toggle {
    display: block !important;
  }

  .sidebar-mobile,
  .sidebar-overlay {
    display: block !important;
  }

  /* 기존 사이드바 숨김 */
  .sidebar {
    display: none !important;
  }

  /* 헤더 아래 마진 */
  .main-container {
    margin-top: 100px;
    padding: 0 20px;
  }

  /* 홈 레이아웃 */
  .home-layout {
    display: block;
  }

  /* 게임/도구 컨테이너 - 전체 너비 사용 */
  .games-container,
  .tools-container {
    display: block !important;
    width: 100%;
    margin-bottom: 3px;
  }

  .game-content,
  .tool-content {
    width: 100%;
    order: 1 !important;
  }

  /* 헤더 조정 */
  .header-container {
    padding: 0 20px;
  }

  .logo {
    font-size: 22px;
  }

  .logo-text {
    font-size: 22px;
  }

  .nav-menu {
    gap: 20px;
  }

  .nav-item {
    padding: 10px 16px;
    font-size: 15px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* 배너 조정 */
  .hero-banner {
    height: 280px;
    margin: 10px -20px 0 -20px;
  }

  .banner-title {
    font-size: 36px;
  }

  .banner-subtitle {
    font-size: 16px;
    padding: 0 20px;
  }

  /* 게임/도구 스타일 조정 */
  .game-header {
    padding: 15px 25px;
  }

  .game-title {
    font-size: 22px;
    margin-left: 40px;
  }

  .game-area {
    min-height: 590px;
    max-height: 600px;
  }

  .game-area-aim,
  .game-area-reaction {
    min-height: 570px;
    max-height: 580px;
  }

  .reaction-area {
    height: 550px;
  }

  .memory-instructions {
    margin-bottom: 10px;
  }

  .memory-grid {
    gap: 13px;
  }

  .memory-controls {
    margin-top: 10px;
  }

  .color-game-area {
    gap: 25px;
    padding: 35px;
  }

  .color-options {
    gap: 15px;
  }

  .tool-header {
    padding: 15px 20px;
  }

  .tool-title {
    font-size: 22px;
    margin-left: 40px;
  }

  .tool-area {
    max-height: 600px;
  }

  /* 푸터 그리드 태블릿에서 4x1 */
  .footer-grid {
    grid-template-columns: repeat(4, 1fr);
    max-width: 800px;
  }

  .ads-hide {
    display: none !important;
  }
}

/* ===== 모바일 (767px 이하) ===== */
@media (max-width: 767px) {
  .desktop-only,
  .tablet-only {
    display: none !important;
  }
  .mobile-only {
    display: block !important;
  }

  /* 광고 사이드바 완전 제거, 모바일 광고 표시 */

  .ad-section {
    width: 100%;
  }

  .ad-sidebar {
    display: none !important;
  }

  .mobile-ads {
    display: block !important;
  }

  .about-container {
    display: block !important;
  }

  .about-content {
    max-width: 100%;
    padding: 25px 20px;
  }

  /* 토글 버튼 표시 */
  .sidebar-toggle {
    display: block !important;
  }

  .sidebar-mobile,
  .sidebar-overlay {
    display: block !important;
  }

  /* 기존 사이드바 숨김 */
  .sidebar {
    display: none !important;
  }

  /* 헤더 높이 조정 */
  .site-header {
    padding: 10px 0;
  }

  .main-container {
    margin-top: 180px;
    padding: 0 15px;
  }

  /* 홈 레이아웃 모바일 버전 */
  .home-layout {
    display: block;
    padding: 0;
  }

  .home-content {
    width: 100%;
  }

  /* 게임/도구 컨테이너 - 전체 너비 사용 */
  .games-container,
  .tools-container {
    display: block !important;
    width: 100%;
  }

  .game-content,
  .tool-content {
    width: 100%;
    order: 1 !important;
  }

  /* 헤더 모바일 최적화 */
  .header-container {
    flex-direction: column;
    gap: 15px;
    padding: 15px;
  }

  .logo {
    font-size: 20px;
  }

  .logo-text {
    font-size: 20px;
  }

  .nav-menu {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    width: 100%;
  }

  .nav-item {
    padding: 12px 18px;
    font-size: 14px;
    min-height: 44px;
    display: flex;
    align-items: center;
    border-radius: 22px;
    flex: 0 0 auto;
  }

  /* 배너 */
  .hero-banner {
    height: 220px;
    margin: 20px -15px 0 -15px;
    position: relative;
    z-index: 1;
  }

  .banner-title {
    font-size: 28px;
    line-height: 1.2;
  }

  .banner-subtitle {
    font-size: 15px;
    padding: 0 20px;
    line-height: 1.4;
  }

  /* 게임/도구 스타일 조정 */
  .game-header {
    padding: 15px 20px;
    margin-top: 20px;
  }

  .game-title {
    font-size: 18px;
  }

  .game-area {
    min-height: 540px;
    max-height: 550px;
  }

  .game-area-aim,
  .game-area-reaction {
    min-height: 500px;
    max-height: 510px;
  }

  .reaction-area {
    height: 470px;
  }

  .start-title {
    font-size: 24px;
  }

  .start-subtitle {
    font-size: 14px;
    padding: 0 15px;
  }

  .game-over-title {
    font-size: 24px;
    margin-bottom: 20px;
  }

  .final-stats {
    gap: 10px;
    margin-bottom: 20px;
  }

  .final-stat-value {
    font-size: 20px;
  }

  .final-stat-label {
    font-size: 14px;
  }

  .memory-instructions {
    margin-top: 0;
    margin-bottom: 5px;
    padding: 0 15px;
  }

  .memory-instructions p {
    font-size: 14px;
    font-weight: bold;
  }

  .memory-grid {
    gap: 10px;
  }

  .memory-card {
    width: 70px;
    height: 70px;
    font-size: 22px;
  }

  .memory-controls {
    margin-top: 5px;
  }

  .color-game-area {
    gap: 20px;
    padding: 30px;
  }

  .color-instruction {
    font-size: 15px;
    margin: 0 auto;
  }

  .target-color {
    width: 120px;
    height: 120px;
  }

  .color-options {
    gap: 10px;
  }

  .color-option {
    width: 100px;
    height: 100px;
  }

  .tool-header {
    padding: 15px 20px;
    margin-top: 20px;
  }

  .tool-title {
    font-size: 18px;
  }

  .tool-area {
    min-height: 550px;
  }

  .text-transformer-form {
    min-height: 600px;
    max-height: 650px;
  }

  .transform-buttons {
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
    font-size: 14px;
  }

  /* 푸터 모바일에서 2x2 */
  .footer-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    max-width: 400px;
  }

  .footer-info {
    padding: 20px 15px;
    margin-top: 40px;
  }

  .footer-item {
    padding: 15px;
    font-size: 15px;
  }

  .footer-language {
    margin-top: 20px;
  }

  .footer-lang-buttons {
    gap: 10px;
  }

  .lang-btn {
    padding: 12px 20px;
    font-size: 14px;
  }

  .footer-biz-item {
    font-size: 11px;
  }

  .ads-hide {
    display: none !important;
  }
}

/* ===== 소형 모바일 (479px 이하) ===== */
@media (max-width: 479px) {
  .main-container {
    margin-top: 200px;
    padding: 0 10px;
  }

  .header-container {
    padding: 12px;
  }

  .logo {
    font-size: 18px;
  }

  .logo-text {
    font-size: 18px;
  }

  .nav-item {
    padding: 10px 15px;
    font-size: 13px;
  }

  .hero-banner {
    height: 180px;
    margin: 20px -10px 0 -10px;
  }

  .banner-title {
    font-size: 22px;
  }

  .banner-subtitle {
    font-size: 13px;
    padding: 0 15px;
  }

  .ad-section {
    width: 100%;
  }

  .mobile-ads {
    padding: 20px 10px;
  }

  .about-content {
    padding: 20px 10px;
  }

  .footer-info {
    padding: 20px 10px;
  }

  .footer-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    max-width: 280px;
  }

  .footer-item {
    font-size: 14px;
  }

  .ads-hide {
    display: none !important;
  }
}

/* ===== 터치 디바이스 전용 개선 ===== */
@media (hover: none) and (pointer: coarse) {
  .nav-item:hover,
  .game-item:hover,
  .tool-item:hover,
  .sitemap-item:hover,
  .footer-item:hover {
    transform: none;
  }

  .nav-item:active,
  .game-item:active,
  .tool-item:active,
  .tool-button:active,
  .start-button:active,
  .restart-button:active,
  .footer-item:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
  }

  .sidebar-toggle:active {
    transform: scale(0.95);
  }
}
