/* ---------- base ---------- */
* { box-sizing:border-box; }
body { background:var(--bg); color:var(--text); font-family:system-ui,-apple-system,sans-serif; margin:0; transition:background .15s,color .15s; }
a { color:var(--link); }
header { display:flex; flex-wrap:wrap; gap:8px 12px; align-items:center; padding:10px 16px; background:var(--card); border-bottom:1px solid var(--border); position:sticky; top:0; z-index:5; }
header a.logo { color:var(--accent); font-weight:700; text-decoration:none; font-size:1.1rem; }
form.go { display:flex; gap:8px; flex:1; max-width:600px; }
form.go input { flex:1; padding:8px 12px; border-radius:8px; border:1px solid var(--border); background:var(--card2); color:var(--text); }
form.go select, .toolbar select, .theme-select { padding:8px; border-radius:8px; border:1px solid var(--border); background:var(--card2); color:var(--text); }
form.go button, .toolbar button { padding:8px 14px; border-radius:8px; border:none; background:var(--accent); color:var(--accent-text); cursor:pointer; font-weight:600; }
/* redlib-style search bar with in-sub checkbox */
.searchbar { display:flex; gap:8px; flex:1 1 240px; min-width:0; max-width:600px; align-items:center; }
.searchbar input[type=text] { flex:1; min-width:0; padding:8px 12px; border-radius:8px; border:1px solid var(--border); background:var(--card2); color:var(--text); }
.searchbar .subchk { display:flex; gap:4px; align-items:center; font-size:.78rem; color:var(--muted); white-space:nowrap; }
.searchbar .subchk input { accent-color:var(--accent); }
.searchbar button { padding:8px 14px; border-radius:8px; border:none; background:var(--accent); color:var(--accent-text); cursor:pointer; font-weight:600; }
main { max-width:820px; margin:0 auto; padding:16px; }
/* backend-fallback warning (Master 2026-11-06): shown when the requested
   backend failed and another one served the page */
.fallback-note { background:var(--card2); border:1px solid var(--accent); color:var(--text); border-radius:8px; padding:8px 12px; font-size:.85rem; margin:0 0 10px; }
/* content-width setting (ALL pages, always centered):
   wide (default, fills screen) / normal (1000px) / narrow (820px).
   The sub page is a flex row [sidebar | main] — width caps go on the
   .sub-layout itself with margin:0 auto so the content stays CENTERED
   (capping .sub-main alone would leave it left-aligned). */
main:has(.sub-layout) { max-width:none; }
.sub-layout { max-width:none; margin:0 auto; }
.sub-layout[data-width="normal"] { max-width:1000px; }
.sub-layout[data-width="narrow"] { max-width:820px; }
@media (max-width:768px) {
  header { padding:8px 10px; }
  .searchbar { flex-basis:100%; max-width:none; order:3; }
  .searchbar input[type=text] { padding:7px 10px; }
  .sub-layout { max-width:100% !important; }
  /* mobile: tighter cards, smaller thumbs, wrapped controls */
  main { padding:10px; }
  .card { padding:10px 12px; margin-bottom:10px; }
  .card.pinned { border-color:var(--accent); box-shadow:0 0 0 1px var(--accent); }
  .thumb-link { max-width:90px; }
  .thumb { max-width:90px; max-height:64px; }
  .card h2 { font-size:1rem; }
  .toolbar { gap:6px; }
  .toolbar a { font-size:.85rem; }
  .backend-sel { margin-left:6px; }
  h1.sub-title { font-size:1.05rem; }
  /* round 7 (found by the logged-in mobile check, pre-existing): on the
     sub page the wrapped searchbar row = input + the nowrap in-sub
     checkbox ("r/OnePunchMan") + the search button — the input's default
     min-width:auto refused to shrink and the row overflowed the viewport
     by ~29px. min-width:0 above lets it give way; very long sub names
     ellipsize instead of pushing the button off-screen. */
  .searchbar .subchk span { max-width:110px; overflow:hidden; text-overflow:ellipsis; }
  /* round 15: the theme dropdown panel would overflow a narrow viewport
     if it stayed anchored to the small .theme-menu box (menu sits ~150px
     from the left edge + a 170px panel > 320px screens). On mobile the
     details box becomes static so the panel anchors to the STICKY HEADER
     instead (a positioned ancestor) and spans the viewport width — it
     can never poke past the right edge, and the 65vh scroll cap keeps
     long lists (16 themes + 5 group headers) usable. */
  .theme-menu { position: static; }
  .theme-panel { left: 10px; right: 10px; min-width: 0; }
}
.card { background:var(--card); border-radius:10px; padding:14px 16px; margin-bottom:12px; border:1px solid var(--border); overflow:hidden; }
.card.pinned { border-color:var(--accent); box-shadow:0 0 0 1px var(--accent); }
.card h2 { margin:0 0 6px; font-size:1.05rem; }
.card h2 a { color:var(--text); text-decoration:none; }
.card h2 a:hover { color:var(--link); }
.meta { color:var(--muted); font-size:.85rem; margin-bottom:6px; }
.meta a { color:var(--muted); }
.preview { color:var(--muted); font-size:.9rem; }
/* ---------- long-content wrapping (Master 2026-11-06: "text on search on
   mobile can overflow destroying the mobile view") — search queries,
   post titles and preview text can contain unbreakable runs (urls, ids,
   long words). Without these the page grows wider than the viewport and the
   whole mobile layout breaks (horizontal scroll). 'anywhere' also allows
   breaking WITHIN long words, not just at spaces. .card h2 covers EVERY
   listing view (sub / index / user / search — round 4 unified them on the
   card markup); text-mode .e lives in base_text.html's inline <style>. */
h1 { overflow-wrap:anywhere; }
.card h2 { overflow-wrap:anywhere; }
.preview { overflow-wrap:anywhere; word-break:break-word; }
.fallback-note { overflow-wrap:anywhere; }
.thumb-link { float:right; margin-left:10px; position:relative; display:block; max-width:110px; }
.thumb { max-width:110px; max-height:80px; border-radius:6px; display:block; }
.media-label { position:absolute; bottom:2px; left:50%; transform:translateX(-50%); background:rgba(0,0,0,.72); color:#fff; font-size:.65rem; padding:1px 6px; border-radius:4px; letter-spacing:.02em; white-space:nowrap; }
/* round 24: the flair chip is a LINK now — the sub-restricted flair
   search (old-reddit's own flair chip shape). Custom flair colors arrive
   inline (hex-validated upstream in reddit/parsers/markdown.py) and
   override the theme chip; the hover border is the clickable affordance. */
.flare { background:var(--card2); border:1px solid var(--border); padding:0 6px; border-radius:4px; font-size:.75rem; margin-right:6px; color:var(--text); text-decoration:none; white-space:nowrap; }
.flare:hover { border-color:var(--accent); text-decoration:none; }
/* the author's user flair — display-only (no search operator exists),
   a touch smaller and muted next to the author link */
.aflare { background:var(--card2); border:1px solid var(--border); padding:0 5px; border-radius:4px; font-size:.7rem; margin-left:4px; color:var(--muted); white-space:nowrap; }
.repost-badge { background:rgba(210,58,0,.15); border:1px solid var(--accent); color:var(--accent); padding:0 6px; border-radius:4px; font-size:.75rem; margin-right:6px; text-decoration:none; }
.score, .cmt { margin-left:8px; color:var(--muted); }
.age { margin-left:8px; color:var(--muted); white-space:nowrap; }
/* (`.cmt a.cmt, .meta a.cmt { text-decoration:none }` was removed in round 5:
   no a.cmt lives inside .meta/.cmt anymore — the standalone line below
   carries its own text-decoration. post.html's span.cmt keeps the rules
   above.) */
/* ---------- comments link = the LAST line of each listing entry (Master
   2026-11-07: "In the sub view the comments link should be the last line
   of each entry") — a standalone block at the card bottom instead of an
   inline bit of the .meta row, where it wrapped unpredictably between
   score and age (worst on mobile). Shared by sub/index/search cards.
   .card a.cmt-last (0,2,1) out-ranks the inline .cmt margin-left rule. */
.card a.cmt-last { display:block; margin:2px 0 0; color:var(--muted); font-size:.85rem; text-decoration:none; }
.card a.cmt-last:hover { color:var(--link); text-decoration:underline; }
.cmt-img { max-width:100%; border-radius:6px; margin:4px 0; display:block; }
.cmt-video { max-width:100%; border-radius:6px; margin:4px 0; display:block; background:#000; }
/* ---------- voting (round 7: "implement up and downvote when logged in")
   .vote replaces the anon ▲-score span in the .meta row when logged in.
   base.js posts dir 1/-1/0 to /api/vote and toggles .on on the arrow;
   clicking the active arrow sends 0 (vote removed). */
.vote { display:inline-flex; align-items:center; gap:2px; margin-left:8px; vertical-align:middle; }
.vote .vote-btn { background:none; border:none; padding:1px 3px; cursor:pointer; color:var(--muted); font-size:.85rem; line-height:1; }
.vote .vote-btn:hover { color:var(--link); }
.vote .vote-btn.on { color:var(--accent); font-weight:700; }
.vote .score { margin-left:4px; color:var(--muted); }
.vote.err .vote-btn { color:var(--link); }
/* ---------- logged-in username in the upper right corner (round 7).
   Sits AFTER the searchbar (which flex-grows), so it lands at the right
   edge; margin-left:auto keeps it right when the searchbar wraps to its
   own row on mobile. */
.header-user { margin-left:auto; color:var(--accent); font-size:.9rem; font-weight:600; text-decoration:none; white-space:nowrap; }
.header-user:hover { text-decoration:underline; }
/* ---------- submit modal (round 7: "fix the create post button to show
   a popup"). The markup + JS existed since 2026-10-24 but NO stylesheet
   defined these classes — the form rendered as an unstyled inline block
   shoved into the page flow. [hidden] override needed: display:flex below
   would otherwise beat the UA sheet's [hidden]{display:none}. */
.submit-toggle { padding:6px 14px; border-radius:8px; border:1px solid var(--border); background:var(--card2); color:var(--accent); cursor:pointer; font-weight:600; font-size:.85rem; }
.submit-toggle:hover { background:var(--border); }
.submit-wrap { margin-bottom:10px; }
.modal-overlay { position:fixed; inset:0; background:rgba(0,0,0,.55); display:flex; align-items:center; justify-content:center; z-index:50; padding:16px; }
.modal-overlay[hidden] { display:none; }
.submit-form { background:var(--card); border:1px solid var(--border); border-radius:12px; padding:16px; width:100%; max-width:520px; display:flex; flex-direction:column; gap:10px; box-shadow:0 12px 40px rgba(0,0,0,.35); }
.submit-form .modal-head { display:flex; justify-content:space-between; align-items:center; gap:10px; }
.submit-form input[type=text], .submit-form textarea { padding:8px 12px; border-radius:8px; border:1px solid var(--border); background:var(--card2); color:var(--text); font:inherit; width:100%; }
.modal-close { background:none; border:none; color:var(--muted); font-size:1.4rem; line-height:1; cursor:pointer; padding:2px 6px; }
.modal-close:hover { color:var(--text); }
/* ---------- post view media ---------- */
.post-thumb { max-width:100%; border-radius:8px; margin:4px 0; }
.external-link { margin:8px 0; word-break:break-all; }
.ext-link { display:block; }
.ext-box { display:block; height:100%; min-height:120px; box-sizing:border-box;
  padding:10px; word-break:break-all; color:var(--link);
  border:1px dashed var(--border, #444); border-radius:8px;
  font-size:12px; overflow:hidden; }
.external-link a { color:var(--link); }
.video-wrap { position:relative; display:inline-block; margin:4px 0; }
.video-wrap .media-label { font-size:.8rem; padding:2px 8px; }
/* gallery carousel */
.gallery-carousel { position:relative; margin:10px 0; max-width:760px; }
.gallery-carousel .gc-slide { display:none; }
.gallery-carousel .gc-slide img { width:100%; border-radius:8px; }
/* r25: a gif compressed to webm renders as <video> in the same slots */
.gallery-carousel .gc-slide video { width:100%; border-radius:8px; }
.video-wrap .cmt-video, video.post-thumb { max-width:100%; border-radius:8px; }
.gallery-carousel .gc-prev, .gallery-carousel .gc-next { position:absolute; top:50%; transform:translateY(-50%); background:rgba(0,0,0,.55); color:#fff; border:none; border-radius:50%; width:34px; height:34px; font-size:1.3rem; cursor:pointer; line-height:1; }
.gallery-carousel .gc-prev { left:10px; }
.gallery-carousel .gc-next { right:10px; }
.gallery-carousel .gc-prev:hover, .gallery-carousel .gc-next:hover { background:rgba(0,0,0,.8); }
.gallery-carousel .gc-count { position:absolute; bottom:8px; right:10px; background:rgba(0,0,0,.6); color:#fff; font-size:.75rem; padding:1px 8px; border-radius:4px; }
.badge { display:inline-block; background:var(--card2); color:var(--muted); border-radius:10px; padding:1px 8px; font-size:.75rem; margin-left:6px; }
.badge.err { background:#5c1a1a; color:#ff9c9c; }
.backend-sel { display:inline-flex; gap:2px; margin-left:10px; }
.backend-opt { font-size:.75rem; padding:1px 8px; border-radius:10px; color:var(--muted); text-decoration:none; }
.backend-opt:hover { color:var(--text); background:var(--card2); }
.backend-opt.active { color:var(--text); background:var(--card2); font-weight:600; }
.backend-opt.disabled { opacity:.4; cursor:not-allowed; }
.sub-note { margin:-6px 0 14px; font-size:.8rem; }
.toolbar { display:flex; gap:8px; align-items:center; flex-wrap:wrap; margin-bottom:14px; }
.toolbar a { color:var(--link); text-decoration:none; font-size:.9rem; }
.toolbar a.on { font-weight:700; color:var(--text); }
a.more, .more { display:inline-block; margin:10px 0; color:var(--link); text-decoration:none; font-weight:600; }
.muted { color:var(--muted); }
.error { background:var(--card); border:1px solid #5c1a1a; border-radius:10px; padding:16px; }
h1.sub-title { margin:4px 0 12px; }
.debug-footer { margin:16px 0 8px; padding:8px 12px; background:var(--code-bg); border-radius:8px; font-size:.78rem; }
.debug-footer code { white-space:pre-wrap; word-break:break-all; }
[hidden] { display:none !important; }

/* noautoload: click-to-load image toggle (bandwidth branch) */
.img-toggle summary { cursor: pointer; color: var(--muted); margin: 8px 0; }
.img-toggle summary:hover { color: var(--accent); }

/* ---------- theme quick-switch dropdown (round 15, Master: "Add a
   dropdown menu next to the right of the settings link to quickly switch
   between them"). Native <details>/<summary>: opens without JS; base.js
   adds close-on-outside-click + the no-reload swap. The panel is
   absolutely positioned against the summary's .theme-menu box; the
   header is position:sticky (= a positioned ancestor) so the panel
   scrolls with it. z-index above page content but below modals (50). */
.theme-menu { position: relative; }
.theme-menu > summary {
  list-style: none; cursor: pointer; user-select: none;
  font-size: .85rem; color: var(--muted); white-space: nowrap;
  padding: 2px 6px; border-radius: 6px;
}
.theme-menu > summary::-webkit-details-marker { display: none; }
.theme-menu > summary::after { content: "\25BE"; font-size: .7em; margin-left: 3px; }
.theme-menu > summary:hover { color: var(--text); background: var(--card2); }
.theme-menu[open] > summary { color: var(--text); background: var(--card2); }
.theme-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35); padding: 6px; min-width: 170px;
  max-height: min(430px, 65vh); overflow-y: auto;
}
.theme-group {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 7px 8px 2px;
}
.theme-group:first-child { padding-top: 2px; }
.theme-item {
  display: block; padding: 5px 10px; border-radius: 6px;
  color: var(--text); text-decoration: none; font-size: .85rem; white-space: nowrap;
}
.theme-item:hover { background: var(--card2); }
.theme-item.active { color: var(--accent); font-weight: 700; }
.theme-item.active::before { content: "\2713\00a0"; }
