/* Layout: one centred column of full-width posts separated by rules, 9gag style; sticky header with tabs and topic chips. */
:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --ink: #1c1a17;
  --muted: #6d675e;
  --rule: #e2dcd2;
  --accent: #b2701c;
  --accent-ink: #ffffff;
  --chip: #ece6dc;
  --media-bg: #e9e4db;
  --display: 'Bricolage Grotesque', 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  --body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412; --surface: #1d1b18; --ink: #efe9df; --muted: #a29a8d; --rule: #2d2a25;
    --accent: #e6aa52; --accent-ink: #1a1408; --chip: #2a2723; --media-bg: #0e0d0c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 var(--body);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
button, input, select, textarea { font: inherit; color: inherit; }
img, video, iframe { display: block; max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
  padding-top: env(safe-area-inset-top, 0px);
}
.bar {
  max-width: 640px; margin: 0 auto; height: 52px;
  display: flex; align-items: center; gap: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.mark {
  font: 800 24px/1 var(--display); letter-spacing: -0.03em;
  color: var(--ink); text-decoration: none;
}
.mark span { color: var(--accent); }
.tabs { display: flex; gap: 2px; margin: 0 auto; }
.tab {
  background: none; border: 0; padding: 8px 10px; border-radius: 8px;
  font-weight: 600; font-size: 15px; color: var(--muted); cursor: pointer; white-space: nowrap;
}
@media (max-width: 430px) {
  .bar { gap: 4px; }
  .mark { font-size: 20px; }
  .tab { padding: 8px 6px; font-size: 14px; }
  .tools { gap: 0; }
  .icon { width: 34px; height: 34px; }
  .icon svg { width: 20px; height: 20px; }
}
@media (max-width: 380px) { .tab { padding: 8px 4px; font-size: 13.5px; } .icon { width: 31px; } }
.tab[aria-selected="true"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }
.tools { display: flex; gap: 4px; }
.icon {
  width: 38px; height: 38px; border: 0; border-radius: 50%;
  background: none; color: var(--ink); cursor: pointer; display: grid; place-items: center;
}
.icon:hover { background: var(--chip); }
.icon svg { width: 22px; height: 22px; }

.topics {
  max-width: 640px; margin: 0 auto;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 2px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
}
.topics::-webkit-scrollbar { display: none; }
.topics button {
  flex: none; border: 1px solid var(--rule); background: var(--surface);
  padding: 5px 12px; border-radius: 999px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.topics button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.progress { height: 2px; background: var(--rule); position: relative; }
.progress::after {
  content: ""; position: absolute; inset: 0 auto 0 0; width: var(--p, 0%);
  background: var(--accent); transition: width .3s ease;
}

/* ---------- feed ---------- */
main { max-width: 640px; margin: 0 auto; }
.post {
  padding: 18px 0 8px; border-bottom: 8px solid var(--rule);
  background: var(--surface);
}
@media (min-width: 660px) {
  main { padding-top: 16px; }
  .post { border: 1px solid var(--rule); border-radius: 10px; margin-bottom: 16px; overflow: hidden; }
}
.post.gone { display: none; }
.meta, .title, .body, .actions, .undo {
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.meta { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.topic-chip {
  border: 0; background: none; padding: 0; cursor: pointer;
  font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent);
}
.src { font-weight: 500; color: var(--ink); opacity: .8; }
.title {
  margin: 6px 0 12px; font: 700 20px/1.25 var(--display); letter-spacing: -0.01em;
  text-wrap: pretty; overflow-wrap: anywhere;
}
.body { margin: 12px 0 4px; font-size: 16px; line-height: 1.55; color: var(--ink); }
.post > .title + .body { margin-top: -2px; }
.body p { margin: 0; white-space: pre-line; overflow-wrap: anywhere; max-width: 68ch; }
.body.folded p { max-height: 11.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 60%, transparent); mask-image: linear-gradient(#000 60%, transparent); }
.body.folded.short p { max-height: 6.2em; }
.body .from { display: block; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.readmore { margin-top: 2px; }

.media { position: relative; background: var(--media-bg); }
.media img, .media video { width: 100%; height: auto; max-height: 82vh; object-fit: contain; margin: 0 auto; }
.media.clipped { max-height: 70vh; overflow: hidden; }
.media.clipped img { max-height: none; }
.expand {
  position: absolute; left: 0; right: 0; bottom: 0; border: 0; cursor: pointer;
  padding: 40px 0 14px; font-weight: 700; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
}
.gifwrap .badge {
  position: absolute; left: 10px; top: 10px; padding: 2px 7px; border-radius: 5px;
  background: rgba(0,0,0,.6); color: #fff; font-size: 11px; font-weight: 800; letter-spacing: .08em;
}
video.gif { cursor: pointer; }
#sound[aria-pressed="true"] { color: var(--accent); }
.note { display: block; font-size: 12px; color: var(--muted); padding: 6px 16px; background: var(--surface); }

.gallery .strip { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.gallery .strip::-webkit-scrollbar { display: none; }
.gallery .strip img { flex: 0 0 100%; scroll-snap-align: center; max-height: 82vh; object-fit: contain; }
.count {
  position: absolute; top: 10px; right: 10px; padding: 3px 9px; border-radius: 999px;
  background: rgba(0,0,0,.6); color: #fff; font-size: 12px; font-variant-numeric: tabular-nums;
}

.yt { aspect-ratio: 16 / 9; max-width: 100%; overflow: hidden; }
.yt.short { aspect-ratio: 9 / 16; max-height: 80vh; margin: 0 auto; width: min(100%, calc(80vh * 9 / 16)); }
.yt img, .yt iframe { width: 100%; height: 100%; object-fit: cover; border: 0; max-height: none; }
.play {
  position: absolute; inset: 0; margin: auto; width: 76px; height: 76px; border-radius: 50%;
  border: 0; cursor: pointer; display: grid; place-items: center; gap: 0;
  background: rgba(0,0,0,.62); color: #fff;
}
.play svg { width: 34px; height: 34px; margin-left: 4px; }
.play span { position: absolute; bottom: -26px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; text-shadow: 0 1px 3px #000; }

.actions { display: flex; align-items: center; gap: 4px; padding-top: 8px; padding-bottom: 4px; flex-wrap: wrap; }
.score { font-size: 13px; color: var(--muted); margin-right: auto; font-variant-numeric: tabular-nums; }
.act {
  display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--rule); background: none;
  border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 600; color: var(--ink);
  text-decoration: none; cursor: pointer;
}
.act svg { width: 17px; height: 17px; }
.act.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
@media (max-width: 420px) { .act span { display: none; } .act { padding: 8px 12px; } .act.on span { display: none; } }

.undo {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding-top: 14px; padding-bottom: 14px; border-bottom: 8px solid var(--rule);
  font-size: 14px; color: var(--muted); background: var(--surface);
}
.link { border: 0; background: none; color: var(--accent); font-weight: 700; cursor: pointer; padding: 4px 0; }

.empty, .end { padding: 64px 24px; text-align: center; }
.empty h2 { font: 700 22px/1.2 var(--display); margin: 0 0 8px; }
.empty p, .end p { color: var(--muted); margin: 0 auto 16px; max-width: 34ch; }
.btn {
  border: 1px solid var(--rule); background: var(--surface); border-radius: 8px;
  padding: 8px 14px; font-weight: 600; cursor: pointer;
}
#sentinel { height: 1px; }

/* ---------- settings ---------- */
.sheet {
  width: min(560px, 100vw); max-height: 92vh; margin: auto auto 0; border: 0; padding: 0;
  border-radius: 16px 16px 0 0; background: var(--surface); color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 16px; } }
.sheet::backdrop { background: rgba(0,0,0,.5); }
.sheet-head {
  position: sticky; top: 0; background: var(--surface); z-index: 1;
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--rule);
}
.sheet h2 { margin: 0; font: 700 20px/1.2 var(--display); }
.sheet section { padding: 16px 20px; border-bottom: 1px solid var(--rule); }
.sheet h3 { margin: 0 0 6px; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.hint { display: block; font-size: 14px; color: var(--muted); margin: 0 0 12px; }
textarea, .add input, .add select {
  width: 100%; border: 1px solid var(--rule); border-radius: 8px; padding: 9px 10px; background: var(--bg);
}
.add { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
@media (max-width: 480px) { .add { grid-template-columns: 1fr auto; } .add input { grid-column: 1 / -1; } }

.learned { display: grid; gap: 6px; margin-bottom: 10px; }
.lrow { display: grid; grid-template-columns: 96px 1fr 34px; gap: 10px; align-items: center; font-size: 14px; }
.ltrack { height: 8px; background: var(--chip); border-radius: 4px; overflow: hidden; }
.lbar { height: 100%; background: var(--accent); border-radius: 4px; }
.lbar.neg { background: var(--muted); }
.lval { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

.sources { display: grid; gap: 2px; }
.srow { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; padding: 7px 0; align-items: center; cursor: pointer; }
.srow input { grid-row: span 2; width: 18px; height: 18px; accent-color: var(--accent); }
.sname { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.stopics { font-size: 13px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 30;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; font-weight: 600; max-width: calc(100vw - 32px); text-align: center;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
