:root {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --sub: #94a3b8;
  --accent: #2dd4bf;
  --accent-text: #042f2e;
  --danger: #f87171;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Pretendard, Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overscroll-behavior-y: contain;
}

#topBar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
#topBar.hidden { display: none; }

#topTitle { flex: 1; font-size: 15px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#topRight { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 18px;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 6px;
  text-decoration: none;
  display: inline-flex;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); }

.btn { border: none; border-radius: 6px; padding: 10px 16px; font-size: 14px; cursor: pointer; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.secondary { background: var(--panel); color: var(--text); border: 1px solid var(--border); }

main { flex: 1; overflow-y: auto; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.screen[hidden] { display: none; }

.status { font-size: 12px; color: var(--sub); }

.list-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }

.menu-list, .file-list { display: flex; flex-direction: column; gap: 8px; }

.menu-item, .file-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.menu-item:active, .file-item:active { background: #29394f; }

.menu-item .menu-main, .file-item .file-main { flex: 1; min-width: 0; }
.menu-item .menu-name, .file-item .file-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item .menu-bookmark { font-size: 11px; color: var(--accent); margin-top: 2px; }
.file-item .file-meta { font-size: 11px; color: var(--sub); margin-top: 2px; }

.bookmark-clear {
  border: none;
  background: none;
  color: var(--sub);
  font-size: 16px;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 6px;
}
.bookmark-clear:hover { background: rgba(255,255,255,0.08); color: var(--danger); }

.empty-hint { text-align: center; color: var(--sub); padding: 24px; font-size: 13px; }

/* 리더 화면: 기본적으로 전체 화면처럼 사용 */
#readerScreen { padding: 0; position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; }
#readerScreen[hidden] { display: none; }

.reader-tap-area { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.reader-pages { display: flex; flex-direction: column; }
.reader-pages img.page-img {
  width: 100%;
  display: block;
  background: #1e293b;
  min-height: 300px;
}

.reader-chrome {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 21;
}
.reader-chrome.visible { opacity: 1; }
.reader-chrome.visible .reader-topinfo,
.reader-chrome.visible .reader-nav { pointer-events: auto; }

.reader-topinfo {
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: linear-gradient(rgba(0,0,0,0.7), transparent);
  font-size: 13px;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-nav {
  display: flex;
  background: rgba(15, 23, 42, 0.92);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text);
  padding: 14px 4px 12px;
  min-height: 64px;
  cursor: pointer;
}
.nav-btn:active { background: rgba(255,255,255,0.08); }
.nav-btn:disabled { color: var(--sub); opacity: 0.4; }

.nav-icon { font-size: 28px; line-height: 1; }
.nav-label { font-size: 12px; line-height: 1; }

/* 저장하는 순간 잠깐 반짝이는 피드백 */
#navBookmark.active { color: var(--accent); }
/* 지금 보고 있는 파일이 이 대메뉴의 북마크로 저장돼 있는 동안 계속 유지되는 표시 */
#navBookmark.bookmarked { color: var(--accent); }
#navBookmark.bookmarked .nav-icon { text-shadow: 0 0 8px rgba(45, 212, 191, 0.55); }
