:root {
      --toolbar-bg: #f0f0f0;
      --toolbar-button-bg: #e0e0e0;
      --canvas-bg: #fafafa;
      --node-bg: #fff;
      --node-border: #000;
      --text-color: #000;
      --connector-color: #456;
      --selected-outline: #36f;
      --link-color: #0000ee;
      --link-visited-color: #551a8b;
      --popup-bg: var(--toolbar-button-bg);
      --popup-text: var(--text-color);
      --popup-border: var(--node-border);
      --tag-connector-color: #f90;
      --code-bg: #e0e0e0;
    }
    body.dark {
      --toolbar-bg: #444;
      --toolbar-button-bg: #555;
      --canvas-bg: #333;
      --node-bg: #555;
      --node-border: #ccc;
      --text-color: #ddd;
      --connector-color: #9cf;
      --selected-outline: #58a;
      --link-color: #ff4444;        /* true red for dark mode */
      --link-visited-color: #cc3333; /* darker red for visited */
      --popup-bg: var(--toolbar-button-bg);
      --popup-text: var(--text-color);
      --popup-border: var(--node-border);
      --tag-connector-color: #fc0;
      --code-bg: #2a2a2a;
    }
    body {
      margin: 0; padding: 0;
      font-family: sans-serif;
      background: var(--canvas-bg);
      color: var(--text-color);
      transition: background-color 0.3s, color 0.3s;
    }
    #toolbar {
      display: flex; flex-wrap: wrap; align-items: center;
      padding: 5px;
      background: var(--toolbar-bg);
      border-bottom: 1px solid var(--node-border);
      position: sticky; top: 0; z-index: 10;
    }
    #toolbar button,
    #toolbar select,
    #toolbar input[type="color"] {
      margin: 2px; padding: 5px;
      background: var(--toolbar-button-bg);
      color: var(--text-color);
      border: 1px solid var(--node-border);
      border-radius: 4px;
      cursor: pointer;
      font-size: 0.9em;
    }
    #toolbar button:hover {
      background: var(--canvas-bg);
    }
    #toolbar input[type="color"] {
      width: 40px; height: 28px; padding: 2px;
      vertical-align: middle;
    }
    #toolbar label {
      margin-left: 5px;
    }
    #toolbar input[type="number"] {
      width: 50px;
    }
    .toolbar-divider {
      margin: 0 10px;
      font-size: 1.2em;
      color: var(--node-border);
      opacity: 0.5;
    }
    #versionLabel {
      margin-left: auto; padding-right: 10px;
      font-size: 0.9em;
    }
    #canvas {
      position: relative;
      background: var(--canvas-bg);
      min-height: 100vh;
      transform-origin: top left;
    }
    .node {
      position: absolute;
      background: var(--node-bg);
      border: 2px solid var(--node-border);
      box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
      display: flex; align-items: center; justify-content: center;
      user-select: none; cursor: move; z-index: 2;
    }
    .rect    { min-width:100px; min-height:50px; }
    .circle  { width:100px; height:100px; border-radius:50%; min-width:50px; min-height:50px; }
    .ellipse { width:150px; height:75px; border-radius:50%; min-width:100px; min-height:50px; }
    .image   { width:200px; height:150px; }
    .circle, .ellipse { border-width: 5px; }
    .selected {
      outline: 3px dashed var(--selected-outline);
      outline-offset: 2px;
    }
    .text {
      width:100%; height:100%; padding:10px;
      box-sizing: border-box; overflow:auto; outline:none;
      text-align:center; color:var(--text-color);
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
    .text a {
      color: var(--link-color);
      text-decoration: underline;
    }
    .text a:visited {
      color: var(--link-visited-color);
    }
    .text-bold      { font-weight: bold; }
    .text-italic    { font-style: italic; }
    .text-underline { text-decoration: underline; }
    .resize-handle {
      position:absolute; width:10px; height:10px;
      background:var(--selected-outline);
      border:1px solid var(--node-border);
      bottom:-5px; right:-5px;
      cursor:nwse-resize; display:none; z-index:5;
    }
    .selected .resize-handle {
      display: block;
    }
    #linkPopup {
      position: absolute; display: none;
      background: var(--popup-bg); color: var(--popup-text);
      border: 1px solid var(--popup-border);
      padding: 3px 8px; border-radius: 4px;
      font-size: 0.8em; white-space: nowrap;
      pointer-events: none; z-index: 1000;
    }
    canvas.jtk-connector {
      position: absolute !important;
      pointer-events: auto;
      z-index: 1;
      cursor: pointer;
    }
    .jtk-connector-selected path {
      stroke: var(--selected-outline) !important;
      stroke-width: 4px !important;
      animation: dash 0.5s linear infinite;
    }
    @keyframes dash {
      to {
        stroke-dashoffset: -20;
      }
    }
    #footer {
      position: fixed; bottom:5px; right:10px;
      font-size: 0.8em; opacity: 0.7;
    }
    .text pre {
      background: var(--code-bg);
      padding: 10px;
      border-radius: 4px;
      text-align: left;
      white-space: pre;
      overflow: auto;
      max-height: 100%;
      box-sizing: border-box;
    }
    .text code {
      font-family: monospace;
    }
    /* Modal styles */
    .modal-overlay {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0,0,0,0.5);
      display: none; /* Initially hidden */
      align-items: center;
      justify-content: center;
      z-index: 2000;
    }
    .modal-content {
      background: var(--toolbar-bg);
      padding: 20px;
      border-radius: 8px;
      box-shadow: 0 5px 15px rgba(0,0,0,0.3);
      width: 400px;
      max-width: 90%;
      border: 1px solid var(--node-border);
    }
    .modal-content h3 {
      margin-top: 0;
      color: var(--text-color);
    }
    #tagInput {
      width: 100%;
      padding: 8px;
      box-sizing: border-box;
      margin-bottom: 10px;
      background: var(--canvas-bg);
      color: var(--text-color);
      border: 1px solid var(--node-border);
      border-radius: 4px;
    }
    #tagSuggestions {
      list-style: none;
      padding: 0;
      margin: 0;
      max-height: 100px;
      overflow-y: auto;
      border: 1px solid var(--node-border);
      border-radius: 4px;
      display: none; /* Initially hidden */
    }
    #tagSuggestions li {
      padding: 8px;
      cursor: pointer;
      background: var(--canvas-bg);
      color: var(--text-color);
    }
    #tagSuggestions li:hover {
      background: var(--toolbar-button-bg);
    }
    .modal-buttons {
      text-align: right;
      margin-top: 20px;
    }
    .modal-buttons button {
      margin-left: 10px;
      padding: 5px 15px;
      background: var(--toolbar-button-bg);
      color: var(--text-color);
      border: 1px solid var(--node-border);
      border-radius: 4px;
      cursor: pointer;
    }
