/* ════════════════════════════════════════════
   styles.css — 전역 스타일 (반응형)
   ════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Gaegu:wght@300;400;700&family=Noto+Sans+KR:wght@300;400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f5efe6;
  --bg2:       #ede4d8;
  --bg3:       #e2d5c4;
  --card:      #ffffff;
  --ink:       #1a1a2e;
  --ink2:      #3d3550;
  --ink3:      #8b7fa0;
  --border:    rgba(155,143,160,0.2);
  --accent:    #ff6b6b;
  --accent2:   #ffd93d;
  --purple:    #a78bca;
  --purple-lt: #ede8f5;
  --amber:     #d4860a;
  --shadow-sm: 0 2px 8px rgba(90,70,110,0.10);
  --shadow-md: 0 6px 24px rgba(90,70,110,0.14);
  --shadow-lg: 0 16px 48px rgba(90,70,110,0.18);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --font-sans:    'Noto Sans KR', sans-serif;
  --font-display: 'Gaegu', cursive;

  /* 책장 높이 — 반응형으로 조절 */
  --shelf-book-h: 158px;
}

html, body, #root { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 99px; }

/* ════════════════════════════════════════════
   LAYOUT
   ════════════════════════════════════════════ */

.app { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Header ── */
.header {
  position: sticky; top: 0; z-index: 300;
  background: rgba(245,239,230,0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 clamp(16px, 4vw, 40px);
  height: 58px;
  display: flex; align-items: center; justify-content: space-between;
}
.header-logo {
  font-family: var(--font-display);
  font-size: clamp(18px, 3vw, 24px); font-weight: 700; color: var(--ink);
}
.header-logo em { font-style: normal; color: var(--accent); }
.header-actions { display: flex; align-items: center; gap: 8px; }

/* ── Main content ── */
/* 모바일: 1단, 태블릿+: 중앙 정렬, 데스크탑: 넓게 */
.main {
  flex: 1;
  width: 100%;
  max-width: 900px;     /* 데스크탑 최대 너비 */
  margin: 0 auto;
  padding: clamp(16px, 3vw, 32px) clamp(14px, 4vw, 40px) 100px;
}

/* ════════════════════════════════════════════
   STATS
   ════════════════════════════════════════════ */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 2vw, 14px);
  margin-bottom: clamp(16px, 2vw, 24px);
}
.stat-card {
  background: var(--card); border-radius: var(--radius-md);
  padding: clamp(12px, 2vw, 18px) 10px; text-align: center;
  box-shadow: var(--shadow-sm); transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-val {
  font-family: var(--font-display);
  font-size: clamp(22px, 4vw, 32px); font-weight: 700; color: var(--ink); line-height: 1;
}
.stat-lbl { font-size: clamp(10px, 1.5vw, 12px); color: var(--ink3); margin-top: 4px; }

/* ════════════════════════════════════════════
   AD SLOT
   ════════════════════════════════════════════ */
.ad-slot {
  background: var(--bg2); border: 1.5px dashed var(--bg3);
  border-radius: var(--radius-md); height: 72px;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink3); font-size: 11px;
  margin-bottom: clamp(16px, 2vw, 24px);
}

/* ════════════════════════════════════════════
   SEARCH BAR (홈 화면 — 클릭 시 검색 페이지 이동)
   ════════════════════════════════════════════ */
.search-wrap {
  background: var(--card); border-radius: var(--radius-xl);
  padding: 12px 18px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow-sm);
  margin-bottom: clamp(16px, 2vw, 24px);
  cursor: pointer; transition: box-shadow 0.18s;
}
.search-wrap:hover { box-shadow: var(--shadow-md); }
.search-placeholder { color: var(--ink3); font-size: 14px; flex: 1; }

/* ════════════════════════════════════════════
   SECTION TITLE
   ════════════════════════════════════════════ */
.section-title {
  font-size: clamp(13px, 2vw, 16px); font-weight: 700; color: var(--ink);
  margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.section-badge {
  font-size: 11px; font-weight: 500; color: var(--ink3);
  background: var(--bg2); padding: 2px 8px; border-radius: 99px;
}

/* ════════════════════════════════════════════
   BOOKSHELF
   ════════════════════════════════════════════ */
.shelf-container {
  background: linear-gradient(160deg, #fdf6ee 0%, #f0e4d0 100%);
  border-radius: var(--radius-lg);
  padding: clamp(14px, 2vw, 22px) clamp(14px, 2vw, 22px) 0;
  box-shadow: var(--shadow-sm);
  overflow-x: auto;          /* 책이 많으면 가로 스크롤 */
  overflow-y: visible;
  margin-bottom: clamp(20px, 3vw, 32px);
}
/* 스크롤바 숨기기 (드래그 스크롤) */
.shelf-container::-webkit-scrollbar { height: 0; }

.shelf-row {
  display: flex;
  flex-wrap: nowrap;          /* 한 줄로 — 넘치면 가로 스크롤 */
  gap: clamp(4px, 0.8vw, 7px);
  align-items: flex-end;
  position: relative;
  min-height: calc(var(--shelf-book-h) + 24px);
  padding-bottom: 0;
  min-width: min-content;     /* 책 넓이 합만큼 확장 */
}
.shelf-row::after {
  content: '';
  position: absolute; bottom: 0;
  left: calc(-1 * clamp(14px, 2vw, 22px));
  right: calc(-1 * clamp(14px, 2vw, 22px));
  height: 22px;
  background: linear-gradient(180deg, #c49a6c 0%, #a07840 100%);
  box-shadow: 0 4px 12px rgba(0,0,0,0.28);
  z-index: 0;
}
.shelf-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px; padding: 20px 0 44px;
  color: var(--ink3); font-size: 13px; text-align: center; line-height: 1.8;
  min-width: 200px;
}

/* ════════════════════════════════════════════
   BOOK SPINE — 너비는 JS에서 페이지 수 기반으로 인라인 style 지정
   ════════════════════════════════════════════ */
.book-spine {
  /* width는 JS에서 동적 지정 (페이지 수 비례) */
  height: var(--shelf-book-h);
  border-radius: 3px 6px 6px 3px;
  position: relative; cursor: pointer; flex-shrink: 0; overflow: hidden;
  transition: transform 0.26s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.22s;
  box-shadow: 2px 3px 8px rgba(0,0,0,0.22);
  z-index: 1;
}
.book-spine:hover {
  transform: translateY(-18px) rotate(-1.5deg);
  box-shadow: 6px 18px 28px rgba(0,0,0,0.32);
  z-index: 10;
}
.book-spine-base { position: absolute; inset: 0; background: #fff; }
.book-spine-edge { position: absolute; top:0; left:0; bottom:0; width:3px; background: rgba(0,0,0,0.12); }
.book-spine-fill { position: absolute; bottom:0; left:0; right:0; transition: height 0.7s ease; }
.book-spine-label {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  writing-mode: vertical-rl; text-orientation: mixed;
  font-size: clamp(9px, 1.2vw, 11px); font-weight: 600;
  padding: 6px 3px; z-index: 2; overflow: hidden;
  user-select: none; line-height: 1.3;
}
.book-spine-pct {
  position: absolute; bottom: 3px; right: 2px;
  font-size: 8px; font-weight: 700;
  color: rgba(255,255,255,0.9); background: rgba(0,0,0,0.25);
  border-radius: 3px; padding: 1px 3px; z-index: 3; line-height: 1.4;
}
.book-spine-done {
  position: absolute; top: 4px; right: 3px;
  font-size: 10px; z-index: 3;
}

/* 필터 탭 */
.shelf-filter {
  display: flex; gap: 7px; margin-bottom: 14px;
  overflow-x: auto; padding-bottom: 4px;
}
.shelf-filter::-webkit-scrollbar { height: 0; }
.filter-chip {
  padding: 5px 14px; border-radius: 99px; border: 1.5px solid var(--border);
  font-size: 12px; font-weight: 500; color: var(--ink2); background: var(--card);
  cursor: pointer; white-space: nowrap; transition: all 0.15s; flex-shrink: 0;
}
.filter-chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ════════════════════════════════════════════
   PAGES — 검색·상세·기록
   ════════════════════════════════════════════ */
.page-search, .page-detail, .page-record {
  animation: pageIn 0.22s ease;
}
@keyframes pageIn { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }

/* 검색 입력 */
.search-input-wrap {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: var(--radius-xl);
  padding: 12px 18px; margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.search-input-field {
  flex: 1; border: none; outline: none; background: transparent;
  font-family: var(--font-sans); font-size: 15px; color: var(--ink);
}
.search-input-field::placeholder { color: var(--ink3); }

/* 검색 결과 */
.search-result-list { display: flex; flex-direction: column; gap: 10px; }
.search-result-card {
  background: var(--card); border-radius: var(--radius-md);
  padding: 14px; display: flex; gap: 14px; align-items: flex-start;
  box-shadow: var(--shadow-sm); cursor: pointer; transition: all 0.18s;
}
.search-result-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.src-thumb {
  width: 54px; height: 76px; object-fit: cover; border-radius: 6px;
  background: var(--bg2); flex-shrink: 0;
  box-shadow: 2px 3px 10px rgba(0,0,0,0.15);
}
.src-info { flex: 1; min-width: 0; }
.src-title { font-size: 14px; font-weight: 700; color: var(--ink); line-height: 1.4; margin-bottom: 4px; }
.src-author { font-size: 12px; color: var(--ink3); margin-bottom: 6px; }
.src-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.src-tag {
  font-size: 11px; padding: 2px 8px; border-radius: 99px;
  background: var(--purple-lt); color: var(--purple);
}
.src-arrow { color: var(--ink3); font-size: 18px; align-self: center; }

/* 책 상세 */
.detail-cover-wrap { display: flex; justify-content: center; margin-bottom: 24px; }
.detail-cover {
  width: clamp(100px, 20vw, 140px);
  height: auto; aspect-ratio: 7/10;
  object-fit: cover; border-radius: 8px;
  box-shadow: 8px 12px 32px rgba(0,0,0,0.22);
}
.detail-info-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.detail-info-table tr { border-bottom: 1px solid var(--border); }
.detail-info-table tr:last-child { border-bottom: none; }
.detail-info-table td { padding: 11px 0; font-size: 13px; vertical-align: top; }
.dit-label { color: var(--ink3); width: 64px; font-weight: 500; }
.dit-value { color: var(--ink); font-weight: 400; }
.detail-desc {
  font-size: 13px; color: var(--ink2); line-height: 1.7; margin-bottom: 4px;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.detail-desc.expanded { -webkit-line-clamp: unset; }

/* 기록 페이지 */
.record-book-header { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 22px; }
.record-cover {
  width: clamp(60px, 12vw, 80px); height: auto; aspect-ratio: 7/10;
  object-fit: cover; border-radius: 6px;
  box-shadow: 4px 6px 16px rgba(0,0,0,0.18); flex-shrink: 0;
}
.record-book-title { font-size: clamp(14px, 2.5vw, 17px); font-weight: 700; color: var(--ink); margin-bottom: 4px; line-height: 1.4; }
.record-book-author { font-size: 13px; color: var(--ink3); }

/* Pills */
.pills-row { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 14px; }

/* Progress */
.progress-section { margin-bottom: 20px; }
.progress-label-row {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--ink3); margin-bottom: 8px;
}
.progress-label-pct { font-weight: 700; color: var(--ink); }
.progress-track { height: 8px; background: var(--bg2); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 99px; transition: width 0.4s ease; }

/* Form */
.log-form-card {
  background: var(--bg); border-radius: var(--radius-md);
  padding: 16px; margin-bottom: 20px;
}
.form-section-title { font-size: 13px; font-weight: 700; color: var(--ink2); margin-bottom: 12px; }
.form-row { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.form-group { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 100px; }
.form-label { font-size: 11px; color: var(--ink3); font-weight: 500; }
.form-control {
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; font-family: var(--font-sans); font-size: 13px;
  color: var(--ink); background: var(--card); outline: none; width: 100%;
  transition: border-color 0.15s;
}
.form-control:focus { border-color: var(--purple); }
.form-textarea { resize: vertical; min-height: 72px; }

/* Log list */
.log-list { display: flex; flex-direction: column; gap: 16px; }
.log-entry { position: relative; padding-right: 28px; }
.log-entry-pct { font-size: 16px; font-weight: 700; color: var(--ink); margin-bottom: 2px; }
.log-entry-date { font-size: 12px; color: var(--ink3); margin-bottom: 8px; }
.log-entry-body { font-size: 13px; color: var(--ink2); line-height: 1.7; }
.log-entry-del {
  position: absolute; top: 0; right: 0;
  background: none; border: none; cursor: pointer;
  font-size: 12px; color: var(--ink3); opacity: 0.4;
  transition: opacity 0.15s, color 0.15s;
}
.log-entry-del:hover { opacity: 1; color: var(--accent); }
.log-divider { height: 1px; background: var(--border); }

/* ════════════════════════════════════════════
   BUTTONS
   ════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 8px 18px; border-radius: 99px; border: none; cursor: pointer;
  font-family: var(--font-sans); font-size: 13px; font-weight: 500;
  transition: all 0.18s; white-space: nowrap;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink2); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--ink2); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--bg2); }
.btn-pill-active { background: var(--accent); color: #fff; font-size: 12px; padding: 6px 14px; }
.btn-pill { background: var(--ink); color: #fff; font-size: 12px; padding: 6px 14px; }
.btn-pill-outline { background: transparent; color: var(--ink); border: 1.5px solid var(--border); font-size: 12px; padding: 6px 14px; }
.btn-pill-outline:hover { background: var(--bg2); }
.btn-add-shelf {
  width: 100%; padding: 16px; border-radius: var(--radius-lg);
  background: var(--ink); color: #fff;
  font-size: 15px; font-weight: 600; border: none; cursor: pointer;
  transition: all 0.18s; margin-bottom: 20px;
}
.btn-add-shelf:hover:not(:disabled) { background: var(--ink2); transform: translateY(-1px); }
.btn-add-shelf:disabled { opacity: 0.6; cursor: default; }

/* ════════════════════════════════════════════
   MISC
   ════════════════════════════════════════════ */
.back-btn {
  background: none; border: none; cursor: pointer;
  font-size: 20px; color: var(--ink); padding: 4px; line-height: 1;
  display: flex; align-items: center; transition: color 0.15s;
  flex-shrink: 0;
}
.back-btn:hover { color: var(--accent); }

.page-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: clamp(16px, 2vw, 24px);
}
.page-header-title {
  font-size: clamp(15px, 2.5vw, 18px); font-weight: 700; color: var(--ink);
  flex: 1; text-align: center;
  /* 긴 제목이 헤더를 넘치지 않도록 */
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.empty-state { text-align: center; padding: 40px 20px; color: var(--ink3); font-size: 13px; line-height: 2; }
.empty-icon { font-size: 44px; display: block; margin-bottom: 10px; }

.card { background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* Toast */
.toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(14px);
  background: var(--ink); color: #fff;
  padding: 10px 24px; border-radius: 99px; font-size: 13px;
  opacity: 0; pointer-events: none; z-index: 9999;
  transition: opacity 0.24s, transform 0.24s; white-space: nowrap;
  box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Sync bar */
.sync-bar {
  position: fixed; bottom: 22px; right: 16px;
  background: var(--ink); color: var(--accent2);
  font-size: 12px; padding: 7px 16px; border-radius: 99px;
  box-shadow: var(--shadow-md); z-index: 400;
  opacity: 0; transform: translateY(10px);
  transition: opacity 0.22s, transform 0.22s; pointer-events: none;
}
.sync-bar.show { opacity: 1; transform: translateY(0); }

/* Spinner */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--bg2); border-top-color: var(--purple);
  border-radius: 50%; animation: spin 0.65s linear infinite;
  display: inline-block; flex-shrink: 0; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ════════════════════════════════════════════ */

/* ── 태블릿 (600px+) ── */
@media (min-width: 600px) {
  :root { --shelf-book-h: 168px; }

  .search-result-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── 데스크탑 (900px+) ── */
@media (min-width: 900px) {
  :root { --shelf-book-h: 180px; }

  .search-result-list {
    grid-template-columns: repeat(2, 1fr);
  }

  /* 상세·기록 페이지: 표지와 내용 옆으로 배치 */
  .detail-page-inner {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 32px;
    align-items: start;
  }
  .detail-cover-wrap { margin-bottom: 0; }
  /* .detail-cover { width: 100%; } */
}

/* ── 모바일 (480px 이하) ── */
@media (max-width: 480px) {
  :root { --shelf-book-h: 138px; }

  .stats-row { gap: 8px; }
  .book-spine-label { font-size: 9px; }
  .search-result-list { grid-template-columns: 1fr; }

  /* 폼 행 세로 배치 */
  .form-row { flex-direction: column; }
  .form-group { min-width: unset; }
}
