/* ============================================
   Stream — refined editorial aesthetic
   ============================================ */

:root {
  /* Pure-black YouTube-style dark theme */
  --paper: #0f0f0f;
  --paper-soft: #1f1f1f;
  --paper-deep: #272727;
  --ink: #ffffff;
  --ink-soft: #d6d6d6;
  --ink-mute: #aaaaaa;
  --ink-faint: #717171;
  --rule: #272727;
  --rule-soft: #1f1f1f;

  /* Accent stays terracotta for the brand mark / focus rings */
  --accent: #d97056;
  --accent-soft: #4a2218;
  --accent-deep: #f0c1b1;

  /* Type */
  --serif: 'Fraunces', 'Hoefler Text', Georgia, serif;
  --sans: 'Inter', -apple-system, 'Roboto', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;

  /* Layout */
  --sidebar-w: 248px;
  --max-content: 720px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

input { font: inherit; color: inherit; }

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

/* ============================================
   App layout
   ============================================ */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.topbar { display: none; }

/* ============================================
   Sidebar
   ============================================ */

.sidebar {
  border-right: 1px solid var(--rule);
  padding: 28px 20px 20px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--paper);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 28px;
}

.brand-mark {
  font-family: var(--serif);
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
}

.brand-name {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 19px;
  letter-spacing: -0.01em;
}

.nav-primary {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 32px;
}

.nav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--ink-soft);
  font-size: 14px;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}

.nav-item:hover {
  background: var(--paper-soft);
  color: var(--ink);
}

.nav-item.is-active {
  background: var(--paper-deep);
  color: var(--ink);
  font-weight: 500;
}

.nav-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  font-weight: 400;
}

.nav-item.is-active .nav-count {
  color: var(--ink-mute);
}

.nav-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 10px;
  margin-bottom: 8px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.add-source-btn {
  font-size: 16px;
  color: var(--ink-mute);
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.add-source-btn:hover { background: var(--paper-soft); color: var(--ink); }

.nav-sources {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px;
}

.source-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--ink-soft);
  font-size: 13px;
  text-align: left;
  transition: background 0.12s;
  position: relative;
}

.source-item:hover { background: var(--paper-soft); }

.source-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.source-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-remove {
  opacity: 0;
  font-size: 14px;
  color: var(--ink-faint);
  padding: 0 4px;
  line-height: 1;
}

.source-item:hover .source-remove { opacity: 1; }
.source-remove:hover { color: var(--accent); }

.sidebar-footer {
  padding-top: 16px;
  margin-top: 16px;
  border-top: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.footer-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-soft);
  padding: 6px 8px;
  border-radius: 5px;
}

.footer-btn:hover { background: var(--paper-soft); color: var(--ink); }
.footer-btn svg { transition: transform 0.4s; }
.footer-btn.is-loading svg { animation: spin 0.9s linear infinite; }

.footer-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-faint);
  text-align: right;
}

/* ============================================
   Main column
   ============================================ */

.main {
  padding: 56px 56px 80px;
  max-width: calc(var(--max-content) + 112px);
  margin: 0 auto;
  width: 100%;
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 28px;
}

.view-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 38px;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--ink);
}

.view-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-mute);
  margin-top: 6px;
  letter-spacing: 0.02em;
}

.btn-ghost {
  font-size: 12px;
  color: var(--ink-soft);
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 16px;
  transition: all 0.15s;
}

.btn-ghost:hover { border-color: var(--ink-mute); color: var(--ink); }

.btn-ghost[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* ============================================
   Paste bar
   ============================================ */

.paste-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  border-radius: 10px;
  margin-bottom: 32px;
  transition: border-color 0.15s, background 0.15s;
}

.paste-bar:focus-within {
  border-color: var(--accent);
  background: var(--paper);
}

.paste-icon {
  font-size: 16px;
  color: var(--ink-mute);
  line-height: 1;
  font-weight: 300;
}

.paste-bar:focus-within .paste-icon { color: var(--accent); }

#paste-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  color: var(--ink);
}

#paste-input::placeholder { color: var(--ink-mute); }

.paste-hint {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-faint);
  padding: 3px 7px;
  background: var(--paper);
  border-radius: 4px;
  border: 1px solid var(--rule);
}

/* ============================================
   Feed
   ============================================ */

.feed {
  display: flex;
  flex-direction: column;
  gap: 36px;
}

.feed-item {
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: opacity 0.2s;
}

.feed-item.is-read { opacity: 0.55; }
.feed-item.is-removing { opacity: 0; transform: translateX(8px); transition: all 0.2s; }

.feed-item-row {
  display: grid;
  grid-template-columns: 36px 1fr 28px;
  gap: 12px;
  align-items: start;
}

.feed-item-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  color: #fff;
  text-transform: uppercase;
  flex-shrink: 0;
  user-select: none;
}

.feed-item-body { min-width: 0; }

.feed-item-title {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 16px;
  line-height: 1.35;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}

.feed-item-title:hover { color: var(--ink); }

.feed-item-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 6px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-mute);
  letter-spacing: 0;
  text-transform: none;
}

.feed-item-sep { color: var(--ink-mute); }

/* Menu (3-dot) */
.feed-item-menu {
  position: relative;
  align-self: start;
  justify-self: end;
}

.menu-trigger {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  transition: background 0.12s;
}

.menu-trigger:hover { background: var(--paper-soft); }
.menu-trigger svg  { width: 18px; height: 18px; }

.menu-pop {
  position: absolute;
  top: 32px;
  right: 0;
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 6px;
  min-width: 180px;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.menu-pop[hidden] { display: none; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink-soft);
  text-align: left;
  transition: background 0.12s, color 0.12s;
}

.menu-item:hover  { background: var(--paper-deep); color: var(--ink); }
.menu-item.is-active { color: var(--accent); }
.menu-item svg    { width: 15px; height: 15px; }

.feed-item-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: var(--paper-soft);
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease-out;
}

.feed-item-thumb:hover { transform: translateY(-2px); }

.feed-item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.feed-item-thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 64px;
  color: var(--ink-faint);
}

.video-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0,0,0,0.85);
  color: white;
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.video-badge svg { width: 9px; height: 9px; }

/* ============================================
   Empty + loading states
   ============================================ */

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--ink-mute);
}

.empty-mark {
  font-family: var(--serif);
  font-size: 48px;
  color: var(--accent);
  opacity: 0.4;
  margin-bottom: 20px;
}

.empty-state h2 {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 400;
  color: var(--ink);
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}

.empty-state p {
  font-size: 14px;
  max-width: 320px;
  margin: 0 auto;
  line-height: 1.6;
}

.empty-state em {
  font-style: italic;
  color: var(--ink);
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 20px;
  color: var(--ink-mute);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.spinner {
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================
   Modal
   ============================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20,18,15,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fade-in 0.15s ease-out;
}

.modal-backdrop[hidden] { display: none; }
.toast[hidden]          { display: none; }
.loading[hidden]        { display: none; }
.empty-state[hidden]    { display: none; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--paper);
  border-radius: 12px;
  border: 1px solid var(--rule);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
  animation: slide-up 0.2s ease-out;
}

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

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--rule);
}

.modal-header h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.modal-close {
  font-size: 22px;
  color: var(--ink-mute);
  width: 28px;
  height: 28px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.modal-close:hover { background: var(--paper-soft); color: var(--ink); }

.modal-body { padding: 20px 24px 24px; }

.modal-hint {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.55;
  margin-bottom: 16px;
}

#source-form {
  display: flex;
  gap: 8px;
}

#source-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  border-radius: 7px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

#source-input:focus {
  border-color: var(--accent);
  background: var(--paper);
}

.btn-primary {
  padding: 10px 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--accent); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.modal-status {
  margin-top: 14px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-mute);
  min-height: 16px;
}

.modal-status.is-error { color: var(--accent); }
.modal-status.is-success { color: var(--ink); }

/* ============================================
   Settings
   ============================================ */

.settings-toggle {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  cursor: pointer;
}

.settings-toggle input[type="checkbox"] {
  margin-top: 3px;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.settings-toggle-label { display: flex; flex-direction: column; gap: 2px; }

.settings-toggle-title {
  font-size: 14px;
  color: var(--ink);
  font-weight: 500;
}

.settings-toggle-desc {
  font-size: 12px;
  color: var(--ink-mute);
  line-height: 1.45;
}

.settings-section + .settings-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
}

.settings-h3 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 15px;
  margin-bottom: 8px;
  color: var(--ink);
}

.sync-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--paper-soft);
  border-radius: 7px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 14px;
}

.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex-shrink: 0;
}

.sync-dot.is-connected { background: #1d6e56; }
.sync-dot.is-syncing  { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.sync-dot.is-error    { background: var(--accent); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

#sync-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

#sync-passphrase {
  flex: 1;
  padding: 10px 14px;
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  border-radius: 7px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

#sync-passphrase:focus {
  border-color: var(--accent);
  background: var(--paper);
}

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.btn-ghost.is-danger {
  margin-left: auto;
  border-color: var(--rule);
  color: var(--ink-mute);
}

.btn-ghost.is-danger:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================
   Toast
   ============================================ */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 8px;
  z-index: 200;
  animation: toast-in 0.2s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ============================================
   Mobile
   ============================================ */

@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--rule);
    background: var(--paper);
    position: sticky;
    top: 0;
    z-index: 50;
  }

  .topbar-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--serif);
    font-size: 17px;
  }

  .topbar-menu, .topbar-add {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-soft);
    font-size: 22px;
    line-height: 1;
  }

  .topbar-menu:hover, .topbar-add:hover {
    background: var(--paper-soft);
    color: var(--ink);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease-out;
    box-shadow: 0 0 40px rgba(0,0,0,0.1);
  }

  .sidebar.is-open { transform: translateX(0); }

  .main {
    padding: 24px 20px 80px;
  }

  .view-title { font-size: 28px; }

  .feed { gap: 28px; }
  .feed-item-title { font-size: 18px; }
  .feed-item-desc { font-size: 13px; -webkit-line-clamp: 2; }

  .paste-hint { display: none; }
}

/* Tablet sweet spot */
@media (min-width: 721px) and (max-width: 1000px) {
  .main { padding: 40px 40px 80px; }
}
