:root {
  --bg: #121212;
  --panel: rgba(22, 22, 24, .94);
  --fg: #eee;
  --muted: #9a9a9a;
  --line: #2e2e30;
  --accent: #ffb547;
  --danger: #e5484d;
  --card: #1d1d1f;
  --folder: #3a3a3c;          /* 기본 폴더색 (진회색) */
  --f-coral: #d9695b;
  --f-amber: #d39a2f;
  --f-sage: #5f9a6e;
  --f-teal: #2f8f8f;
  --f-indigo: #5566c4;
  --f-plum: #8e5fae;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font-family: -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button, select, input { font: inherit; color: inherit; }
input { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }

/* ───── 공통 ───── */
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; }
.icon { background: none; border: 0; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 10px; color: var(--fg); }
.icon:active, .icon.on { background: #2a2a2c; }
.icon.on { color: var(--accent); }
.icon:disabled { opacity: .3; }
.pill { background: #2a2a2c; border: 1px solid #3a3a3c; border-radius: 999px; padding: 8px 14px; min-height: 40px; cursor: pointer; white-space: nowrap; }
.pill:active { background: #3a3a3c; }
.pill.danger { border-color: #7a3a3a; color: #ff9d8f; }
.danger-fill, .pill.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 700; }
.primary { background: var(--accent); color: #111; border: 0; border-radius: 10px; padding: 12px; font-weight: 700; min-height: 44px; cursor: pointer; }
.primary:disabled { opacity: .5; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.err { color: #ff7b6b; font-size: 14px; margin: 0; min-height: 1em; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.chk input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ───── 서재 ───── */
#library { min-height: 100%; padding-top: var(--safe-t); padding-bottom: calc(80px + var(--safe-b)); }
.libbar { position: sticky; top: 0; z-index: 5; background: var(--panel);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); flex-wrap: wrap; }
.libbar h1 { font-size: 20px; margin: 0 6px 0 0; }
#search { flex: 1 1 180px; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid #333; background: #1a1a1a; }
#sort { padding: 10px; border-radius: 10px; border: 1px solid #333; background: #1a1a1a; }
.tools { display: flex; gap: 2px; margin-left: auto; }
.crumbs { display: flex; align-items: center; gap: 4px; padding: 4px 10px; min-height: 48px; }
.crumbpath { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-size: 15px; min-width: 0; }
.crumbpath button { background: none; border: 0; padding: 6px 6px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.crumbpath button:last-child { color: var(--fg); font-weight: 600; }
.crumbpath .sep { color: #555; }
.status { color: var(--muted); padding: 0 16px; }
.scanbar { display: flex; align-items: center; gap: 10px; margin: 0 16px 6px; padding: 8px 12px; background: #1a1a1c; border: 1px solid var(--line);
  border-radius: 10px; font-size: 13px; color: var(--muted); }
.scanbar .spin { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: 0 0 auto; }
.scanbar.err .spin { display: none; }
.scanbar button { margin-left: auto; }

.continue { padding: 0 16px 6px; }
.continue h3 { font-size: 14px; color: var(--muted); margin: 6px 0 8px; }
.continue .row { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px; -webkit-overflow-scrolling: touch; }
.continue .card { width: 110px; flex: 0 0 auto; }

.grid { display: grid; gap: 18px 14px; padding: 8px 16px 24px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.card { cursor: pointer; position: relative; }
.card .cv { position: relative; aspect-ratio: 3 / 4.2; background: var(--card); border-radius: 10px; overflow: hidden;
  box-shadow: 0 3px 10px rgba(0,0,0,.4); transition: transform .12s; }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s; -webkit-user-drag: none; }
.card img.ok { opacity: 1; }
.card .t { font-size: 13px; line-height: 1.35; margin-top: 7px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-all; }
.card .m { font-size: 11px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .prog { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0,0,0,.5); }
.card .prog i { display: block; height: 100%; background: var(--accent); }
.card .done { position: absolute; right: 6px; top: 6px; background: rgba(0,0,0,.65); color: var(--accent); font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 999px; }
.card:active .cv, .card.pressing .cv { transform: scale(.96); }

/* 폴더 카드 */
.card.folder .cv { background: var(--folder); display: flex; align-items: center; justify-content: center; }
.card.folder .cv svg.i { width: 46%; height: auto; aspect-ratio: 1; stroke: rgba(255,255,255,.85); stroke-width: 1.4; }
.card.folder .cv .cnt { position: absolute; left: 10px; bottom: 9px; font-size: 12px; color: rgba(255,255,255,.8); font-weight: 600; }
.card.folder .lockbadge { position: absolute; left: 50%; top: 52%; transform: translate(-50%, -50%); width: 30%; aspect-ratio: 1; border-radius: 50%;
  background: rgba(20,20,22,.85); display: flex; align-items: center; justify-content: center; z-index: 1; }
.card.folder .lockbadge svg.i { width: 52% !important; stroke: #fff !important; stroke-width: 2.2 !important; }
.card.folder.locked .cv::after { content: ""; position: absolute; inset: 0; background: rgba(0,0,0,.18); }
.fc-coral  { background: var(--f-coral)  !important; }
.fc-amber  { background: var(--f-amber)  !important; }
.fc-sage   { background: var(--f-sage)   !important; }
.fc-teal   { background: var(--f-teal)   !important; }
.fc-indigo { background: var(--f-indigo) !important; }
.fc-plum   { background: var(--f-plum)   !important; }

/* 선택 모드 */
.card .sel { position: absolute; right: 8px; top: 8px; width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff;
  background: rgba(0,0,0,.35); display: none; align-items: center; justify-content: center; z-index: 2; }
.selecting .card .sel { display: flex; }
.card.selected .sel { background: var(--accent); border-color: var(--accent); }
.card.selected .sel svg.i { width: 16px; height: 16px; stroke: #111; stroke-width: 3; }
.card.selected .cv { outline: 3px solid var(--accent); outline-offset: 2px; }
.selbar { position: fixed; left: 0; right: 0; margin: 0 auto; width: max-content; bottom: calc(14px + var(--safe-b)); z-index: 30;
  display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 10px 12px; box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: calc(100vw - 20px); flex-wrap: wrap; justify-content: center;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.selbar #selCount { font-weight: 600; padding: 0 6px; }

/* ───── 모달 / 시트 ───── */
.modal { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.panel { width: 100%; max-width: 400px; max-height: 88vh; overflow-y: auto; background: #1c1c1e; border: 1px solid #333;
  border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 12px; -webkit-overflow-scrolling: touch; }
.panel h2 { margin: 0; font-size: 19px; } .panel h3 { margin: 10px 0 0; font-size: 14px; color: var(--muted); }
.panel input:not([type]), .panel input[type=password], .panel input[type=text], .panel input[inputmode], .panel select {
  width: 100%; padding: 12px; border-radius: 10px; border: 1px solid #3a3a3a; background: #111; font-size: 16px; }
.panel .btns { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.panel .btns > * { flex: 1 1 auto; }
.msg { font-size: 15px; line-height: 1.5; margin: 0; word-break: break-all; white-space: pre-line; }
#login { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.75); padding: 16px; }

/* 길게 누르기 메뉴 */
.sheet-title { display: flex; align-items: center; gap: 10px; }
.sheet-title .tt { font-weight: 700; font-size: 16px; word-break: break-all; }
.menu { display: flex; flex-direction: column; background: #151517; border-radius: 12px; overflow: hidden; }
.menu button { display: flex; align-items: center; gap: 12px; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 14px 14px; text-align: left; font-size: 16px; cursor: pointer; min-height: 50px; }
.menu button:last-child { border-bottom: 0; }
.menu button:active { background: #232326; }
.menu button.danger { color: #ff6b6b; }
.menu button.danger-box { background: var(--danger); color: #fff; font-weight: 700; justify-content: center; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; padding: 4px 2px; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; background: var(--folder); }
.swatch.on { border-color: #fff; }

/* 설정 (분할 버튼) */
.pref { display: flex; flex-direction: column; gap: 6px; }
.pref .lbl { font-size: 13px; color: var(--muted); }
.seg { display: flex; background: #111; border: 1px solid #333; border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 9px 6px; cursor: pointer; font-size: 14px; line-height: 1.25; }
.seg button small { display: block; font-size: 11px; color: var(--muted); }
.seg button.on { background: var(--accent); color: #111; font-weight: 700; }
.seg button.on small { color: #3b2a0a; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.list li { background: #151517; border-radius: 10px; padding: 10px; display: flex; align-items: center; gap: 8px; }
.list li .grow { flex: 1; min-width: 0; word-break: break-all; }
.list li.cur { border: 1px solid var(--accent); }

/* 폴더 선택기 */
.picker { display: flex; flex-direction: column; max-height: 50vh; overflow-y: auto; background: #151517; border-radius: 12px; }
.picker button { display: flex; align-items: center; gap: 10px; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 12px; text-align: left; font-size: 15px; cursor: pointer; }
.picker button:disabled { opacity: .35; }
.picker button .dot { width: 14px; height: 14px; border-radius: 4px; background: var(--folder); flex: 0 0 auto; }

/* PIN 패드 */
.pin .dots { display: flex; justify-content: center; gap: 16px; margin: 6px 0; }
.pin .dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #aaa; }
.pin .dots i.f { background: var(--accent); border-color: var(--accent); }
.pin .dots.shake { animation: shake .35s; }
@keyframes shake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
.pin .keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin .keys button { height: 58px; border-radius: 14px; border: 0; background: #2a2a2c; font-size: 22px; cursor: pointer; }
.pin .keys button:active { background: #3a3a3c; }
.pin .keys button.sm { font-size: 13px; background: none; color: var(--muted); }

/* ───── 뷰어 ───── */
#viewer { position: fixed; inset: 0; background: #000; overflow: hidden; z-index: 20; overscroll-behavior: none; }
#stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
#stage.fit-width { touch-action: pan-y; }
#track { position: absolute; top: 0; bottom: 0; width: 300%; left: -100%; display: flex; will-change: transform; }
.slot { width: 33.3334%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.slot img { max-width: 100%; max-height: 100%; object-fit: contain; transform-origin: 0 0; -webkit-user-drag: none; }
#stage.fit-width .slot { align-items: flex-start; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#stage.fit-width .slot img { width: 100%; max-height: none; height: auto; }
#track.anim { transition: transform .22s ease-out; }

/* 세로 스크롤(웹툰) */
#vscroll { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
#vlist { max-width: 900px; margin: 0 auto; }
.vpage { position: relative; background: #0b0b0b; }
.vpage img { display: block; width: 100%; height: auto; }
.vpage .ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #333; font-size: 13px; }
.vend { padding: 40px 20px calc(60px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; align-items: center; color: var(--muted); }
.vend button { min-width: 240px; }

#spinner { position: absolute; left: 50%; top: 50%; width: 42px; height: 42px; margin: -21px 0 0 -21px; z-index: 3;
  border: 3px solid rgba(255,255,255,.2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#ui .top, #ui .bottom { position: absolute; left: 0; right: 0; z-index: 5; background: var(--panel); transition: transform .22s, opacity .22s; }
#ui .top { top: 0; padding-top: calc(10px + var(--safe-t)); }
#ui .bottom { bottom: 0; padding-bottom: calc(14px + var(--safe-b)); }
#ui.hidden .top { transform: translateY(-100%); opacity: 0; pointer-events: none; }
#ui.hidden .bottom { transform: translateY(100%); opacity: 0; pointer-events: none; }
.navbtn { display: inline-flex; align-items: center; gap: 4px; padding-left: 8px; }
.navbtn svg.i { width: 18px; height: 18px; }
.vtitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.pno { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; white-space: nowrap; }
#slider { flex: 1; height: 44px; accent-color: var(--accent); }
#slider.rtl { transform: scaleX(-1); }
.endcard { position: absolute; inset: 0; z-index: 8; background: rgba(0,0,0,.72); display: flex; align-items: center; justify-content: center; padding: 16px; }

.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 90;
  background: rgba(40,40,40,.96); padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 90vw; text-align: center; }

/* ───── 디버그 오버레이 ───── */
#debug { position: fixed; left: 8px; bottom: calc(8px + var(--safe-b)); z-index: 95; max-width: min(520px, 90vw); max-height: 34vh;
  overflow-y: auto; background: rgba(0,0,0,.82); color: #9f9; font: 11px/1.4 ui-monospace, Menlo, monospace; padding: 8px;
  border-radius: 8px; white-space: pre-wrap; pointer-events: none; }
