/* Sample feed — dark glass look ported from the SkyFeed draft.
   Everything lives under .feed-root, which covers the viewport so jsPsych's
   centred, 18px "Open Sans" page styling does not leak into the feed. */

:root {
  --bg: #020617;
  --glass: rgba(255, 255, 255, 0.05);
  --glass-strong: rgba(255, 255, 255, 0.1);
  --line: rgba(255, 255, 255, 0.1);
  --text: #e2e8f0;
  --strong: #f8fafc;
  --muted: #94a3b8;
  --faint: #64748b;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --less: #fb7185;
  --more: #34d399;
  --panel-width: 340px;
}

body {
  background: var(--bg);
}

.feed-root {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--text);
  text-align: left;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(40% 40% at 8% 25%, rgba(14, 165, 233, 0.12), transparent 70%),
    radial-gradient(50% 50% at 70% 100%, rgba(79, 70, 229, 0.12), transparent 70%),
    var(--bg);
  animation: feed-enter 0.35s ease-out;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.feed-root.leaving {
  opacity: 0;
  transform: translateY(-28px);
}
@keyframes feed-enter {
  from { opacity: 0; transform: translateY(28px); }
}

.feed-root button,
.feed-root input {
  font: inherit;
}

/* ── Top bar ────────────────────────────────────────────────────────────── */
.feed-top {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 16px 4px;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.progress {
  width: min(240px, 60vw);
  height: 3px;
  border-radius: 3px;
  background: var(--glass-strong);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}

/* ── Stage: post + rail ─────────────────────────────────────────────────── */
.feed-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  padding: 8px 12px 16px;
  transition: padding-right 0.3s ease;
}
.feed-root.panel-open .feed-stage {
  padding-right: calc(var(--panel-width) + 12px);
}
.post-wrap {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 720px;
  min-height: 0;
}
/* The card is as tall as its content up to the space available; the post scrolls
   inside it while the rating below stays put. */
.post-card {
  box-sizing: border-box; /* so max-height counts the padding, and a tall card stops at the slot's edge */
  flex: 1;
  min-width: 0;
  align-self: center;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 20px 22px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(24px);
}
.post-body {
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

/* ── Follow (simulated; nothing is sent to Bluesky) ─────────────────────── */
.follow-btn {
  flex: none;
  margin-left: auto;
  padding: 6px 14px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.follow-btn:hover { background: var(--glass-strong); }
.follow-btn[aria-pressed="true"] { background: var(--accent); color: #0b1220; }
.follow-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Author + text ──────────────────────────────────────────────────────── */
.author {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.avatar {
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 50%;
  object-fit: cover;
  background: var(--glass-strong);
}
.avatar-fallback {
  display: grid;
  place-items: center;
  font-weight: 700;
}
.author-names {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.display-name {
  color: var(--strong);
  font-weight: 700;
  font-size: 17px;
  overflow-wrap: anywhere;
}
.handle {
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}
.post-text {
  margin-bottom: 14px;
  font-size: 17px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.facet {
  color: var(--accent);
  text-decoration: none;
}
a.facet:hover,
.facet[data-reading]:hover {
  text-decoration: underline;
}
.facet[data-reading] { cursor: pointer; }

/* ── Media ──────────────────────────────────────────────────────────────── */
.images {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
}
.images img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.4);
}
.images-1 img { max-height: 42vh; object-fit: contain; }
.images-2, .images-3, .images-4 { grid-template-columns: 1fr 1fr; }
.images-2 img, .images-3 img, .images-4 img { aspect-ratio: 3 / 2; }
.images-3 img:first-child { grid-column: 1 / -1; aspect-ratio: 2 / 1; }

.link-card {
  display: block;
  margin-bottom: 14px;
  overflow: hidden;
  color: inherit;
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 16px;
}
a.link-card:hover,
.link-card[data-reading]:hover {
  background: var(--glass);
}
.link-card[data-reading] { cursor: pointer; }
.link-card[data-reading]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Reading list: links never open during the survey; they are saved ─── */
.reading-row { display: flex; margin: -4px 0 14px; }
.reading-btn {
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 999px;
}
.reading-btn:hover { background: var(--glass-strong); }
.reading-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.reading-btn > span { display: inline-flex; align-items: center; gap: 6px; }
.reading-btn .icon svg { width: 16px; height: 16px; }
.reading-btn .reading-on { display: none; }
.reading-btn[aria-pressed="true"] { color: #0b1220; background: var(--accent); }
.reading-btn[aria-pressed="true"] .reading-off { display: none; }
.reading-btn[aria-pressed="true"] .reading-on { display: inline-flex; }
.reading-toast {
  position: fixed;
  left: 50%;
  top: 56px;
  z-index: 40;
  max-width: min(92vw, 460px);
  padding: 10px 16px;
  font-size: 14px;
  color: var(--strong);
  text-align: center;
  background: #0f172a;
  border: 1px solid var(--accent);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  transform: translateX(-50%);
}
.reading-toast[hidden] { display: none; }

/* a citation [n] or a source in an AI answer: also saves, never opens */
.ai-cite, .ai-source-link { color: var(--accent); cursor: pointer; }
.ai-cite { padding: 0 1px; font-size: 0.82em; font-weight: 600; text-decoration: none; vertical-align: super; line-height: 0; }
.ai-cite:hover, .ai-source-link:hover { text-decoration: underline; }
.nopaste-note { margin-top: 6px; font-size: 13px; color: #fbbf24; }
.nopaste-note[hidden] { display: none; }
.card-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1.91;
  max-height: 30vh;
  object-fit: cover;
}
.card-body {
  padding: 12px 14px;
  background: var(--glass);
}
.card-title {
  color: var(--strong);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-desc {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-host {
  margin-top: 8px;
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.quote {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
}
.quote-author {
  color: var(--strong);
  font-weight: 700;
  font-size: 14px;
}
.quote-text {
  margin-top: 4px;
  font-size: 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ── Response: choose one of three, then Next ───────────────────────────── */
.rating {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding: 16px 0 0;
  border-top: 1px solid var(--line);
}
.rating-prompt {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}
.choices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}
.choice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 54px;
  padding: 10px 12px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 16px;
  transition: background 0.15s, border-color 0.15s, opacity 0.2s, transform 0.1s;
}
.choice .icon svg {
  width: 18px;
  height: 18px;
  flex: none;
}
.choice:active:not(:disabled) { transform: scale(0.97); }
/* once Next is pressed the choices lock and the card leaves a quarter-second later */
.choice:disabled { cursor: default; transition: none; }
.choice:disabled:not(.selected) { opacity: 0.35; }
.next-row { display: flex; align-items: center; justify-content: flex-end; gap: 14px; width: 100%; min-height: 44px; }
.next-hint { font-size: 13px; color: var(--faint); }
.next-hint[hidden] { display: none; }
.next-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: #0b1220;
  cursor: pointer;
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  transition: background 0.15s, opacity 0.2s;
}
.next-btn:hover:not(:disabled) { background: var(--accent-strong); }
.next-btn:disabled { cursor: not-allowed; opacity: 0.35; }
.next-btn:focus-visible { outline: 2px solid var(--strong); outline-offset: 2px; }
.next-btn .icon svg { width: 18px; height: 18px; }

.choice-less { color: var(--less); }
.choice-less:hover:not(:disabled) { background: rgba(251, 113, 133, 0.14); border-color: rgba(251, 113, 133, 0.55); }
.choice-less.selected { color: #fff; background: #e11d48; border-color: #fb7185; }

.choice-neutral { color: #cbd5e1; }
.choice-neutral:hover:not(:disabled) { background: rgba(203, 213, 225, 0.12); border-color: rgba(203, 213, 225, 0.45); }
.choice-neutral.selected { color: #fff; background: #475569; border-color: #94a3b8; }

.choice-more { color: var(--more); }
.choice-more:hover:not(:disabled) { background: rgba(52, 211, 153, 0.14); border-color: rgba(52, 211, 153, 0.55); }
.choice-more.selected { color: #fff; background: #059669; border-color: #34d399; }

.choice:focus-visible, .rail-btn:focus-visible, .ai-close:focus-visible, .ai-send:focus-visible,
.reply-post:focus-visible, .reply-cancel:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Action rail ────────────────────────────────────────────────────────── */
.rail {
  flex: none;
  align-self: flex-end;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 58px;
  padding: 14px 0;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(24px);
}
.rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}
.rail-btn .icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #cbd5e1;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
}
.rail-btn:hover .icon { background: var(--glass-strong); }
.rail-count {
  min-height: 1em;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}
.rail-btn[aria-label="Like"][aria-pressed="true"] .icon { color: #ec4899; }
.rail-btn[aria-label="Like"][aria-pressed="true"] .icon svg { fill: currentColor; }
.rail-btn.replied .icon, .rail-btn[aria-label="Reply"][aria-expanded="true"] .icon { color: #60a5fa; }
.rail-btn[aria-label="Repost"][aria-pressed="true"] .icon { color: #4ade80; }
.rail-btn[aria-label="Share"][aria-pressed="true"] .icon { color: #fbbf24; }
.rail-ai {
  margin-top: 4px;
  color: var(--accent);
}
.rail-ai .icon {
  width: 48px;
  height: 48px;
  color: #fff;
  background: var(--accent-strong);
  border-color: rgba(56, 189, 248, 0.5);
  box-shadow: 0 8px 20px rgba(14, 165, 233, 0.3);
}
.rail-ai:hover .icon { background: var(--accent); }
.rail-ai .rail-count { font-weight: 700; }

/* ── Side panels (AI, reply) ────────────────────────────────────────────── */
.side-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  width: var(--panel-width);
  max-width: 100%;
  background: rgba(15, 23, 42, 0.96);
  border-left: 1px solid var(--line);
  backdrop-filter: blur(24px);
  transform: translateX(100%);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.side-panel.open {
  transform: none;
  box-shadow: -20px 0 40px rgba(0, 0, 0, 0.5);
}
.ai-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 14px 0 20px;
  background: var(--glass);
  border-bottom: 1px solid var(--line);
}
.ai-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-weight: 700;
}
.ai-title .icon svg { width: 20px; height: 20px; }
.ai-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.ai-close:hover { color: #fff; background: var(--glass-strong); }
.ai-close .icon svg { width: 20px; height: 20px; }

.panel-scroll {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
}
.ai-msg {
  max-width: 92%;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  border-radius: 16px;
}
.ai-assistant {
  align-self: flex-start;
  color: var(--text);
  background: var(--glass-strong);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-top-left-radius: 4px;
}
.ai-user {
  align-self: flex-end;
  color: #fff;
  background: #4f46e5;
  border-top-right-radius: 4px;
}
.ai-error {
  color: #fecaca;
  font-style: italic;
  background: rgba(244, 63, 94, 0.12);
  border-color: rgba(244, 63, 94, 0.3);
}
.ai-msg .md > :first-child { margin-top: 0; }
.ai-msg .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 0.6em; }
.md ul, .md ol { margin: 0 0 0.6em; padding-left: 1.3em; }
.md li { margin-bottom: 0.25em; }
.md .md-heading { font-weight: 700; color: var(--strong); }
.md code {
  padding: 1px 5px;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 4px;
}

/* three bouncing dots until the first token arrives */
.ai-msg.pending .md::before {
  content: "";
  display: block;
  width: 36px;
  height: 8px;
  background:
    radial-gradient(circle 3px at 4px 4px, var(--accent) 98%, transparent) 0 0 / 12px 8px repeat-x;
  animation: dots 1s steps(4) infinite;
}
@keyframes dots {
  50% { opacity: 0.3; }
}

.ai-form {
  flex: none;
  position: relative;
  padding: 12px 14px 6px;
  background: var(--glass);
  border-top: 1px solid var(--line);
}
.ai-input {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 46px 11px 16px;
  color: #fff;
  font-size: 14px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.ai-input::placeholder { color: var(--faint); }
.ai-input:focus { outline: none; border-color: rgba(56, 189, 248, 0.6); box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.5); }
.ai-input:disabled { opacity: 0.6; }
.ai-send {
  position: absolute;
  top: 50%;
  right: 20px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-top: -10px;
  color: #fff;
  background: var(--accent-strong);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.ai-send:disabled { opacity: 0.5; cursor: default; }
.ai-send .icon svg { width: 16px; height: 16px; }
.ai-disclosure {
  flex: none;
  margin: 0;
  padding: 4px 16px 12px;
  color: var(--faint);
  font-size: 11px;
  text-align: center;
  background: var(--glass);
}

/* ── Reply panel ────────────────────────────────────────────────────────── */
.reply-context {
  margin: 0;
  color: var(--faint);
  font-size: 13px;
}
.reply-msg {
  align-self: stretch;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  background: var(--glass-strong);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 16px;
}
.reply-meta {
  margin-bottom: 2px;
  color: var(--faint);
  font-size: 12px;
}
.reply-text { white-space: pre-wrap; }
.reply-form {
  flex: none;
  padding: 12px 14px 6px;
  background: var(--glass);
  border-top: 1px solid var(--line);
}
.reply-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 11px 14px;
  color: #fff;
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.reply-input::placeholder { color: var(--faint); }
.reply-input:focus { outline: none; border-color: rgba(56, 189, 248, 0.6); box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.5); }
.reply-input:disabled { opacity: 0.6; }
.reply-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.reply-counter {
  flex: 1;
  color: var(--faint);
  font-size: 12px;
}
.reply-cancel, .reply-post {
  padding: 8px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: 999px;
  cursor: pointer;
}
.reply-cancel {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
}
.reply-cancel:hover { background: var(--glass-strong); }
.reply-post {
  color: #fff;
  background: var(--accent-strong);
  border: 0;
}
.reply-post:disabled { opacity: 0.45; cursor: default; }

/* ── AI sources ─────────────────────────────────────────────────────────── */
.ai-sources {
  margin-top: 10px;
  padding-top: 8px;
  font-size: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.ai-sources-label {
  margin-bottom: 4px;
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.ai-sources ol { margin: 0; padding-left: 1.4em; }
.ai-sources li { margin-bottom: 3px; }
.ai-sources a { color: var(--accent); }
.ai-source-host { color: var(--faint); }

/* ── Small screens: the panel is a bottom sheet, the post stays above it ──
   The post card (with the Less / Neutral / More buttons pinned under the post) shrinks into the
   space above the sheet and the post scrolls inside it, so nothing the participant needs is covered. */
@media (max-width: 760px) {
  .feed-root { --sheet-height: min(46dvh, 400px); }
  .feed-root.panel-open .feed-stage { padding-right: 12px; padding-bottom: calc(var(--sheet-height) + 8px); }
  .side-panel {
    top: auto;
    left: 0;
    width: 100%;
    height: var(--sheet-height);
    border-left: none;
    border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    transform: translateY(100%);
  }
  .side-panel.open { box-shadow: 0 -16px 36px rgba(0, 0, 0, 0.5); }
  .rail { width: 52px; }
  /* With the sheet open there is less height: compact the action rail so it isn't clipped. */
  .feed-root.panel-open .rail { gap: 6px; padding: 8px 0; }
  .feed-root.panel-open .rail-btn .icon { width: 34px; height: 34px; }
}

/* narrow cards: icon above the label */
@media (max-width: 560px) {
  .choice { flex-direction: column; gap: 4px; min-height: 64px; padding: 8px 4px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .feed-root, .feed-stage, .side-panel, .progress-fill { animation: none; transition: none; }
}

/* ── Non-feed screens (instructions, end) ───────────────────────────────── */
/* The page stays dark between posts so nothing flashes white during transitions. */
.jspsych-display-element {
  color: var(--text);
}
.info-screen {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px;
  text-align: left;
  line-height: 1.6;
}
.info-screen h2 {
  margin-top: 0;
  color: var(--strong);
  text-align: center;
}
.info-screen .note {
  padding: 10px 14px;
  font-size: 15px;
  color: #fde68a;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: 8px;
}
.info-screen code {
  padding: 1px 5px;
  font-size: 0.9em;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}
