:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #17181c; --muted: #6b6e76; --line: #e4e2dc; --soft: #efede8;
  --accent: #5b5bd6; --accent-ink: #fff; --accent-soft: #e9e8fb; --warn: #b4441f; --star: #e0a100;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --panel: #171a20; --ink: #eceef2; --muted: #9a9fab; --line: #262a33; --soft: #1e222a;
    --accent: #8b8bf5; --accent-ink: #0f1115; --accent-soft: #252848; --warn: #f08a63; --shadow: 0 1px 2px rgba(0,0,0,.4); }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
mark { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 2px; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--warn); }
.btn.icon { padding: 8px 12px; font-weight: 700; }
.btn:disabled { opacity: .6; cursor: default; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 32px; width: min(360px, 100%); text-align: center; box-shadow: var(--shadow); display: grid; gap: 12px; }
.login-card h1 { margin: 4px 0 0; } .login-card p { margin: 0; color: var(--muted); }
.login-card img { margin: 0 auto; }
input, textarea, select { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.err { color: var(--warn); min-height: 1.2em; margin: 0; font-size: 14px; }

/* header */
.top { position: sticky; top: 0; z-index: 5; display: flex; gap: 12px; align-items: center; padding: 12px max(16px, env(safe-area-inset-left)); padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand small { font-weight: 500; color: var(--muted); font-size: 13px; }
.search { flex: 1; position: relative; max-width: 720px; }
.search svg { position: absolute; left: 11px; top: 50%; translate: 0 -50%; width: 18px; fill: var(--muted); }
.search input { padding-left: 36px; padding-right: 36px; border-radius: 12px; height: 40px; }
.search kbd { position: absolute; right: 10px; top: 50%; translate: 0 -50%; font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; }
.actions { position: relative; display: flex; gap: 8px; margin-left: auto; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: grid; min-width: 230px; }
.menu button { text-align: left; background: none; border: 0; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--soft); }

.filters { padding: 10px 16px 0; display: grid; gap: 8px; }
.filters .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters select { width: auto; padding: 6px 10px; border-radius: 999px; font-size: 14px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 12px; font-size: 14px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.keywords { flex-wrap: nowrap !important; overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; mask-image: linear-gradient(90deg, #000 92%, transparent); }
.keywords .chip { font-size: 13px; padding: 3px 10px; flex: none; }
.keywords .chip small { color: var(--muted); margin-left: 3px; }
.keywords .chip[aria-pressed="true"] small { color: inherit; }

.queue { margin: 10px 16px 0; padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }

/* grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; padding: 16px; padding-bottom: max(32px, env(safe-area-inset-bottom)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; box-shadow: var(--shadow); transition: transform .12s, border-color .12s; text-align: left; padding: 0; }
.card:hover { transform: translateY(-2px); border-color: var(--muted); }
.thumb { aspect-ratio: 16 / 10; background: var(--soft); position: relative; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ph { position: absolute; inset: 0; display: grid; place-items: center; font-size: 40px; color: var(--muted); }
.badge { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.62); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 999px; backdrop-filter: blur(4px); }
.badge.right { left: auto; right: 8px; }
.card .body { padding: 12px 14px 14px; display: grid; gap: 6px; }
.card h3 { margin: 0; overflow-wrap: anywhere; font-size: 15.5px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card p { margin: 0; color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card .snip { font-size: 13px; color: var(--muted); border-left: 2px solid var(--accent); padding-left: 8px; -webkit-line-clamp: 2; }
.meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); align-items: center; }
.tag { background: var(--soft); border-radius: 6px; padding: 1px 7px; font-size: 12.5px; color: var(--muted); }
.cat { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.star { color: var(--star); }
.feed-count { display: none; }
.empty { text-align: center; color: var(--muted); padding: 60px 16px; }

/* dialogs */
dialog.sheet { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 18px; padding: 0; width: min(980px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog.sheet.narrow { width: min(620px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(10,10,15,.55); backdrop-filter: blur(2px); }
dialog form { padding: 20px 22px; display: grid; gap: 12px; }
dialog h2 { margin: 0; font-size: 20px; }
dialog label { display: grid; gap: 4px; font-size: 14px; font-weight: 600; }
dialog label small { font-weight: 400; color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.buttons { display: flex; gap: 8px; justify-content: flex-end; }
.hint { margin: 0; font-size: 13.5px; color: var(--muted); }

.detail { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); min-height: 0; }
.detail .media { background: #000; position: relative; min-height: 300px; display: flex; flex-direction: column; }
.detail .stage { flex: 1; display: grid; place-items: center; min-height: 0; max-height: calc(100dvh - 110px); }
.detail .stage img, .detail .stage video { max-width: 100%; max-height: calc(100dvh - 110px); object-fit: contain; display: block; }
.detail .strip { display: flex; gap: 4px; padding: 6px; overflow-x: auto; background: #000; }
.detail .strip button { flex: none; width: 54px; height: 54px; padding: 0; border: 2px solid transparent; border-radius: 6px; overflow: hidden; background: #222; cursor: pointer; }
.detail .strip button[aria-current="true"] { border-color: var(--accent); }
.detail .strip img { width: 100%; height: 100%; object-fit: cover; }
.nav { position: absolute; top: 45%; translate: 0 -50%; background: rgba(0,0,0,.5); color: #fff; border: 0; width: 38px; height: 38px; border-radius: 50%; font-size: 20px; cursor: pointer; }
.nav.prev { left: 8px; } .nav.next { right: 8px; }
.counter { position: absolute; top: 10px; left: 10px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; border-radius: 999px; padding: 2px 9px; }
.detail .info { padding: 20px 22px; overflow-y: auto; max-height: calc(100dvh - 24px); display: grid; gap: 14px; align-content: start; }
.detail .info h2 { font-size: 21px; line-height: 1.3; overflow-wrap: anywhere; }
.detail .info .summary { margin: 0; font-size: 15.5px; }
.detail ul.points { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.section h4 { margin: 0 0 6px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.mentions { display: flex; flex-wrap: wrap; gap: 6px; }
.mentions a { text-decoration: none; background: var(--soft); border: 1px solid var(--line); padding: 3px 10px; border-radius: 8px; font-size: 14px; }
.mentions a:hover { border-color: var(--accent); }
.note { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; margin: 0; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; }
details pre { white-space: pre-wrap; word-break: break-word; font: 13px/1.5 ui-monospace, Menlo, monospace; background: var(--soft); border-radius: 10px; padding: 10px; max-height: 280px; overflow: auto; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.close { position: absolute; right: 10px; top: 10px; z-index: 2; background: rgba(0,0,0,.55); color: #fff; border: 0; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 16px; }
.detail.nomedia { grid-template-columns: 1fr; }
.detail.nomedia .media { display: none; }
.kw { display: flex; flex-wrap: wrap; gap: 6px; }
.kw button { border: 1px solid var(--line); background: var(--soft); border-radius: 999px; padding: 2px 10px; font-size: 13px; cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); translate: -50% 0; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 50; box-shadow: var(--shadow); font-size: 14px; }

@media (max-width: 760px) {
  .top { flex-wrap: wrap; }
  .brand small, .search kbd { display: none; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  /* Swipe feed: one link per screen, swipe left/right; snaps to each card. */
  html, body { overscroll-behavior: none; }
  #app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
  .top { position: static; flex: none; }
  .filters, .queue { flex: none; }
  .filters .row { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .filters .row::-webkit-scrollbar { display: none; }
  .filters .row > * { flex: none; }
  .grid { flex: 1 1 auto; min-height: 0; display: flex; gap: 12px; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scrollbar-width: none;
    padding: 10px 6vw max(28px, calc(env(safe-area-inset-bottom) + 24px));
    -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
  .grid::-webkit-scrollbar { display: none; }
  .card { flex: 0 0 88vw; scroll-snap-align: center; scroll-snap-stop: always; height: 100%; }
  .card:hover { transform: none; }
  .card .thumb { aspect-ratio: auto; flex: 1 1 auto; min-height: 140px; }
  .card .body { flex: none; padding: 12px 14px 14px; gap: 7px; }
  .card h3 { font-size: 17px; -webkit-line-clamp: 3; }
  .card p { -webkit-line-clamp: 4; font-size: 14px; }
  .card .tags { display: flex; }
  .feed-count { display: block; position: fixed; left: 50%; translate: -50% 0; bottom: max(4px, env(safe-area-inset-bottom)); z-index: 4; line-height: 18px; font-size: 12px;
    background: color-mix(in srgb, var(--panel) 85%, transparent); border: 1px solid var(--line); border-radius: 999px; padding: 1px 10px; color: var(--muted); }
  .empty { padding: 40px 16px; }
  .filters { padding-top: 8px; }
  .queue { margin-top: 8px; font-size: 13px; padding: 6px 10px; }
  dialog.sheet, dialog.sheet.narrow { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; border: 0; }
  /* Phones: a plain column that scrolls; the media keeps its natural height (capped) instead of being squeezed. */
  .detail { display: flex; flex-direction: column; height: 100%; overflow-y: auto; overscroll-behavior: contain; }
  .detail .media { flex: none; min-height: 0; }
  .detail .stage { flex: none; min-height: 200px; max-height: none; overflow: hidden; }
  .detail .stage img, .detail .stage video { max-width: 100%; max-height: 62dvh; width: auto; height: auto; }
  .detail .stage video { width: 100%; }
  .detail .info { flex: none; max-height: none; overflow: visible; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  .nav { top: 31dvh; }
  .close { position: fixed; top: max(10px, env(safe-area-inset-top)); right: 10px; z-index: 5; }
  .two { grid-template-columns: 1fr; }
}
