/* Minimal, old-reddit-style layout */
:root {
  color-scheme: dark;
  --bg: #0f1115;
  --bg-elevated: #171b22;
  --text: #f5f6f9;
  --muted: #99a4b6;
  --line: #262e38;
  --link: #7dabff;
  /* Keep visited links consistent with brand palette */
  --link-visited: #9cb8ff;
  --accent-up: #ff4500;
  --accent-down: #7193ff;
  --chip-border: #303a45;
  --btn-bg: #11161d;
  --btn-text: #cbd4e2;
  --comment-indent: 16px;
  --comment-guide-1: rgba(125, 171, 255, 0.24);
  --comment-guide-2: rgba(125, 171, 255, 0.32);
  --comment-guide-3: rgba(125, 171, 255, 0.4);
  --comment-guide-4: rgba(125, 171, 255, 0.48);
  --comment-guide-5: rgba(125, 171, 255, 0.56);
  --comment-guide-6: rgba(125, 171, 255, 0.64);
}

.theme-light {
  color-scheme: light;
  --bg: #ffffff;
  --bg-elevated: #fafafa;
  --text: #111111;
  --muted: #6e7781;
  --line: #e6e6e6;
  --link: #0066cc;
  --link-visited: #0066cc;
  --accent-up: #ff4500;
  --accent-down: #7193ff;
  --chip-border: #d7dce2;
  --btn-bg: #ffffff;
  --btn-text: #333333;
  --comment-indent: 18px;
  --comment-guide-1: rgba(0, 102, 204, 0.18);
  --comment-guide-2: rgba(0, 102, 204, 0.24);
  --comment-guide-3: rgba(0, 102, 204, 0.3);
  --comment-guide-4: rgba(0, 102, 204, 0.36);
  --comment-guide-5: rgba(0, 102, 204, 0.42);
  --comment-guide-6: rgba(0, 102, 204, 0.48);
}
* { box-sizing: border-box; }
html, body { margin:0; padding:0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
a { color: var(--link); text-decoration: none; }
/* Unify visited color site-wide for consistency */
a:visited { color: var(--link-visited); }
a:hover, a:focus-visible { text-decoration: underline; }
/* Ensure "muted" anchors remain muted in all states */
a.muted, a.muted:visited, .muted a, .muted a:visited { color: var(--muted); }
li p { margin-top: 0; margin-bottom: 0; }
/* Keep special nav/brand/buttons consistent regardless of visited state */
a.brand, a.brand:visited { color: var(--text); }
a.nav-link, a.nav-link:visited { color: var(--text); }
a.btn-link, a.btn-link:visited { color: var(--link); }
.reply-link:visited { color: var(--link); }
.muted { color: var(--muted); }
.container { width: 96%; max-width: 980px; margin: 0 auto; padding: 0 8px; }

/* Top bar */
.topbar { border-bottom: 1px solid var(--line); background: var(--bg-elevated); }
.topbar-inner { display: flex; gap: 16px; align-items: center; padding: 8px 0; }
.brand { font-weight: 700; color: var(--text); }
.nav { display: flex; gap: 12px; margin-left: 8px; }
.nav-link { color: var(--text); }
.nav-icon { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; line-height: 0; padding: 0; }
.nav-icon i { font-size: 18px; }
.nav-icon:hover,
.nav-icon:focus-visible { text-decoration: none; }
.inbox-link { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; line-height: 0; padding: 0; }
.inbox-link .icon { width: 18px; height: 18px; display: inline-block; }
.inbox-link:hover,
.inbox-link:focus-visible { text-decoration: none; }
/* Make inbox icon visibly different when there are unread notifications.
   Use higher CSS specificity to override the generic nav visited rule. */
.nav a.inbox-link.has-unread { color: var(--accent-up); font-weight: 700; }
.auth { margin-left: auto; display: flex; gap: 12px; }

/* Content */
main.container { padding: 16px 0 48px; }

/* Chamber cards */
.chamber-card { border-bottom: 1px solid var(--line); padding: 12px 0; }
.chamber-title { margin: 0; font-size: 16px; }
.chamber-name { margin-left: 6px; font-weight: normal; color: var(--muted); font-size: 12px; }
.chamber-desc { margin: 6px 0; }
.chamber-flags { list-style: none; padding: 0; display: inline-flex; gap: 6px; margin: 4px 0 0; }
.flag { font-size: 11px; border: 1px solid var(--chip-border); padding: 1px 6px; border-radius: 3px; color: var(--muted); background: var(--bg); }
.flag.nsfw { color: #b00; border-color: #f3b; }

/* Posts */
.post { border-bottom: 1px solid var(--line); padding: 12px 0; }
.post-title { margin: 0 0 4px; font-size: 16px; }
.post-title a,
.post-title a:visited { color: var(--text); }
.post-meta { font-size: 12px; }
.post-actions .btn { font-size: 12px; }
.vote { display: inline-flex; gap: 6px; align-items: center; margin-right: 8px; }
.vote-btn { border: 1px solid var(--line); border-radius: 3px; padding: 2px 6px; color: var(--btn-text); background: var(--btn-bg); }
.vote-btn.active-up { color: var(--accent-up); border-color: var(--accent-up); }
.vote-btn.active-down { color: var(--accent-down); border-color: var(--accent-down); }
.vote-score { font-weight: 600; color: var(--text); min-width: 2ch; text-align: center; }
.vote-btn.processing { opacity: 0.6; filter: grayscale(40%); }

/* Expand/collapse toggle for text previews */
.post-expand { margin: 6px 0 4px; }
.expand-toggle {
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 2px 6px;
  color: var(--btn-text);
  background: var(--btn-bg);
  font-weight: 600;
}
.expand-toggle:hover,
.expand-toggle:focus-visible {
  outline: none;
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--line);
  text-decoration: none;
}

/* Comments */
.comment {
  border-bottom: 1px solid var(--line);
  padding: 8px 0 8px 14px;
  position: relative;
}
.comment .comment-body { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.comment .comment-body[data-md-rendered='1'] { white-space: normal; }
.comment .comment-body ol,
.comment .comment-body ul { white-space: normal; margin: 6px 0; padding-left: 22px; }
.comment .comment-body li { margin: 0; }
.comment::before {
  content: '';
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 4px;
  width: 4px;
  border-radius: 999px;
  background: transparent;
  opacity: 0;
}
.comment-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.comment-meta .collapse-toggle {
  border: 1px solid var(--line);
  background: var(--btn-bg);
  color: var(--muted);
  border-radius: 3px;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}
.comment-meta .collapse-toggle:hover,
.comment-meta .collapse-toggle:focus-visible {
  border-color: var(--link);
  color: var(--text);
}
.comment.collapsed .collapse-toggle {
  background: var(--link);
  border-color: var(--link);
  color: var(--text);
}
.comment.collapsed > .comment-body,
.comment.collapsed > .comment-actions,
.comment.collapsed > .reply-container {
  display: none;
}
.comment.collapsed .comment-meta-text { color: var(--text); font-weight: 600; }
.comment.collapsed-hidden { display: none !important; }
.comment.depth-0 { margin-left: 0; padding-left: 0; }
.comment.depth-0::before { content: none; }
.comment.depth-1 { margin-left: var(--comment-indent); }
.comment.depth-1::before { background: var(--comment-guide-1); opacity: 1; }
.comment.depth-2 { margin-left: calc(var(--comment-indent) * 2); }
.comment.depth-2::before { background: var(--comment-guide-2); opacity: 1; }
.comment.depth-3 { margin-left: calc(var(--comment-indent) * 3); }
.comment.depth-3::before { background: var(--comment-guide-3); opacity: 1; }
.comment.depth-4 { margin-left: calc(var(--comment-indent) * 4); }
.comment.depth-4::before { background: var(--comment-guide-4); opacity: 1; }
.comment.depth-5 { margin-left: calc(var(--comment-indent) * 5); }
.comment.depth-5::before { background: var(--comment-guide-5); opacity: 1; }
.comment.depth-6 { margin-left: calc(var(--comment-indent) * 6); }
.comment.depth-6::before { background: var(--comment-guide-6); opacity: 1; }

/* Comment jump highlight */
.comment.jump-target {
  outline: 2px solid var(--link);
  outline-offset: -2px;
  background: rgba(125, 171, 255, 0.08);
  animation: comment-jump-fade 2000ms ease-out;
}
@keyframes comment-jump-fade {
  from { background: rgba(125, 171, 255, 0.18); }
  to { background: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .comment.jump-target { animation: none; }
}

/* Comment form */
.comment-form { margin-top: 12px; }
.comment-form textarea { width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 4px; padding: 6px; font: inherit; }
.comment-form .btn { margin-top: 6px; }
.reply-link, .permalink-link { color: var(--link); margin-left: 8px; font-size: 12px; }
.reply-form { margin-top: 8px; }
.reply-form textarea { width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 4px; padding: 6px; font: inherit; }
.reply-form .btn { margin-top: 6px; }

/* Footer */
.footer { border-top: 1px solid var(--line); padding: 16px 0; background: var(--bg-elevated); }
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.theme-toggle { border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; background: transparent; color: var(--text); font: inherit; transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease; }
.theme-toggle:hover,
.theme-toggle:focus-visible { background: var(--btn-bg); color: var(--btn-text); border-color: var(--link); outline: none; }
.theme-toggle:active { transform: translateY(1px); }

/* Buttons */
.btn { cursor: pointer; border: none; background: none; padding: 0; }
.btn-link { color: var(--link); }
.btn[disabled] { cursor: not-allowed; opacity: 0.6; }
.btn.is-loading .btn-label { opacity: 0.6; }
.btn.is-loading { pointer-events: none; }
.spinner[hidden] { display: none !important; }

/* Spinner */
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--link); border-radius: 50%; animation: spin 0.8s linear infinite; margin-left: 8px; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Auth forms */
.auth-form { max-width: 420px; margin: 12px 0; }
.auth-form .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.auth-form input { border: 1px solid var(--line); border-radius: 4px; padding: 8px; font: inherit; }
.auth-form .actions { display: flex; align-items: center; gap: 12px; }
.auth-form .error { color: #b00020; margin-top: 6px; }
.auth-form .link { padding: 0; }
.popover { display: none; background: var(--bg-elevated); border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; font-size: 12px; color: var(--text); position: relative; }
.popover.show { display: inline-block; }
.popover::after { content: ''; position: absolute; left: 10px; top: -6px; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 6px solid var(--line); }

/* Report popover specifics */
.report-wrap { display: inline-block; position: relative; margin-left: 8px; }
.report-link.reported { color: var(--muted); pointer-events: none; }
.report-popover { position: absolute; z-index: 10; left: 0; top: 120%; min-width: 260px; max-width: 360px; }
.report-popover .report-title { font-weight: 600; margin-bottom: 4px; }
.report-popover .report-reason { width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 4px; padding: 6px; font: inherit; background: var(--bg); color: var(--text); }
.report-popover .report-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.report-popover .report-error { color: #b00020; margin-top: 4px; }

/* Home */
.home-hero { padding: 8px 0 16px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.home-title { margin: 0 0 4px; font-size: 20px; }

/* Post body wrapping: prevent long strings from overflowing */
.post-body { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.post-body[data-md-rendered='1'] { white-space: normal; margin-top: 14px; margin-bottom: 14px; }
.post-body[data-md-rendered='1'] > * { margin-top: 0; margin-bottom: 0; }
.post-body[data-md-rendered='1'] > * + * { margin-top: 14px; }
.home-title a,
.home-title a:visited { color: var(--text); }
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.section-title { margin: 0 0 8px; font-size: 14px; color: var(--text); }
.view-counter { font-weight: 600; margin-left: 8px; color: var(--muted); }
.list { display: grid; gap: 4px; }
.sort-bar { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.sort-bar select { border: 1px solid var(--line); border-radius: 4px; padding: 6px; font: inherit; }
.sort-bar label { display: flex; align-items: center; gap: 6px; color: var(--text); }

@media (max-width: 720px) {
  .home-grid { grid-template-columns: 1fr; }
}
