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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  line-height: 1.5;
  min-height: 100vh;
}

img, svg {
  display: block;
  max-width: 100%;
}

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

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

ul, ol {
  list-style: none;
}

h1, h2, h3, h4, h5, h6 {
  font-size: inherit;
  font-weight: inherit;
}

/* ===== Design 3: Twitter/X Timeline ===== */

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f7f9f9;
  --bg-hover: #f0f2f5;
  --border-color: #eff3f4;
  --text-primary: #0f1419;
  --text-secondary: #536471;
  --text-tertiary: #8899a6;
  --accent: #1d9bf0;
  --accent-hover: #1a8cd8;
  --unread: #1d9bf0;
  --new-badge: #f91880;
  --avatar-size: 48px;
  --max-width: 600px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --scrollbar-bg: transparent;
  --scrollbar-thumb: #cfd9de;
}

/* ===== Dark Theme ===== */
[data-theme="dark"] {
  --bg-primary: #15202b;
  --bg-secondary: #1e2d3d;
  --bg-hover: #1c2938;
  --border-color: #38444d;
  --text-primary: #e7e9ea;
  --text-secondary: #8b98a5;
  --text-tertiary: #6e767d;
  --accent: #1d9bf0;
  --accent-hover: #1a8cd8;
  --unread: #1d9bf0;
  --new-badge: #f91880;
  --scrollbar-bg: transparent;
  --scrollbar-thumb: var(--border-color);
}

[data-theme="dark"] .top-bar {
  background: rgba(21, 32, 43, 0.85);
}

[data-theme="dark"] .story-title-bar {
  background: rgba(21, 32, 43, 0.92);
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* ===== Header ===== */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
}

.top-bar-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

.back-link {
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  transition: color 0.15s;
}

.back-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.logo {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.logo-t {
  color: var(--accent);
}

.top-bar-right {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ===== Tab bar (Home page) ===== */
.tab-bar {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  border-bottom: 1px solid var(--border-color);
}

.tab {
  flex: 1;
  text-align: center;
  padding: 14px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  position: relative;
  transition: color 0.15s;
  cursor: default;
}

.tab.active {
  color: var(--text-primary);
}

.tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}

/* ===== Feed ===== */
.feed {
  max-width: var(--max-width);
  margin: 0 auto;
}

/* ===== Story Card ===== */
.story-card {
  display: flex;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  transition: background 0.15s;
  cursor: pointer;
  user-select: none;
}

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

/* Avatar */
.avatar {
  width: var(--avatar-size);
  height: var(--avatar-size);
  min-width: var(--avatar-size);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  user-select: none;
  flex-shrink: 0;
}

.avatar-sm {
  width: 36px;
  height: 36px;
  min-width: 36px;
  font-size: 13px;
}

/* Card body */
.card-body {
  flex: 1;
  min-width: 0;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.card-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.card-time {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.card-badge-area {
  margin-left: auto;
  flex-shrink: 0;
}

/* Mini timeline inside card */
.mini-timeline {
  margin: 4px 0 0;
  padding-left: 4px;
}

.mini-event {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  position: relative;
  padding-bottom: 6px;
  padding-left: 16px;
}

/* Dot & connector */
.mini-event::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 7px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.mini-event::after {
  content: '';
  position: absolute;
  left: 6px;
  top: 15px;
  bottom: -2px;
  width: 2px;
  background: var(--border-color);
}

.mini-event:last-child::after {
  display: none;
}

.mini-event-date {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  min-width: 44px;
}

.mini-event-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Extra events: hidden by default, animated in ── */
.mini-event.extra {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  padding-bottom: 0;
  transition: max-height 0.3s ease, opacity 0.25s ease, padding-bottom 0.3s ease;
}

.story-card.expanded .mini-event.extra {
  max-height: 60px;
  opacity: 1;
  padding-bottom: 6px;
}

/* ── Action buttons: hidden by default, slide in ── */
.card-actions-bar {
  display: flex;
  gap: 8px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  margin-top: 0;
  transition: max-height 0.3s ease, opacity 0.25s ease 0.05s, margin-top 0.3s ease;
}

.story-card.expanded .card-actions-bar {
  max-height: 50px;
  opacity: 1;
  margin-top: 10px;
}

.card-btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
  white-space: nowrap;
  text-decoration: none;
  text-align: center;
  display: inline-flex;
  align-items: center;
}

.btn-follow {
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  background: transparent;
}

.btn-follow:hover {
  background: var(--bg-hover);
  border-color: var(--text-secondary);
}

.btn-follow.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-follow.active:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.tab-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.tab-empty-text {
  font-size: 15px;
  line-height: 1.5;
}

.btn-read-more {
  background: var(--accent);
  color: #fff;
  border: none;
}

.btn-read-more:hover {
  background: var(--accent-hover);
}

.btn-mark-read {
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  background: transparent;
}

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

.btn-mark-read:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Icon inside buttons */
.btn-icon {
  width: 14px;
  height: 14px;
  fill: currentColor;
  vertical-align: -2px;
  margin-right: 2px;
}

/* Story page action bar */
.story-actions-bar {
  display: flex;
  gap: 8px;
  padding: 8px 0 2px;
}

/* Unread badge (pill) */
.unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 2px 10px;
  line-height: 1.4;
}

.unread-badge.unread-new {
  background: var(--new-badge);
}

.unread-badge.caught-up {
  background: var(--text-tertiary);
  opacity: 0.6;
}

/* ===== Read Status on Cards ===== */
.story-card.status-caught-up {
  opacity: 0.55;
}

.story-card.status-caught-up:hover {
  opacity: 0.8;
}

.story-card.status-caught-up .card-name {
  font-weight: 500;
}

.story-card.status-has-updates {
  border-left: 3px solid var(--accent);
}

.story-card.status-unread .card-name {
  color: var(--accent);
}

.story-card.status-unread {
  border-left: 3px solid var(--new-badge);
}

/* ===== Story Page — Title Bar ===== */
.story-title-bar {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px;
  position: sticky;
  top: 57px;
  z-index: 90;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
}

.story-title-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}

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

.story-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.story-count {
  font-size: 12px;
  color: var(--text-secondary);
}

.story-title-right {
  flex-shrink: 0;
}

/* ===== Story Page — Full Timeline ===== */
.story-timeline-full {
  max-width: var(--max-width);
  padding: 8px 16px 32px;
}

.story-timeline-full .mini-timeline {
  padding-left: 0;
}

.story-timeline-full .mini-event {
  padding-bottom: 10px;
}

.story-timeline-full .mini-event-text {
  white-space: normal;
  overflow: visible;
  font-size: 14px;
  line-height: 1.45;
}

.story-timeline-full .month-divider {
  padding: 12px 0 8px 16px;
}

/* ===== Month divider ===== */
.month-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  max-width: var(--max-width);
}

.month-divider span {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.month-divider::before,
.month-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-bg); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

/* ===== Theme Toggle Button ===== */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  transition: background 0.2s;
  cursor: pointer;
  color: var(--text-secondary);
}

.theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  :root {
    --avatar-size: 40px;
  }

  .top-bar-inner {
    padding: 10px 14px;
  }

  .story-card {
    padding: 12px 14px;
  }

  .card-name {
    font-size: 14px;
  }

  .mini-event-text {
    font-size: 12px;
  }

  .story-title-bar {
    top: 49px;
  }

  .timeline-text {
    font-size: 14px;
  }

  .timeline-event {
    padding: 0 14px;
  }

  .card-btn {
    font-size: 12px;
    padding: 5px 12px;
  }
}
