/*
 * @connextar/house — the styles its components need that utility classes
 * cannot say: rich text, the editor's own chrome, and the trail's tinted pills.
 *
 * Import it once in the app's global stylesheet, after Tailwind:
 *
 *   @import "tailwindcss";
 *   @import "@connextar/house/house.css";
 *   @source "../node_modules/@connextar/house/dist";
 *
 * The @source line is not optional. Tailwind does not scan node_modules, so
 * without it every utility class that appears only inside this package — and
 * the components use many — is silently missing from the build.
 *
 * Colours come from the app's own theme tokens (--primary, --border, …) through
 * a --house-* variable at each use, so a theme that stores tokens as HSL
 * triplets ("222 47% 11%") can map them once without forking this file:
 *
 *   :root { --house-primary: hsl(var(--primary)); --house-border: hsl(var(--border)); … }
 */

@layer components {
  /* ── Rich text — the editor while writing, and RichTextContent while reading ── */

  .house-prose {
    color: var(--house-foreground, var(--foreground));
    line-height: 1.65;
    font-size: 0.925rem;
  }

  .house-prose h1,
  .house-prose h2,
  .house-prose h3 {
    font-weight: 650;
    color: var(--house-foreground, var(--foreground));
    line-height: 1.25;
    margin: 1.4em 0 0.5em;
  }

  .house-prose h1 {
    font-size: 1.5em;
  }
  .house-prose h2 {
    font-size: 1.25em;
  }
  .house-prose h3 {
    font-size: 1.1em;
  }

  .house-prose h1:first-child,
  .house-prose h2:first-child,
  .house-prose h3:first-child,
  .house-prose p:first-child {
    margin-top: 0;
  }

  .house-prose p {
    margin: 0.45em 0;
  }

  .house-prose ul,
  .house-prose ol {
    margin: 0.45em 0;
    padding-left: 1.4em;
  }

  .house-prose ul {
    list-style: disc;
  }
  .house-prose ol {
    list-style: decimal;
  }
  .house-prose li {
    margin: 0.2em 0;
  }
  .house-prose li > ul,
  .house-prose li > ol {
    margin: 0.15em 0;
  }

  /* Task lists — both the editor's data-type DOM and the renderer's own. */
  .house-prose ul[data-type="taskList"],
  .house-prose ul.house-task-list {
    list-style: none;
    padding-left: 0.2em;
  }

  .house-prose ul[data-type="taskList"] li,
  .house-prose ul.house-task-list li {
    display: flex;
    align-items: baseline;
    gap: 0.55em;
  }

  .house-prose ul[data-type="taskList"] li > label {
    flex: 0 0 auto;
    user-select: none;
  }

  .house-prose ul[data-type="taskList"] li > div {
    flex: 1 1 auto;
  }

  .house-prose input[type="checkbox"] {
    accent-color: var(--house-primary, var(--primary));
    width: 0.95em;
    height: 0.95em;
    position: relative;
    top: 0.08em;
  }

  .house-prose li[data-checked="true"] > div,
  .house-prose li.house-task-done > span {
    color: var(--house-muted-foreground, var(--muted-foreground));
    text-decoration: line-through;
  }

  .house-prose blockquote {
    margin: 0.7em 0;
    border-left: 3px solid color-mix(in oklab, var(--house-primary, var(--primary)) 60%, transparent);
    padding: 0.1em 0 0.1em 0.9em;
    color: var(--house-muted-foreground, var(--muted-foreground));
    font-style: italic;
  }

  .house-prose code {
    background: var(--house-muted, var(--muted));
    border-radius: 0.3em;
    padding: 0.12em 0.35em;
    font-size: 0.86em;
    font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  }

  .house-prose pre {
    background: var(--house-muted, var(--muted));
    border: 1px solid var(--house-border, var(--border));
    border-radius: 0.5rem;
    padding: 0.7em 0.9em;
    margin: 0.7em 0;
    overflow-x: auto;
  }

  .house-prose pre code {
    background: transparent;
    padding: 0;
    font-size: 0.85em;
  }

  .house-prose hr {
    border: 0;
    border-top: 1px solid var(--house-border, var(--border));
    margin: 1.2em 0;
  }

  .house-prose a {
    color: var(--house-primary, var(--primary));
    font-weight: 500;
    text-decoration: underline;
    text-decoration-color: color-mix(in oklab, var(--house-primary, var(--primary)) 40%, transparent);
    text-underline-offset: 2px;
  }

  /* An inline #hashtag, a quiet chip in read views. */
  .house-prose .house-hashtag {
    color: var(--house-primary, var(--primary));
    background: color-mix(in oklab, var(--house-primary, var(--primary)) 10%, transparent);
    border-radius: 0.35em;
    padding: 0.05em 0.3em;
    font-weight: 500;
    font-size: 0.92em;
  }

  /* ── The editor ─────────────────────────────────────────────────────────── */

  /* The content area (Tiptap adds .tiptap to the contenteditable). */
  .house-rich-text .tiptap {
    outline: none;
    min-height: var(--rich-text-min-height, 7rem);
    padding: 0.65rem 0.85rem;
  }

  /* A page editor: a gutter on the left for each block's `+` and grip, and no
     box — the page is the surface. */
  .house-rich-text--document {
    --rich-text-min-height: 20rem;
  }

  .house-rich-text--document .tiptap {
    padding: 0.5rem 1rem 6rem 2.75rem;
  }

  /* The empty document's prompt, and "Type / for blocks" on an empty block. */
  .house-rich-text .tiptap .is-empty::before {
    content: attr(data-placeholder);
    float: left;
    height: 0;
    pointer-events: none;
    color: var(--house-muted-foreground, var(--muted-foreground));
  }

  /* The block gutter: `+` and grip beside the hovered block. The extension
     positions it; this only styles it and fades it in. */
  .house-block-handle {
    display: flex;
    align-items: center;
    gap: 1px;
    margin-right: 0.25rem;
    opacity: 0;
    transition: opacity 120ms ease;
  }

  .house-block-handle[data-show="true"],
  .house-block-handle:hover,
  .house-block-handle:focus-within,
  .house-rich-text--document:hover .house-block-handle {
    opacity: 1;
  }

  /* A block picked up by its grip, or selected whole. */
  .house-rich-text .tiptap .ProseMirror-selectednode,
  .house-rich-text .tiptap [draggable="true"]:active {
    background: color-mix(in oklab, var(--house-primary, var(--primary)) 8%, transparent);
    border-radius: 0.375rem;
  }

  .house-rich-text .tiptap.dragging,
  .house-rich-text .tiptap.dragging * {
    cursor: grabbing;
  }

  /* The in-flight text of a lookup, before it resolves. */
  .house-rich-text .house-suggestion {
    color: var(--house-primary, var(--primary));
    background: color-mix(in oklab, var(--house-primary, var(--primary)) 8%, transparent);
    border-radius: 0.25em;
  }

  /* ── The trail ──────────────────────────────────────────────────────────── */

  /* Each step deeper a shade further from the card, so the rail reads as depth. */
  .house-trail-pill {
    background: color-mix(
      in oklab,
      var(--house-card, var(--card)) calc(100% - var(--house-trail-step, 0) * 6%),
      var(--house-accent, var(--accent))
    );
  }

  .house-trail-pill[data-current] {
    box-shadow: inset 3px 0 0 var(--house-primary, var(--primary));
  }
}

/* The trail bar shows below the lg breakpoint and adds its height less the page
   padding it overlaps. A screen that fills the viewport subtracts --trail-bar so
   the page doesn't scroll by that much. */
@media (width < 64rem) {
  :root:has([data-trail-bar]) {
    --trail-bar: 37px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .house-block-handle {
    transition: none;
  }
}
