/* ── Reset & Base ────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

  --bg: #fffcf0;
  --bg-card: #fffef8;
  --bg-hover: #f7f4e8;
  --bg-comment: #faf7eb;
  --border: #e8e2cc;
  --border-light: #f0ead6;

  --text-primary: #2b2b2b;
  --text-secondary: #6b6558;
  --text-tertiary: #9c9482;
  --text-link: #2b2b2b;

  --accent: #2e8b57;
  --accent-light: #eaf5ef;
  --accent-hover: #256d46;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.08);

  --transition: 150ms ease;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scrollbar-gutter: stable;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* ── Header ──────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 252, 240, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.logo-mark {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  background: var(--accent);
  color: white;
  padding: 3px 7px;
  border-radius: var(--radius-sm);
  letter-spacing: -0.5px;
}

.logo-text {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.nav {
  display: flex;
  gap: 2px;
}

.nav-btn {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.nav-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.nav-btn.active {
  color: var(--accent);
  background: var(--accent-light);
}

.search-wrapper {
  position: relative;
  margin-left: auto;
  flex-shrink: 0;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-input {
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 7px 12px 7px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-primary);
  width: 200px;
  outline: none;
  transition: all var(--transition);
}

.search-input::placeholder {
  color: var(--text-tertiary);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  width: 260px;
}

.search-kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  pointer-events: none;
  transition: opacity var(--transition);
}

.search-input:focus + .search-kbd {
  opacity: 0;
}

/* ── Main ────────────────────────────────────────────── */
.main {
  padding: 24px 0 80px;
}

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ── Story List ──────────────────────────────────────── */
.story-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.story-item {
  background: var(--bg-card);
  padding: 16px 20px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
  transition: background var(--transition);
  cursor: pointer;
}

.story-item:hover {
  background: var(--bg-hover);
}

.story-rank {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-tertiary);
  min-width: 28px;
  text-align: right;
  padding-top: 2px;
  flex-shrink: 0;
}

.story-content {
  flex: 1;
  min-width: 0;
}

.story-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.45;
  letter-spacing: -0.2px;
}

.story-title:hover {
  color: var(--accent);
}

.story-domain {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-tertiary);
  margin-left: 6px;
  font-weight: 400;
}

.story-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.story-meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.story-meta-item svg {
  flex-shrink: 0;
}

.story-score {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--accent);
}

.story-comments-btn {
  font-size: 12.5px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color var(--transition);
}

.story-comments-btn:hover {
  color: var(--accent);
}

/* ── Bookmark Button ─────────────────────────────────── */
.bookmark-btn {
  flex-shrink: 0;
  padding: 6px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  transition: all var(--transition);
  align-self: center;
}

.bookmark-btn:hover {
  color: var(--accent);
  background: var(--accent-light);
}

.bookmark-btn.bookmarked {
  color: var(--accent);
}

.detail-bookmark-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.detail-bookmark-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}

.detail-bookmark-btn.bookmarked {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}

/* ── Story Detail ────────────────────────────────────── */
.story-detail {
  animation: fadeIn 200ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  transition: all var(--transition);
}

.back-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.detail-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
}

.detail-title {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.4px;
  color: var(--text-primary);
}

.detail-title a:hover {
  color: var(--accent);
}

.detail-domain {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 6px;
}

.detail-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
  font-size: 13px;
  color: var(--text-secondary);
}

.detail-meta .story-score {
  font-size: 13px;
}

.detail-text {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--text-primary);
}

.detail-text a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(46, 139, 87, 0.3);
  text-underline-offset: 2px;
}

.detail-text a:hover {
  text-decoration-color: var(--accent);
}

.detail-text p {
  margin-bottom: 12px;
}

.detail-text pre {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg);
  padding: 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin-bottom: 12px;
}

.detail-text code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg);
  padding: 2px 5px;
  border-radius: 3px;
}

/* ── Comments ────────────────────────────────────────── */
.comments-section {
  margin-top: 28px;
}

.comments-header {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.comments-count {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-light);
  padding: 2px 8px;
  border-radius: 20px;
}

.comment {
  position: relative;
}

.comment-inner {
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  margin-bottom: 8px;
  transition: border-color var(--transition);
}

.comment-inner:hover {
  border-color: var(--border);
}

.comment-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12.5px;
}

.comment-author {
  font-weight: 600;
  color: var(--text-primary);
}

.comment-author.op {
  color: var(--accent);
}

.comment-time {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-tertiary);
}

.comment-toggle {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  margin-left: auto;
  padding: 2px 6px;
  border-radius: 3px;
  transition: all var(--transition);
}

.comment-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.comment-body {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-primary);
}

.comment-body a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(46, 139, 87, 0.3);
  text-underline-offset: 2px;
}

.comment-body a:hover {
  text-decoration-color: var(--accent);
}

.comment-body p {
  margin-bottom: 8px;
}

.comment-body p:last-child {
  margin-bottom: 0;
}

.comment-body pre,
.comment-body code {
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.comment-body pre {
  background: var(--bg);
  padding: 10px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 8px 0;
}

.comment-body code {
  background: var(--bg);
  padding: 1px 4px;
  border-radius: 3px;
}

.comment-children {
  margin-left: 20px;
  padding-left: 16px;
  border-left: 2px solid var(--border-light);
}

.comment-collapsed .comment-body,
.comment-collapsed .comment-children {
  display: none;
}

.comment-dead .comment-body {
  color: var(--text-tertiary);
  font-style: italic;
}

/* ── Loader ──────────────────────────────────────────── */
.loader {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 40px;
}

.loader-dot {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1.2s ease-in-out infinite;
}

.loader-dot:nth-child(2) { animation-delay: 0.15s; }
.loader-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ── Load More ───────────────────────────────────────── */
.load-more {
  text-align: center;
  padding: 24px;
}

.load-more-btn {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 10px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.load-more-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}

/* ── Search Results ──────────────────────────────────── */
.search-header {
  padding: 16px 20px;
  background: var(--bg-card);
  font-size: 13px;
  color: var(--text-secondary);
}

.search-header strong {
  color: var(--text-primary);
}

/* ── Empty State ─────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-tertiary);
}

.empty-state-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state-text {
  font-size: 14px;
}

/* ── Skeleton Loader ─────────────────────────────────── */
.skeleton-item {
  cursor: default;
}

.skeleton-item:hover {
  background: var(--bg-card);
}

.skeleton {
  background: linear-gradient(90deg, var(--border-light) 25%, var(--bg-hover) 50%, var(--border-light) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 4px;
}

.skeleton-rank {
  width: 24px;
  height: 16px;
  flex-shrink: 0;
  margin-top: 4px;
}

.skeleton-title {
  width: 75%;
  height: 16px;
  margin-bottom: 10px;
}

.skeleton-meta {
  width: 45%;
  height: 12px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Retry Button ────────────────────────────────────── */
.retry-btn {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  padding: 8px 20px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  margin-top: 12px;
  transition: all var(--transition);
}

.retry-btn:hover {
  background: var(--accent-light);
}

/* ── Load Replies Button ─────────────────────────────── */
.load-replies-btn {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  padding: 6px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  margin: 4px 0;
  transition: all var(--transition);
}

.load-replies-btn:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

/* ── Utilities ───────────────────────────────────────── */
.hidden {
  display: none !important;
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 768px) {
  .header-inner {
    padding: 0 12px;
    gap: 8px;
    flex-wrap: wrap;
    height: auto;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .logo-text {
    display: none;
  }

  .nav {
    order: 3;
    width: 100%;
    gap: 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav-btn {
    padding: 5px 10px;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .search-wrapper {
    flex: 1;
    min-width: 0;
  }

  .search-input {
    width: 100%;
  }

  .search-input:focus {
    width: 100%;
  }

  .search-kbd {
    display: none;
  }

  .container {
    padding: 0 12px;
  }

  .story-item {
    padding: 14px 16px;
    gap: 12px;
  }

  .story-rank {
    min-width: 24px;
    font-size: 12px;
  }

  .story-title {
    font-size: 14px;
  }

  .detail-card {
    padding: 20px;
  }

  .detail-title {
    font-size: 18px;
  }

  .comment-children {
    margin-left: 12px;
    padding-left: 12px;
  }
}

@media (max-width: 480px) {
  .nav-btn {
    padding: 6px 6px;
    font-size: 11.5px;
  }

  .story-meta {
    flex-wrap: wrap;
    gap: 6px 10px;
  }
}
