:root {
  --bg-deep: #050814;
  --bg-surface: rgba(15, 22, 41, 0.76);
  --bg-surface-solid: rgba(5, 8, 20, 0.92);
  --bg-raised: rgba(26, 31, 53, 0.72);
  --bg-card: rgba(15, 22, 41, 0.84);
  --glass-border: rgba(217, 168, 255, 0.16);
  --text-primary: #ffffff;
  --text-secondary: #d9d7e6;
  --text-muted: #89849d;
  --accent-morning: #8be7ff;
  --accent-morning-dim: rgba(139, 231, 255, 0.12);
  --accent-evening: #d9a8ff;
  --accent-evening-dim: rgba(217, 168, 255, 0.13);
  --accent-evening-glow: rgba(217, 168, 255, 0.42);
  --accent-base: #7c3aed;
  --accent-base-dim: rgba(124, 58, 237, 0.14);
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 14px;
  --r-2xl: 18px;
}

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

body {
  font-family: 'Figtree', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(circle at 20% 0%, rgba(124, 58, 237, 0.26), transparent 30rem),
    radial-gradient(circle at 85% 90%, rgba(236, 72, 153, 0.14), transparent 30rem),
    linear-gradient(180deg, #0f1629 0%, var(--bg-deep) 100%);
}

.app-header {
  height: 64px;
  background: var(--bg-surface-solid);
  border-bottom: 1px solid var(--glass-border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.logo-mark {
  width: 34px;
  height: 34px;
  border-radius: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  color: var(--accent-evening);
  filter: drop-shadow(0 0 14px rgba(217, 168, 255, 0.38));
}

.logo-mark::before {
  content: '';
  width: 100%;
  height: 100%;
  background: currentColor;
  -webkit-mask: url('/brand-mark.svg') center / contain no-repeat;
  mask: url('/brand-mark.svg') center / contain no-repeat;
}

.logo h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.logo h1 span {
  color: var(--text-secondary);
  font-weight: 400;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-pill {
  font-size: 11.5px;
  font-family: 'JetBrains Mono', monospace;
  padding: 5px 12px;
  border-radius: var(--r-md);
  background: var(--bg-raised);
  color: var(--text-secondary);
  border: 1px solid var(--glass-border);
}

.chronicle-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 32px calc(88px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.hero-card,
.artifact-column,
.reader-card {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-2xl);
  overflow: hidden;
  position: relative;
}

.hero-card {
  padding: 20px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: linear-gradient(135deg, rgba(139, 231, 255, 0.08), rgba(15, 22, 41, 0.9));
  border-color: rgba(139, 231, 255, 0.24);
}

.card-eyebrow,
.section-label,
.reader-kicker {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-evening);
}

.hero-card h2 {
  font-size: 22px;
  letter-spacing: -0.02em;
}

.hero-card p {
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.45;
  max-width: 560px;
}

.coach-link,
.edit-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--r-md);
  border: 1px solid rgba(139, 231, 255, 0.3);
  background: var(--accent-morning-dim);
  color: var(--accent-morning);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.reader-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.reader-highlight-btn,
.sidebar-toggle-btn {
  width: 34px;
  height: 34px;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sidebar-toggle-btn {
  padding: 5px;
  border-color: rgba(217, 215, 230, 0.38);
  color: var(--text-secondary);
  transform: translateX(0);
}

.sidebar-toggle-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-toggle-btn:hover,
.sidebar-toggle-btn.is-collapsed {
  border-color: rgba(217, 215, 230, 0.62);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.reader-highlight-btn:hover {
  border-color: rgba(255, 224, 102, 0.4);
}

.reader-highlight-btn.active,
.reader-highlight-btn[aria-pressed="true"] {
  background: rgba(255, 224, 102, 0.9);
  border-color: rgba(255, 224, 102, 1);
  box-shadow: 0 0 0 4px rgba(255, 224, 102, 0.25), 0 0 12px rgba(255, 224, 102, 0.4);
}

.reader-highlight-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.reader-highlight-icon {
  display: block;
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.reader-undo-btn {
  width: 34px;
  height: 34px;
  padding: 6px;
  border: 1px solid rgba(129, 140, 248, 0.26);
  border-radius: var(--r-md);
  background: var(--accent-evening-dim);
  color: var(--accent-evening);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.reader-undo-btn:hover {
  background: var(--accent-evening-dim);
  border-color: rgba(129, 140, 248, 0.4);
}

.reader-undo-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.reader-card.highlight-mode .reader-body {
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

/* Edge fades hint that section pills scroll horizontally (esp. mobile). */
.section-tabs-scroll {
  position: relative;
}

.section-tabs-scroll::before,
.section-tabs-scroll::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 32px;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.22s ease;
}

.section-tabs-scroll::before {
  left: 0;
  background: linear-gradient(90deg, var(--bg-deep) 0%, rgba(13, 13, 15, 0) 100%);
}

.section-tabs-scroll::after {
  right: 0;
  background: linear-gradient(270deg, var(--bg-deep) 0%, rgba(13, 13, 15, 0) 100%);
}

.section-tabs-scroll.section-tabs-scroll--left::before {
  opacity: 1;
}

.section-tabs-scroll.section-tabs-scroll--right::after {
  opacity: 1;
}

.section-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.section-tabs::-webkit-scrollbar { display: none; }

.section-tab {
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  background: var(--bg-raised);
  color: var(--text-secondary);
  padding: 9px 14px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}

.section-tab.active {
  color: var(--accent-evening);
  background: var(--accent-evening-dim);
  border-color: rgba(129, 140, 248, 0.28);
}

.chronicle-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 18px;
  align-items: start;
}

.chronicle-grid.sidebar-collapsed {
  grid-template-columns: 1fr;
}

.chronicle-grid.sidebar-collapsed .artifact-column {
  display: none;
}

.artifact-column {
  position: sticky;
  top: 82px;
  max-height: calc(100dvh - 168px);
  display: flex;
  flex-direction: column;
}

.column-header,
.reader-header {
  padding: 20px;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.column-header-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}

.reader-heading-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
}

.reader-title-block {
  min-width: 0;
}

.reader-sidebar-toggle-slot {
  flex: 0 0 auto;
}

.reader-sidebar-toggle-slot:empty {
  display: none;
}

.column-header h3,
.reader-header h2 {
  margin-top: 6px;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.item-count {
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
}

.artifact-list {
  padding: 10px;
  overflow-y: auto;
}

.artifact-card {
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--r-xl);
  padding: 14px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.artifact-card:hover {
  background: rgba(255, 255, 255, 0.04);
}

.artifact-card.active {
  background: var(--accent-base-dim);
  border-color: rgba(129, 140, 248, 0.28);
}

.artifact-selected-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid rgba(139, 231, 255, 0.24);
  border-radius: var(--r-xl);
  background: linear-gradient(135deg, rgba(139, 231, 255, 0.08), rgba(15, 22, 41, 0.9));
}

.artifact-selected-copy {
  min-width: 0;
}

.artifact-list-expand {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid rgba(139, 231, 255, 0.32);
  background: rgba(139, 231, 255, 0.1);
  color: var(--accent-morning);
  cursor: pointer;
  box-shadow: 0 0 14px rgba(139, 231, 255, 0.22);
}

.artifact-list-expand svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.artifact-list-expand:hover {
  border-color: rgba(139, 231, 255, 0.5);
  box-shadow: 0 0 18px rgba(139, 231, 255, 0.32);
}

.artifact-meta {
  color: var(--text-muted);
  font-size: 10.5px;
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
}

.artifact-title {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 650;
  color: var(--text-primary);
  line-height: 1.35;
}

.artifact-snippet,
.artifact-empty,
.reader-empty {
  margin-top: 7px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

#readerPath {
  margin-top: 4px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  overflow-wrap: anywhere;
}

.reader-body {
  padding: 28px;
  color: var(--text-secondary);
  line-height: 1.75;
  font-size: 15px;
}

.reader-body h1,
.reader-body h2,
.reader-body h3 {
  color: var(--text-primary);
  line-height: 1.25;
  letter-spacing: -0.02em;
  margin: 1.5em 0 0.65em;
}

.reader-body h1:first-child,
.reader-body h2:first-child,
.reader-body h3:first-child {
  margin-top: 0;
}

.reader-body h1 { font-size: 30px; }
.reader-body h2 { font-size: 22px; }
.reader-body h3 { font-size: 16px; color: var(--accent-evening); }

.reader-body p,
.reader-body ul,
.reader-body ol,
.reader-body blockquote {
  margin: 0 0 1em;
}

.reader-body ul,
.reader-body ol {
  padding-left: 1.35em;
}

.reader-body blockquote {
  padding: 12px 16px;
  border-left: 3px solid var(--accent-evening);
  background: rgba(129, 140, 248, 0.08);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  color: var(--text-primary);
}

.reader-body code {
  font-family: 'JetBrains Mono', monospace;
  color: #e879f9;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  padding: 1px 4px;
}

.reader-body hr {
  border: 0;
  border-top: 1px solid var(--glass-border);
  margin: 24px 0;
}

.highlights-view {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-2xl);
  overflow: hidden;
}

.highlights-header {
  padding: 22px 24px;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  gap: 24px;
}

.highlights-header h3 {
  margin-top: 6px;
  font-size: 20px;
  letter-spacing: -0.02em;
}

.highlights-header p {
  max-width: 520px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.55;
}

.highlights-header code {
  font-family: 'JetBrains Mono', monospace;
  color: #fff3b0;
}

.highlights-grid {
  display: grid;
  gap: 1px;
  background: var(--glass-border);
}

/* Snippet (source + highlighted text) first; note second — desktop: note on the right. */
.highlight-row {
  display: grid;
  grid-template-columns: 1fr minmax(220px, 360px);
  align-items: stretch;
  background: var(--bg-card);
}

.highlight-snippet-card,
.highlight-note-card {
  padding: 18px;
  min-width: 0;
}

.highlight-note-card {
  border-left: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.022);
}

.highlight-comment-label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.highlight-comment {
  width: 100%;
  min-height: 96px;
  resize: none;
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  background: rgba(13, 13, 15, 0.55);
  color: var(--text-primary);
  padding: 12px;
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  outline: none;
}

.highlight-comment:focus {
  border-color: rgba(129, 140, 248, 0.45);
  box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.12);
}

.highlight-comment-status {
  min-height: 16px;
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 11px;
}

.highlight-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.highlight-source-link {
  color: var(--accent-evening);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  overflow-wrap: anywhere;
  text-decoration: none;
}

.highlight-source-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.highlight-remove-btn {
  flex: 0 0 auto;
  min-width: 40px;
  min-height: 40px;
  width: auto;
  height: auto;
  padding: 4px;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.highlight-remove-btn:hover {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
}

.highlight-remove-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.highlight-remove-btn .highlight-remove-icon {
  display: block;
  width: 40px;
  height: 40px;
  object-fit: contain;
  opacity: 0.95;
  /* Drop baked-in black matte: white strokes stay visible on dark surfaces */
  mix-blend-mode: lighten;
}

.highlight-remove-btn:hover .highlight-remove-icon {
  opacity: 1;
}

.highlight-context {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.75;
  white-space: normal;
}

.highlight-mark {
  background: rgba(255, 224, 102, 0.28);
  color: #fff3b0;
  border-radius: 4px;
  padding: 0.05em 0.18em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.highlights-loading,
.highlights-empty {
  padding: 28px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}

.orphaned-comments {
  border-top: 1px solid var(--glass-border);
  padding: 18px 24px 24px;
  color: var(--text-secondary);
}

.orphaned-comments summary {
  cursor: pointer;
  color: var(--accent-evening);
  font-weight: 650;
}

.orphaned-comments p {
  margin: 10px 0 14px;
  color: var(--text-muted);
  font-size: 13px;
}

.orphaned-comment {
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  padding: 12px;
  margin-top: 10px;
  background: rgba(255, 255, 255, 0.025);
}

.orphaned-source {
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  overflow-wrap: anywhere;
}

.orphaned-text {
  margin-top: 8px;
  color: #fff3b0;
}

.orphaned-note {
  margin-top: 8px;
  color: var(--text-primary);
  white-space: pre-wrap;
}

@media (max-width: 860px) {
  .app-header {
    padding: 0 18px;
  }

  .logo {
    flex: 0 0 auto;
  }

  .logo h1 {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 17px;
    line-height: 1;
    letter-spacing: 0.18em;
  }

  .logo h1 span {
    display: block;
  }

  .header-meta {
    min-width: 0;
  }

  .date-pill {
    max-width: 116px;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    text-align: center;
    white-space: normal;
    line-height: 1.05;
  }

  /* Stronger edge cue on narrow viewports where tabs often overflow. */
  .section-tabs-scroll::before,
  .section-tabs-scroll::after {
    width: 48px;
  }

  .chronicle-shell {
    padding: 22px 16px calc(88px + env(safe-area-inset-bottom, 0px));
  }

  .hero-card {
    align-items: stretch;
    flex-direction: column;
    gap: 14px;
    padding: 18px;
  }

  .chronicle-grid {
    grid-template-columns: 1fr;
  }

  .artifact-column {
    position: static;
    max-height: none;
  }

  .chronicle-grid.sidebar-collapsed .artifact-column {
    display: flex;
  }

  .sidebar-toggle-btn {
    display: none;
  }

  .highlights-header {
    flex-direction: column;
  }

  /* Highlights Review: stacked cards — highlight on top, your note below. */
  .highlights-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 14px 14px 18px;
    background: transparent;
  }

  .highlight-row {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--glass-border);
    border-radius: var(--r-xl);
    overflow: hidden;
  }

  .highlight-snippet-card,
  .highlight-note-card {
    padding: 16px;
    border: none;
    border-radius: 0;
    background: var(--bg-card);
  }

  .highlight-snippet-card {
    border-bottom: 1px solid var(--glass-border);
  }

  .highlight-note-card {
    border-left: none;
    background: rgba(255, 255, 255, 0.03);
  }

  .highlight-remove-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 6px;
  }

  .highlight-remove-btn .highlight-remove-icon {
    width: 32px;
    height: 32px;
  }
}
