  * { box-sizing: border-box; }

  :root {
    --font-shift: 0px;
    --fs-base: 16px;
    --fs-brand: 14px;
    --fs-h1: 19px;
    --fs-h2: 18px;
    --fs-h3: 17px;
    --fs-code-block: 15px;
    --fs-table: 15px;
    --fs-button: 13px;
    --fs-modal-h2: 14px;
    --fs-label: 12px;
    --fs-input: 14px;
    --icon-btn-w: 25px;
    --icon-btn-h: 25px;
    --icon-size: 12px;
    --toolbar-btn-w: 28px;
    --toolbar-btn-h: 24px;
    --toolbar-icon-size: 18px;
    --content-pad-x: clamp(24px, 8vw, 200px);
    --page-pad-top: 72px;
  }

  @media (max-width: 640px) {
    :root {
      --font-shift: -2px;
      --page-pad-top: 56px;
    }
  }

  html, body {
    margin: 0;
    padding: 0;
    background: #000;
    color: #cfcaca;
    height: 100%;
  }

  body {
    font-family: "JetBrains Mono", Menlo, Consolas, "Courier New", monospace;
    -webkit-font-smoothing: antialiased;
  }

  ::selection {
    background: #830f0f;
  }

  #app-bottombar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    padding: 0 var(--content-pad-x);
    background: #000;
  }

  #brand {
    background: transparent;
    border: none;
    color: #ff3b3b;
    font-family: inherit;
    font-size: calc(var(--fs-brand) + var(--font-shift));
    font-weight: 700;
    letter-spacing: 0.3px;
    padding: 6px 0;
    border-radius: 5px;
    cursor: default;
  }


  [data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(-4px);
    background: #1a1a1a;
    border: 1px solid #2e2e2e;
    color: #eee;
    font-family: inherit;
    font-size: 9px;
    font-weight: 400;
    white-space: nowrap;
    padding: 5px 8px;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease 0.3s, transform 0.15s ease 0.3s;
    z-index: 80;
  }

  [data-tooltip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }

  #toolbar-more-btn.active::after {
    display: none;
  }

  .ql-toolbar.ql-snow {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 55;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    background: #000;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 10px 24px;
  }

  .ql-toolbar.ql-snow .ql-formats {
    margin-right: 6px;
  }

  .ql-toolbar.ql-snow button {
    width: calc(var(--toolbar-btn-w) + var(--font-shift));
    height: calc(var(--toolbar-btn-h) + var(--font-shift));
  }

  .ql-toolbar.ql-snow button svg {
    width: calc(var(--toolbar-icon-size) + var(--font-shift));
    height: calc(var(--toolbar-icon-size) + var(--font-shift));
  }

  .ql-toolbar.ql-snow button,
  .ql-toolbar.ql-snow .ql-picker-label {
    color: #cfcaca;
  }

  .ql-toolbar.ql-snow .ql-stroke {
    stroke: #cfcaca;
  }

  .ql-toolbar.ql-snow .ql-fill {
    fill: #cfcaca;
  }

  .ql-toolbar.ql-snow button:hover,
  .ql-toolbar.ql-snow button.ql-active,
  .ql-toolbar.ql-snow .ql-picker-label:hover {
    color: #fff;
  }

  .ql-toolbar.ql-snow button:hover .ql-stroke,
  .ql-toolbar.ql-snow button.ql-active .ql-stroke {
    stroke: #fff;
  }

  .ql-toolbar.ql-snow button:hover .ql-fill,
  .ql-toolbar.ql-snow button.ql-active .ql-fill {
    fill: #fff;
  }

  .ql-toolbar.ql-snow .ql-copy,
  .ql-toolbar.ql-snow .ql-open,
  .ql-toolbar.ql-snow .ql-download {
    color: #ff3b3b;
  }

  .ql-toolbar.ql-snow .ql-copy .ql-stroke,
  .ql-toolbar.ql-snow .ql-open .ql-stroke,
  .ql-toolbar.ql-snow .ql-download .ql-stroke {
    stroke: #ff3b3b;
  }

  .ql-toolbar.ql-snow .ql-copy:hover,
  .ql-toolbar.ql-snow .ql-open:hover,
  .ql-toolbar.ql-snow .ql-download:hover {
    color: #ff6b6b;
  }

  .ql-toolbar.ql-snow .ql-copy:hover .ql-stroke,
  .ql-toolbar.ql-snow .ql-open:hover .ql-stroke,
  .ql-toolbar.ql-snow .ql-download:hover .ql-stroke {
    stroke: #ff6b6b;
  }

  .ql-toolbar.ql-snow .ql-formats:first-child {
    position: relative;
    padding-right: 12px;
    margin-right: 12px;
  }

  .ql-toolbar.ql-snow .ql-formats:first-child::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    width: 1px;
    height: 20px;
    background: #333;
  }

  #toolbar-more-btn {
    position: relative;
    display: none;
    background: transparent;
    border: 1px solid #333;
    color: #cfcaca;
    align-items: center;
    justify-content: center;
    width: calc(var(--toolbar-btn-w) + var(--font-shift));
    height: calc(var(--toolbar-btn-h) + var(--font-shift));
    border-radius: 5px;
    cursor: pointer;
    padding: 0;
    margin-left: 4px;
  }

  #toolbar-more-btn svg {
    width: calc(var(--toolbar-icon-size) + var(--font-shift) - 2px);
    height: calc(var(--toolbar-icon-size) + var(--font-shift) - 2px);
    stroke: currentColor;
    transition: transform 0.15s;
  }

  #toolbar-more-btn.active svg {
    transform: rotate(180deg);
  }

  #toolbar-more-btn:hover,
  #toolbar-more-btn.active {
    color: #fff;
    border-color: #555;
  }

  @media (max-width: 640px) {
    .ql-toolbar.ql-snow .ql-header[value="2"],
    .ql-toolbar.ql-snow .ql-blockquote,
    .ql-toolbar.ql-snow .ql-code-block,
    .ql-toolbar.ql-snow .ql-image,
    .ql-toolbar.ql-snow .ql-list[value="ordered"],
    .ql-toolbar.ql-snow .ql-list[value="check"],
    .ql-toolbar.ql-snow .ql-divider,
    .ql-toolbar.ql-snow .ql-mdtable {
      display: none;
    }

    .ql-toolbar.ql-snow.expanded .ql-header[value="2"],
    .ql-toolbar.ql-snow.expanded .ql-blockquote,
    .ql-toolbar.ql-snow.expanded .ql-code-block,
    .ql-toolbar.ql-snow.expanded .ql-image,
    .ql-toolbar.ql-snow.expanded .ql-list[value="ordered"],
    .ql-toolbar.ql-snow.expanded .ql-list[value="check"],
    .ql-toolbar.ql-snow.expanded .ql-divider,
    .ql-toolbar.ql-snow.expanded .ql-mdtable {
      display: inline-block;
    }

    #toolbar-more-btn {
      display: flex;
    }
  }

  .ql-snow .ql-tooltip {
    background: #1a1a1a;
    border: 1px solid #2e2e2e;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    color: #cfcaca;
    font-family: "JetBrains Mono", Menlo, Consolas, "Courier New", monospace;
  }

  .ql-snow .ql-tooltip input[type="text"] {
    background: #050505;
    border: 1px solid #2a2a2a;
    color: #eee;
    font-family: "JetBrains Mono", Menlo, Consolas, "Courier New", monospace;
    font-variant-ligatures: none;
    font-feature-settings: "liga" 0, "calt" 0;
  }

  .ql-snow .ql-tooltip a.ql-action,
  .ql-snow .ql-tooltip a.ql-remove {
    color: #6ea8fe;
  }

  .page {
    width: 100%;
    padding: var(--page-pad-top) var(--content-pad-x) calc(30vh + 56px);
    min-height: 100vh;
    position: relative;
  }

  #editor-root {
    font-size: calc(var(--fs-base) + var(--font-shift));
    position: relative;
    border: none;
  }

  #table-edit-btn,
  #table-delete-btn {
    position: absolute;
    display: none;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 5px;
    color: #888;
    cursor: pointer;
    z-index: 56;
  }

  #table-edit-btn.visible,
  #table-delete-btn.visible {
    display: flex;
  }

  #table-edit-btn svg,
  #table-delete-btn svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
  }

  #table-edit-btn:hover,
  #table-delete-btn:hover {
    color: #ff3b3b;
    border-color: #ff3b3b;
  }

  #editor-root .ql-editor {
    padding: 0;
    font-family: "JetBrains Mono", Menlo, Consolas, "Courier New", monospace;
    font-size: calc(var(--fs-base) + var(--font-shift));
    line-height: 1.3;
    font-weight: 600;
    color: #cfcaca;
    caret-shape: block;
    caret-color: rgba(207, 202, 202, 0.7);
    font-variant-ligatures: none;
    font-feature-settings: "liga" 0, "calt" 0;
  }

  #editor-root .ql-editor.ql-blank::before {
    color: #444;
    font-style: normal;
    font-family: inherit;
    left: 0;
    right: 0;
  }

  #editor-root .ql-editor p {
    margin: 0 0 18px;
  }

  #editor-root .ql-editor b, #editor-root .ql-editor strong {
    font-weight: 800;
    color: #fff;
  }

  #editor-root .ql-editor h1, #editor-root .ql-editor h2, #editor-root .ql-editor h3 {
    font-weight: 800;
    color: #fff;
    margin: 32px 0 14px;
  }

  #editor-root .ql-editor h1 { font-size: var(--fs-h1); letter-spacing: -0.3px; }
  #editor-root .ql-editor h2 { font-size: var(--fs-h2); margin-top: 28px; }
  #editor-root .ql-editor h3 { font-size: calc(var(--fs-h3) + var(--font-shift)); margin-top: 24px; }

  @media (max-width: 640px) {
    #editor-root .ql-editor h1 { font-size: calc(var(--fs-h1) - 3px); }
    #editor-root .ql-editor h2 { font-size: calc(var(--fs-h2) - 3px); }
  }

  #editor-root .ql-editor blockquote {
    margin: 18px 0;
    padding-left: 16px;
    border-left: 2px solid #444;
    color: #b6b6b3;
    font-style: italic;
  }

  #editor-root .ql-editor code {
    background: #161616;
    border: 1px solid #2a2a2a;
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 0.92em;
    color: #cfcaca;
  }

  #editor-root .ql-editor .ql-code-block-container {
    background: #0d0d0d;
    border: 1px solid #222;
    border-radius: 6px;
    margin: 20px 0;
    padding: 14px 0;
    counter-reset: codeline;
    font-family: inherit;
  }

  #editor-root .ql-editor .ql-code-block {
    counter-increment: codeline;
    position: relative;
    padding: 1px 16px 1px 52px;
    font-size: calc(var(--fs-code-block) + var(--font-shift));
    line-height: 1.3;
    font-weight: 600;
    color: #fff;
    white-space: pre-wrap;
    word-break: break-word;
  }

  #editor-root .ql-editor .ql-code-block::before {
    content: counter(codeline);
    position: absolute;
    left: 0;
    width: 36px;
    text-align: right;
    color: #4a4a4a;
    user-select: none;
  }

  #editor-root .ql-editor a {
    color: #6ea8fe;
    text-decoration: underline;
    text-decoration-color: rgba(110, 168, 254, 0.5);
    text-underline-offset: 3px;
    cursor: pointer;
  }

  #editor-root .ql-editor a:hover {
    color: #8fbbff;
    text-decoration-color: #8fbbff;
  }

  #editor-root .ql-editor ul, #editor-root .ql-editor ol {
    margin: 0 0 18px;
    padding-left: 24px;
  }

  #editor-root .ql-editor li {
    margin-bottom: 6px;
  }

  #editor-root .ql-editor li[data-list="checked"],
  #editor-root .ql-editor li[data-list="unchecked"] {
    padding-left: 1.5em;
    display: flex;
    align-items: center;
  }

  #editor-root .ql-editor li[data-list="checked"] > .ql-ui,
  #editor-root .ql-editor li[data-list="unchecked"] > .ql-ui {
    position: relative;
    flex: none;
    display: inline-block;
    width: 18px;
    height: 18px;
    box-sizing: border-box;
    border: 2px solid #cfcaca;
    border-radius: 4px;
    background: transparent;
    margin-left: -1.5em;
    margin-right: 8px;
  }

  #editor-root .ql-editor li[data-list="checked"] > .ql-ui {
    border-color: #fff;
    background: #fff;
  }

  #editor-root .ql-editor li[data-list="checked"] > .ql-ui::before,
  #editor-root .ql-editor li[data-list="unchecked"] > .ql-ui::before {
    content: none;
  }

  #editor-root .ql-editor li[data-list="checked"] > .ql-ui::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 4px;
    height: 8px;
    border: solid #000;
    border-width: 0 1.5px 1.5px 0;
    transform: rotate(45deg);
  }

  #editor-root .ql-editor hr {
    border: none;
    border-top: 1px solid #333;
    margin: 32px 0;
  }

  #editor-root .ql-editor img {
    display: block;
    max-width: min(100%, 640px);
    max-height: 520px;
    width: auto;
    height: auto;
    margin: 24px auto;
    border-radius: 6px;
  }

  /* Quill's built-in table format (formats/table.ts): cells are plain <td>
     elements (TableCell is a Block, not a Container with an inner <p>), so
     these selectors target the tag directly rather than a custom class. */
  #editor-root .ql-editor table {
    border-collapse: collapse;
    margin: 18px 0;
    width: 100%;
  }

  #editor-root .ql-editor table td {
    border: 1px solid #333;
    padding: 9px 10px;
    text-align: left;
    outline: none;
    min-width: 60px;
    min-height: 22px;
    line-height: 1.3;
    font-size: calc(var(--fs-table) + var(--font-shift));
    font-weight: 600;
    color: #cfcaca;
  }

  #editor-root .ql-editor table tr:first-child td {
    color: #fff;
    font-weight: 800;
    background: #111;
  }

  .overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
  }

  .overlay.visible {
    display: flex;
  }

  .modal-actions button {
    background: #1a1a1a;
    border: 1px solid #333;
    color: #ddd;
    font-family: inherit;
    font-size: calc(var(--fs-button) + var(--font-shift));
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
  }

  .modal-actions button:hover {
    background: #262626;
  }

  .modal-actions button.primary {
    background: #cfcaca;
    color: #000;
    border-color: #cfcaca;
    font-weight: 700;
  }

  .modal-actions button.primary:hover {
    background: #fff;
  }

  #table-size-modal {
    background: #0d0d0d;
    border: 1px solid #2a2a2a;
    border-radius: 10px;
    width: min(280px, 90vw);
    padding: 18px;
  }

  #table-size-modal h2 {
    font-size: calc(var(--fs-modal-h2) + var(--font-shift));
    margin: 0 0 16px;
    color: #ccc;
    font-weight: 700;
  }

  #table-size-fields {
    display: flex;
    gap: 12px;
  }

  #table-size-fields label {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: calc(var(--fs-label) + var(--font-shift));
    color: #888;
  }

  #table-size-fields input {
    background: #050505;
    border: 1px solid #2a2a2a;
    border-radius: 6px;
    color: #eee;
    font-family: inherit;
    font-size: calc(var(--fs-input) + var(--font-shift));
    padding: 8px 10px;
    width: 100%;
  }

  #table-size-fields input:focus {
    outline: none;
    border-color: #555;
  }

  #table-size-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
    justify-content: flex-end;
  }
