/*!
 * SyBlog - Fully Responsive CSS v2.0
 * 모든 기기(320px~4K) 완벽 반응형
 */

/* ════════════════════════════════════════════
   0. 전역 리셋 & 기본
════════════════════════════════════════════ */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  padding-top: 56px;   /* sticky navbar 높이 */
  overflow-x: hidden;
  word-break: break-word;
}

img, video, iframe {
  max-width: 100%;
  height: auto;
}

/* 텍스트 선택 색 */
::selection { background: rgba(108,99,255,.25); }

/* ════════════════════════════════════════════
   1. 반응형 폰트 (clamp 사용)
════════════════════════════════════════════ */
html { font-size: clamp(13px, 2.5vw, 17px); }

h1 { font-size: clamp(1.5rem, 5vw, 2.4rem); }
h2 { font-size: clamp(1.3rem, 4vw, 2rem);   }
h3 { font-size: clamp(1.1rem, 3.5vw, 1.6rem);}
h4 { font-size: clamp(1rem,   3vw, 1.3rem);  }
h5 { font-size: clamp(.9rem,  2.5vw, 1.1rem);}
h6 { font-size: clamp(.85rem, 2vw, 1rem);    }

/* ════════════════════════════════════════════
   2. 내비게이션바
════════════════════════════════════════════ */
.navbar {
  padding: .4rem 1rem !important;
  min-height: 54px;
}

.navbar-brand {
  font-size: clamp(1rem, 3.5vw, 1.3rem) !important;
  font-weight: 800 !important;
  white-space: nowrap;
}

/* 모바일 메뉴 드롭다운 */
@media (max-width: 991px) {
  .navbar-collapse {
    background: linear-gradient(135deg, #2d3436, #6c63ff);
    border-radius: 0 0 14px 14px;
    padding: 8px 0 12px;
    margin-top: 6px;
    box-shadow: 0 10px 30px rgba(0,0,0,.3);
    max-height: 70vh;
    overflow-y: auto;
  }
  .navbar-collapse .nav-link {
    padding: 10px 20px !important;
    border-bottom: 1px solid rgba(255,255,255,.07);
    font-size: .93rem !important;
  }
  .navbar-collapse .nav-link:last-child { border-bottom: none; }
  .navbar-nav .dropdown-menu {
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 10px;
    margin: 4px 14px;
  }
  .navbar-nav .dropdown-item {
    color: rgba(255,255,255,.85) !important;
    padding: 8px 16px;
    font-size: .88rem;
  }
  .navbar-nav .dropdown-item:hover {
    background: rgba(108,99,255,.35);
    color: #fff !important;
  }
  /* 모바일 크레딧 배지 */
  #ai-credit-badge-mobile, .ai-credit-badge-shared {
    font-size: .7rem !important;
    padding: 3px 8px !important;
    border-radius: 12px !important;
  }
}

/* 초소형 모바일(320px) */
@media (max-width: 360px) {
  .navbar { padding: .3rem .6rem !important; }
  .navbar-brand { font-size: .95rem !important; }
}

/* ════════════════════════════════════════════
   3. 컨테이너 & 레이아웃
════════════════════════════════════════════ */
.container {
  padding-left: 15px;
  padding-right: 15px;
}

@media (max-width: 576px) {
  .container {
    padding-left: 10px;
    padding-right: 10px;
  }
}

@media (max-width: 360px) {
  .container {
    padding-left: 6px;
    padding-right: 6px;
  }
}

/* ════════════════════════════════════════════
   4. 카드
════════════════════════════════════════════ */
.card {
  border-radius: 12px !important;
  overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}

.card-img-top {
  height: 200px;
  object-fit: cover;
}

@media (max-width: 768px) {
  .card-img-top { height: 180px; }
}

@media (max-width: 576px) {
  .card {
    border-radius: 10px !important;
    margin-bottom: 12px !important;
  }
  .card-body  { padding: 12px !important; }
  .card-header { padding: 10px 12px !important; font-size: .88rem !important; }
  .card-footer { padding: 8px 12px !important; font-size: .8rem !important; }
  .card-img-top { height: 150px; }
  .card-title { font-size: .95rem !important; line-height: 1.4; }
}

@media (max-width: 360px) {
  .card-img-top { height: 130px; }
  .card-body { padding: 10px !important; }
}

/* ════════════════════════════════════════════
   5. 버튼
════════════════════════════════════════════ */
@media (max-width: 576px) {
  .btn {
    padding: 6px 12px;
    font-size: .85rem;
    border-radius: 8px !important;
  }
  .btn-sm {
    padding: 4px 9px;
    font-size: .78rem;
  }
  .btn-lg {
    padding: 10px 18px;
    font-size: .95rem;
  }
  /* 블록 버튼 스택 */
  .btn-block + .btn-block { margin-top: 6px; }
}

/* ════════════════════════════════════════════
   6. 폼
════════════════════════════════════════════ */
.form-control {
  font-size: .9rem;
  padding: 8px 12px;
  border-radius: 8px !important;
}

@media (max-width: 576px) {
  .form-control {
    font-size: 16px !important; /* iOS 자동 확대 방지 */
    padding: 9px 12px;
  }
  textarea.form-control { min-height: 110px; }
  .input-group { flex-wrap: nowrap; }
  .input-group .form-control { min-width: 0; flex: 1; }
  .input-group-append .btn { padding: 8px 12px; }
  select.form-control { font-size: 16px !important; }
}

/* ════════════════════════════════════════════
   7. 사이드바
════════════════════════════════════════════ */
.sidebar-widget {
  padding: 16px !important;
  border-radius: 12px;
  margin-bottom: 14px;
}

@media (max-width: 991px) {
  /* 태블릿: 사이드바를 메인 아래 */
  .sidebar-widget { padding: 13px !important; }
  .sidebar-widget h5 { font-size: .88rem !important; }
}

@media (max-width: 576px) {
  .sidebar-widget { padding: 10px !important; border-radius: 10px; margin-bottom: 10px; }
  .sidebar-widget h5 { font-size: .82rem !important; margin-bottom: 8px !important; padding-bottom: 5px !important; }
  /* 사이드바 아바타 */
  .sidebar-widget .rounded-circle { width: 46px !important; height: 46px !important; }
  /* 레벨 배지 */
  .level-badge { font-size: .68rem !important; padding: 2px 8px !important; }
  /* 사이드바 버튼들 */
  .sidebar-widget .btn-sm { font-size: .75rem !important; padding: 4px 8px !important; }
}

/* ════════════════════════════════════════════
   8. 게시글 상세
════════════════════════════════════════════ */
.post-detail-content {
  font-size: .97rem;
  line-height: 1.8;
}

@media (max-width: 576px) {
  .post-detail-content {
    font-size: .9rem;
    line-height: 1.75;
  }
  .post-detail-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
  }
  .post-detail-content pre {
    overflow-x: auto;
    font-size: .76rem;
    padding: 10px;
    border-radius: 8px;
    white-space: pre;
    -webkit-overflow-scrolling: touch;
  }
  .post-detail-content code {
    font-size: .78rem;
    word-break: break-word;
  }
  .post-detail-content table {
    font-size: .8rem;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .post-detail-content blockquote {
    padding: 10px 14px;
    font-size: .88rem;
    margin-left: 0;
    margin-right: 0;
  }
  .post-detail-content h1 { font-size: 1.4rem; }
  .post-detail-content h2 { font-size: 1.2rem; }
  .post-detail-content h3 { font-size: 1.05rem; }
}

/* ════════════════════════════════════════════
   9. 댓글
════════════════════════════════════════════ */
@media (max-width: 576px) {
  .comment-item { padding: 10px !important; }
  .comment-form textarea { font-size: 16px !important; }
  .comment-avatar { width: 32px !important; height: 32px !important; }
}

/* ════════════════════════════════════════════
  10. 페이지네이션
════════════════════════════════════════════ */
@media (max-width: 576px) {
  .pagination {
    flex-wrap: wrap;
    justify-content: center;
    gap: 3px;
  }
  .page-link {
    padding: 5px 9px;
    font-size: .78rem;
    border-radius: 6px !important;
  }
}

/* ════════════════════════════════════════════
  11. 테이블
════════════════════════════════════════════ */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
}

@media (max-width: 576px) {
  table { font-size: .78rem; }
  th, td { padding: 6px 8px !important; }
  .table-sm th, .table-sm td { padding: 4px 6px !important; }
}

/* ════════════════════════════════════════════
  12. 모달
════════════════════════════════════════════ */
@media (max-width: 576px) {
  .modal-dialog {
    margin: 8px !important;
    max-width: calc(100% - 16px) !important;
  }
  .modal-body { padding: 14px !important; }
  .modal-header { padding: 12px 14px !important; }
  .modal-footer { padding: 10px 14px !important; flex-wrap: wrap; gap: 6px; }
  .modal-footer .btn { flex: 1; min-width: 80px; }
}

/* ════════════════════════════════════════════
  13. 알림/공지 배너
════════════════════════════════════════════ */
.notice-banner {
  font-size: .85rem;
  padding: 8px 12px !important;
}

@media (max-width: 576px) {
  .notice-banner {
    font-size: .78rem !important;
    padding: 6px 10px !important;
  }
  .notice-banner .container { gap: 5px !important; }
  .alert { font-size: .83rem; padding: 9px 12px; }
}

/* ════════════════════════════════════════════
  14. 토스트
════════════════════════════════════════════ */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: min(320px, calc(100vw - 40px));
}

@media (max-width: 576px) {
  #toast-container {
    bottom: 10px;
    right: 8px;
    left: 8px;
    max-width: 100%;
  }
}

.toast-msg {
  background: #2d3436;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: .84rem;
  box-shadow: 0 4px 18px rgba(0,0,0,.35);
  animation: slideUp .3s ease;
  word-break: break-word;
  pointer-events: all;
}
.toast-msg.error  { background: #ef4444; }
.toast-msg.warn   { background: #f59e0b; }
.toast-msg.success{ background: #10b981; }

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ════════════════════════════════════════════
  15. 크레딧 샵
════════════════════════════════════════════ */
.credit-package-card {
  transition: transform .15s, box-shadow .15s;
  cursor: pointer;
  border-radius: 14px !important;
}
.credit-package-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 28px rgba(0,0,0,.15) !important;
}

@media (max-width: 576px) {
  .credit-status-card { position: static !important; }
  .credit-package-card .card-body { padding: 14px !important; }
  .credit-package-card .display-1 { font-size: 2.2rem !important; }
}

@media (max-width: 400px) {
  /* 크레딧 카드 1열 */
  .credit-package-card { margin-bottom: 10px; }
}

/* ════════════════════════════════════════════
  16. AI 웹빌더
════════════════════════════════════════════ */

/* 프로젝트 에디터 레이아웃 */
#editor-layout {
  display: flex;
  height: calc(100vh - 56px);
  overflow: hidden;
}

/* 사이드바 파일트리 */
#file-sidebar {
  width: 220px;
  min-width: 180px;
  flex-shrink: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border-color, #eee);
  background: var(--card-bg, #fff);
}

/* 메인 패널 */
#main-panel {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* 모바일 웹빌더 */
@media (max-width: 768px) {
  #editor-layout {
    flex-direction: column;
    height: auto;
  }
  #file-sidebar {
    width: 100%;
    min-width: unset;
    height: auto;
    max-height: 160px;
    border-right: none;
    border-bottom: 1px solid var(--border-color, #eee);
  }
  #main-panel {
    height: calc(100vh - 200px);
  }
}

/* 기능 안내 카드 (2x2 그리드) */
@media (max-width: 576px) {
  .col-6.col-md-3 {
    padding: 5px !important;
  }
  .col-6.col-md-3 .card {
    padding: 10px !important;
  }
  .col-6.col-md-3 .card div[style*="font-size:2rem"] {
    font-size: 1.6rem !important;
  }
  .col-6.col-md-3 small.fw-bold {
    font-size: .73rem !important;
  }
  .col-6.col-md-3 small.text-muted {
    font-size: .68rem !important;
  }
}

/* 모바일 탭바 */
#mobile-tab-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--card-bg, #fff);
  border-top: 1px solid var(--border-color, #eee);
  box-shadow: 0 -4px 20px rgba(0,0,0,.12);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

@media (max-width: 768px) {
  #mobile-tab-bar { display: flex; }
  /* 탭바 있을 때 바디 하단 패딩 */
  body.webdev-page { padding-bottom: 60px; }
}

#mobile-tab-bar button {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 4px;
  font-size: .7rem;
  color: #636e72;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  transition: color .2s;
}
#mobile-tab-bar button .icon { font-size: 1.2rem; }
#mobile-tab-bar button.active { color: #6c63ff; }
#mobile-tab-bar button:active { opacity: .7; }

/* 백그라운드 진행 표시 */
#bg-progress {
  display: none;
  position: fixed;
  bottom: 70px;
  left: 10px;
  right: 10px;
  z-index: 1100;
  background: rgba(30,30,46,.95);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

@media (min-width: 769px) {
  #bg-progress {
    bottom: 20px;
    left: auto;
    right: 20px;
    width: 320px;
  }
}

/* ════════════════════════════════════════════
  17. 대시보드
════════════════════════════════════════════ */
@media (max-width: 576px) {
  .row.g-3 > [class*="col-"] {
    padding-left: 6px;
    padding-right: 6px;
    margin-bottom: 8px;
  }
  /* 통계 카드 */
  .stat-card {
    padding: 12px !important;
  }
  .stat-card .display-4 {
    font-size: 2rem !important;
  }
}

/* ════════════════════════════════════════════
  18. 게시글 목록
════════════════════════════════════════════ */
@media (max-width: 576px) {
  /* 포스트 카드 푸터 아이콘들 */
  .card-footer .d-flex { flex-wrap: wrap; gap: 4px; }
  .card-footer small { font-size: .73rem; }
  /* 작성자 정보 */
  .card-footer .rounded-circle { width: 22px !important; height: 22px !important; }
  /* 더 보기 버튼 */
  .card-body .btn-sm { font-size: .78rem; padding: 4px 10px; }
}

/* ════════════════════════════════════════════
  19. 리더보드 / 챌린지
════════════════════════════════════════════ */
@media (max-width: 576px) {
  .leaderboard-item { padding: 8px 10px !important; }
  .leaderboard-rank { font-size: 1.1rem !important; min-width: 28px !important; }
  .leaderboard-avatar { width: 36px !important; height: 36px !important; }
}

/* ════════════════════════════════════════════
  20. 푸터
════════════════════════════════════════════ */
footer {
  margin-top: 20px !important;
  padding: 20px 0 !important;
  font-size: .85rem;
}

@media (max-width: 767px) {
  footer .col-md-4 {
    margin-bottom: 12px;
    text-align: center !important;
  }
  footer .text-right {
    text-align: center !important;
  }
}

@media (max-width: 576px) {
  footer { padding: 16px 0 !important; font-size: .78rem; }
}

/* ════════════════════════════════════════════
  21. 읽기 진행률 바
════════════════════════════════════════════ */
#reading-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, #6c63ff, #48cfad);
  z-index: 10000;
  transition: width .1s;
  pointer-events: none;
}

/* ════════════════════════════════════════════
  22. 자동완성 드롭다운
════════════════════════════════════════════ */
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1050;
  background: var(--card-bg, #fff);
  border: 1px solid var(--border-color, #eee);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
  max-height: 260px;
  overflow-y: auto;
}

.autocomplete-item {
  padding: 9px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .88rem;
}
.autocomplete-item:hover { background: rgba(108,99,255,.08); }

@media (max-width: 576px) {
  .autocomplete-dropdown { border-radius: 0 0 10px 10px; }
  .autocomplete-item { padding: 9px 12px; font-size: .82rem; }
}

/* ════════════════════════════════════════════
  23. 크레딧 배지 애니메이션
════════════════════════════════════════════ */
.ai-credit-badge-shared {
  display: inline-flex !important;
  align-items: center;
  gap: 3px;
  transition: background .3s, transform .2s;
  white-space: nowrap;
}

@keyframes pulse {
  0%, 100% { opacity: 1;   transform: scale(1);    }
  50%       { opacity: .75; transform: scale(1.05); }
}

/* ════════════════════════════════════════════
  24. 검색 페이지
════════════════════════════════════════════ */
@media (max-width: 576px) {
  .search-result-item { padding: 12px !important; }
  .search-highlight   { font-size: .82rem; }
}

/* ════════════════════════════════════════════
  25. 랜딩 페이지
════════════════════════════════════════════ */
@media (max-width: 576px) {
  .hero-section { padding: 40px 0 30px !important; }
  .hero-section h1 { font-size: clamp(1.5rem, 8vw, 2.2rem); }
  .hero-section p  { font-size: .9rem; }
  .feature-card    { padding: 16px !important; }
  .feature-icon    { font-size: 2.2rem !important; }
}

/* ════════════════════════════════════════════
  26. 배지/뱃지 시스템
════════════════════════════════════════════ */
@media (max-width: 576px) {
  .badge-grid       { grid-template-columns: repeat(3, 1fr) !important; gap: 8px !important; }
  .badge-item       { padding: 8px !important; border-radius: 10px !important; }
  .badge-item .icon { font-size: 1.6rem !important; }
  .badge-item small { font-size: .65rem !important; }
}

/* ════════════════════════════════════════════
  27. 마크다운 에디터 (게시글 작성)
════════════════════════════════════════════ */
@media (max-width: 768px) {
  .markdownx-preview { font-size: .88rem; }
  .markdownx textarea { font-size: 15px !important; min-height: 200px; }
}

@media (max-width: 576px) {
  .markdownx textarea { font-size: 16px !important; }
  /* 게시글 작성 폼 */
  .post-form-container { padding: 12px !important; }
  .post-form-container .form-group { margin-bottom: 12px; }
}

/* ════════════════════════════════════════════
  28. 미니게임 / 챌린지
════════════════════════════════════════════ */
@media (max-width: 576px) {
  .game-card { border-radius: 10px !important; }
  .game-card .card-body { padding: 12px !important; }
  .game-card .card-title { font-size: .88rem !important; }
  canvas { max-width: 100% !important; touch-action: none; }
}

/* ════════════════════════════════════════════
  29. 유틸리티
════════════════════════════════════════════ */

/* iOS safe area */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .navbar.sticky-top { padding-top: env(safe-area-inset-top, 0); }
  #mobile-tab-bar    { padding-bottom: env(safe-area-inset-bottom, 0); }
}

/* 오버플로우 방지 */
.overflow-x-hidden { overflow-x: hidden !important; }

/* 이미지 반응형 */
.img-responsive {
  max-width: 100%;
  height: auto;
  display: block;
}

/* flex gap 호환 (구형 브라우저) */
.gap-1 { gap: .25rem !important; }
.gap-2 { gap: .5rem  !important; }
.gap-3 { gap: 1rem   !important; }

/* 터치 타겟 최소 크기 (접근성) */
@media (max-width: 768px) {
  a, button, [role="button"] {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }
  /* 단, 인라인 링크 예외 */
  p a, li a, td a, .dropdown-item {
    min-height: unset;
    display: inline;
  }
}

/* 스크롤바 스타일 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(108,99,255,.4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(108,99,255,.7); }

/* ════════════════════════════════════════════
  30. 다크모드 반응형 보완
════════════════════════════════════════════ */
html.dark-mode .autocomplete-dropdown { box-shadow: 0 8px 24px rgba(0,0,0,.5); }
html.dark-mode .toast-msg { box-shadow: 0 4px 18px rgba(0,0,0,.6); }
html.dark-mode .navbar-collapse { background: linear-gradient(135deg, #0f3460, #6c63ff); }

/* ── i18n 언어 토글 ── */
.lang-toggle {
  display: flex; align-items: center; gap: 4px;
  cursor: pointer; font-size: .75rem; font-weight: 700;
  color: rgba(255,255,255,.85); padding: 5px 10px;
  background: rgba(255,255,255,.1); border-radius: 20px;
  border: 1px solid rgba(255,255,255,.2); transition: .15s;
}
.lang-toggle:hover { background: rgba(255,255,255,.2); }

/* ── PWA 오프라인 배너 ── */
#offline-banner {
  display: none; position: fixed; bottom: 20px; left: 50%;
  transform: translateX(-50%); z-index: 9999;
  background: #2d3436; color: #fff; padding: 10px 20px;
  border-radius: 20px; font-size: .85rem; font-weight: 700;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
}

/* ── 원형 아바타 찌그러짐 방지 ─────────────────────────────────────────
   - object-fit: 정사각형이 아닌 사진도 잘라서 채움 (늘어나 타원 되는 것 방지)
   - flex-shrink:0 : d-flex 안에서 옆 영역에 밀려 가로로 줄어드는 것 방지
   - aspect-ratio : height 속성이 없는 <img width="22"> 같은 곳도 항상 정사각형 */
img.rounded-circle {
  object-fit: cover;
  flex-shrink: 0;
  aspect-ratio: 1 / 1;
}
