:root {
  --bg: #f3f3f6;
  --card: #ffffff;
  --text: #16171c;
  --muted: #6b6f7b;
  --line: #e2e3e8;
  --accent: #5b5bf0;
  --bar: rgba(243, 243, 246, 0.86);
  --chip: #e6e6ee;
  --d0: #5b5bf0; --d1: #1fa37a; --d2: #e08a1e; --d3: #d2436b; --d4: #2b9bd6; --d5: #8a5cd6;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f13;
    --card: #17181e;
    --text: #e9eaf0;
    --muted: #8d91a0;
    --line: #262832;
    --accent: #8b8bff;
    --bar: rgba(14, 15, 19, 0.86);
    --chip: #23252e;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

.overlay { z-index: 10; transform: translateX(100%); visibility: hidden; transition: transform .28s cubic-bezier(.2,.8,.2,1), visibility 0s .28s; box-shadow: -8px 0 24px rgba(0,0,0,.18); }
.overlay.open { transform: none; visibility: visible; transition: transform .28s cubic-bezier(.2,.8,.2,1), visibility 0s; }

.bar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: var(--bar); backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--line); min-height: 48px;
}
.title-btn { font-weight: 700; font-size: 19px; flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--muted); font-size: 14px; }
.bar-title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; font-size: 22px; border-radius: 10px; color: var(--accent); flex: none; }
.icon-btn.back { font-size: 34px; line-height: 1; }
.icon-btn:active { background: var(--chip); }

.sorts { display: flex; gap: 6px; padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--line); overflow-x: auto; }
.sorts:empty { display: none; }
.sorts button { padding: 5px 14px; border-radius: 999px; background: var(--chip); font-size: 14px; font-weight: 600; color: var(--muted); }
.sorts button.on { background: var(--accent); color: #fff; }

.feed { max-width: 720px; margin: 0 auto; padding: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--card); padding: 12px 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); cursor: pointer; }
@media (min-width: 740px) { .card { border: 1px solid var(--line); border-radius: 12px; } }
.card:active { filter: brightness(.97); }
.meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.meta a { color: var(--text); font-weight: 600; }
.card h2, .post-head h1 { font-size: 17px; line-height: 1.3; margin: 6px 0 8px; font-weight: 650; overflow-wrap: anywhere; }
.post-head h1 { font-size: 20px; }
.flair { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--chip); color: var(--muted); font-weight: 600; }
.tag { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; color: #fff; background: #d2436b; }
.tag.spoiler { background: #555; }
.snippet { color: var(--muted); font-size: 14.5px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin: 0 0 8px; overflow-wrap: anywhere; }
.stats { font-size: 13px; color: var(--muted); display: flex; gap: 14px; margin-top: 6px; }

.media { position: relative; margin: 4px -14px 6px; background: #000; max-height: 72vh; display: flex; justify-content: center; overflow: hidden; }
.media img, .media video { width: 100%; height: 100%; max-height: 72vh; object-fit: contain; display: block; }
.media.blur img, .media.blur video { filter: blur(28px); transform: scale(1.1); pointer-events: none; }
.media.blur::after { content: attr(data-label); position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .04em; }
.gallery { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; margin: 4px -14px 6px; background: #000; max-height: 72vh; }
.gallery img { flex: 0 0 100%; width: 100%; max-height: 72vh; object-fit: contain; scroll-snap-align: center; }
.gallery-count { font-size: 12px; color: var(--muted); margin: -2px 0 4px; }
.link-card { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin: 4px 0 6px; color: var(--text); overflow: hidden; }
.link-card img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; flex: none; }
.link-card span { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

.post-wrap { max-width: 720px; margin: 0 auto; }
.post-head { background: var(--card); padding: 14px; border-bottom: 1px solid var(--line); }
.md { font-size: 15.5px; overflow-wrap: anywhere; }
.md p { margin: 0 0 .6em; }
.md p:last-child { margin-bottom: 0; }
.md blockquote { margin: .4em 0; padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.md pre { overflow-x: auto; background: var(--chip); padding: 8px; border-radius: 6px; font-size: 13px; }
.md code { font-size: .9em; background: var(--chip); padding: 0 3px; border-radius: 3px; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; }
.md img { max-width: 100%; }
.md ul, .md ol { padding-left: 1.3em; margin: .3em 0 .6em; }

.comments { padding: 6px 0 0; }
.comments-head { padding: 10px 14px 4px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.c { padding: 8px 0 0 10px; border-left: 2px solid var(--dc, var(--line)); margin-left: 8px; }
.comments > .c { margin-left: 0; border-left: 0; padding: 10px 14px 4px; background: var(--card); border-top: 1px solid var(--line); }
.c-head { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; padding: 2px 0 4px; cursor: pointer; user-select: none; }
.c-head b { color: var(--text); font-weight: 600; }
.c-head .op { color: var(--accent); }
.c-head .mod { color: #1fa37a; }
.c-body { padding-right: 10px; }
.c.collapsed > .c-body, .c.collapsed > .c-kids { display: none; }
.c.collapsed > .c-head::after { content: attr(data-hidden); color: var(--accent); }
.more-btn { display: block; color: var(--accent); font-size: 14px; font-weight: 600; padding: 8px 0 8px 10px; margin-left: 8px; text-align: left; }

.status { text-align: center; color: var(--muted); padding: 28px 16px; font-size: 14px; }
.status .err { color: #d2436b; margin-bottom: 10px; }
.retry { padding: 8px 18px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 600; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.sheet { position: fixed; inset: 0; z-index: 20; visibility: hidden; transition: visibility 0s .25s; }
.sheet.open { visibility: visible; transition: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); opacity: 0; transition: opacity .25s; }
.sheet.open .sheet-backdrop { opacity: 1; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 82vh; overflow-y: auto; background: var(--card);
  border-radius: 16px 16px 0 0; padding: 6px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .25s cubic-bezier(.2,.8,.2,1); max-width: 720px; margin: 0 auto;
}
.sheet.open .sheet-panel { transform: none; }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
#subInput { width: 100%; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); outline: none; }
#subInput:focus { border-color: var(--accent); }
.sheet h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 4px; }
#subList, #subResults { list-style: none; margin: 0; padding: 0; }
.sub-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.sub-row .go { flex: 1; text-align: left; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-row .go small { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
.sub-row .x, .sub-row .add { width: 32px; height: 32px; border-radius: 50%; color: var(--muted); font-size: 18px; }
.sub-row .add { color: var(--accent); font-size: 22px; }
.sub-row.current .go { color: var(--accent); }
.hint { font-size: 13.5px; color: var(--muted); margin: 6px 0; padding-left: 0; }
ol.hint { padding-left: 1.3em; }
ol.hint li { margin: 3px 0; }
.hint.ok { color: #1fa37a; font-weight: 600; }
.setup-row { display: flex; gap: 8px; }
#clientIdInput { flex: 1; min-width: 0; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); outline: none; }
#clientIdInput:focus { border-color: var(--accent); }
