:root {
  --scale: 1;
  --accent: #ff4d4f;
  --bg: #ffffff;
  --bg2: #f4f5f7;
  --fg: #16181d;
  --fg2: #5d6370;
  --fg3: #9aa0ab;
  --line: #eceef1;
  --read: #a3a8b2;
  --sheet: #ffffff;
  --skel: #eef0f3;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #0f1115;
  --bg2: #181b21;
  --fg: #eceef2;
  --fg2: #a5abb6;
  --fg3: #6c7380;
  --line: #22262d;
  --read: #5d636e;
  --sheet: #15181d;
  --skel: #1d2127;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: calc(16px * var(--scale)); }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overflow: hidden; overscroll-behavior: none; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Apple SD Gothic Neo', 'Noto Sans KR', 'Noto Sans JP', 'Noto Sans SC', 'Hiragino Sans', sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; height: 100%; }
.top { display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-t) + 6px) 8px 0 16px; height: calc(var(--safe-t) + 50px); flex: none; }
.brand { margin: 0 auto 0 0; font-size: 1.2rem; font-weight: 800; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; }
.brand-logo { width: 1.55em; height: 1.55em; flex: none; }
.icon-btn { position: relative; }
.badge { position: absolute; top: 6px; right: 4px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; line-height: 17px; text-align: center; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: var(--fg2); flex: none; }
.icon-btn:active { background: var(--bg2); }

/* 상단 탭 */
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; padding: 0 10px; border-bottom: 1px solid var(--line); flex: none; scroll-behavior: smooth; }
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; flex: none; padding: 12px 10px 11px; font-size: 0.95rem; font-weight: 600; color: var(--fg3); white-space: nowrap; display: flex; align-items: center; gap: 6px; transition: color .15s; }
.tab .clogo { opacity: .55; transition: opacity .15s; }
.tab.on .clogo { opacity: 1; }

/* 커뮤니티 로고: 사이트 아이콘, 없으면 색 배지 + 첫 글자 */
.clogo { --s: 1.25rem; position: relative; width: var(--s); height: var(--s); flex: none; border-radius: 28%; background: linear-gradient(140deg, color-mix(in srgb, var(--c) 75%, #fff), var(--c)); display: inline-grid; place-items: center; overflow: hidden; color: #fff; }
.clogo b { font-size: calc(var(--s) * .56); font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.clogo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; }
.clogo.img { background: #fff; box-shadow: inset 0 0 0 1px #0001; }
.clogo.img img { opacity: 1; padding: 8%; }
.clogo.img b { display: none; }
.clogo.app { background: none; }
.clogo.app img { opacity: 1; }
.clogo.sm { --s: 1.15rem; }
.clogo.xs { --s: 0.95rem; }
.tab.on { color: var(--fg); }
.tab.on::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px; border-radius: 3px; background: var(--c, var(--accent)); }

.banner { margin: 8px 12px 0; padding: 10px 12px; border-radius: 12px; background: var(--bg2); font-size: 0.85rem; color: var(--fg2); display: flex; gap: 10px; align-items: center; flex: none; }
.banner span { flex: 1; min-width: 0; }
.banner button { color: var(--fg3); padding: 4px; }

/* 좌우 스와이프 페이지 */
.pager { flex: 1; display: flex; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain; }
.pager::-webkit-scrollbar { display: none; }
.page { flex: 0 0 100%; width: 100%; height: 100%; overflow-y: auto; scroll-snap-align: start; scroll-snap-stop: always; overscroll-behavior-y: contain; position: relative; -webkit-overflow-scrolling: touch; }
.list { padding-bottom: calc(var(--safe-b) + 24px); }

.ptr { height: 0; overflow: hidden; display: flex; align-items: flex-end; justify-content: center; color: var(--fg3); font-size: 0.8rem; transition: height .2s; }
.ptr span { padding-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.ptr.dragging { transition: none; }

.item { display: flex; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.item:active { background: var(--bg2); }
.item .body { flex: 1; min-width: 0; }
.item .title { font-size: 1rem; line-height: 1.42; font-weight: 500; word-break: break-word; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.item .cmt { color: var(--accent); font-weight: 700; font-size: 0.85em; margin-left: 4px; white-space: nowrap; }
.item.read .title { color: var(--read); }
.meta { margin-top: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 0.75rem; color: var(--fg3); line-height: 1.3; }
.meta > span { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.meta svg { width: 1.05em; height: 1.05em; opacity: .8; }
.src { color: var(--c) !important; font-weight: 700; gap: 5px !important; }
.mk { color: var(--accent) !important; }
.unsave { flex: none; align-self: center; width: 34px; height: 34px; border-radius: 50%; color: var(--fg3); font-size: 0.85rem; }
.unsave:active { background: var(--bg2); }
.thumb { width: 3.6rem; height: 3.6rem; border-radius: 10px; object-fit: cover; background: var(--skel); flex: none; }

.rank { width: 1.4rem; flex: none; font-weight: 800; font-size: 0.95rem; color: var(--fg3); padding-top: 1px; text-align: center; }
.rank.top { color: var(--accent); }

.state { padding: 64px 24px; text-align: center; color: var(--fg2); font-size: 0.95rem; line-height: 1.6; }
.state.pre { white-space: pre-line; }
.state button { margin-top: 14px; padding: 10px 22px; border-radius: 999px; background: var(--fg); color: var(--bg); font-weight: 600; }
.note { margin: 8px 12px; padding: 8px 12px; font-size: 0.78rem; color: var(--fg2); background: var(--bg2); border-radius: 10px; }

.skel { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.skel i { display: block; height: 0.95rem; border-radius: 6px; background: var(--skel); margin-bottom: 8px; animation: pulse 1.2s ease-in-out infinite; }
.skel i:nth-child(2) { width: 60%; }
.skel i:last-child { width: 35%; height: 0.7rem; margin: 0; }
@keyframes pulse { 50% { opacity: .45; } }

/* 설정 시트 */
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-t) + 6px) 8px 6px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 1.15rem; }
.sheet-body { flex: 1; overflow-y: auto; padding: 8px 0 calc(var(--safe-b) + 32px); background: var(--bg2); }
.group { background: var(--sheet); margin: 10px 12px; border-radius: 14px; overflow: hidden; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); font-size: 0.95rem; min-height: 52px; width: 100%; text-align: left; }
.row:last-child { border-bottom: 0; }
.row.col { flex-direction: column; align-items: stretch; gap: 10px; }
.row.link { color: var(--accent); font-weight: 600; }
.row.nav i { font-style: normal; color: var(--fg3); font-size: 1.2rem; }
.sheet-body.plain { background: var(--bg); padding-top: 0; }
.foot { text-align: center; color: var(--fg3); font-size: 0.75rem; margin: 18px 0 0; }
.doc-frame { flex: 1; width: 100%; border: 0; background: var(--bg); }
.row select { font: inherit; color: var(--fg); background: var(--bg2); border: 0; border-radius: 10px; padding: 8px 10px; max-width: 64%; }
.hint { color: var(--fg3); font-size: 0.78rem; margin-top: -6px; }
.muted { color: var(--fg3); }
.seg { display: flex; background: var(--bg2); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-width: 0; padding: 8px 4px; border-radius: 9px; font-size: 0.85rem; color: var(--fg2); line-height: 1.25; overflow-wrap: break-word; hyphens: auto; }
.seg button.on { background: var(--sheet); color: var(--fg); font-weight: 700; box-shadow: 0 1px 3px #0002; }
.font-preview { font-size: 1rem; color: var(--fg2); }
.switch { appearance: none; -webkit-appearance: none; width: 48px; height: 28px; border-radius: 99px; background: var(--line); position: relative; flex: none; transition: background .2s; margin: 0; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px #0003; transition: transform .2s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.tab-list { list-style: none; margin: 0; padding: 0; }
.tab-list li { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 16px; border-top: 1px solid var(--line); font-size: 0.95rem; }
.tab-list li label { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; cursor: pointer; }
.tab-list li label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-list input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.tab-list .mv { width: 38px; height: 38px; border-radius: 10px; color: var(--fg2); font-size: 0.9rem; }
.tab-list .mv:active { background: var(--bg2); }
.tab-list .mv:disabled { opacity: .25; }

/* 길게 누르기 메뉴 */
.action-sheet { position: fixed; inset: 0; z-index: 30; background: #0006; display: flex; align-items: flex-end; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.action-box { width: 100%; background: var(--sheet); border-radius: 18px 18px 0 0; padding: 8px 8px calc(var(--safe-b) + 8px); animation: up .2s ease-out; }
.act-title { padding: 12px 12px 10px; font-size: 0.85rem; color: var(--fg2); border-bottom: 1px solid var(--line); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.action-box button { display: block; width: 100%; padding: 15px 12px; text-align: left; font-size: 1rem; border-radius: 12px; }
.action-box button:active { background: var(--bg2); }
.action-box .cancel { text-align: center; color: var(--fg2); margin-top: 4px; }

.blocker { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--fg2); font-size: 0.9rem; }
.blocker.dim { background: #0005; color: #fff; }
.blocker-logo { width: 64px; height: 64px; }
.blocker.dim .blocker-logo { display: none; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.ptr .spinner { width: 16px; height: 16px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 28px); transform: translateX(-50%); z-index: 60; background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 0.88rem; max-width: 86vw; text-align: center; animation: fade .2s; }

/* 글 보기 (웹 미리보기용 — 앱에서는 네이티브 웹뷰) */
#viewer { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; animation: vin .24s ease-out; }
#viewer.out { animation: vout .22s ease-in forwards; }
@keyframes vin { from { transform: translateX(40%); opacity: 0; } }
@keyframes vout { to { transform: translateX(100%); opacity: .4; } }
.vbar { display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-t) + 6px) 6px 6px 14px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 0.95rem; }
.vname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vx { width: 40px; height: 40px; border-radius: 10px; color: var(--fg2); }
.vbody { flex: 1; position: relative; overflow: hidden; }
.vbody iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; transition: transform .32s ease, opacity .32s; }
.vbody iframe.enter { transform: translateY(100%); }
.vbody iframe.leave { transform: translateY(-30%); opacity: 0; }

/* 넓은 화면(웹사이트) */
@media (min-width: 760px) {
  #app, .sheet, #viewer { max-width: 760px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .sheet, #viewer { left: 0; right: 0; }
  body { background: var(--bg2); }
  #app { background: var(--bg); }
}
