 :root {
      --bg: #111217;
      --panel: #1b1d26;
      --panel-2: #242734;
      --border: #3a3f55;
      --text: #f2f2f2;
      --muted: #aeb3c7;
      --accent: #8a2be2;
      --accent-2: #b169ff;
      --danger: #ff6b6b;
      --shadow: rgba(0,0,0,.35);

      --editorPanelHeight: 100%;
      --editorPanelWidth: 100%;
      --editorFontSize: 14px;
    }

    * {
      box-sizing: border-box;
    }

    body {
      margin: 0;
      min-height: 100vh;
      background:
        radial-gradient(circle at top left, rgba(138,43,226,.25), transparent 35%),
        linear-gradient(135deg, #101116 0%, #181a22 55%, #0f1015 100%);
      color: var(--text);
      font-family: Arial, Helvetica, sans-serif;
      overflow: hidden;
    }

    header {
      min-height: 64px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 1rem;
      padding: 10px 18px;
      background: rgba(17,18,23,.92);
      border-bottom: 1px solid var(--border);
      box-shadow: 0 2px 14px var(--shadow);
    }

    .brand {
      display: flex;
      align-items: center;
      gap: .7rem;
      font-weight: 700;
      letter-spacing: .2px;
      white-space: nowrap;
    }

    .logo {
      width: 34px;
      height: 34px;
      display: grid;
      place-items: center;
      border-radius: 8px;
      background: linear-gradient(135deg, var(--accent), #4c1a8f);
      box-shadow: 0 0 18px rgba(138,43,226,.45);
      font-weight: 900;
	  cursor: pointer;
    }

    .hint {
      color: var(--muted);
      font-size: .78rem;
      margin-left: .5rem;
      font-weight: 400;
    }

    .toolbar {
      display: flex;
      flex-wrap: wrap;
      gap: .45rem;
      justify-content: flex-end;
    }

    button {
      border: 1px solid var(--border);
      background: var(--panel-2);
      color: var(--text);
      border-radius: 7px;
      padding: .48rem .68rem;
      cursor: pointer;
      font-weight: 700;
      transition: transform .12s ease, border-color .12s ease, background .12s ease;
    }

    button:hover {
      transform: translateY(-1px);
      border-color: var(--accent-2);
      background: #2d3142;
    }
.theme-picker {
      height: 36px;
      border: 1px solid var(--border);
      background: var(--panel-2);
      color: var(--text);
      border-radius: 7px;
      padding: 0 .55rem;
      font-weight: 700;
      cursor: pointer;
      outline: none;
    }

    .theme-picker:hover,
    .theme-picker:focus {
      border-color: var(--accent-2);
      background: #2d3142;
    }

    button.primary,
    button.active-layout {
      background: linear-gradient(135deg, var(--accent), #5f1fb5);
      border-color: var(--accent-2);
    }

    .icon-button,
    .layout-icon-btn {
      width: 42px;
      height: 36px;
      padding: 0;
      display: inline-grid;
      place-items: center;
    }

    .new-tab-icon {
      position: relative;
      width: 22px;
      height: 18px;
      display: inline-block;
    }

    .new-tab-icon::before,
    .new-tab-icon::after {
      content: "";
      position: absolute;
      border: 2px solid currentColor;
      border-radius: 3px;
      background: rgba(255,255,255,.04);
    }

    .new-tab-icon::before {
      width: 14px;
      height: 11px;
      left: 1px;
      top: 5px;
      opacity: .8;
    }

    .new-tab-icon::after {
      width: 14px;
      height: 11px;
      right: 1px;
      top: 1px;
      box-shadow: 0 0 0 2px rgba(36,39,52,.85);
    }

    .layout-icon {
      width: 30px;
      height: 25px;
      display: grid;
      gap: 2px;
      padding: 1px;
    }

    .layout-icon .mini {
      border: 0;
      background: currentColor;
      min-width: 0;
      min-height: 0;
      box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
    }

    .layout-icon .editor-a,
    .layout-icon .editor-b,
    .layout-icon .editor-c,
    .layout-icon .preview-mini {
      background: currentColor;
    }

    .layout-icon-1 {
      grid-template-columns: repeat(3, 1fr);
      grid-template-rows: 9px 13px;
    }

    .layout-icon-1 .editor-a {
      border-radius: 4px 0 0 0;
    }

    .layout-icon-1 .editor-b {
      border-radius: 2px;
    }

    .layout-icon-1 .editor-c {
      border-radius: 0 4px 0 0;
    }

    .layout-icon-1 .preview-mini {
      grid-column: 1 / 4;
      border-radius: 0 0 4px 4px;
    }

    .layout-icon-2 {
      grid-template-columns: repeat(3, 1fr);
      grid-template-rows: 13px 9px;
    }

    .layout-icon-2 .preview-mini {
      grid-column: 1 / 4;
      grid-row: 1;
      border-radius: 4px 4px 0 0;
    }

    .layout-icon-2 .editor-a {
      border-radius: 0 0 0 4px;
    }

    .layout-icon-2 .editor-b {
      border-radius: 2px;
    }

    .layout-icon-2 .editor-c {
      border-radius: 0 0 4px 0;
    }

    .layout-icon-3 {
      grid-template-columns: 11px 16px;
      grid-template-rows: 1fr 1fr 1fr;
    }

    .layout-icon-3 .editor-a {
      grid-column: 1;
      border-radius: 4px 0 0 0;
    }

    .layout-icon-3 .editor-b {
      grid-column: 1;
      border-radius: 2px;
    }

    .layout-icon-3 .editor-c {
      grid-column: 1;
      border-radius: 0 0 0 4px;
    }

    .layout-icon-3 .preview-mini {
      grid-column: 2;
      grid-row: 1 / 4;
      border-radius: 0 4px 4px 0;
    }

    .layout-icon-4 {
      grid-template-columns: 16px 11px;
      grid-template-rows: 1fr 1fr 1fr;
    }

    .layout-icon-4 .preview-mini {
      grid-column: 1;
      grid-row: 1 / 4;
      border-radius: 4px 0 0 4px;
    }

    .layout-icon-4 .editor-a {
      grid-column: 2;
      border-radius: 0 4px 0 0;
    }

    .layout-icon-4 .editor-b {
      grid-column: 2;
      border-radius: 2px;
    }

    .layout-icon-4 .editor-c {
      grid-column: 2;
      border-radius: 0 0 4px 0;
    }

    main {
      height: calc(100vh - 64px);
      padding: 6px;
      gap: 4px;
      display: grid;
      min-width: 0;
      min-height: 0;
    }

    .layout-1 {
      grid-template-columns: 1fr;
      grid-template-rows: minmax(170px, var(--topSize, 34%)) 6px minmax(220px, 1fr);
    }

    .layout-2 {
      grid-template-columns: 1fr;
      grid-template-rows: minmax(220px, 1fr) 6px minmax(170px, var(--bottomSize, 34%));
    }

    .layout-3 {
      grid-template-columns: minmax(300px, var(--leftSize, 50%)) 6px minmax(300px, 1fr);
      grid-template-rows: 1fr;
    }

    .layout-4 {
      grid-template-columns: minmax(300px, 1fr) 6px minmax(300px, var(--rightSize, 50%));
      grid-template-rows: 1fr;
    }

    .editors {
      display: flex;
      gap: 4px;
      min-width: 0;
      min-height: 0;
      overflow: hidden;
    }

    .editors-row {
      flex-direction: row;
      height: var(--editorPanelHeight);
      width: 100%;
      align-self: stretch;
    }

    .editors-column {
      flex-direction: column;
      width: var(--editorPanelWidth);
      height: 100%;
      justify-self: stretch;
    }

    .output-stack {
      display: grid;
      gap: 4px;
      min-width: 0;
      min-height: 0;
    }

    .layout-3 .output-stack,
    .layout-4 .output-stack {
      grid-template-columns: 1fr;
      grid-template-rows: minmax(260px, var(--previewSize, 1fr)) 6px minmax(90px, var(--consoleSize, 16%));
    }

    .layout-1 .output-stack,
    .layout-2 .output-stack {
      display: grid;
      grid-template-columns: 1fr;
      grid-template-rows: minmax(260px, var(--previewSize, 1fr)) 6px minmax(90px, var(--consoleSize, 14%));
    }

    .panel {
      background: rgba(27,29,38,.96);
      border: 1px solid var(--border);
      border-radius: 10px;
      box-shadow: 0 8px 24px var(--shadow);
      overflow: hidden;
      min-width: 0;
      min-height: 0;
      resize: none;
    }

    .editor-panel {
      min-width: 120px;
      min-height: 85px;
    }

    .editors-row .editor-panel {
      flex: 1 1 0;
      height: var(--editorPanelHeight);
    }

    .editors-column .editor-panel {
      width: var(--editorPanelWidth);
      flex: 1 1 0;
    }

    .editors-row .editor-splitter {
      display: block;
      flex: 0 0 6px;
      height: var(--editorPanelHeight);
    }

    .editors-column .editor-splitter {
      display: block;
      flex: 0 0 6px;
      width: var(--editorPanelWidth);
      height: 6px;
    }

    .preview-panel,
    .console-panel {
      resize: none;
      min-width: 260px;
      min-height: 90px;
    }

    .preview-panel {
      background: #fff;
    }

    .console-panel {
      background: #090a0f;
      color: #e8e8e8;
    }

    .panel-title {
      height: 36px;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      gap: .55rem;
      padding: 0 .75rem;
      background: linear-gradient(180deg, #282c3a, #202331);
      border-bottom: 1px solid var(--border);
      color: var(--text);
      font-size: .9rem;
      font-weight: 700;
    }

    .panel-title .badge {
      margin-left: auto;
    }

    .editor-title .fullscreen-btn {
      margin-left: auto;
    }

    .fullscreen-btn {
      width: 25px;
      height: 25px;
      display: grid;
      place-items: center;
      padding: 0;
      border-radius: 6px;
      font-size: .9rem;
      line-height: 1;
      background: rgba(255,255,255,.06);
    }

    .fullscreen-btn.active {
      background: linear-gradient(135deg, var(--accent), #5f1fb5);
      border-color: var(--accent-2);
    }

    .editor-panel:fullscreen, .preview-panel:fullscreen, .console-panel:fullscreen  {
      width: 100vw !important;
      height: 100vh !important;
      max-width: none !important;
      max-height: none !important;
      flex: none !important;
      border-radius: 0;
      border: none;
      min-width: 0;
      min-height: 0;
      background: rgba(27,29,38,.98);
    }

    .editor-panel:fullscreen .editor-wrap {
      height: calc(100vh - 36px);
    }

    .editor-panel:fullscreen .CodeMirror {
      width: 100vw !important;
      height: calc(100vh - 36px) !important;
    }

    .editor-panel:fullscreen .CodeMirror-scroll {
      width: 100% !important;
      height: 100% !important;
    }

    .editor-panel.fullscreen-fallback, .preview-panel.fullscreen-fallback, .console-panel.fullscreen-fallback {
      position: fixed !important;
      inset: 0 !important;
      z-index: 9999;
      width: 100vw !important;
      height: 100vh !important;
      max-width: none !important;
      max-height: none !important;
      border-radius: 0;
      border: none;
      min-width: 0;
      min-height: 0;
      flex: none !important;
      background: rgba(27,29,38,.98);
      box-shadow: 0 0 0 9999px rgba(0,0,0,.75);
    }

    .editor-panel.fullscreen-fallback .editor-wrap {
      height: calc(100vh - 36px);
    }

    .editor-panel.fullscreen-fallback .CodeMirror {
      width: 100vw !important;
      height: calc(100vh - 36px) !important;
    }

    .editor-panel.fullscreen-fallback .CodeMirror-scroll {
      width: 100% !important;
      height: 100% !important;
    }

    body:has(.fullscreen-fallback) .editor-splitter,
    body:has(.fullscreen-fallback) #mainSplitter,
    body:has(.fullscreen-fallback) #outputStack {
      display: none !important;
    }

    .badge {
      color: var(--muted);
      font-size: .75rem;
      font-weight: 400;
    }

    .editor-wrap {
      height: calc(100% - 36px);
    }


    .CodeMirror-selected {
      background: rgba(177, 105, 255, 0.38) !important;
    }

    .CodeMirror-focused .CodeMirror-selected {
      background: rgba(177, 105, 255, 0.52) !important;
    }

    .CodeMirror-line::selection,
    .CodeMirror-line > span::selection,
    .CodeMirror-line > span > span::selection {
      background: rgba(177, 105, 255, 0.52);
    }


    .CodeMirror {
      height: 100%;
      font-size: var(--editorFontSize);
      line-height: 1.45;
      font-family: Consolas, Monaco, "Courier New", monospace;
    }

    .preview-frame {
      width: 100%;
      height: calc(100% - 36px);
      border: 0;
      background: white;
      display: block;
    }

    .console-body {
      height: calc(100% - 36px);
      overflow: auto;
      padding: .65rem .85rem;
      font-family: Consolas, Monaco, "Courier New", monospace;
      font-size: 13px;
      line-height: 1.45;
      white-space: pre-wrap;
    }

    .console-line {
      padding: .18rem 0;
      border-bottom: 1px solid rgba(255,255,255,.04);
    }

    .splitter {
      background: transparent;
      border-radius: 999px;
      position: relative;
      z-index: 10;
      flex: 0 0 10px;
    }

    .splitter::before {
      content: "";
      position: absolute;
      border-radius: 999px;
      background: rgba(177,105,255,.25);
      transition: background .12s ease;
    }

    .splitter-horizontal::before {
      left: 1px;
      right: 1px;
      top: 2px;
      height: 2px;
    }

    .splitter-vertical::before {
      top: 1px;
      bottom: 1px;
      left: 2px;
      width: 2px;
    }

    .splitter:hover::before,
    .splitter.dragging::before {
      background: rgba(177,105,255,.65);
    }

    .splitter-horizontal {
      cursor: row-resize;
      width: 100%;
      height: 6px;
    }

    .splitter-vertical {
      cursor: col-resize;
      height: 100%;
      width: 6px;
    }

    body.resizing {
      user-select: none;
      cursor: grabbing;
    }


    .console-log { color: #e8e8e8; }
    .console-warn { color: #ffd166; }
    .console-error { color: var(--danger); }
    .console-info { color: #7cc7ff; }

    .modal-overlay {
      position: fixed;
      inset: 0;
      z-index: 20000;
      display: grid;
      place-items: center;
      padding: 1rem;
      background: rgba(0,0,0,.68);
      backdrop-filter: blur(3px);
    }

    .modal-overlay[hidden] {
      display: none;
    }

    .modal-dialog {
      width: min(430px, 94vw);
      padding: 1.25rem;
      border: 1px solid var(--border);
      border-radius: 12px;
      background: linear-gradient(180deg, #252938, #181a23);
      box-shadow: 0 24px 70px rgba(0,0,0,.55);
      color: var(--text);
    }

    .modal-dialog h2 {
      margin: 0 0 .65rem;
      font-size: 1.25rem;
    }

    .modal-dialog p {
      margin: 0;
      color: var(--muted);
      line-height: 1.45;
    }

    .modal-actions {
      display: flex;
      justify-content: flex-end;
      gap: .55rem;
      margin-top: 1.1rem;
    }

    .danger-button {
      background: linear-gradient(135deg, #d83b5c, #9e1635);
      border-color: #ff7990;
    }

    .danger-button:hover {
      background: linear-gradient(135deg, #ec496b, #aa1b3b);
      border-color: #ffa2b1;
    }

    @media (max-width: 950px) {
      body {
        overflow: auto;
      }

      header {
        align-items: flex-start;
        flex-direction: column;
      }

      main,
      .layout-1,
      .layout-2,
      .layout-3,
      .layout-4 {
        height: auto;
        min-height: calc(100vh - 64px);
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
      }

      .layout-3 .output-stack,
      .layout-4 .output-stack,
      .layout-1 .output-stack,
      .layout-2 .output-stack {
        grid-template-rows: 360px 6px 180px;
      }

      .splitter {
        display: none;
      }

      .editor-splitter {
        display: none !important;
      }

      .editors,
      .editors-row,
      .editors-column {
        flex-direction: column;
        width: 100%;
        height: auto;
      }

      .editors-row .editor-panel,
      .editors-column .editor-panel {
        width: 100% !important;
        height: 260px !important;
        flex: none !important;
      }

      .preview-panel {
        height: 360px;
      }

      .console-panel {
        height: 180px;
      }
    }