  :root{
    --bg: #0A0A0A;
    --text: #F5F5F0;
    --accent: #6EE7C8;
    --panel: #141414;
    --border: #2A2A2A;
    --muted: #9A9A94;
    --font-size: 19px;
    --line-height: 1.65;
    --measure: 68ch;
    --letter-spacing: 0.005em;
    --font-stack: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --content-font: -apple-system, "Segoe UI", "Atkinson Hyperlegible", Roboto, Helvetica, Arial, sans-serif;
  }

  * { box-sizing: border-box; }

  html, body {
    margin: 0;
    padding: 0;
    background: transparent;
    color: var(--text);
    font-family: var(--font-stack);
    min-height: 100vh;
  }

  body { display: flex; flex-direction: column; min-height: 100vh; position: relative; }

  #bgCanvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
  }

  /* ---------- Top bar ---------- */
  header {
    position: relative; z-index: 2;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--panel);
    flex-wrap: wrap;
  }

  .brand { display: flex; align-items: baseline; gap: 10px; }
  .brand-mark { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; }
  .brand h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: 0.01em; }
  .brand span.tag { color: var(--muted); font-size: 13px; }

  .header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

  .modes {
    display: flex; gap: 6px; background: var(--bg); border: 1px solid var(--border);
    border-radius: 10px; padding: 4px;
  }
  .mode-btn {
    appearance: none; border: none; background: transparent; color: var(--muted);
    font-family: inherit; font-size: 14px; font-weight: 600; padding: 8px 14px;
    border-radius: 7px; cursor: pointer; transition: background 0.15s ease, color 0.15s ease;
  }
  .mode-btn.active { background: var(--accent); color: #06110D; }
  .mode-btn:hover:not(.active) { color: var(--text); }
  .mode-btn:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

  .contrast-badge {
    display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600;
    padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border);
    background: var(--bg); white-space: nowrap;
  }
  .contrast-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

  .icon-btn {
    appearance: none; border: 1px solid var(--border); background: var(--bg); color: var(--text);
    font-family: inherit; font-size: 13px; font-weight: 700; width: 32px; height: 32px;
    border-radius: 8px; cursor: pointer; display:flex; align-items:center; justify-content:center;
  }
  .icon-btn:hover { border-color: var(--accent); }

  /* ---------- Layout ---------- */
  main { position: relative; z-index: 1; flex: 1; display: flex; gap: 0; min-height: 0; }

  .editor-col { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }

  .editor-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 24px 0; flex-wrap: wrap; gap: 10px; position: relative; z-index: 2;
  }

  .doc-title-input {
    background: transparent; border: none; color: var(--muted); font-family: inherit;
    font-size: 13px; font-weight: 600; padding: 4px 0; max-width: 320px;
  }
  .doc-title-input:focus { color: var(--text); outline: none; }

  .toggle-pair {
    display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--border);
    border-radius: 8px; padding: 3px;
  }
  .toggle-pair button {
    appearance: none; border: none; background: transparent; color: var(--muted);
    font-family: inherit; font-size: 12.5px; font-weight: 600; padding: 6px 11px;
    border-radius: 6px; cursor: pointer;
  }
  .toggle-pair button.active { background: var(--accent); color: #06110D; }

  .editor-wrap {
    flex: 1; display: flex; justify-content: center; padding: 20px 24px 24px;
    overflow-y: auto; min-height: 0;
  }

  #editor, #preview {
    width: 100%;
    max-width: var(--measure);
    min-height: 55vh;
    font-size: var(--font-size);
    line-height: var(--line-height);
    letter-spacing: var(--letter-spacing);
    font-family: var(--content-font);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 30px 36px;
  }

  #editor {
    color: var(--text);
    resize: none;
    outline: none;
    white-space: pre-wrap;
    word-wrap: break-word;
    caret-color: var(--accent);
  }
  #editor::placeholder { color: var(--muted); }

  #preview { display: none; }
  #preview h1, #preview h2, #preview h3 { line-height: 1.3; margin: 1.1em 0 0.4em; }
  #preview h1 { font-size: 1.6em; }
  #preview h2 { font-size: 1.35em; }
  #preview h3 { font-size: 1.15em; }
  #preview p { margin: 0.7em 0; }
  #preview ul, #preview ol { margin: 0.6em 0; padding-left: 1.4em; }
  #preview li { margin: 0.25em 0; }
  #preview blockquote { margin: 0.8em 0; padding: 4px 16px; border-left: 3px solid var(--accent); color: var(--muted); }
  #preview code { background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 0.9em; }
  #preview pre { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; overflow-x: auto; }
  #preview pre code { border: none; background: none; padding: 0; }
  #preview a { color: var(--accent); }
  #preview hr { border: none; border-top: 1px solid var(--border); margin: 1.4em 0; }

  #printArea { display: none; }

  /* ---------- Side panel ---------- */
  aside {
    position: relative; z-index: 2;
    width: 300px; flex: none; border-left: 1px solid var(--border); background: var(--panel);
    padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 20px;
  }

  .control-group h2 {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
    margin: 0 0 10px; font-weight: 700;
  }

  .slider-row { margin-bottom: 14px; }
  .slider-row:last-child { margin-bottom: 0; }
  .slider-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
  .slider-label span.val { color: var(--muted); font-variant-numeric: tabular-nums; }
  input[type="range"] { width: 100%; accent-color: var(--accent); height: 18px; cursor: pointer; }

  .btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
  .btn {
    appearance: none; border: 1px solid var(--border); background: var(--bg); color: var(--text);
    font-family: inherit; font-size: 13px; font-weight: 600; padding: 9px 12px; border-radius: 8px;
    cursor: pointer; flex: 1; transition: border-color 0.15s ease;
  }
  .btn:hover { border-color: var(--accent); }
  .btn.primary { background: var(--accent); color: #06110D; border-color: var(--accent); }
  .btn.primary:hover { filter: brightness(1.08); }

  .meta { font-size: 12px; color: var(--muted); line-height: 1.5; }
  .divider { height: 1px; background: var(--border); border: none; margin: 0; }

  .doc-list { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; }
  .doc-item {
    display: flex; align-items: center; gap: 8px; padding: 8px 9px; border-radius: 8px;
    border: 1px solid var(--border); cursor: pointer; background: var(--bg);
  }
  .doc-item:hover { border-color: var(--accent); }
  .doc-item.active { border-color: var(--accent); }
  .doc-item-text { flex: 1; min-width: 0; }
  .doc-item-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .doc-item-date { font-size: 11px; color: var(--muted); }
  .doc-item-del { appearance: none; border: none; background: transparent; color: var(--muted); font-size: 15px; cursor: pointer; padding: 2px 6px; border-radius: 5px; flex: none; }
  .doc-item-del:hover { color: #FF6B5E; background: rgba(255,107,94,0.1); }
  .empty-note { font-size: 12px; color: var(--muted); font-style: italic; padding: 4px 0; }

  .swatch-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .swatch-btn {
    appearance: none; border: 1px solid var(--border); background: var(--bg); color: var(--muted);
    font-family: inherit; font-size: 11.5px; font-weight: 600; padding: 10px 4px; border-radius: 8px;
    cursor: pointer; text-align: center;
  }
  .swatch-btn.active { border-color: var(--accent); color: var(--accent); }
  .swatch-btn:hover { border-color: var(--accent); }
  .swatch-dot { display: block; width: 16px; height: 16px; margin: 0 auto 5px; border-radius: 50%; }

  /* ---------- Shortcuts modal ---------- */
  .modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 10;
    align-items: center; justify-content: center;
  }
  .modal-overlay.open { display: flex; }
  .modal-box {
    background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
    padding: 26px 28px; width: 360px; max-width: 90vw; color: var(--text);
    max-height: 80vh; overflow-y: auto;
  }
  .modal-box h3 { margin: 0 0 14px; font-size: 16px; }
  .shortcut-row { display: flex; justify-content: space-between; font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--border); }
  .shortcut-row:last-child { border-bottom: none; }
  kbd {
    background: var(--bg); border: 1px solid var(--border); border-radius: 5px;
    padding: 2px 7px; font-family: inherit; font-size: 12px; color: var(--muted);
  }
  .modal-close { margin-top: 16px; width: 100%; }

  select { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-family: inherit; font-size: 13px; }

  @media (max-width: 760px) {
    main { flex-direction: column; }
    aside { width: auto; border-left: none; border-top: 1px solid var(--border); }
    .editor-wrap { padding: 16px; }
    .editor-toolbar { padding: 10px 16px 0; }
    #editor, #preview { padding: 20px; }
  }

  @media print {
    /* Previous approach used visibility:hidden on every other element,
       which still reserves their layout space (the full-screen canvas,
       sidebar, modals, etc.) -- that made the printed "page" far taller
       than one sheet, and an absolutely-positioned #printArea got
       reprinted on every resulting page (a real browser print quirk, not
       a one-off). Removing everything else from layout with display:none
       and letting #printArea flow normally (not position:absolute) fixes
       both the multi-page bug and the triplicated content in one change. */
    body > *:not(#printArea) { display: none !important; }
    #printArea {
      display: block !important;
      position: static; width: 100%;
      background: var(--bg); color: var(--text);
      -webkit-print-color-adjust: exact; print-color-adjust: exact;
      padding: 20px 10px;
      font-family: var(--content-font);
      font-size: var(--font-size);
      line-height: var(--line-height);
    }
    #printArea h1.print-title { font-size: 1.6em; margin-bottom: 0.6em; }
    html, body { background: var(--bg) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; height: auto !important; }
  }


  /* Install banner (opened from the landing page's Download Clarity button) */
  .install-banner {
    position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60;
    width: min(440px, calc(100% - 24px)); padding: 18px 20px; border-radius: 14px;
    background: var(--panel); color: var(--text); border: 1px solid var(--accent);
    box-shadow: 0 10px 40px rgba(0,0,0,0.45);
  }
  .install-banner[hidden] { display: none; }
  .install-title { font-weight: 700; font-size: 1.05rem; margin-bottom: 4px; }
  .install-text { color: var(--muted); font-size: 0.95rem; line-height: 1.5; }
  .install-steps { margin: 10px 0 0; padding-left: 1.3rem; font-size: 0.95rem; line-height: 1.55; }
  .install-banner .btn-row { margin-top: 14px; }
  .install-banner .btn-row:empty { display: none; }
