*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #dae0e6;
  --card: #ffffff;
  --border: #edeff1;
  --text: #1c1c1c;
  --muted: #7c7c7c;
  --accent: #ff4500;
  --accent-soft: #fff3f0;
  --upvote: #ff4500;
  --downvote: #7193ff;
  --link: #0079d3;
}

body {
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}

header .logo {
  font-weight: 700;
  font-size: 18px;
  color: var(--accent);
  text-decoration: none;
}

header .subreddit {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}

header .sep { color: var(--muted); }

.sort-bar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 12px;
  display: flex;
  gap: 8px;
  margin: 16px auto;
  max-width: 740px;
}

.sort-btn {
  background: none;
  border: none;
  padding: 6px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.sort-btn:hover, .sort-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.feed {
  max-width: 740px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 40px;
}

.post-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex;
  cursor: pointer;
  transition: border-color 0.15s;
}

.post-card:hover { border-color: #818384; }

.vote-col {
  width: 40px;
  background: #f8f9fa;
  border-radius: 4px 0 0 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  gap: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.vote-icon { font-size: 16px; }

.post-body { padding: 8px 8px 8px 8px; flex: 1; min-width: 0; }

.post-flair {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 2px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
}

.post-title {
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 6px;
}

.post-meta {
  font-size: 12px;
  color: var(--muted);
}

.post-meta a { color: var(--muted); text-decoration: none; }
.post-meta a:hover { text-decoration: underline; }

.post-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.post-action {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.post-action:hover { background: var(--border); }

/* ---- Post page ---- */

.post-page { max-width: 740px; margin: 0 auto; padding-bottom: 40px; }

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--link);
  cursor: pointer;
  text-decoration: none;
  margin: 12px 0;
}

.back-btn:hover { text-decoration: underline; }

.post-detail {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 12px;
}

.post-detail .post-title { font-size: 20px; margin-bottom: 10px; }

.post-selftext {
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.post-link-preview {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 4px;
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
  word-break: break-all;
}

.comments-section { }

.comments-header {
  font-size: 14px;
  font-weight: 700;
  padding: 12px 0 8px;
  color: var(--text);
}

.comment {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  margin-bottom: 6px;
}

.comment-meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.comment-meta .author { font-weight: 700; color: var(--text); }
.comment-meta .score { color: var(--upvote); font-weight: 700; }

.comment-body {
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.comment-replies {
  margin-top: 10px;
  margin-left: 16px;
  border-left: 2px solid var(--border);
  padding-left: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.reply {
  font-size: 13px;
}

.reply .comment-meta { font-size: 11px; }
.reply .comment-body { font-size: 13px; }

.loading {
  text-align: center;
  color: var(--muted);
  padding: 40px;
  font-size: 14px;
}

.error-msg {
  text-align: center;
  color: var(--accent);
  padding: 40px;
  font-size: 14px;
}

.post-img {
  max-width: 100%;
  border-radius: 4px;
  margin-top: 12px;
  max-height: 600px;
  object-fit: contain;
  display: block;
}

.post-thumb {
  margin-top: 8px;
  max-width: 100%;
  max-height: 320px;
  border-radius: 4px;
  object-fit: cover;
  display: block;
}
