    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    :root {
      --bg: #ffffff;
      --bg-alt: #f8fafc;
      --surface: #f8fafc;
      --card-bg: #ffffff;
      --text: #0f172a;
      --text-secondary: #475569;
      --border: #e2e8f0;
      --primary: #3b82f6;
      --primary-hover: #2563eb;
      --radius: 8px;
      --shadow: 0 1px 3px rgba(0,0,0,0.08);
      --font: 'Inter', system-ui, -apple-system, sans-serif;
      --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
    }

    body.dark-ui {
      --bg: #0f172a;
      --bg-alt: #1e293b;
      --surface: #1e293b;
      --card-bg: #1e293b;
      --text: #f1f5f9;
      --text-secondary: #94a3b8;
      --border: #334155;
      --primary: #3b82f6;
      --primary-hover: #60a5fa;
      --shadow: 0 1px 3px rgba(0,0,0,0.3);
    }

    body {
      font-family: var(--font);
      background: var(--bg);
      color: var(--text);
      height: 100vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }

    /* Header — left/center/right on desktop */
    .header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 8px 16px;
      border-bottom: 1px solid var(--border);
      background: var(--bg);
      flex-shrink: 0;
      gap: 8px;
      position: sticky;
      top: 0;
      z-index: 100;
    }

    .header-left {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    /* Mobile fullscreen button hidden on desktop */
    .show-mobile-only { display: none; }

    .logo {
      font-size: 14px;
      font-weight: 700;
      color: var(--text);
      white-space: nowrap;
    }

    .logo-sub { color: var(--text-secondary); font-weight: 400; }
    .logo-short { display: none; }
    .logo-full { display: inline; }

    .header-center {
      display: flex;
      align-items: center;
      gap: 4px;
    }

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

    /* Template name indicator */
    .template-name {
      font-size: 12px;
      color: var(--text-secondary);
      max-width: 160px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .template-name:empty {
      display: none;
    }

    /* Buttons */
    .btn {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 6px 12px;
      border: 1px solid var(--border);
      border-radius: 6px;
      background: var(--bg);
      color: var(--text);
      font-size: 13px;
      font-family: var(--font);
      cursor: pointer;
      transition: all 0.15s ease;
      white-space: nowrap;
      min-height: 32px;
    }

    .btn:hover { background: var(--bg-alt); border-color: #cbd5e1; }
    .btn.active { background: var(--primary); color: white; border-color: var(--primary); }
    .btn.active:hover { background: var(--primary-hover); }

    .btn-primary {
      background: var(--primary);
      color: white;
      border-color: var(--primary);
    }
    .btn-primary:hover { background: var(--primary-hover); }

    .btn-icon {
      padding: 6px;
      min-width: 32px;
      justify-content: center;
    }

    /* Viewport buttons */
    .viewport-group {
      display: flex;
      border: 1px solid var(--border);
      border-radius: 6px;
      overflow: hidden;
    }

    .viewport-group .btn {
      border: none;
      border-radius: 0;
      border-right: 1px solid var(--border);
      min-height: 32px;
    }

    .viewport-group .btn:last-child { border-right: none; }

    /* Main layout */
    .main {
      display: flex;
      flex: 1;
      min-height: 0;
    }

    /* Editor panel */
    .editor-panel {
      width: var(--editor-width, 50%);
      display: flex;
      flex-direction: column;
      border-right: none;
      min-width: 0;
    }

    .divider {
      width: 6px;
      background: var(--bg-alt);
      border-left: 1px solid var(--border);
      border-right: 1px solid var(--border);
      cursor: col-resize;
      flex-shrink: 0;
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: background 0.15s ease;
    }
    .divider:hover, .divider.dragging {
      background: var(--border);
    }
    .divider::after {
      content: '';
      width: 2px;
      height: 24px;
      border-radius: 1px;
      background: var(--text-secondary);
    }

    .editor-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 6px 12px;
      border-bottom: 1px solid var(--border);
      background: var(--bg-alt);
      flex-shrink: 0;
    }

    .editor-header span {
      font-size: 12px;
      font-weight: 600;
      color: var(--text-secondary);
      text-transform: uppercase;
      letter-spacing: 0.05em;
    }

    /* Monaco editor fills container */
    #editorContainer {
      min-height: 0;
    }

    /* Preview panel */
    .preview-panel {
      flex: 1;
      display: flex;
      flex-direction: column;
      min-width: 0;
      background: var(--bg-alt);
    }

    .preview-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 6px 12px;
      border-bottom: 1px solid var(--border);
      background: var(--bg-alt);
      flex-shrink: 0;
    }

    .preview-header span {
      font-size: 12px;
      font-weight: 600;
      color: var(--text-secondary);
      text-transform: uppercase;
      letter-spacing: 0.05em;
    }

    .preview-container {
      flex: 1;
      display: flex;
      justify-content: center;
      padding: 16px;
      overflow: auto;
      min-height: 0;
    }

    .preview-container iframe {
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      width: 100%;
      height: 100%;
      min-height: 0;
      transition: width 0.3s ease;
    }

    /* Presets dropdown */
    .presets-dropdown {
      position: relative;
    }

    .presets-menu {
      display: none;
      position: absolute;
      top: 100%;
      left: 0;
      margin-top: 4px;
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      box-shadow: 0 4px 12px rgba(0,0,0,0.1);
      min-width: 180px;
      z-index: 100;
      padding: 4px;
    }

    .presets-menu.open { display: flex; flex-direction: column; }

    .presets-search {
      position: sticky;
      top: 0;
      z-index: 1;
      padding: 6px;
      background: var(--bg);
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }

    .presets-search input {
      width: 100%;
      padding: 6px 8px 6px 30px;
      border: 1px solid var(--border);
      border-radius: 6px;
      font-size: 13px;
      font-family: var(--font);
      color: var(--text);
      background: var(--bg);
      outline: none;
    }

    .presets-search input:focus {
      border-color: var(--primary);
      box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
    }

    .presets-search input::placeholder { color: var(--text-secondary); }

    .presets-search svg {
      position: absolute;
      left: 14px;
      top: 50%;
      transform: translateY(-50%);
      pointer-events: none;
    }

    .presets-list {
      overflow-y: auto;
      flex: 1;
      padding: 4px;
    }

    .presets-empty {
      padding: 16px 12px;
      text-align: center;
      font-size: 13px;
      color: var(--text-secondary);
    }

    .theme-swatch {
      width: 16px;
      height: 16px;
      border-radius: 50%;
      border: 2px solid transparent;
      cursor: pointer;
      transition: border-color 0.15s, transform 0.15s;
      padding: 0;
      flex-shrink: 0;
    }
    .theme-swatch:hover { transform: scale(1.2); }
    .theme-swatch.active {
      border-color: var(--text);
      box-shadow: 0 0 0 2px var(--bg);
    }

    .pers-btn {
      padding: 3px 10px;
      border: 1.5px solid var(--primary);
      border-radius: 9999px;
      background: var(--bg);
      color: var(--primary);
      font-size: 11px;
      font-weight: 600;
      font-family: var(--font);
      cursor: pointer;
      transition: all 0.15s ease;
      white-space: nowrap;
    }
    .pers-btn:hover { background: var(--primary); color: white; }
    .pers-btn.active { background: var(--primary); color: white; }

    .style-btn {
      padding: 3px 8px;
      border: 1px solid var(--border);
      border-radius: 4px;
      background: var(--bg);
      color: var(--text-secondary);
      font-size: 11px;
      font-family: var(--font);
      cursor: pointer;
      transition: all 0.15s ease;
      white-space: nowrap;
    }
    .style-btn:hover { border-color: var(--text-secondary); }
    .style-btn.active { background: var(--text); color: var(--bg); border-color: var(--text); }

    .presets-menu button {
      display: block;
      width: 100%;
      text-align: left;
      padding: 8px 12px;
      border: none;
      background: none;
      font-size: 13px;
      font-family: var(--font);
      color: var(--text);
      cursor: pointer;
      border-radius: 4px;
    }

    .presets-menu button:hover { background: var(--bg-alt); }

    /* Template button + nav arrows + name — single row */
    .template-btn-group {
      display: inline-flex;
      align-items: center;
      gap: 0;
    }
    .template-btn-group > .btn.has-nav {
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
      border-right: none;
    }
    .template-btn-group > .template-nav {
      display: flex;
      align-items: center;
      border: 1px solid var(--border);
      border-left: none;
      border-radius: 0;
      overflow: hidden;
    }
    .template-btn-group > .template-name {
      padding: 0 10px;
      border: 1px solid var(--border);
      border-left: none;
      border-radius: 0 6px 6px 0;
      min-height: 32px;
      display: inline-flex;
      align-items: center;
      background: var(--bg);
    }
    /* When no nav arrows, name attaches directly to button */
    .template-btn-group > .btn:not(.has-nav) + .template-nav + .template-name:not(:empty) {
      border-left: none;
      border-radius: 0 6px 6px 0;
    }
    .template-btn-group > .btn.has-nav ~ .template-name:not(:empty) {
      border-radius: 0 6px 6px 0;
    }
    /* Hide border artifacts when name is empty */
    .template-btn-group > .template-name:empty {
      display: none;
    }
    .btn-nav {
      padding: 4px 5px;
      min-width: 26px;
      min-height: 30px;
      border: none;
      border-radius: 0;
      background: var(--bg);
      color: var(--text);
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      transition: background 0.15s ease;
      font-size: 0;
    }
    .btn-nav:hover { background: var(--bg-alt); }
    .btn-nav + .btn-nav { border-left: 1px solid var(--border); }


    /* Toast notification */
    .toast {
      position: fixed;
      bottom: 16px;
      right: 16px;
      background: #0f172a;
      color: #f1f5f9;
      padding: 10px 16px;
      border-radius: var(--radius);
      font-size: 13px;
      opacity: 0;
      transform: translateY(8px);
      transition: all 0.2s ease;
      pointer-events: none;
      z-index: 1100;
    }

    body.dark-ui .toast {
      background: #f1f5f9;
      color: #0f172a;
    }

    .toast.show {
      opacity: 1;
      transform: translateY(0);
    }

    /* Mobile tab bar (hidden on desktop) */
    .mobile-tabs {
      display: none;
    }
    .mobile-tab {
      flex: 1;
      padding: 8px 0;
      border: none;
      background: var(--bg);
      color: var(--text-secondary);
      font-size: 13px;
      font-weight: 600;
      font-family: var(--font);
      cursor: pointer;
      border-bottom: 2px solid transparent;
      transition: all 0.15s ease;
    }
    .mobile-tab.active {
      color: var(--primary);
      border-bottom-color: var(--primary);
    }

    /* Mobile preview toolbar (hidden on desktop) */
    .mobile-preview-toolbar {
      display: none;
      background: var(--bg-alt);
    }
    .mobile-toolbar-toggle {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      width: 100%;
      padding: 6px 12px;
      border: none;
      background: none;
      color: var(--text-secondary);
      font-size: 11px;
      font-family: var(--font);
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      cursor: pointer;
      min-height: 32px;
    }
    .mobile-toolbar-toggle:active {
      background: var(--border);
    }
    .mobile-toolbar-chevron {
      transition: transform 0.2s ease;
    }
    .mobile-toolbar-toggle[aria-expanded="true"] .mobile-toolbar-chevron {
      transform: rotate(180deg);
    }
    .mobile-toolbar-content {
      display: none;
      flex-direction: column;
      gap: 8px;
      padding: 0 10px 10px;
    }
    .mobile-toolbar-content.open {
      display: flex;
    }
    .mobile-toolbar-row {
      display: flex;
      align-items: center;
      gap: 4px;
      flex-wrap: wrap;
    }
    .mobile-toolbar-row:empty {
      display: none;
    }

    /* Fullscreen preview mode */
    body.fullscreen-preview .header,
    body.fullscreen-preview .mobile-tabs,
    body.fullscreen-preview .editor-panel,
    body.fullscreen-preview .divider,
    body.fullscreen-preview .preview-header,
    body.fullscreen-preview .mobile-preview-toolbar {
      display: none !important;
    }
    body.fullscreen-preview .preview-panel {
      position: fixed;
      inset: 0;
      z-index: 1000;
    }
    body.fullscreen-preview .preview-container {
      padding: 0;
      border-radius: 0;
    }
    body.fullscreen-preview .preview-container iframe {
      border: none;
      border-radius: 0;
      box-shadow: none;
    }

    /* Mobile layout */
    @media (max-width: 768px) {
      .header {
        display: grid;
        grid-template-columns: auto 1fr auto;
        align-items: center;
        padding: 6px 10px;
        gap: 4px 8px;
      }
      /* Row 1: logo | spacer | buttons */
      .header-left {
        display: contents;
      }
      .logo {
        grid-column: 1;
        grid-row: 1;
      }
      .header-right {
        grid-column: 3;
        grid-row: 1;
        display: flex;
        gap: 4px;
      }
      .header-center { display: none; }
      /* Row 2: template dropdown spans full width */
      .presets-dropdown {
        grid-column: 1 / -1;
        grid-row: 2;
      }
      .hide-mobile { display: none !important; }
      .show-mobile-only { display: inline-flex !important; }
      .divider { display: none; }

      .header-left { min-width: 0; }

      /* Logo: show short version on mobile */
      .logo-full { display: none; }
      .logo-short { display: inline; }

      /* Template name: more room now that logo is shorter */
      .template-name {
        max-width: 140px;
        font-size: 11px;
      }
      .template-btn-group {
        max-width: calc(100vw - 80px);
        overflow: hidden;
      }
      .template-btn-group > .template-name {
        padding: 4px 6px;
      }

      /* Tab bar visible */
      .mobile-tabs {
        display: flex;
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
      }

      /* Tab-based panel switching */
      .main { flex-direction: column; }
      .editor-panel {
        width: 100% !important;
        height: 100%;
        border-right: none;
        display: none;
      }
      .editor-panel.mobile-visible {
        display: flex;
      }
      .preview-panel {
        height: 100%;
        display: flex;
      }
      .preview-panel.mobile-hidden {
        display: none;
      }

      /* Hide sub-headers on mobile — controls are in the header/tabs */
      .editor-header { display: none; }
      .preview-header { display: none; }

      /* Mobile preview toolbar visible only when it has controls */
      .mobile-preview-toolbar.has-controls {
        display: flex;
        flex-direction: column;
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
      }
      /* Hide when editor is visible (HTML tab active) */
      .preview-panel.mobile-hidden .mobile-preview-toolbar {
        display: none;
      }

      /* Shorten logo on small screens — only hide subtitle */
      .logo { font-size: 13px; }
      .logo-sub { display: none; }
      .logo-full { display: none; }
      .logo-short { display: inline !important; }
    }
