/* Wikipedia's palette and type, laid out like the classic Twitter mobile timeline. */

:root {
  --bg: #ffffff;
  --surface: #f8f9fa;
  --surface-hover: #f8f9fa;
  --text: #202122;
  --muted: #54595d;
  --subtle: #72777d;
  --border: #a2a9b1;
  --divider: #eaecf0;
  --link: #3366cc;
  --link-hover: #447ff5;
  --link-visited: #795cb2;
  --accent: #3366cc;
  --accent-text: #ffffff;
  --skeleton: #eaecf0;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.16);

  --serif: 'Linux Libertine', 'Georgia', 'Times', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --topbar-h: 50px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --surface: #202122;
    --surface-hover: #161a1e;
    --text: #eaecf0;
    --muted: #a2a9b1;
    --subtle: #8b9299;
    --border: #54595d;
    --divider: #27292d;
    --link: #88a3e8;
    --link-hover: #a6bbf5;
    --link-visited: #a799cd;
    --accent: #6d8af0;
    --accent-text: #101418;
    --skeleton: #27292d;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
}

button {
  font: inherit;
  color: inherit;
}

a {
  color: var(--link);
  text-decoration: none;
}
a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

/* ---- Top bar ---- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--divider);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px;
  border: 0;
  background: none;
  cursor: pointer;
}
.brand-mark {
  font-family: var(--serif);
  font-size: 28px;
  line-height: 1;
}
.brand-name {
  font-family: var(--serif);
  font-size: 21px;
  letter-spacing: 0.01em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pill {
  min-height: 32px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.pill:hover {
  background: var(--surface);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.icon-button:hover {
  background: var(--surface);
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Timeline ---- */

.timeline {
  max-width: 600px;
  min-height: calc(100vh - var(--topbar-h));
  margin: 0 auto;
  border-left: 1px solid var(--divider);
  border-right: 1px solid var(--divider);
}
@media (max-width: 600px) {
  .timeline {
    border-left: 0;
    border-right: 0;
  }
}

.timeline-heading {
  padding: 10px 16px;
  border-bottom: 1px solid var(--divider);
  font-family: var(--serif);
  font-size: 19px;
}

.card {
  padding: 10px 16px 12px;
  border-bottom: 1px solid var(--divider);
  transition: background 0.15s;
}
.card:hover {
  background: var(--surface-hover);
}

.card-context {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 4px 34px;
  color: var(--subtle);
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.card-context svg {
  flex: none;
}
.card-context a {
  color: inherit;
}

.card-row {
  display: flex;
  gap: 12px;
}

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 5px;
  background: var(--topic-color);
  color: #fff;
  font-family: var(--serif);
  font-size: 26px;
  line-height: 1;
}

.card-main {
  flex: 1;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
  white-space: nowrap;
}
.card-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-handle,
.card-meta {
  color: var(--subtle);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-more {
  flex: none;
  align-self: center;
  width: 32px;
  height: 28px;
  margin: -4px -8px -4px auto;
  border: 0;
  border-radius: 14px;
  background: none;
  color: var(--subtle);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.card-more:hover {
  background: var(--divider);
  color: var(--text);
}

.card-title {
  margin: 2px 0 4px;
  font-family: var(--serif);
  font-size: 21px;
  font-weight: normal;
  line-height: 1.25;
}
.card-title a {
  color: var(--text);
}
.card-title a:hover {
  color: var(--link);
}

.card-extract {
  margin: 0;
  white-space: pre-line;
  overflow-wrap: anywhere;
  cursor: pointer;
}
.card-extract.clamped {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
  line-clamp: 5;
  overflow: hidden;
}

.show-more {
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--link);
  cursor: pointer;
}
.show-more:hover {
  text-decoration: underline;
}

.card-media {
  display: block;
  margin-top: 10px;
  overflow: hidden;
  border: 1px solid var(--divider);
  border-radius: 8px;
  background: var(--surface);
}
.card-media img {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  object-position: center 30%;
}
.card-media.contain img {
  object-fit: contain;
  background: #fff;
}

.card-foot {
  display: flex;
  align-items: center;
  margin-top: 8px;
  font-size: 14px;
}
.read-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.read-link .w {
  font-family: var(--serif);
  font-size: 16px;
}

.card-dismissed {
  padding: 14px 16px;
  border-bottom: 1px solid var(--divider);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
}

/* ---- Loading, errors, end of feed ---- */

.skeleton {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--divider);
}
.skeleton .avatar {
  background: var(--skeleton);
}
.skeleton-lines {
  flex: 1;
}
.skeleton-line {
  height: 12px;
  margin-bottom: 10px;
  border-radius: 6px;
  background: var(--skeleton);
  animation: pulse 1.4s ease-in-out infinite;
}
.skeleton-line.title {
  width: 60%;
  height: 18px;
}
.skeleton-line.short {
  width: 40%;
}
@keyframes pulse {
  50% {
    opacity: 0.5;
  }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton-line {
    animation: none;
  }
}

.feed-status {
  padding: 28px 24px;
  color: var(--muted);
  text-align: center;
}
.feed-status button {
  margin-top: 12px;
}

#sentinel {
  height: 1px;
}

/* ---- Buttons ---- */

.button-primary {
  min-height: 36px;
  padding: 6px 18px;
  border: 1px solid var(--accent);
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  cursor: pointer;
}
.button-primary:hover {
  filter: brightness(1.08);
}
.button-primary:disabled {
  border-color: var(--divider);
  background: var(--divider);
  color: var(--subtle);
  cursor: default;
  filter: none;
}

/* ---- Interests sheet ---- */

.sheet {
  width: min(560px, 100vw - 24px);
  max-height: min(88vh, 820px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow);
}
.sheet::backdrop {
  background: rgba(0, 0, 0, 0.45);
}
.sheet-body {
  padding: 20px 20px 0;
}
.sheet-title {
  margin: 0 0 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  font-family: var(--serif);
  font-size: 26px;
  font-weight: normal;
}
.sheet-lede {
  margin: 8px 0 16px;
  color: var(--muted);
}
.sheet-subtitle {
  margin: 20px 0 4px;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: normal;
}
.sheet-note {
  margin: 0 0 10px;
  color: var(--subtle);
  font-size: 13px;
}

.topic-group h3 {
  margin: 14px 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg);
  cursor: pointer;
}
.chip[aria-pressed='true'] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0;
  cursor: pointer;
}
.toggle-label {
  display: block;
  font-weight: 600;
}
.toggle-row .sheet-note {
  display: block;
  margin: 2px 0 0;
}
.switch {
  appearance: none;
  flex: none;
  position: relative;
  width: 44px;
  height: 26px;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--divider);
  cursor: pointer;
  transition: background 0.15s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}
.switch:checked {
  border-color: var(--accent);
  background: var(--accent);
}
.switch:checked::after {
  transform: translateX(18px);
}

.tuning-bars {
  margin: 0;
  padding: 0;
  list-style: none;
}
.tuning-bars li {
  display: grid;
  grid-template-columns: 9.5em 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 13px;
}
.tuning-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--topic-color);
  min-width: 4px;
}

.sheet-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  margin: 16px -20px 0;
  padding: 12px 20px;
  border-top: 1px solid var(--divider);
  background: var(--bg);
}

/* ---- Card overflow menu ---- */

.menu {
  position: absolute;
  z-index: 20;
  min-width: 240px;
  padding: 4px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: var(--shadow);
}
.menu button {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.menu button:hover {
  background: var(--surface);
}
