:root {
  --bg: #ffffff;
  --bg-hover: #f7f7f7;
  --border: #eff3f4;
  --text: #0f1419;
  --text-secondary: #536471;
  --accent: #1d9bf0;
  --card-max: 600px;
}
:root[data-theme="dark"] {
  --bg: #000000;
  --bg-hover: #0a0a0a;
  --border: #2f3336;
  --text: #e7e9ea;
  --text-secondary: #71767b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --bg-hover: #0a0a0a;
    --border: #2f3336;
    --text: #e7e9ea;
    --text-secondary: #71767b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.35;
}

#theme-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 10;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.profile-header {
  max-width: var(--card-max);
  margin: 0 auto;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  position: relative;
}
.back-link {
  display: inline-block;
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  line-height: 36px;
  text-align: center;
  text-decoration: none;
  font-size: 18px;
}
.banner {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
  background: var(--border);
}
.profile-info {
  padding: 12px 16px 16px;
  position: relative;
}
.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
  width: 48px;
  height: 48px;
}
.avatar-sm { width: 40px; height: 40px; }
.avatar-lg {
  width: 120px;
  height: 120px;
  border: 4px solid var(--bg);
  margin-top: -64px;
  display: block;
}
.profile-info .display-name {
  font-weight: 800;
  font-size: 20px;
  margin-top: 10px;
}
.profile-info .handle {
  color: var(--text-secondary);
  display: block;
}
.bio {
  margin-top: 10px;
  white-space: pre-wrap;
}
.profile-stats {
  margin-top: 12px;
  color: var(--text-secondary);
}
.profile-stats span { margin-right: 16px; }
.profile-stats b { color: var(--text); }

.timeline, .timeline-detail {
  max-width: var(--card-max);
  margin: 0 auto;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.timeline-detail { padding-top: 44px; position: relative; }
.timeline-detail .back-link { position: static; background: transparent; color: var(--accent); }

.tweet-card {
  display: block;
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  color: inherit;
  text-decoration: none;
  position: relative;
}
a.tweet-link {
  color: inherit;
  text-decoration: none;
}
a.tweet-link:hover { background: var(--bg-hover); }
.icon {
  width: 16px;
  height: 16px;
  vertical-align: -3px;
  margin-right: 4px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}
.tweet-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.names { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.names .display-name { font-weight: 700; }
.names .handle, .tweet-date, .tweet-datetime {
  color: var(--text-secondary);
  font-size: 14px;
}
.tweet-header .tweet-date { margin-left: auto; white-space: nowrap; }
.reply-note {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 4px 0 0 58px;
}
.reply-note a { color: var(--accent); text-decoration: none; }
.tweet-text {
  margin-top: 8px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.tweet-text a { color: var(--accent); text-decoration: none; }
.tweet-text a:hover { text-decoration: underline; }
.tweet-datetime {
  margin-top: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.tweet-stats {
  display: flex;
  gap: 20px;
  margin-top: 10px;
  color: var(--text-secondary);
  font-size: 14px;
}

.muted {
  color: var(--text-secondary);
}

.media-grid {
  margin-top: 10px;
  display: grid;
  gap: 2px;
  border-radius: 16px;
  overflow: hidden;
}
.media-grid-1 { grid-template-columns: 1fr; }
.media-grid-1 .media-item {
  width: 100%;
  max-height: 500px;
  object-fit: cover;
  display: block;
  background: var(--border);
}
.media-grid-2, .media-grid-3, .media-grid-4 {
  aspect-ratio: 16 / 9;
}
.media-grid-2 { grid-template-columns: 1fr 1fr; }
.media-grid-3 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.media-grid-3 .grid-cell:nth-child(1) { grid-column: 1; grid-row: 1 / 3; }
.media-grid-3 .grid-cell:nth-child(2) { grid-column: 2; grid-row: 1; }
.media-grid-3 .grid-cell:nth-child(3) { grid-column: 2; grid-row: 2; }
.media-grid-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.media-grid-2 .grid-cell,
.media-grid-3 .grid-cell,
.media-grid-4 .grid-cell {
  overflow: hidden;
}
.media-grid-2 .media-item,
.media-grid-3 .media-item,
.media-grid-4 .media-item {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: var(--border);
}

.reply-card {
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding: 12px 16px;
}
.reply-body { flex: 1; min-width: 0; }
.reply-body .names { flex-direction: row; gap: 6px; align-items: baseline; flex-wrap: wrap; }

.replies-heading {
  padding: 12px 16px;
  font-weight: 700;
  border-top: 1px solid var(--border);
}

@media (max-width: 620px) {
  .profile-header, .timeline, .timeline-detail { border-left: none; border-right: none; }
}
