:root {
      color-scheme: dark;
      --bg: #101218;
      --panel: #171a22;
      --panel-2: #12141b;
      --workspace: #1a1d27;
      --line: rgba(255, 255, 255, 0.08);
      --text: #eceae6;
      --muted: #9b968d;
      --amber: #f0b429;
      --font: Outfit, "Segoe UI", sans-serif;
      --mono: "IBM Plex Mono", Consolas, ui-monospace, monospace;
    }
    * { box-sizing: border-box; }
    html, body { height: 100%; margin: 0; }
    body {
      background: var(--bg);
      color: var(--text);
      font-family: var(--font);
      font-size: 14px;
    }
    button, select, input { font: inherit; }
    button { cursor: pointer; }
    button:disabled { opacity: 0.4; cursor: default; }
    button:focus-visible, select:focus-visible, input:focus-visible {
      outline: 2px solid var(--amber);
      outline-offset: 2px;
    }
    .app {
      min-width: 980px;
      height: 100%;
      display: grid;
      grid-template-rows: 60px minmax(0, 1fr);
    }
    header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 16px;
      padding: 0 16px;
      background: #161922;
      border-bottom: 1px solid var(--line);
    }
    .brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
    .brand h1 { margin: 0; font-size: 18px; letter-spacing: -0.03em; font-weight: 700; }
    .brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
    .header-actions { display: flex; align-items: center; gap: 10px; }
    .seg {
      display: flex;
      background: #0e1016;
      border-radius: 999px;
      padding: 3px;
      border: 1px solid var(--line);
    }
    .seg button {
      border: 0;
      background: transparent;
      color: var(--muted);
      border-radius: 999px;
      padding: 6px 12px;
      font-weight: 600;
    }
    .seg button.on { background: #2c3344; color: white; }
    #run, .primary {
      background: var(--amber);
      color: #2a2112;
      border: 0;
      border-radius: 999px;
      padding: 8px 16px;
      font-weight: 700;
    }
    #run:hover { filter: brightness(1.05); }
    #examples, .ghost-btn {
      background: transparent;
      color: var(--text);
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 6px 9px;
      font-size: 13px;
    }
    .layout {
      min-height: 0;
      display: grid;
      grid-template-columns: minmax(0, 1fr) 420px;
    }
    #palette {
      overflow: auto;
      background: var(--panel);
      padding-bottom: 16px;
    }
    .pal-intro, .pal-foot {
      color: var(--muted);
      font-size: 12px;
      line-height: 1.45;
      margin: 0;
      padding: 14px 14px 4px;
    }
    .pal-foot { padding-top: 8px; }
    .cat-section { padding: 12px 14px 2px; }
    .cat-section h2 {
      margin: 0 0 8px;
      font-size: 11px;
      letter-spacing: 0.08em;
      text-transform: uppercase;
      color: var(--muted);
      display: flex;
      align-items: center;
      gap: 8px;
      font-weight: 700;
    }
    .cat-section h2 i { width: 8px; height: 8px; border-radius: 99px; display: block; }
    .cat-blocks { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
    .var-manager { display: flex; flex-direction: column; gap: 6px; width: 100%; }
    .var-row { display: flex; align-items: center; gap: 6px; width: 100%; }
    .var-name { font-family: var(--mono); font-size: 12px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    .var-row button, #new-var {
      border: 1px solid var(--line);
      background: transparent;
      color: var(--text);
      border-radius: 7px;
      padding: 4px 7px;
      font-size: 11px;
    }
    .muted { color: var(--muted); font-size: 12px; margin: 0; }
    #trash {
      display: none;
      margin: 16px auto 20px;
      width: min(320px, calc(100% - 40px));
      border: 1.5px dashed rgba(255, 255, 255, 0.25);
      border-radius: 10px;
      padding: 12px;
      text-align: center;
      color: var(--muted);
      position: sticky;
      bottom: 16px;
      background: #1c2030;
      z-index: 5;
    }
    body.dragging-existing #trash { display: block; }
    #trash.active-drop { background: rgba(228, 84, 108, 0.25); color: white; border-color: #e4546c; }
    main { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); }
    .ws-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 8px 12px;
      background: var(--panel);
      border-bottom: 1px solid var(--line);
    }
    .ws-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
    .ws-title strong { font-size: 13px; }
    .ws-title span, .hint { color: var(--muted); font-size: 12px; }
    .hint { margin: 0; white-space: nowrap; }
    .ws-actions { display: flex; align-items: center; gap: 8px; }
    #workspace {
      overflow: auto;
      min-height: 0;
      background-color: var(--workspace);
      background-image: radial-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px);
      background-size: 20px 20px;
    }
    .program { padding: 28px 32px 80px; min-width: max-content; }
    .hat {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      background: linear-gradient(#ffd56a, #e6a61e);
      color: #2c220f;
      font-weight: 700;
      border-radius: 16px 16px 10px 10px;
      padding: 8px 14px 8px 12px;
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 2px 0 rgba(0, 0, 0, 0.25);
      margin: 0 0 8px 14px;
    }
    .hat.running { box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.45), 0 2px 0 rgba(0, 0, 0, 0.25); }
    .play {
      width: 18px;
      height: 18px;
      display: inline-grid;
      place-items: center;
      background: rgba(0, 0, 0, 0.12);
      border-radius: 99px;
      font-size: 10px;
    }
    .stack { display: flex; flex-direction: column; align-items: flex-start; min-width: 80px; }
    .program > .stack { margin-left: 14px; }
    .gap { height: 6px; width: 100%; min-width: 88px; border-radius: 7px; }
    body.dragging-statement .gap { height: 16px; background: rgba(255, 255, 255, 0.05); }
    .gap.active-drop { height: 32px; background: rgba(255, 255, 255, 0.32); }
    .stack.active-drop { background: rgba(255, 255, 255, 0.08); border-radius: 8px; }
    .empty-hint { pointer-events: none; color: rgba(255, 255, 255, 0.55); font-size: 12px; padding: 6px 4px 8px; }
    .program > .stack .empty-hint { color: var(--muted); }
    .cat-io { --c: #2b7de9; }
    .cat-control { --c: #e8922a; }
    .cat-operators { --c: #3aa655; }
    .cat-text { --c: #c44db8; }
    .cat-variables { --c: #e4546c; }
    .cat-values { --c: #1aa0b8; }
    .cat-lists { --c: #7b6cff; }
    .cat-dicts { --c: #d9783a; }
    .cat-functions { --c: #3aa89a; }
    .cat-flask { --c: #6b8f71; }
    .cat-json { --c: #c4a35a; }
    .cat-pandas { --c: #d36b8f; }
    .cat-sqlite { --c: #4d91c6; }
    .cat-requests { --c: #62a0a8; }
    .cat-regex { --c: #a778c2; }
    .cat-pathlib { --c: #8b795e; }
    .cat-os { --c: #607d8b; }
    .cat-sys { --c: #667c91; }
    .cat-imported { --c: #9b7fd1; }
    .cat-notes { --c: #6d7480; }
    .block { color: white; font-size: 13.5px; user-select: none; }
    #workspace .block { cursor: grab; }
    .palette-item { cursor: grab; }
    body.dragging, body.dragging .block { cursor: grabbing; }
    .block.statement, .block.reporter, .block.boolean {
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 42%), var(--c);
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 2px 0 rgba(0, 0, 0, 0.25);
    }
    .block.statement {
      display: flex;
      flex-direction: column;
      width: max-content;
      max-width: 100%;
      border-radius: 12px;
    }
    .block.reporter, .block.boolean {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 3px 8px;
      border-radius: 999px;
      max-width: 100%;
    }
    .block.boolean { position: relative; padding-left: 14px; padding-right: 14px; }
    .block.boolean::before, .block.boolean::after {
      content: "";
      position: absolute;
      top: 50%;
      width: 8px;
      height: 8px;
      background: var(--c);
      transform: translateY(-50%) rotate(45deg);
    }
    .block.boolean::before { left: -4px; }
    .block.boolean::after { right: -4px; }
    .block.selected { outline: 2px solid #fff; outline-offset: 2px; z-index: 2; }
    .row { display: flex; align-items: center; gap: 6px; padding: 7px 10px; flex-wrap: wrap; }
    .tok { font-weight: 600; white-space: nowrap; }
    .mid { padding: 0 12px 6px; font-weight: 700; }
    .block.if-then { --c: #e8922a; }
    .block.if-else { --c: #c2471a; }
    .block.if-else > .row { background: rgba(0, 0, 0, 0.16); border-radius: 12px 12px 0 0; }
    .elif-mid {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      gap: 6px;
      margin: 0 8px;
      padding: 6px 10px;
      background: rgba(0, 0, 0, 0.22);
      border-radius: 8px 8px 0 0;
      font-weight: 800;
    }
    .else-mid {
      color: #ffd7b0;
      font-style: italic;
      letter-spacing: 0.03em;
      margin: 0 8px;
      padding: 6px 12px 4px;
      background: rgba(0, 0, 0, 0.28);
      border-radius: 8px 8px 0 0;
    }
    .elif-nest, .else-nest { margin-top: 0; }
    .else-nest { background: rgba(0, 0, 0, 0.28); }
    .if-branch-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      padding: 2px 10px 10px;
    }
    .if-branch-actions button {
      border: 1px solid rgba(255, 255, 255, 0.28);
      background: rgba(0, 0, 0, 0.2);
      color: white;
      border-radius: 7px;
      padding: 3px 8px;
      font-size: 11px;
      font-weight: 700;
    }
    .if-branch-actions button:hover { background: rgba(0, 0, 0, 0.34); }
    .mini-nest.else-mini { border-color: rgba(0, 0, 0, 0.45); }
    .nest {
      margin: 0 8px 8px;
      background: rgba(0, 0, 0, 0.18);
      border-radius: 8px;
      padding: 6px;
      min-width: 120px;
    }
    .mini-nest {
      height: 10px;
      margin: 0 10px 8px 16px;
      border-left: 3px solid rgba(0, 0, 0, 0.25);
      border-bottom: 3px solid rgba(0, 0, 0, 0.25);
      border-radius: 0 0 0 8px;
      width: 46px;
    }
    .socket {
      display: inline-flex;
      align-items: center;
      background: rgba(0, 0, 0, 0.2);
      border-radius: 999px;
      padding: 3px;
      min-height: 28px;
      max-width: 100%;
    }
    .socket .hole {
      display: block;
      width: 28px;
      height: 16px;
      border-radius: 999px;
      background: rgba(0, 0, 0, 0.28);
      box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.35);
    }
    .socket.boolean { border-radius: 8px; }
    .socket.boolean .hole {
      width: 12px;
      height: 12px;
      margin: 5px 7px;
      border-radius: 2px;
      transform: rotate(45deg);
    }
    body.dragging-value .socket.compatible { box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.55); }
    .socket.active-drop { box-shadow: 0 0 0 2px #fff; }
    .socket.type-warn { box-shadow: 0 0 0 2px #f0b429; }
    .var-label { font-family: var(--mono); font-weight: 700; }
    .var-create { display: flex; gap: 6px; width: 100%; }
    .var-create input, .var-create select, .var-row select {
      background: #0e1016;
      color: var(--text);
      border: 1px solid var(--line);
      border-radius: 7px;
      padding: 4px 6px;
      font-size: 12px;
      min-width: 0;
    }
    .var-create input { flex: 1; width: 0; }
    .block input, .block select, .block textarea {
      font-family: inherit;
      font-weight: 600;
      font-size: 13px;
      color: #1c1e27;
      background: rgba(255, 255, 255, 0.94);
      border: 0;
      border-radius: 7px;
      padding: 2px 6px;
      min-height: 24px;
    }
    .block input.text { width: 10ch; max-width: 28ch; }
    .block input.num { width: 4.6rem; }
    .block textarea.code {
      width: min(34rem, 58vw);
      min-width: 12ch;
      max-width: 100%;
      min-height: 24px;
      resize: both;
      white-space: pre;
      line-height: 1.35;
    }
    .block select { font-weight: 700; }
    #palette .block input, #palette .block select, #palette .block textarea { pointer-events: none; }
    .cat-notes .tok, .cat-notes input, .cat-notes textarea { font-style: italic; }
    .side {
      min-height: 0;
      display: grid;
      grid-template-rows: minmax(0, 1.25fr) minmax(168px, 0.75fr);
      border-left: 1px solid var(--line);
      background: var(--panel-2);
    }
    .panel { min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); }
    .panel + .panel { border-top: 1px solid var(--line); }
    .panel-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      padding: 8px 10px;
      border-bottom: 1px solid var(--line);
      min-height: 46px;
    }
    .panel-bar strong { font-size: 13px; }
    #rules-label { color: var(--muted); font-weight: 500; font-size: 12px; margin-left: 6px; }
    #code, #output {
      margin: 0;
      min-height: 0;
      overflow: auto;
      padding: 12px 14px 20px;
      font-family: var(--mono);
      font-size: 12.5px;
      line-height: 1.55;
    }
    #code { white-space: pre; user-select: text; cursor: text; }
    #output { white-space: pre-wrap; user-select: text; }
    #code .kw { color: #c792ea; }
    #code .st { color: #c3e88d; }
    #code .nu { color: #f78c6c; }
    #code .cm { color: #6f7787; }
    #code .fn { color: #82aaff; }
    #output .placeholder { color: var(--muted); white-space: pre-wrap; }
    #output .err { color: #ff9b9b; }
    .watch { padding: 0 14px 10px; color: var(--muted); font-family: var(--mono); font-size: 12px; }
    .ask-box { display: flex; gap: 8px; align-items: center; padding: 0 14px 12px; color: var(--muted); font-size: 12px; }
    .ask-box input { flex: 1; background: #0e1016; color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 4px 8px; }
    #palette-search { width: calc(100% - 28px); margin: 12px 14px 0; background: #0e1016; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; }
    .menu { position: fixed; z-index: 2500; background: #222636; border: 1px solid var(--line); border-radius: 8px; padding: 4px; min-width: 140px; }
    .menu button { display: block; width: 100%; text-align: left; background: transparent; color: var(--text); border: 0; border-radius: 6px; padding: 6px 8px; }
    .menu button:hover { background: #2c3344; }
    .block.traced { outline: 2px solid var(--amber); outline-offset: 2px; }
    #zoom { width: 90px; }
    dialog { background: #1c2030; color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; width: min(420px, calc(100vw - 32px)); }
    dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
    dialog h2 { margin: 0 0 8px; font-size: 18px; }
    dialog p { margin: 0 0 12px; }
    .choice { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; }
    .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
    .choice input { margin-top: 3px; }
    dialog.block-dialog {
      width: min(380px, calc(100vw - 28px));
      height: min(760px, calc(100vh - 28px));
      padding: 0;
      overflow: hidden;
    }
    .block-dialog-form {
      height: 100%;
      display: grid;
      grid-template-rows: auto minmax(0, 1fr);
    }
    dialog.library-dialog {
      width: min(820px, calc(100vw - 28px));
      height: min(720px, calc(100vh - 28px));
      padding: 0;
      overflow: hidden;
    }
    .library-dialog form {
      height: 100%;
      display: grid;
      grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    }
    .library-heading {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 16px;
      padding: 20px 22px 8px;
    }
    .library-heading p { margin-bottom: 0; }
    .library-count {
      flex: 0 0 auto;
      color: var(--amber);
      font-size: 12px;
      font-weight: 700;
      padding-top: 4px;
    }
    .library-tools {
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      gap: 10px;
      padding: 10px 22px;
    }
    .library-tools input, .library-tools select {
      min-width: 0;
      background: #111521;
      color: var(--text);
      border: 1px solid var(--line);
      border-radius: 9px;
      padding: 9px 11px;
      font: inherit;
    }
    .library-legend {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      gap: 8px;
      color: var(--muted);
      font-size: 11px;
      padding: 0 22px 10px;
      border-bottom: 1px solid var(--line);
    }
    .library-badge {
      display: inline-flex;
      align-items: center;
      border-radius: 999px;
      padding: 3px 7px;
      font-size: 10px;
      font-weight: 800;
      letter-spacing: .04em;
      text-transform: uppercase;
    }
    .library-badge.builtin { background: rgba(79, 154, 138, .18); color: #8de0c8; border: 1px solid rgba(141, 224, 200, .35); }
    .library-badge.pip { background: rgba(240, 180, 41, .14); color: #f0c75e; border: 1px solid rgba(240, 199, 94, .35); }
    .library-section {
      grid-column: 1 / -1;
      display: flex;
      align-items: center;
      gap: 8px;
      margin: 8px 0 2px;
      color: var(--muted);
      font-size: 12px;
      font-weight: 700;
    }
    .library-install.builtin { color: #8de0c8; }
    #import-list {
      overflow: auto;
      padding: 14px 22px 20px;
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      align-content: start;
      gap: 10px;
    }
    .library-card {
      display: grid;
      grid-template-columns: auto minmax(0, 1fr);
      gap: 10px;
      margin: 0;
      padding: 12px;
      min-width: 0;
      background: #151a27;
      border: 1px solid var(--line);
      border-radius: 11px;
      cursor: pointer;
    }
    .library-card:hover { border-color: #59627a; background: #181e2d; }
    .library-card.enabled { border-color: rgba(240, 180, 41, .55); box-shadow: inset 0 0 0 1px rgba(240, 180, 41, .12); }
    .library-card.unavailable { opacity: .58; cursor: not-allowed; }
    .library-card input { margin-top: 3px; }
    .library-card-body { min-width: 0; }
    .library-card-title { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-bottom: 5px; }
    .library-card-title strong { font-size: 13px; }
    .library-card p { margin: 0; color: var(--muted); font-size: 11.5px; line-height: 1.4; }
    .library-install { display: block; margin-top: 6px; color: #f0c75e; font: 10.5px "IBM Plex Mono", monospace; }
    .library-empty { grid-column: 1 / -1; color: var(--muted); text-align: center; padding: 50px 10px; }
    .library-dialog .dialog-actions {
      margin: 0;
      padding: 12px 22px;
      border-top: 1px solid var(--line);
      background: #191e2b;
    }
    .script-drop {
      display: grid;
      place-items: center;
      gap: 10px;
      min-height: 110px;
      padding: 16px;
      border: 1.5px dashed rgba(255, 255, 255, 0.28);
      border-radius: 10px;
      color: var(--muted);
      text-align: center;
    }
    .script-drop.over { border-color: var(--amber); background: rgba(240, 180, 41, 0.08); color: var(--text); }
    .script-source {
      width: 100%;
      min-height: 150px;
      resize: vertical;
      margin-top: 8px;
      padding: 9px;
      color: var(--text);
      background: #0e1016;
      border: 1px solid var(--line);
      border-radius: 8px;
      font-family: var(--mono);
      font-size: 12px;
    }
    .import-status { min-height: 20px; margin: 8px 0 0; color: var(--muted); }
    .import-status.error { color: #ff9b9b; }
    #toast {
      position: fixed;
      left: 50%;
      bottom: 18px;
      transform: translateX(-50%) translateY(8px);
      background: #2c3140;
      color: white;
      border: 1px solid rgba(255, 255, 255, 0.08);
      padding: 10px 14px;
      border-radius: 999px;
      font-size: 13px;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.18s ease, transform 0.18s ease;
      z-index: 3000;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    }
    #toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
    #ghost {
      position: fixed;
      z-index: 2000;
      pointer-events: none;
      margin: 0;
      opacity: 0.94;
      filter: drop-shadow(0 16px 24px rgba(0, 0, 0, 0.4));
    }
    #ghost.copying { outline: 2px dashed white; outline-offset: 3px; }
    #test-results {
      margin: 0;
      padding: 12px 16px 24px;
      background: #07110a;
      color: #b6f0c2;
      font-family: var(--mono);
      font-size: 12px;
      white-space: pre-wrap;
    }
    @media (max-width: 1180px) {
      .layout { grid-template-columns: 250px minmax(0, 1fr) 340px; }
      .hint { display: none; }
    }
    @media (max-width: 640px) {
      .library-tools { grid-template-columns: 1fr; }
      #import-list { grid-template-columns: 1fr; }
      .library-heading, .library-tools, .library-legend { padding-left: 14px; padding-right: 14px; }
      #import-list { padding-left: 14px; padding-right: 14px; }
    }
    @media (prefers-reduced-motion: reduce) {
      * { transition: none !important; }
    }
