---
title: "Comments"
description: "Website blocks - Comments: Blocks for a discussion under an article or a product: the header with the count and sort order, the form for a new comment, and the comments with their nested replies."
slug: "website-comments"
---

import { DocPage, PageHeader, DocText, DocLink } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="website-comments" title="Comments" introStyle="max-width:42rem;">
  Blocks for a discussion under an article or a product: the header with the count and sort order, the form for a new comment, and the comments with their nested replies. Every block is CSS-only and built from the library's components and tokens.
</PageHeader>

<h2 id="template" class="h2-display">The template</h2>

<DocText>The Comments blocks composed into one discussion - the source is the page. A comment's time is its permalink, a route of <DocLink href="routing.html">defuss-dom-router</DocLink> (<code>#/comments/d-3</code>) that highlights it and names its author above the thread, and the sort order is a query parameter (<code>#/?sort=oldest</code>). The actions work: Like counts, Reply opens the reply form under that comment and adds the reply to its thread line, a new comment joins the top, and Report and the guidelines are native dialogs. The language switch translates the frame with <DocLink href="translation.html">defuss-i18n</DocLink> - the times come from <code>Intl.RelativeTimeFormat</code>, what the script writes from one JSON block in both languages, the comments stay as written.</DocText>

<div class="flex flex-wrap items-center gap-2 mb-6">
  <a class="btn" href="full-website-comments.html" target="_blank" rel="noopener"><i data-lucide="maximize-2"></i> Open full screen</a>
</div>

```html example label="A discussion" schema="none" hint="A time is a permalink route (#/comments/d-2), the sort a query (#/?sort=oldest); the switch translates the frame. Comment Header, Comment Form and a thread of Comment Items with nested replies and a reply form - the Comments blocks composed. Click a timestamp to highlight that comment; Like, Reply, Report and Post comment work." previewStyle="align-items:stretch;"
<style>
  @import url('https://fonts.googleapis.com/css2?family=Manrope:wght@500;600;700;800&family=Source+Serif+4:ital,opsz,wght@0,8..60,400;0,8..60,600;1,8..60,400&display=swap');
  /* The discussion under an engineering article: the site bar, the article it belongs to, then a 46rem column -
     header and sort, a composer card, the thread with replies along a line. The author of the article wears a
     badge, a permalinked comment is lit. Looks: Thread (white and indigo, follows light / dark), Late night (slate
     and teal) and Paper (warm paper, a serif for what people wrote, rust for actions, a grain under it). */
  #site-comments {
    --background: oklch(0.99 0.002 260);
    --foreground: oklch(0.21 0.02 265);
    --card: oklch(1 0 0);
    --card-foreground: var(--foreground);
    --muted: oklch(0.965 0.006 265);
    --muted-foreground: oklch(0.48 0.02 265);
    --border: oklch(0.21 0.02 265 / 0.11);
    --input: oklch(0.21 0.02 265 / 0.2);
    --primary: oklch(0.5 0.19 272);
    --primary-foreground: oklch(0.99 0.002 260);
    --secondary: oklch(0.96 0.012 272);
    --secondary-foreground: oklch(0.36 0.13 272);
    --accent: oklch(0.955 0.02 272);
    --accent-foreground: oklch(0.36 0.13 272);
    --ring: var(--primary);
    --radius: 0.625rem;
    --radius-sm: max(0px, calc(var(--radius) - 4px));
    --radius-md: max(0px, calc(var(--radius) - 2px));
    --radius-lg: var(--radius);
    --radius-xl: calc(var(--radius) + 4px);
    --comments-said: 'Manrope', var(--font-sans);
    color-scheme: light;
    position: relative;
    isolation: isolate;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
    padding-block-end: clamp(3rem, 7vw, 5rem);
    background: var(--background);
    color: var(--foreground);
    font:
      400 1rem/1.55 'Manrope',
      var(--font-sans);
  }
  #site-comments > :not(.surface, .comments-bar, dialog) {
    box-sizing: border-box;
    width: 100%;
    max-width: 46rem;
    margin-inline: auto;
    padding-inline: clamp(1rem, 4vw, 1.5rem);
  }
  .dark #site-comments[data-look='thread'] {
    color-scheme: dark;
    --background: oklch(0.18 0.012 265);
    --foreground: oklch(0.94 0.006 265);
    --card: oklch(0.215 0.014 265);
    --muted: oklch(0.24 0.014 265);
    --muted-foreground: oklch(0.74 0.014 265);
    --border: oklch(0.94 0.006 265 / 0.11);
    --input: oklch(0.94 0.006 265 / 0.2);
    --primary: oklch(0.72 0.14 272);
    --primary-foreground: oklch(0.18 0.012 265);
    --secondary: oklch(0.28 0.05 272);
    --secondary-foreground: oklch(0.88 0.06 272);
    --accent: oklch(0.26 0.04 272);
    --accent-foreground: oklch(0.88 0.06 272);
  }
  #site-comments[data-look='night'] {
    color-scheme: dark;
    --background: oklch(0.2 0.018 235);
    --foreground: oklch(0.94 0.008 220);
    --card: oklch(0.235 0.02 235);
    --muted: oklch(0.26 0.02 235);
    --muted-foreground: oklch(0.76 0.016 225);
    --border: oklch(0.94 0.008 220 / 0.12);
    --input: oklch(0.94 0.008 220 / 0.22);
    --primary: oklch(0.8 0.11 180);
    --primary-foreground: oklch(0.2 0.03 220);
    --secondary: oklch(0.3 0.04 185);
    --secondary-foreground: oklch(0.88 0.08 180);
    --accent: oklch(0.27 0.03 190);
    --accent-foreground: oklch(0.88 0.08 180);
  }
  #site-comments[data-look='paper'] {
    color-scheme: light;
    --background: oklch(0.965 0.014 82);
    --foreground: oklch(0.25 0.025 50);
    --card: oklch(0.985 0.01 82);
    --muted: oklch(0.935 0.016 80);
    --muted-foreground: oklch(0.45 0.03 55);
    --border: oklch(0.25 0.025 50 / 0.14);
    --input: oklch(0.25 0.025 50 / 0.26);
    --primary: oklch(0.47 0.13 40);
    --primary-foreground: oklch(0.985 0.01 82);
    --secondary: oklch(0.92 0.03 55);
    --secondary-foreground: oklch(0.4 0.11 40);
    --accent: oklch(0.93 0.03 60);
    --accent-foreground: oklch(0.4 0.11 40);
    --radius: 0.25rem;
    --comments-said: 'Source Serif 4', Georgia, serif;
  }
  #site-comments .comments-look-only {
    display: none;
  }
  #site-comments[data-look='paper'] .comments-look-only[data-for='paper'] {
    display: block;
  }
  #site-comments .comments-grain {
    --surface-size: 180px;
    --surface-ink: oklch(0.3 0.03 50 / 0.03);
    --surface-bg: transparent;
  }
  #site-comments [hidden] {
    display: none !important;
  }
  /* the site bar (Site Header) - the same publication as the article */
  #site-comments .mk-header.comments-bar {
    box-sizing: border-box;
    width: 100%;
    background: transparent;
    border-block-end: 1px solid var(--border);
  }
  #site-comments .comments-bar .mk-header-inner {
    box-sizing: border-box;
    flex-wrap: wrap;
    gap: 0.75rem 1.5rem;
    max-width: none;
    min-height: 4.5rem;
    padding: 0.75rem clamp(1rem, 4vw, 2.5rem);
  }
  #site-comments .comments-bar .mk-header-nav {
    margin-inline-end: auto;
  }
  /* narrow: the menu button sits at the end of the brand's row, the controls wrap below */
  #site-comments .comments-bar .site-menu {
    margin-inline-start: auto;
  }
  #site-comments .sheet .mk-header-sheet-actions {
    display: grid;
    justify-content: stretch;
  }
  #site-comments .comments-bar .nav-menu-list {
    display: flex;
    gap: 1.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
  }
  #site-comments .comments-bar .nav-menu-link {
    padding: 0.25rem 0;
    border: 0;
    background: none;
    color: var(--muted-foreground);
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
  }
  #site-comments .comments-bar .nav-menu-link:hover {
    background: none;
    color: var(--foreground);
  }
  #site-comments span.mk-comment-item-author:hover {
    text-decoration: none;
  }
  /* a permalink names the comment it lights, with the way back to the whole thread */
  #site-comments .comments-permalink {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 1rem;
    margin-block: 1.5rem 0;
    padding-block: 0.75rem;
    border-radius: var(--radius-lg);
    background: var(--accent);
    box-shadow: inset 3px 0 0 var(--primary);
    color: var(--accent-foreground);
    font-size: 0.875rem;
  }
  #site-comments .comments-permalink b {
    color: inherit;
  }
  #site-comments .comments-permalink a {
    margin-inline-start: auto;
    color: var(--primary);
    font-weight: 700;
    text-decoration: none;
  }
  #site-comments .comments-permalink a:hover {
    text-decoration: underline;
  }
  #site-comments .mk-comment-item-actions .btn[aria-pressed='true'] {
    color: var(--primary);
  }
  #site-comments .mk-comment-item-actions .btn[aria-pressed='true'] svg {
    fill: currentColor;
  }
  #site-comments .comments-rules-link {
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-decoration: underline;
    text-underline-offset: 0.2em;
    cursor: pointer;
  }
  /* the dialogs: report a comment, the guidelines */
  #site-comments .comments-dialog .dialog-body {
    display: grid;
    gap: 0.75rem;
  }
  #site-comments .comments-reasons {
    display: grid;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    border: 0;
  }
  #site-comments .comments-reason {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
  }
  #site-comments .comments-reason:has(:checked) {
    border-color: var(--primary);
    background: var(--accent);
    color: var(--accent-foreground);
  }
  #site-comments .comments-rules {
    display: grid;
    gap: 0.625rem;
    margin: 0;
    padding-inline-start: 1.25rem;
    line-height: 1.5;
  }
  /* the footer (Site Footer, simple) */
  #site-comments > .mk-footer.comments-footer {
    max-width: none;
    margin-block-start: 1rem;
    margin-block-end: calc(-1 * clamp(3rem, 7vw, 5rem));
    padding: 0;
    border-block-start: 1px solid var(--border);
    background: var(--card);
  }
  #site-comments .comments-footer .mk-footer-inner {
    max-width: none;
    padding: 1.75rem clamp(1rem, 4vw, 2.5rem);
  }
  #site-comments .comments-footer .mk-footer-brand {
    color: var(--foreground);
    font-weight: 800;
    letter-spacing: -0.02em;
  }
  #site-comments .comments-footer .mk-footer-brand span {
    color: var(--muted-foreground);
    font-weight: 600;
  }
  #site-comments .comments-footer .mk-footer-links :is(a, button) {
    padding: 0;
    border: 0;
    background: none;
    color: var(--muted-foreground);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
  }
  #site-comments .comments-footer .mk-footer-links :is(a, button):hover {
    color: var(--foreground);
  }
  #site-comments .comments-brand {
    display: block;
    color: var(--foreground);
    text-decoration: none;
    font-weight: 800;
    font-size: 1.0625rem;
    letter-spacing: -0.02em;
  }
  #site-comments .comments-brand span {
    color: var(--muted-foreground);
    font-weight: 600;
  }
  #site-comments .comments-bar-controls {
    display: flex;
    flex-wrap: wrap;
    flex-shrink: 1;
    gap: 0.5rem;
    min-width: 0;
  }
  #site-comments .comments-bar .select {
    min-width: 8.5rem;
  }
  /* the article this discussion belongs to */
  #site-comments .comments-context {
    display: grid;
    gap: 0.25rem;
    margin-block-start: clamp(1.5rem, 4vw, 2.5rem);
  }
  #site-comments .comments-context span {
    color: var(--muted-foreground);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }
  #site-comments .comments-context a {
    color: var(--foreground);
    font:
      700 clamp(1.5rem, 3vw, 2rem)/1.15 'Source Serif 4',
      Georgia,
      serif;
    letter-spacing: -0.015em;
    text-decoration: none;
  }
  #site-comments .comments-context a:hover {
    color: var(--primary);
  }
  /* the header and the sort */
  #site-comments .mk-comment-header {
    padding-block-start: 1.5rem;
    border-block-start: 1px solid var(--border);
  }
  #site-comments .mk-comment-header-title {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
  }
  #site-comments .mk-comment-header-title .badge {
    border: 0;
    background: var(--secondary);
    color: var(--secondary-foreground);
    font-weight: 700;
  }
  #site-comments .mk-comment-header-sort {
    color: var(--muted-foreground);
    font-size: 0.875rem;
  }
  /* the composer: a card with the textarea inside it */
  #site-comments > .mk-comment-form {
    padding: 1.25rem clamp(1rem, 4vw, 1.5rem);
  }
  #site-comments .mk-comment-form-main {
    padding: 0.75rem;
    border: 1px solid var(--input);
    border-radius: var(--radius-xl);
    background: var(--card);
    box-shadow: 0 1px 2px oklch(0 0 0 / 0.04);
  }
  #site-comments .mk-comment-form-main:focus-within {
    border-color: var(--ring);
    box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 18%, transparent);
  }
  #site-comments .mk-comment-form-main .textarea {
    min-height: 4.5rem;
    padding: 0.25rem;
    border: 0;
    background: transparent;
    box-shadow: none;
    font: inherit;
    font-family: var(--comments-said);
  }
  #site-comments .mk-comment-form-main .textarea:focus-visible {
    outline: none;
    box-shadow: none;
  }
  #site-comments .mk-comment-form-hint {
    color: var(--muted-foreground);
    font-size: 0.8125rem;
  }
  /* the thread */
  #site-comments [data-comments-thread] {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  #site-comments .mk-comment-item {
    gap: 0.875rem;
    padding: 1rem;
    border-radius: var(--radius-xl);
    transition: background-color 0.3s;
  }
  #site-comments [data-comments-thread] > .mk-comment-item + .mk-comment-item {
    border-block-start: 1px solid var(--border);
    border-start-start-radius: 0;
    border-start-end-radius: 0;
  }
  #site-comments .mk-comment-item .avatar {
    width: 2.5rem;
    height: 2.5rem;
  }
  #site-comments .mk-comment-item-author {
    color: var(--foreground);
    font-weight: 700;
    text-decoration: none;
  }
  #site-comments .mk-comment-item-time {
    color: var(--muted-foreground);
    font-size: 0.8125rem;
    text-decoration: none;
  }
  #site-comments .mk-comment-item-time:hover {
    color: var(--primary);
    text-decoration: underline;
  }
  #site-comments .mk-comment-item-body {
    margin-block: 0.25rem 0.375rem;
    font-family: var(--comments-said);
    font-size: 1rem;
    line-height: 1.6;
  }
  #site-comments[data-look='paper'] .mk-comment-item-body {
    font-size: 1.0625rem;
  }
  #site-comments .mk-comment-item-actions .btn {
    color: var(--muted-foreground);
    font-weight: 600;
  }
  #site-comments .mk-comment-item-actions .btn:hover {
    color: var(--foreground);
  }
  #site-comments .mk-comment-item-replies {
    margin-inline-start: 1.25rem;
    padding-inline-start: 1.5rem;
    border-inline-start: 2px solid var(--border);
  }
  #site-comments .mk-comment-item-replies .mk-comment-item {
    padding-inline: 0.75rem;
  }
  /* the reply form opens under the comment it answers */
  #site-comments .mk-comment-item > .mk-comment-form {
    grid-column: 2;
    margin-block-start: 0.25rem;
  }
  /* the article's author: a badge in the accent */
  #site-comments .badge[data-i18n-target='author'] {
    height: 1.25rem;
    border: 0;
    background: var(--primary);
    color: var(--primary-foreground);
    font-size: 0.6875rem;
    font-weight: 800;
    letter-spacing: 0.04em;
  }
  /* a permalinked comment is lit, with a bar in the accent */
  #site-comments .mk-comment-item[data-highlighted] {
    background: var(--accent);
    box-shadow: inset 3px 0 0 var(--primary);
  }
  @media (prefers-reduced-motion: reduce) {
    #site-comments .mk-comment-item {
      transition: none;
    }
  }
  /* light or dark: the Swap writes the page's dark class - every look has a light and a dark palette */
  #site-comments .site-mode {
    flex: none;
    border: 1px solid var(--input);
    border-radius: var(--radius-md);
    background: var(--background);
    color: var(--foreground);
  }
  #site-comments .site-mode:hover {
    background: var(--accent);
    color: var(--accent-foreground);
  }
  /* -- modes: each look in light and dark, derived from the palettes above (the other mode of each look) -- */
  :root:not(.dark) #site-comments[data-look='thread'] {
    --accent: oklch(0.945 0.02 260);
    --accent-foreground: oklch(0.21 0.02 265);
  }
  .dark #site-comments[data-look='thread'] {
    --accent: oklch(0.27 0.04 272);
    --accent-foreground: oklch(0.94 0.006 265);
  }
  .dark #site-comments[data-look='night'] {
    --accent: oklch(0.29 0.03 190);
    --accent-foreground: oklch(0.94 0.008 220);
  }
  :root:not(.dark) #site-comments[data-look='night'] {
    color-scheme: light;
    --background: oklch(0.985 0.018 235);
    --foreground: oklch(0.2 0.008 220);
    --card: oklch(0.997 0.02 235);
    --card-foreground: oklch(0.2 0.008 220);
    --muted: oklch(0.95 0.02 235);
    --muted-foreground: oklch(0.46 0.016 225);
    --border: oklch(0.2 0.008 220 / 0.12);
    --input: oklch(0.2 0.008 220 / 0.12);
    --primary: oklch(0.53 0.11 180);
    --primary-foreground: oklch(0.985 0.005 180);
    --secondary: oklch(0.955 0.025 185);
    --secondary-foreground: oklch(0.25 0.03 180);
    --accent: oklch(0.94 0.025 190);
    --accent-foreground: oklch(0.2 0.008 220);
    --ring: oklch(0.55 0.11 180);
    --popover: oklch(0.997 0 0);
    --popover-foreground: oklch(0.2 0 0);
  }
  :root:not(.dark) #site-comments[data-look='paper'] {
    --accent: oklch(0.92 0.03 60);
    --accent-foreground: oklch(0.25 0.025 50);
  }
  .dark #site-comments[data-look='paper'] {
    color-scheme: dark;
    --background: oklch(0.17 0.014 82);
    --foreground: oklch(0.94 0.025 50);
    --card: oklch(0.205 0.01 82);
    --card-foreground: oklch(0.94 0.025 50);
    --muted: oklch(0.24 0.016 80);
    --muted-foreground: oklch(0.74 0.03 55);
    --border: oklch(0.95 0.02 50 / 0.14);
    --input: oklch(0.95 0.02 50 / 0.14);
    --primary: oklch(0.71 0.13 40);
    --primary-foreground: oklch(0.17 0.03 40);
    --secondary: oklch(0.25 0.03 55);
    --secondary-foreground: oklch(0.9 0.03 40);
    --accent: oklch(0.26 0.03 60);
    --accent-foreground: oklch(0.94 0.025 50);
    --ring: oklch(0.71 0.13 40);
    --popover: oklch(0.215 0 0);
    --popover-foreground: oklch(0.94 0 0);
  }
  /* -- modes: end -- */
</style>
<section id="site-comments" data-look="thread" data-i18n-component aria-labelledby="discussion-title">
  <div
    class="surface comments-grain comments-look-only"
    data-for="paper"
    data-variant="background"
    data-pattern="grain"
    aria-hidden="true"
  ></div>
  <header class="mk-header comments-bar">
    <div class="mk-header-inner">
      <a class="mk-header-brand comments-brand" href="#/" data-router-link>Acme <span>Engineering</span></a>
      <button
        type="button"
        class="btn mk-header-menu site-menu"
        data-variant="ghost"
        data-size="icon"
        data-sheet-trigger="comments-menu"
        aria-haspopup="dialog"
        aria-label="Open menu"
        data-i18n-aria-label-en="Open menu"
        data-i18n-aria-label-de="Menü öffnen"
        ><svg
          viewBox="0 0 24 24"
          width="20"
          height="20"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          aria-hidden="true"
        >
          <path d="M4 6h16M4 12h16M4 18h16" /></svg
      ></button>
      <nav
        class="mk-header-nav"
        aria-label="Discussion"
        data-i18n-aria-label-en="Discussion"
        data-i18n-aria-label-de="Diskussion"
      >
        <ul class="nav-menu-list">
          <li class="nav-menu-item"
            ><a
              class="nav-menu-link"
              href="full-website-article.html#/articles/offline-sync"
              data-i18n-target="nav-article"
              >The article</a
            ></li
          >
          <li class="nav-menu-item"
            ><button
              type="button"
              class="nav-menu-link"
              commandfor="comments-rules"
              command="show-modal"
              data-i18n-target="nav-rules"
              >Guidelines</button
            ></li
          >
        </ul>
      </nav>
      <div class="mk-header-actions comments-bar-controls">
        <select
          class="select"
          data-size="sm"
          data-site-look
          aria-label="Look"
          data-i18n-aria-label-en="Look"
          data-i18n-aria-label-de="Stil"
          style="width: auto"
        >
          <option value="thread" data-i18n-target="look-thread">Thread</option>
          <option value="night" data-i18n-target="look-night">Late night</option>
          <option value="paper" data-i18n-target="look-paper">Paper</option>
        </select>
        <div
          class="language-switcher"
          data-app-locale
          role="group"
          aria-label="Language"
          data-i18n-aria-label-en="Language"
          data-i18n-aria-label-de="Sprache"
          data-languages="en de"
          data-value="en"
          data-size="sm"
          data-display="code"
          data-flag-shape="circle"
          data-align="end"
        ></div>
        <label class="swap site-mode" data-variant="rotate" data-size="sm">
          <input
            type="checkbox"
            data-site-mode
            aria-label="Dark mode"
            data-i18n-aria-label-en="Dark mode"
            data-i18n-aria-label-de="Dunkler Modus"
          />
          <span class="swap-on" aria-hidden="true"><i data-lucide="moon"></i></span>
          <span class="swap-off" aria-hidden="true"><i data-lucide="sun"></i></span>
        </label>
      </div>
    </div>
    <!-- narrow: the navigation in a Sheet behind the menu button -->
    <dialog
      id="comments-menu"
      class="sheet"
      data-side="right"
      role="dialog"
      aria-modal="true"
      aria-labelledby="comments-menu-title"
    >
      <div class="sheet-content">
        <div class="sheet-header">
          <h2 class="sheet-title" id="comments-menu-title">Acme Engineering</h2>
        </div>
        <div class="sheet-body">
          <ul class="mk-header-sheet-nav">
            <li
              ><a href="full-website-article.html#/articles/offline-sync" data-sheet-close data-i18n-target="sh-article"
                >The article</a
              ></li
            >
            <li
              ><a href="#/" data-router-link data-sheet-close data-i18n-target="sh-thread">The whole discussion</a></li
            >
            <li><a href="mailto:community@acme.example" data-i18n-target="sh-write">Write to the moderators</a></li>
          </ul>
        </div>
        <div class="sheet-footer mk-header-sheet-actions">
          <button
            type="button"
            class="btn"
            data-variant="outline"
            data-sheet-close
            commandfor="comments-rules"
            command="show-modal"
            data-i18n-target="sh-rules"
            >Community guidelines</button
          >
        </div>
      </div>
      <button
        type="button"
        class="sheet-close-x"
        data-sheet-close
        aria-label="Close"
        data-i18n-aria-label-en="Close"
        data-i18n-aria-label-de="Schließen"
        ><svg
          width="15"
          height="15"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          aria-hidden="true"
        >
          <path d="M18 6 6 18M6 6l12 12" /></svg
      ></button>
    </dialog>
  </header>
  <p class="comments-context"
    ><span data-i18n-target="on">The discussion of</span>
    <a href="full-website-article.html#/articles/offline-sync">How offline sync works in Acme 4.0</a></p
  >
  <p class="comments-permalink" data-comments-permalink hidden
    ><span><span data-i18n-target="linked">A linked comment by</span> <b data-comments-permalink-author></b></span>
    <a href="#/" data-router-link data-i18n-target="show-all">Show the whole discussion</a></p
  >
  <header class="mk-comment-header">
    <h2 class="mk-comment-header-title" id="discussion-title"
      ><span data-i18n-target="title">Comments</span>
      <span class="badge" data-variant="secondary" data-comments-count>4</span></h2
    >
    <div class="mk-comment-header-actions">
      <label class="mk-comment-header-sort"
        ><span data-i18n-target="sort">Sort by</span>
        <select class="select" data-size="sm" name="sort" data-comments-sort>
          <option value="top" data-i18n-target="sort-top">Top</option>
          <option value="newest" data-i18n-target="sort-newest">Newest</option>
          <option value="oldest" data-i18n-target="sort-oldest">Oldest</option>
        </select>
      </label>
    </div>
  </header>
  <form
    class="mk-comment-form"
    aria-label="Add a comment"
    data-i18n-aria-label-en="Add a comment"
    data-i18n-aria-label-de="Einen Kommentar schreiben"
    data-comments-new
  >
    <span class="avatar"><img class="avatar-image" src="images/avatars/12-96.webp" alt="" /></span>
    <div class="mk-comment-form-main">
      <textarea
        class="textarea"
        name="comment"
        rows="2"
        required
        minlength="2"
        placeholder="Join the discussion..." data-i18n-placeholder-en="Join the discussion..." data-i18n-placeholder-de="Diskutiere mit..."
        aria-label="Comment" data-i18n-aria-label-en="Comment" data-i18n-aria-label-de="Kommentar"
      ></textarea>
      <div class="mk-comment-form-footer">
        <p class="mk-comment-form-hint" data-i18n-target="hint">Markdown works. Be kind.</p>
        <button type="submit" class="btn" data-i18n-target="post">Post comment</button>
      </div>
    </div>
  </form>
  <div data-comments-thread>
    <article class="mk-comment-item" id="d-1" data-likes="24">
      <span class="avatar"><img class="avatar-image" src="images/avatars/32-96.webp" alt="" /></span>
      <div class="mk-comment-item-main">
        <header class="mk-comment-item-head">
          <span class="mk-comment-item-author">Hannah Lee</span>
          <a class="mk-comment-item-time" href="#/comments/d-1" data-router-link
            ><time datetime="2026-10-01T08:12" data-i18n-target="time-d-1"
              ><span data-i18n-value="ago1">2 hours ago</span></time
            ></a
          >
        </header>
        <div class="mk-comment-item-body"
          ><p
            >The write-ahead log section finally made CRDTs click for me. Would love a follow-up on how you
            garbage-collect old operations.</p
          ></div
        >
        <footer class="mk-comment-item-actions">
          <button
            type="button"
            class="btn"
            data-variant="ghost"
            data-size="xs"
            aria-label="Like (24)"
            aria-pressed="false"
            data-i18n-aria-label-en="Like (24)"
            data-i18n-aria-label-de="Gefällt mir (24)"
            data-comment-like
            ><i data-lucide="thumbs-up"></i> <span data-like-count>24</span></button
          >
          <button type="button" class="btn" data-variant="ghost" data-size="xs" data-comment-reply
            ><i data-lucide="reply"></i> <span data-i18n-target="reply-1">Reply</span></button
          >
          <button
            type="button"
            class="btn"
            data-variant="ghost"
            data-size="xs"
            commandfor="comments-report"
            command="show-modal"
            data-comment-report
            ><i data-lucide="flag"></i> <span data-i18n-target="report-1">Report</span></button
          >
        </footer>
      </div>
      <ol class="mk-comment-item-replies">
        <li>
          <article class="mk-comment-item" id="d-2">
            <span class="avatar"><img class="avatar-image" src="images/avatars/47-96.webp" alt="" /></span>
            <div class="mk-comment-item-main">
              <header class="mk-comment-item-head">
                <span class="mk-comment-item-author">Sophie Tan</span
                ><span class="badge" data-variant="outline" data-i18n-target="author">Author</span>
                <a class="mk-comment-item-time" href="#/comments/d-2" data-router-link
                  ><time datetime="2026-10-01T09:03" data-i18n-target="time-d-2"
                    ><span data-i18n-value="ago2">1 hour ago</span></time
                  ></a
                >
              </header>
              <div class="mk-comment-item-body"
                ><p
                  >That is next on the list! Short version: we compact once every replica has acknowledged an
                  operation.</p
                ></div
              >
              <footer class="mk-comment-item-actions">
                <button
                  type="button"
                  class="btn"
                  data-variant="ghost"
                  data-size="xs"
                  aria-label="Like (11)"
                  aria-pressed="false"
                  data-i18n-aria-label-en="Like (11)"
                  data-i18n-aria-label-de="Gefällt mir (11)"
                  data-comment-like
                  ><i data-lucide="thumbs-up"></i> <span data-like-count>11</span></button
                >
                <button type="button" class="btn" data-variant="ghost" data-size="xs" data-comment-reply
                  ><i data-lucide="reply"></i> <span data-i18n-target="reply-2">Reply</span></button
                >
                <button
                  type="button"
                  class="btn"
                  data-variant="ghost"
                  data-size="xs"
                  commandfor="comments-report"
                  command="show-modal"
                  data-comment-report
                  ><i data-lucide="flag"></i> <span data-i18n-target="report-2">Report</span></button
                >
              </footer>
            </div>
          </article>
        </li>
        <li>
          <article class="mk-comment-item" id="d-3">
            <span class="avatar"><span class="avatar-fallback">AH</span></span>
            <div class="mk-comment-item-main">
              <header class="mk-comment-item-head">
                <span class="mk-comment-item-author">Aron Homberg</span>
                <a class="mk-comment-item-time" href="#/comments/d-3" data-router-link
                  ><time datetime="2026-10-01T09:30" data-i18n-target="time-d-3"
                    ><span data-i18n-value="ago3">40 minutes ago</span></time
                  ></a
                >
              </header>
              <div class="mk-comment-item-body"><p>Seconded - and how it plays with the 30-day branch rule.</p></div>
              <footer class="mk-comment-item-actions">
                <button
                  type="button"
                  class="btn"
                  data-variant="ghost"
                  data-size="xs"
                  aria-label="Like (3)"
                  aria-pressed="false"
                  data-i18n-aria-label-en="Like (3)"
                  data-i18n-aria-label-de="Gefällt mir (3)"
                  data-comment-like
                  ><i data-lucide="thumbs-up"></i> <span data-like-count>3</span></button
                >
                <button type="button" class="btn" data-variant="ghost" data-size="xs" data-comment-reply
                  ><i data-lucide="reply"></i> <span data-i18n-target="reply-3">Reply</span></button
                >
                <button
                  type="button"
                  class="btn"
                  data-variant="ghost"
                  data-size="xs"
                  commandfor="comments-report"
                  command="show-modal"
                  data-comment-report
                  ><i data-lucide="flag"></i> <span data-i18n-target="report-3">Report</span></button
                >
              </footer>
            </div>
          </article>
        </li>
      </ol>
    </article>
    <article class="mk-comment-item" id="d-4" data-likes="5">
      <span class="avatar"><img class="avatar-image" src="images/avatars/45-96.webp" alt="" /></span>
      <div class="mk-comment-item-main">
        <header class="mk-comment-item-head">
          <span class="mk-comment-item-author">Priya Natarajan</span>
          <a class="mk-comment-item-time" href="#/comments/d-4" data-router-link
            ><time datetime="2026-10-01T07:02" data-i18n-target="time-d-4"
              ><span data-i18n-value="ago4">3 hours ago</span></time
            ></a
          >
        </header>
        <div class="mk-comment-item-body"><p>Is the 30-day branch rule configurable per workspace?</p></div>
        <footer class="mk-comment-item-actions">
          <button
            type="button"
            class="btn"
            data-variant="ghost"
            data-size="xs"
            aria-label="Like (5)"
            aria-pressed="false"
            data-i18n-aria-label-en="Like (5)"
            data-i18n-aria-label-de="Gefällt mir (5)"
            data-comment-like
            ><i data-lucide="thumbs-up"></i> <span data-like-count>5</span></button
          >
          <button type="button" class="btn" data-variant="ghost" data-size="xs" data-comment-reply
            ><i data-lucide="reply"></i> <span data-i18n-target="reply-4">Reply</span></button
          >
          <button
            type="button"
            class="btn"
            data-variant="ghost"
            data-size="xs"
            commandfor="comments-report"
            command="show-modal"
            data-comment-report
            ><i data-lucide="flag"></i> <span data-i18n-target="report-4">Report</span></button
          >
        </footer>
      </div>
      <form
        class="mk-comment-form"
        data-variant="reply"
        aria-label="Reply to Priya Natarajan"
        data-i18n-aria-label-en="Reply to Priya Natarajan"
        data-i18n-aria-label-de="Priya Natarajan antworten"
        data-comments-reply="d-4"
      >
        <span class="avatar" data-size="sm"><img class="avatar-image" src="images/avatars/12-96.webp" alt="" /></span>
        <div class="mk-comment-form-main">
          <textarea
          class="textarea"
          name="reply"
          rows="1"
          required
          placeholder="Reply to Priya..." data-i18n-placeholder-en="Reply to Priya..." data-i18n-placeholder-de="Priya antworten..."
          aria-label="Reply to Priya Natarajan" data-i18n-aria-label-en="Reply to Priya Natarajan" data-i18n-aria-label-de="Priya Natarajan antworten"
        ></textarea>
          <div class="mk-comment-form-footer">
            <button type="reset" class="btn" data-variant="ghost" data-size="sm" data-i18n-target="cancel"
              >Cancel</button
            >
            <button type="submit" class="btn" data-size="sm" data-i18n-target="reply-submit">Reply</button>
          </div>
        </div>
      </form>
    </article>
  </div>
  <footer class="mk-footer comments-footer" data-variant="simple">
    <div class="mk-footer-inner">
      <a class="mk-footer-brand" href="#/" data-router-link>Acme <span>Engineering</span></a>
      <ul class="mk-footer-links">
        <li
          ><a href="full-website-article.html#/articles/offline-sync" data-i18n-target="ft-article"
            >Read the article</a
          ></li
        >
        <li
          ><button type="button" commandfor="comments-rules" command="show-modal" data-i18n-target="ft-rules"
            >Community guidelines</button
          ></li
        >
        <li><a href="mailto:community@acme.example" data-i18n-target="ft-write">Write to the moderators</a></li>
      </ul>
      <p class="mk-footer-copy" data-i18n-target="ft-copy">© 2026 Acme Inc. A demo discussion.</p>
    </div>
  </footer>
  <!-- Report and the guidelines: native dialogs, opened by commandfor; a demo - nothing leaves the page -->
  <dialog class="dialog comments-dialog" id="comments-report" aria-labelledby="comments-report-title">
    <form class="dialog-content" data-comments-report-form>
      <div class="dialog-header">
        <h2 class="dialog-title" id="comments-report-title" data-i18n-target="rp-title">Report this comment</h2>
        <p class="dialog-description" data-i18n-target="rp-desc"
          >A moderator reads every report within a day. Nobody learns who sent it.</p
        >
      </div>
      <div class="dialog-body">
        <fieldset class="comments-reasons">
          <legend class="sr-only" data-i18n-target="rp-reason">Reason</legend>
          <label class="comments-reason"
            ><input class="radio" type="radio" name="reason" value="spam" required />
            <span data-i18n-target="rp-spam">Spam or advertising</span></label
          >
          <label class="comments-reason"
            ><input class="radio" type="radio" name="reason" value="rude" />
            <span data-i18n-target="rp-rude">Rude or abusive</span></label
          >
          <label class="comments-reason"
            ><input class="radio" type="radio" name="reason" value="off-topic" />
            <span data-i18n-target="rp-topic">Off topic</span></label
          >
          <label class="comments-reason"
            ><input class="radio" type="radio" name="reason" value="other" />
            <span data-i18n-target="rp-other">Something else</span></label
          >
        </fieldset>
      </div>
      <div class="dialog-footer">
        <button
          type="button"
          class="btn"
          data-variant="outline"
          commandfor="comments-report"
          command="close"
          data-i18n-target="rp-cancel"
          >Cancel</button
        >
        <button type="submit" class="btn" data-variant="destructive" data-i18n-target="rp-go">Report</button>
      </div>
    </form>
    <div class="dialog-content" data-comments-report-done tabindex="-1" hidden>
      <div class="dialog-header">
        <h2 class="dialog-title" data-i18n-target="rp-done">Thank you</h2>
        <p class="dialog-description" data-i18n-target="rp-done-text"
          >A moderator will look at the comment today. You will not see a report button on it again.</p
        >
      </div>
      <div class="dialog-footer">
        <button type="button" class="btn" commandfor="comments-report" command="close" data-i18n-target="rp-close"
          >Close</button
        >
      </div>
    </div>
  </dialog>
  <dialog class="dialog comments-dialog" id="comments-rules" aria-labelledby="comments-rules-title">
    <div class="dialog-content">
      <div class="dialog-header">
        <h2 class="dialog-title" id="comments-rules-title" data-i18n-target="rules-title">Community guidelines</h2>
      </div>
      <div class="dialog-body">
        <ol class="comments-rules">
          <li data-i18n-target="rule-1">Be kind. Argue with ideas, never with people.</li>
          <li data-i18n-target="rule-2">Stay on the article - its subject is the discussion's.</li>
          <li data-i18n-target="rule-3">No advertising and no links someone pays you for.</li>
          <li data-i18n-target="rule-4">Report what breaks these rules; a moderator decides within a day.</li>
        </ol>
      </div>
      <div class="dialog-footer">
        <button type="button" class="btn" commandfor="comments-rules" command="close" data-i18n-target="rules-close"
          >Close</button
        >
      </div>
    </div>
  </dialog>
  <!-- what the script writes into a new comment, in English and German (re-written on a language change) -->
  <script type="application/json" id="comments-ui">
    {
      "en": {
        "you": "You",
        "byYou": "you",
        "like": "Like ({n})",
        "replyTo": "Reply to {name}",
        "replyHint": "Reply to {first}..."
      },
      "de": {
        "you": "Du",
        "byYou": "dir",
        "like": "Gefällt mir ({n})",
        "replyTo": "{name} antworten",
        "replyHint": "{first} antworten..."
      }
    }
  </script>
  <!-- the translations: one template per target and language (defuss-i18n) -->
  <template data-i18n-for="look-thread" data-i18n-locale="en">Thread</template>
  <template data-i18n-for="look-thread" data-i18n-locale="de">Thread</template>
  <template data-i18n-for="look-night" data-i18n-locale="en">Late night</template>
  <template data-i18n-for="look-night" data-i18n-locale="de">Spät nachts</template>
  <template data-i18n-for="look-paper" data-i18n-locale="en">Paper</template>
  <template data-i18n-for="on" data-i18n-locale="en">The discussion of</template>
  <template data-i18n-for="on" data-i18n-locale="de">Die Diskussion zu</template>
  <template data-i18n-for="look-paper" data-i18n-locale="de">Papier</template>
  <template data-i18n-for="title" data-i18n-locale="en">Comments</template>
  <template data-i18n-for="title" data-i18n-locale="de">Kommentare</template>
  <template data-i18n-for="sort" data-i18n-locale="en">Sort by</template>
  <template data-i18n-for="sort" data-i18n-locale="de">Sortieren nach</template>
  <template data-i18n-for="sort-top" data-i18n-locale="en">Top</template>
  <template data-i18n-for="sort-top" data-i18n-locale="de">Beliebteste</template>
  <template data-i18n-for="sort-newest" data-i18n-locale="en">Newest</template>
  <template data-i18n-for="sort-newest" data-i18n-locale="de">Neueste</template>
  <template data-i18n-for="sort-oldest" data-i18n-locale="en">Oldest</template>
  <template data-i18n-for="sort-oldest" data-i18n-locale="de">Älteste</template>
  <template data-i18n-for="hint" data-i18n-locale="en">Markdown works. Be kind.</template>
  <template data-i18n-for="hint" data-i18n-locale="de">Markdown funktioniert. Sei freundlich.</template>
  <template data-i18n-for="post" data-i18n-locale="en">Post comment</template>
  <template data-i18n-for="post" data-i18n-locale="de">Kommentar senden</template>
  <template data-i18n-for="author" data-i18n-locale="en">Author</template>
  <template data-i18n-for="author" data-i18n-locale="de">Autorin</template>
  <template data-i18n-for="reply-1" data-i18n-locale="en">Reply</template>
  <template data-i18n-for="reply-1" data-i18n-locale="de">Antworten</template>
  <template data-i18n-for="reply-2" data-i18n-locale="en">Reply</template>
  <template data-i18n-for="reply-2" data-i18n-locale="de">Antworten</template>
  <template data-i18n-for="reply-3" data-i18n-locale="en">Reply</template>
  <template data-i18n-for="reply-3" data-i18n-locale="de">Antworten</template>
  <template data-i18n-for="reply-4" data-i18n-locale="en">Reply</template>
  <template data-i18n-for="reply-4" data-i18n-locale="de">Antworten</template>
  <template data-i18n-for="time-d-1" data-i18n-locale="en"><span data-i18n-value="ago1"></span></template>
  <template data-i18n-for="time-d-1" data-i18n-locale="de"><span data-i18n-value="ago1"></span></template>
  <template data-i18n-for="time-d-2" data-i18n-locale="en"><span data-i18n-value="ago2"></span></template>
  <template data-i18n-for="time-d-2" data-i18n-locale="de"><span data-i18n-value="ago2"></span></template>
  <template data-i18n-for="time-d-3" data-i18n-locale="en"><span data-i18n-value="ago3"></span></template>
  <template data-i18n-for="time-d-3" data-i18n-locale="de"><span data-i18n-value="ago3"></span></template>
  <template data-i18n-for="time-d-4" data-i18n-locale="en"><span data-i18n-value="ago4"></span></template>
  <template data-i18n-for="time-d-4" data-i18n-locale="de"><span data-i18n-value="ago4"></span></template>
  <template data-i18n-for="cancel" data-i18n-locale="en">Cancel</template>
  <template data-i18n-for="cancel" data-i18n-locale="de">Abbrechen</template>
  <template data-i18n-for="reply-submit" data-i18n-locale="en">Reply</template>
  <template data-i18n-for="reply-submit" data-i18n-locale="de">Antworten</template>
  <template data-i18n-for="report-1" data-i18n-locale="en">Report</template>
  <template data-i18n-for="report-1" data-i18n-locale="de">Melden</template>
  <template data-i18n-for="report-2" data-i18n-locale="en">Report</template>
  <template data-i18n-for="report-2" data-i18n-locale="de">Melden</template>
  <template data-i18n-for="report-3" data-i18n-locale="en">Report</template>
  <template data-i18n-for="report-3" data-i18n-locale="de">Melden</template>
  <template data-i18n-for="report-4" data-i18n-locale="en">Report</template>
  <template data-i18n-for="report-4" data-i18n-locale="de">Melden</template>
  <template data-i18n-for="nav-article" data-i18n-locale="en">The article</template>
  <template data-i18n-for="nav-article" data-i18n-locale="de">Der Artikel</template>
  <template data-i18n-for="nav-rules" data-i18n-locale="en">Guidelines</template>
  <template data-i18n-for="nav-rules" data-i18n-locale="de">Regeln</template>
  <template data-i18n-for="linked" data-i18n-locale="en">A linked comment by</template>
  <template data-i18n-for="linked" data-i18n-locale="de">Ein verlinkter Kommentar von</template>
  <template data-i18n-for="show-all" data-i18n-locale="en">Show the whole discussion</template>
  <template data-i18n-for="show-all" data-i18n-locale="de">Die ganze Diskussion zeigen</template>
  <template data-i18n-for="ft-article" data-i18n-locale="en">Read the article</template>
  <template data-i18n-for="ft-article" data-i18n-locale="de">Den Artikel lesen</template>
  <template data-i18n-for="ft-rules" data-i18n-locale="en">Community guidelines</template>
  <template data-i18n-for="ft-rules" data-i18n-locale="de">Regeln für die Diskussion</template>
  <template data-i18n-for="ft-write" data-i18n-locale="en">Write to the moderators</template>
  <template data-i18n-for="ft-write" data-i18n-locale="de">Der Moderation schreiben</template>
  <template data-i18n-for="ft-copy" data-i18n-locale="en">© 2026 Acme Inc. A demo discussion.</template>
  <template data-i18n-for="ft-copy" data-i18n-locale="de">© 2026 Acme Inc. Eine Demo-Diskussion.</template>
  <template data-i18n-for="rp-title" data-i18n-locale="en">Report this comment</template>
  <template data-i18n-for="rp-title" data-i18n-locale="de">Diesen Kommentar melden</template>
  <template data-i18n-for="rp-desc" data-i18n-locale="en"
    >A moderator reads every report within a day. Nobody learns who sent it.</template
  >
  <template data-i18n-for="rp-desc" data-i18n-locale="de"
    >Die Moderation liest jede Meldung innerhalb eines Tages. Niemand erfährt, wer sie geschickt hat.</template
  >
  <template data-i18n-for="rp-reason" data-i18n-locale="en">Reason</template>
  <template data-i18n-for="rp-reason" data-i18n-locale="de">Grund</template>
  <template data-i18n-for="rp-spam" data-i18n-locale="en">Spam or advertising</template>
  <template data-i18n-for="rp-spam" data-i18n-locale="de">Spam oder Werbung</template>
  <template data-i18n-for="rp-rude" data-i18n-locale="en">Rude or abusive</template>
  <template data-i18n-for="rp-rude" data-i18n-locale="de">Unhöflich oder beleidigend</template>
  <template data-i18n-for="rp-topic" data-i18n-locale="en">Off topic</template>
  <template data-i18n-for="rp-topic" data-i18n-locale="de">Am Thema vorbei</template>
  <template data-i18n-for="rp-other" data-i18n-locale="en">Something else</template>
  <template data-i18n-for="rp-other" data-i18n-locale="de">Etwas anderes</template>
  <template data-i18n-for="rp-cancel" data-i18n-locale="en">Cancel</template>
  <template data-i18n-for="rp-cancel" data-i18n-locale="de">Abbrechen</template>
  <template data-i18n-for="rp-go" data-i18n-locale="en">Report</template>
  <template data-i18n-for="rp-go" data-i18n-locale="de">Melden</template>
  <template data-i18n-for="rp-done" data-i18n-locale="en">Thank you</template>
  <template data-i18n-for="rp-done" data-i18n-locale="de">Danke</template>
  <template data-i18n-for="rp-done-text" data-i18n-locale="en"
    >A moderator will look at the comment today. You will not see a report button on it again.</template
  >
  <template data-i18n-for="rp-done-text" data-i18n-locale="de"
    >Die Moderation sieht sich den Kommentar noch heute an. Du kannst ihn kein zweites Mal melden.</template
  >
  <template data-i18n-for="rp-close" data-i18n-locale="en">Close</template>
  <template data-i18n-for="rp-close" data-i18n-locale="de">Schließen</template>
  <template data-i18n-for="rules-title" data-i18n-locale="en">Community guidelines</template>
  <template data-i18n-for="rules-title" data-i18n-locale="de">Regeln für die Diskussion</template>
  <template data-i18n-for="rule-1" data-i18n-locale="en">Be kind. Argue with ideas, never with people.</template>
  <template data-i18n-for="rule-1" data-i18n-locale="de">Sei freundlich. Streite mit Ideen, nie mit Menschen.</template>
  <template data-i18n-for="rule-2" data-i18n-locale="en"
    >Stay on the article - its subject is the discussion's.</template
  >
  <template data-i18n-for="rule-2" data-i18n-locale="de"
    >Bleib beim Artikel - sein Thema ist das der Diskussion.</template
  >
  <template data-i18n-for="rule-3" data-i18n-locale="en">No advertising and no links someone pays you for.</template>
  <template data-i18n-for="rule-3" data-i18n-locale="de"
    >Keine Werbung und keine Links, für die dich jemand bezahlt.</template
  >
  <template data-i18n-for="rule-4" data-i18n-locale="en"
    >Report what breaks these rules; a moderator decides within a day.</template
  >
  <template data-i18n-for="rule-4" data-i18n-locale="de"
    >Melde, was gegen diese Regeln verstößt; die Moderation entscheidet innerhalb eines Tages.</template
  >
  <template data-i18n-for="rules-close" data-i18n-locale="en">Close</template>
  <template data-i18n-for="rules-close" data-i18n-locale="de">Schließen</template>
  <template data-i18n-for="sh-article" data-i18n-locale="en">The article</template>
  <template data-i18n-for="sh-article" data-i18n-locale="de">Der Artikel</template>
  <template data-i18n-for="sh-thread" data-i18n-locale="en">The whole discussion</template>
  <template data-i18n-for="sh-thread" data-i18n-locale="de">Die ganze Diskussion</template>
  <template data-i18n-for="sh-write" data-i18n-locale="en">Write to the moderators</template>
  <template data-i18n-for="sh-write" data-i18n-locale="de">Der Moderation schreiben</template>
  <template data-i18n-for="sh-rules" data-i18n-locale="en">Community guidelines</template>
  <template data-i18n-for="sh-rules" data-i18n-locale="de">Regeln für die Diskussion</template>
</section>
<script type="module">
  // routing and translation: defuss-dom-router owns the address, defuss-i18n the language
  import { createRouter } from 'https://cdn.jsdelivr.net/npm/defuss-dom-router@0.1.1/dist/index.js';
  import { createDomI18n, createI18n } from 'https://cdn.jsdelivr.net/npm/defuss-i18n@0.2.0/dist/core.js';

  // df$ comes with the component bundle - a full-screen page loads it after this module
  addEventListener('DOMContentLoaded', async () => {
    // light or dark: the switch writes the page's dark class (every look has both palettes); it follows the class when
    // something else sets it (the docs card follows the site's mode)
    const siteMode = df$('#site-comments [data-site-mode]');
    const syncMode = () => siteMode.prop('checked', document.documentElement.classList.contains('dark'));
    siteMode.on('change', () => {
      document.documentElement.classList.toggle('dark', siteMode.prop('checked'));
      document.dispatchEvent(new CustomEvent('defuss-theme-change'));
    });
    new MutationObserver(syncMode).observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
    syncMode();

    const site = df$('#site-comments').get(0);

    // -- translation: the markup is the catalog (the templates at the end of the page)
    const locale = createI18n({
      locale: 'en', // the demos start in English; the language select offers German
    });
    createDomI18n(df$).bind(site, locale, {
      values: () => ({
        // how long ago, from the page's "now" - Intl.RelativeTimeFormat in the language
        ...Object.fromEntries(
          [
            ['ago1', -2, 'hour'],
            ['ago2', -1, 'hour'],
            ['ago3', -40, 'minute'],
            ['ago4', -3, 'hour'],
          ].map(([key, n, unit]) => [
            key,
            new Intl.RelativeTimeFormat(locale.locale, { numeric: 'auto' }).format(n, unit),
          ]),
        ),
      }),
    });
    // the Language Switcher sets the locale on a pick and follows it when something else sets it
    df$.shadcn.languageSwitcher.bind(df$('[data-app-locale]').get(0), locale);

    // -- what the script writes (a like's label, a reply's prompt, a new comment) comes from #comments-ui in both
    // languages: an attribute gets its data-i18n-{attr}-{lang} variants, a text its data-ui key - re-written on a change
    const UI = JSON.parse(df$('#comments-ui').text());
    const say = (lang, key, vars = {}) => UI[lang][key].replace(/\{(\w+)\}/g, (_m, name) => vars[name]);
    const langs = Object.keys(UI);
    const label = (el, attr, key, vars) => {
      for (const lang of langs) df$(el).attr(`data-i18n-${attr}-${lang}`, say(lang, key, vars));
      df$(el).attr(attr, say(locale.locale, key, vars));
    };
    const now = (lang) => new Intl.RelativeTimeFormat(lang, { numeric: 'auto' }).format(0, 'second');
    const thread = df$('[data-comments-thread]');
    const authorOf = (item) => df$(item).find('.mk-comment-item-author').first().text().trim();
    const count = () => df$('[data-comments-count]').text(String([...thread.find('.mk-comment-item')].length));

    // like: a toggle (aria-pressed) that counts; a top-level comment's data-likes orders the "Top" sort
    const likeLabel = (button) =>
      label(button, 'aria-label', 'like', { n: df$(button).find('[data-like-count]').text() });
    const like = (button) => {
      const on = df$(button).attr('aria-pressed') !== 'true';
      const shown = df$(button).find('[data-like-count]');
      const n = Number(shown.text()) + (on ? 1 : -1);
      df$(button).attr('aria-pressed', String(on));
      shown.text(String(n));
      const item = df$(button).closest('.mk-comment-item');
      if (item.attr('data-likes') != null) item.attr('data-likes', String(n));
      likeLabel(button);
    };

    // reply: one reply form, moved under the comment it answers; a reply to a reply joins the same thread line
    const replyForm = df$('[data-comments-reply]');
    const replyField = replyForm.find('textarea');
    let answering = df$('#d-4').get(0);
    const replyLabels = () => {
      const name = authorOf(answering);
      label(replyForm.get(0), 'aria-label', 'replyTo', { name });
      label(replyField.get(0), 'aria-label', 'replyTo', { name });
      label(replyField.get(0), 'placeholder', 'replyHint', { first: name.split(' ')[0] });
    };
    const replyTo = (item) => {
      answering = item;
      replyForm.attr('data-comments-reply', item.id).prop('hidden', false);
      df$(item).append(replyForm.get(0));
      replyLabels();
      replyField.get(0).focus();
    };
    replyForm.on('reset', () => replyForm.prop('hidden', true));

    // a new comment takes the shape of an authored one (its drawn icons included) without its translation targets:
    // the writer's name, "now" and the text, a like button - no reply to or report of oneself
    let made = [...thread.find('.mk-comment-item')].length;
    const comment = (text, top) => {
      const el = df$('#d-4').get(0).cloneNode(true);
      const c = df$(el);
      c.children('ol, form').each((_i, part) => {
        part.remove();
      });
      c.find('[data-comment-reply], [data-comment-report]').each((_i, button) => {
        button.remove();
      });
      c.find('[data-i18n-target]').each((_i, part) => {
        part.removeAttribute('data-i18n-target');
      });
      made += 1;
      c.attr('id', 'd-' + made)
        .attr('data-highlighted', null)
        .attr('data-likes', top ? '0' : null);
      c.find('.avatar-image').attr('src', df$('[data-comments-new] .avatar-image').attr('src'));
      c.find('.mk-comment-item-author').attr('data-ui', 'you').text(say(locale.locale, 'you'));
      c.find('.mk-comment-item-time').attr('href', '#/comments/d-' + made);
      c.find('time').attr('datetime', '2026-10-01T10:12').attr('data-ui-now', '').text(now(locale.locale));
      const body = c.find('.mk-comment-item-body');
      body.html('');
      for (const paragraph of text.split(/\n\s*\n/)) body.append(df$('<p></p>').text(paragraph.trim()).get(0));
      const button = c.find('[data-comment-like]').attr('aria-pressed', 'false');
      button.find('[data-like-count]').text('0');
      likeLabel(button.get(0));
      return el;
    };
    df$('[data-comments-new]').on('submit', (event) => {
      event.preventDefault();
      const form = event.currentTarget;
      const text = df$(form).find('textarea').val().trim();
      if (!text) return;
      thread.prepend(comment(text, true));
      form.reset();
      count();
    });
    replyForm.on('submit', (event) => {
      event.preventDefault();
      const text = replyField.val().trim();
      if (!text) return;
      const top = df$(answering).parent().closest('.mk-comment-item').get(0) ?? answering;
      let list = df$(top).children('.mk-comment-item-replies');
      if (!list.get(0)) {
        list = df$('<ol class="mk-comment-item-replies"></ol>');
        df$(top).children('.mk-comment-item-main').after(list.get(0));
      }
      const entry = df$('<li></li>');
      entry.append(comment(text, false));
      list.append(entry.get(0));
      replyForm.get(0).reset();
      count();
    });

    // report: the button opens the dialog (commandfor); a sent report hides that comment's report button
    const reportForm = df$('[data-comments-report-form]');
    const reportDone = df$('[data-comments-report-done]');
    let reporting = null;
    reportForm.on('submit', (event) => {
      event.preventDefault();
      reportForm.prop('hidden', true);
      reportDone.prop('hidden', false);
      if (reporting) df$(reporting).prop('hidden', true);
      reportDone.find('.btn').get(0).focus();
    });
    df$('#comments-report').on('close', () => {
      reportForm.get(0).reset();
      reportForm.prop('hidden', false);
      reportDone.prop('hidden', true);
    });

    thread.on('click', (event) => {
      const hit = (selector) => df$(event.target).closest(selector).get(0);
      const liked = hit('[data-comment-like]');
      if (liked) like(liked);
      const reply = hit('[data-comment-reply]');
      if (reply) replyTo(df$(reply).closest('.mk-comment-item').get(0));
      const report = hit('[data-comment-report]');
      if (report) reporting = report;
    });

    // a linked comment names its author above the thread ("you" for one's own)
    let linked = null;
    const notice = () => {
      df$('[data-comments-permalink]').prop('hidden', !linked);
      if (!linked) return;
      const own = df$(linked).find('.mk-comment-item-author').first().attr('data-ui') === 'you';
      df$('[data-comments-permalink-author]').text(own ? say(locale.locale, 'byYou') : authorOf(linked));
    };
    // a language change re-writes what the script wrote
    locale.subscribe(() => {
      const lang = locale.locale;
      df$('#site-comments [data-ui]').each((_i, el) => {
        df$(el).text(say(lang, el.dataset.ui));
      });
      df$('#site-comments [data-ui-now]').each((_i, el) => {
        df$(el).text(now(lang));
      });
      df$('#site-comments [data-comment-like]').each((_i, el) => {
        likeLabel(el);
      });
      replyLabels();
      notice();
    });

    // -- the look: one of the site's designs. An element with data-look-set takes that look's attributes (a shader's
    // effect, colors or contrast); a shader reads its colors again on defuss-theme-change
    const lookRoot = df$('#site-comments').get(0);
    const look = df$('#site-comments [data-site-look]');
    const applyLook = (name) => {
      lookRoot.dataset.look = name;
      df$('#site-comments [data-look-set]').each((_i, el) => {
        const sets = JSON.parse(el.dataset.lookSet);
        for (const [attr, value] of Object.entries({ ...sets.default, ...sets[name] })) el.setAttribute(attr, value);
      });
      document.dispatchEvent(new CustomEvent('defuss-theme-change'));
    };
    look.val(lookRoot.dataset.look).on('change', () => applyLook(look.val()));

    // -- routing
    const routes = [
      { id: 'thread', path: '/' },
      { id: 'comment', path: '/comments/:id' },
      { id: 'missing', path: '*' },
    ];
    // ?sort= orders the thread (top: likes, newest / oldest: time); a permalink highlights its comment
    let shownPath = null;
    const show = (to) => {
      const sort = new URLSearchParams(to.search).get('sort') ?? 'top';
      df$('[data-comments-sort]').val(sort);
      const items = [...thread.children('.mk-comment-item')];
      const at = (c) => Date.parse(c.querySelector('time').getAttribute('datetime'));
      items.sort((a, b) =>
        sort === 'top' ? b.dataset.likes - a.dataset.likes : sort === 'newest' ? at(b) - at(a) : at(a) - at(b),
      );
      // moved to the front in reverse, so they read in order; the reply form stays last
      for (const item of items.reverse()) thread.prepend(item);
      linked = null;
      df$('#site-comments .mk-comment-item').each((_i, c) => {
        const on = to.routeId === 'comment' && c.id === to.params.id;
        c.toggleAttribute('data-highlighted', on);
        if (on) linked = c;
      });
      notice();
      // a link to a comment brings it into view - the first view stays where the reader is
      if (linked && shownPath !== null && shownPath !== to.path)
        linked.scrollIntoView({ block: 'center', behavior: 'instant' });
      shownPath = to.path;
    };
    // the sort select navigates: the order is part of the address
    df$('[data-comments-sort]').on('change', (event) => {
      const href = '#/?sort=' + event.currentTarget.value;
      if (router.getSnapshot().current) router.navigate(href);
      else location.hash = href.slice(1);
    });
    const router = createRouter({ mode: 'hash', routes, prepare: ({ to }) => ({ commit: () => show(to) }) });
    router.attachLinks(site);
    if ((await router.start()).status === 'rejected') {
      // no address the router may own - a docs preview is an about:srcdoc frame: the same routes match its hash
      const preview = createRouter({ mode: 'hash', routes, baseUrl: 'https://preview.invalid/' });
      const follow = () => show(preview.resolve(location.hash.startsWith('#/') ? location.hash : '#/'));
      addEventListener('hashchange', follow);
      follow();
    }
  });
</script>
```

<h2 id="blocks" class="h2-display">The blocks</h2>

<div class="grid gap-4 mb-8" style="grid-template-columns:repeat(auto-fill,minmax(16rem,1fr))">
  <a class="card" data-size="sm" href="comment-header.html" style="text-decoration:none;color:inherit">
    <div class="card-header">
      <h3 class="card-title card-title-sm">Comment Header</h3>
      <p class="card-description">Introduces a discussion with its comment count and sorting options - a native Select, or sort links in a segmented row.</p>
    </div>
  </a>
  <a class="card" data-size="sm" href="comment-item.html" style="text-decoration:none;color:inherit">
    <div class="card-header">
      <h3 class="card-title card-title-sm">Comment Item</h3>
      <p class="card-description">Displays one comment with its author, timestamp, and reply action - nested replies on a thread line, permalinks that highlight, compact and deleted states.</p>
    </div>
  </a>
  <a class="card" data-size="sm" href="comment-form.html" style="text-decoration:none;color:inherit">
    <div class="card-header">
      <h3 class="card-title card-title-sm">Comment Form</h3>
      <p class="card-description">Collects a new comment or reply - a growing Textarea beside the avatar, guest name and email fields, native validation, a compact reply form.</p>
    </div>
  </a>
</div>

</DocPage>
