/* 책장 — Surface Pro 와 Android 양쪽에서 쓴다.
   레이아웃은 하나뿐이다. 폰 기준으로 만들고 넓은 화면에서는 그대로 가운데 세운다. */

:root {
  --bg: #141210;
  --bg-soft: #1c1a17;
  --bg-card: #232019;
  --line: #322d25;
  --text: #ece6dc;
  --text-dim: #a29889;
  --text-faint: #6f6759;
  --accent: #c8a26a;
  --accent-dim: #8a6f47;
  --danger: #c46b5c;
  --radius: 12px;        /* 입력·버튼 */
  --radius-card: 16px;   /* 카드·표면 */
  --radius-sheet: 22px;  /* 모달 시트 */
  --radius-cover: 8px;
  --tap: 44px;
  --app-width: 480px;
  --ease: 170ms cubic-bezier(0.2, 0.7, 0.3, 1);
}

* { box-sizing: border-box; }

/**
 * hidden 속성은 UA 스타일시트의 display:none 인데, 작성자가 선언한 display
 * (예: .modal { display: grid })가 그것을 이긴다. 그래서 hidden 을 걸어도
 * 화면에 남는다 — 실제로 모달이 잠금 화면 위에 계속 떠 있었다.
 * 개별 규칙마다 막지 말고 여기서 한 번에 이긴다.
 */
[hidden] { display: none !important; }

a { color: inherit; text-decoration: none; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans KR',
               'Malgun Gothic', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── 화면 전환 ─────────────────────────────────────────────── */

.screen { display: none; }
.screen.is-active { display: block; }

/**
 * 입력과 버튼은 아래에 둔다.
 *
 * 화면을 세로 flex 로 세우고 내용에 flex:1 을 주면, 내용이 짧아도 입력이
 * 위로 딸려 올라오지 않고 엄지 근처에 남는다. 내용이 길면 자연스럽게
 * 아래로 밀려 스크롤 끝에 온다.
 */
#screen-search.is-active,
#screen-book.is-active {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 150px);
}

#search-results, .comment-list { flex: 1 0 auto; }

.page-foot {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.page-foot .btn-block { margin-top: 0; }

.screen-center {
  min-height: 100vh;
  align-content: end;
  justify-items: center;
  padding: 24px 24px max(24px, 12vh);
}
.screen-center.is-active { display: grid; }

/* ── 잠금 / 설정 ───────────────────────────────────────────── */

.lock-box {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lock-title {
  margin: 0 0 8px;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: center;
  color: var(--accent);
}

.label {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.hint {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-faint);
}

/* ── 폼 요소 ───────────────────────────────────────────────── */

.input, .textarea, select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color var(--ease), background var(--ease);
}

.input:focus, .textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent-dim);
  background: var(--bg-card);
}

/* 어두운 배경에서 브라우저 기본 placeholder 는 거의 안 보인다 */
.input::placeholder, .textarea::placeholder {
  color: var(--text-faint);
  opacity: 1;
}

.textarea {
  min-height: 84px;
  resize: vertical;
  line-height: 1.6;
}

.btn {
  min-height: var(--tap);
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease), transform var(--ease);
}

.btn:hover { border-color: var(--accent-dim); }
.btn-primary:hover { background: #d3ae78; border-color: #d3ae78; }
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #191510;
  font-weight: 600;
}

.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-sm { min-height: 34px; padding: 4px 12px; font-size: 0.82rem; }
.btn-block { width: 100%; margin-top: 16px; }

/* ── 상단바 · 탭바 ─────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: rgba(20, 18, 16, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(50, 45, 37, 0.6);
}

.brand {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
}

/**
 * 폰에서는 하단 고정. 한 손으로 쥐었을 때 엄지가 닿는 곳은 화면 아래쪽이고,
 * 상단 탭은 기기를 고쳐 쥐어야 눌린다. 그 재조정이 곧 마찰이다.
 */
.nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 20;
  width: calc(100% - 32px);
  max-width: calc(var(--app-width) - 32px);
  display: flex;
  gap: 4px;
  padding: 5px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.nav-item {
  flex: 1;
  min-height: 46px;
  transition: background var(--ease), color var(--ease);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.92rem;
}

.nav-item.is-active {
  background: rgba(200, 162, 106, 0.14);
  color: var(--accent);
}

.nav-item:active { background: var(--bg-soft); }

/* 탭바에 가려지지 않도록 본문 아래를 비워 둔다 */
#main {
  padding: 16px;
  padding-bottom: calc(92px + env(safe-area-inset-bottom));
}

/* ── 배너 (토큰 만료 경고 등) ──────────────────────────────── */

.banner {
  margin: 12px 16px 0;
  padding: 11px 14px;
  background: #33271a;
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  color: #e8d3ab;
  font-size: 0.84rem;
  line-height: 1.5;
}

/* ── 홈 — 읽는 중 ──────────────────────────────────────────── */

.section-title {
  margin: 26px 0 8px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  text-transform: uppercase;
}

.reading-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  margin-bottom: 14px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

/* 표지와 제목이 통째로 하나의 링크 — 엄지로 겨냥할 면적을 키운다 */
.reading-head {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  align-items: center;
}

.reading-card .cover { width: 64px; height: 94px; }

.reading-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }

.reading-title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
}

.reading-authors {
  font-size: 0.82rem;
  color: var(--text-dim);
}

.comment-form { display: flex; flex-direction: column; gap: 10px; }
.comment-form .textarea { min-height: 76px; }

.comment-row { display: flex; gap: 10px; align-items: center; }

/* 날짜는 대개 오늘 그대로 둔다 — 자리를 덜 주고 버튼에 몰아준다 */
.comment-row .input[type="date"] {
  flex: 0 1 160px;
  min-height: 48px;
  font-size: 0.88rem;
}

.comment-row .btn {
  flex: 1;
  min-height: 48px;
  font-size: 1rem;
}

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.9rem;
}

/* ── 최근 활동 ─────────────────────────────────────────────── */

.recent { display: flex; flex-direction: column; gap: 2px; }

.recent-item {
  display: flex;
  gap: 12px;
  padding: 11px 6px;
  border-radius: var(--radius);
  transition: background var(--ease);
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
  color: var(--text-dim);
  text-decoration: none;
}

.recent-item:last-child { border-bottom: none; }
.recent-item:hover { background: var(--bg-soft); }
.recent-when { color: var(--text-faint); white-space: nowrap; font-size: 0.78rem; }
.recent-what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 서가 ──────────────────────────────────────────────────── */

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

.chip {
  min-height: 40px;
  padding: 6px 16px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
}

.chip:hover { border-color: var(--accent-dim); }

.chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #191510;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 14px;
}

.grid-item { text-decoration: none; color: inherit; }
.grid-item .cover { width: 100%; aspect-ratio: 2 / 3; }

.grid-title {
  margin: 6px 0 0;
  font-size: 0.76rem;
  line-height: 1.35;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── 표지 ──────────────────────────────────────────────────── */

.cover {
  display: block;
  border-radius: var(--radius-cover);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  object-fit: cover;
  overflow: hidden;
}

/* 표지 없는 책 — 제목만 적힌 회색 카드 */
.cover-none {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  font-size: 0.68rem;
  line-height: 1.3;
  color: var(--text-faint);
  text-align: center;
  word-break: keep-all;
}

/* ── 책 상세 ───────────────────────────────────────────────── */

.detail-head { display: flex; gap: 16px; margin-bottom: 18px; }
.detail-head .cover { width: 116px; height: 170px; flex: none; }
.detail-title { margin: 0 0 4px; font-size: 1.15rem; line-height: 1.35; }
.detail-meta { margin: 0; font-size: 0.82rem; color: var(--text-dim); }

.detail-actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0; }

.tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }

.tag {
  padding: 3px 9px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.comment-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

.comment {
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

.comment-text { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 0.92rem; }
.comment-when { margin: 6px 0 0; font-size: 0.72rem; color: var(--text-faint); }

/* ── 검색 결과 ─────────────────────────────────────────────── */

.search-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.search-bar .input { flex: 1; }

.results { display: flex; flex-direction: column; gap: 8px; }

.result {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  text-align: left;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease);
}

.result:hover { border-color: var(--accent-dim); }
.result:active { transform: scale(0.99); }

.result .cover { width: 56px; height: 82px; }
.result-title { margin: 0; font-size: 0.9rem; font-weight: 600; line-height: 1.35; }
.result-meta { margin: 2px 0 0; font-size: 0.76rem; color: var(--text-dim); }

/* ── 모달 ──────────────────────────────────────────────────── */

/**
 * 하단 시트. 떠 있는 탭바와 같은 방향에서 올라온다 — 화면 한가운데
 * 튀어나오는 상자보다 손이 있는 쪽에 가깝다.
 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.62);
  animation: fade-in 170ms ease-out;
}

.modal-box {
  width: 100%;
  max-width: var(--app-width);
  max-height: 88vh;
  overflow-y: auto;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  animation: sheet-up 220ms cubic-bezier(0.2, 0.7, 0.3, 1);
}

/* 시트 손잡이 — 아래에서 올라온 것임을 형태로 말한다 */
.modal-box::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  margin: 0 auto 14px;
  background: var(--line);
  border-radius: 999px;
}

@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .modal, .modal-box { animation: none; }
  * { transition: none !important; }
}

.modal-title { margin: 0 0 14px; font-size: 1.05rem; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; min-height: 50px; font-size: 1rem; }

/* 체크박스는 라벨 전체가 탭 영역이어야 엄지로 눌린다 */
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  color: var(--text-dim);
  font-size: 0.88rem;
  cursor: pointer;
}

.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex: none;
}

.input:disabled { opacity: 0.45; }

/* ── 메시지 / 토스트 ───────────────────────────────────────── */

.msg { margin: 0; font-size: 0.84rem; color: var(--danger); }
.msg.is-info { color: var(--text-dim); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  padding: 10px 18px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.85rem;
}

.spinner { color: var(--text-faint); font-size: 0.85rem; padding: 20px 0; text-align: center; }

/* ── 넓은 화면 ─────────────────────────────────────────────
   레이아웃을 갈라놓지 않는다. 폰에서 만든 것을 그대로 가운데 세운다 —
   Surface Pro 도 터치로 쓰고, 두 기기에서 같은 자리에 같은 것이 있는 편이
   화면을 넓게 쓰는 것보다 낫다. 늘어나는 것은 여백뿐이다. */

#app {
  width: 100%;
  max-width: var(--app-width);
  margin-left: auto;
  margin-right: auto;
}

@media (min-width: 520px) {
  body { background: #100e0c; }
  #app {
    min-height: 100vh;
    background: var(--bg);
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}
