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

  :root {
    --ink: #1a1814;
    --ink-soft: #4a4540;
    --ink-muted: #8a8480;
    --paper: #faf9f6;
    --paper-warm: #f2efe8;
    --paper-card: #ffffff;
    --border: #e0ddd4;
    --border-strong: #c8c4b8;
    --accent: #c84b2f;
    --accent-soft: #f5ede9;
    --accent-hover: #a33920;
    --teal: #1d6e6e;
    --teal-soft: #e6f2f2;
    --gold: #b07d2a;
    --gold-soft: #f7f0e2;
    --success: #2d6a4f;
    --success-soft: #e8f4ee;
    --panel-w: 340px;
    --toolbar-h: 56px;
    --radius: 6px;
    --shadow: 0 2px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.08);
  }

  body {
    font-family: 'DM Sans', sans-serif;
    background: var(--paper);
    color: var(--ink);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* TOOLBAR */
  #toolbar {
    height: var(--toolbar-h);
    background: var(--ink);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    flex-shrink: 0;
    border-bottom: 1px solid #333;
    z-index: 100;
  }

  .logo {
    font-family: 'Fraunces', serif;
    font-size: 20px;
    font-weight: 300;
    color: #fff;
    letter-spacing: -0.5px;
    margin-right: 8px;
  }
  .logo span { color: var(--accent); font-weight: 600; }

  .toolbar-sep { width: 1px; height: 28px; background: #444; margin: 0 4px; }

  .tb-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 14px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: transparent;
    color: #ccc;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
  }
  .tb-btn:hover { background: #2a2a2a; color: #fff; border-color: #444; }
  .tb-btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
  .tb-btn.primary:hover { background: var(--accent-hover); }
  .tb-btn.success { background: var(--success); color: #fff; }
  .tb-btn.success:hover { background: #1d5438; }

  .tb-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

  .tb-spacer { flex: 1; }

  .view-toggle {
    display: flex;
    background: #2a2a2a;
    border-radius: var(--radius);
    border: 1px solid #444;
    overflow: hidden;
  }
  .view-toggle button {
    padding: 5px 14px;
    border: none;
    background: transparent;
    color: #888;
    font-family: 'DM Sans', sans-serif;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
  }
  .view-toggle button.active { background: #444; color: #fff; }

  /* MAIN LAYOUT */
  #app { display: flex; flex: 1; overflow: hidden; }

  /* SIDE PANEL */
  #side-panel {
    width: var(--panel-w);
    background: var(--paper-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
  }

  .panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--paper-warm);
  }
  .panel-tab {
    flex: 1; padding: 12px 8px;
    border: none; background: transparent;
    font-family: 'DM Sans', sans-serif;
    font-size: 12px; font-weight: 500;
    color: var(--ink-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }
  .panel-tab.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--paper-card); }

  .panel-body { flex: 1; overflow-y: auto; padding: 0; }

  /* UPLOAD ZONE */
  #upload-zone {
    margin: 20px;
    border: 1.5px dashed var(--border-strong);
    border-radius: 10px;
    padding: 28px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--paper);
  }
  #upload-zone:hover, #upload-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-soft);
  }
  #upload-zone svg { color: var(--ink-muted); margin-bottom: 10px; }
  #upload-zone .uz-title { font-size: 14px; font-weight: 500; margin-bottom: 4px; }
  #upload-zone .uz-sub { font-size: 12px; color: var(--ink-muted); }
  #file-input { display: none; }

  /* PASTE BOX */
  .paste-section { padding: 0 20px 20px; }
  .paste-label { font-size: 11px; font-weight: 500; color: var(--ink-muted); letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 8px; }
  #paste-area {
    width: 100%;
    min-height: 140px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    font-family: 'DM Mono', monospace;
    font-size: 11.5px;
    color: var(--ink);
    background: var(--paper);
    resize: vertical;
    outline: none;
    transition: border-color 0.15s;
    line-height: 1.6;
  }
  #paste-area:focus { border-color: var(--accent); }

  .load-btn {
    width: 100%;
    margin-top: 10px;
    padding: 10px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
  }
  .load-btn:hover { background: var(--accent-hover); }

  /* IMAGES PANEL */
  #images-list { padding: 16px 20px; }
  .img-item {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    background: var(--paper);
    transition: border-color 0.15s;
  }
  .img-item:hover { border-color: var(--border-strong); }
  .img-thumb {
    width: 48px; height: 48px; border-radius: 4px;
    object-fit: cover; flex-shrink: 0;
    border: 1px solid var(--border);
    background: var(--paper-warm);
  }
  .img-thumb-placeholder {
    width: 48px; height: 48px; border-radius: 4px; flex-shrink: 0;
    background: var(--paper-warm); border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    color: var(--ink-muted);
  }
  .img-details { flex: 1; min-width: 0; }
  .img-tag { font-size: 10px; font-weight: 500; color: var(--teal); background: var(--teal-soft); padding: 2px 6px; border-radius: 3px; display: inline-block; margin-bottom: 4px; }
  .img-url-input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 5px 8px;
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    color: var(--ink);
    background: #fff;
    outline: none;
    transition: border-color 0.15s;
  }
  .img-url-input:focus { border-color: var(--teal); }
  .img-apply-btn {
    margin-top: 6px;
    padding: 4px 10px;
    background: var(--teal);
    color: #fff;
    border: none; border-radius: 4px;
    font-family: 'DM Sans', sans-serif;
    font-size: 11px; cursor: pointer;
    transition: background 0.15s;
  }
  .img-apply-btn:hover { background: #155c5c; }

  .empty-state { padding: 32px 20px; text-align: center; color: var(--ink-muted); font-size: 13px; }
  .empty-state svg { margin-bottom: 10px; opacity: 0.4; }

  /* EDITOR AREA */
  #editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #e8e6e0;
  }

  #editor-header {
    height: 36px;
    background: var(--paper-warm);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 8px;
    flex-shrink: 0;
  }
  .breadcrumb { font-size: 12px; color: var(--ink-muted); font-family: 'DM Mono', monospace; }
  .editing-badge {
    font-size: 10px; font-weight: 500; letter-spacing: 0.05em;
    text-transform: uppercase; padding: 2px 8px; border-radius: 10px;
    background: var(--success-soft); color: var(--success);
  }

  #preview-wrapper {
    flex: 1;
    overflow: auto;
    padding: 32px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
  }

  #preview-frame-box {
    background: #fff;
    box-shadow: var(--shadow-lg);
    border-radius: 8px;
    overflow: visible;
    width: 100%;
    max-width: 1100px;
    align-self: flex-start;
  }

  #preview-frame {
    width: 100%;
    display: block;
    border: none;
    height: 600px;
  }

  /* raw html view */
  #raw-view {
    flex: 1; overflow: auto; padding: 24px;
    display: none;
  }
  #raw-view pre {
    font-family: 'DM Mono', monospace;
    font-size: 12.5px;
    line-height: 1.7;
    color: var(--ink);
    white-space: pre-wrap;
    word-break: break-all;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
  }

  /* FLOATING TOOLBAR */
  #float-toolbar {
    position: fixed;
    z-index: 99999;
    background: var(--ink);
    border-radius: 8px;
    padding: 6px 8px;
    display: none;
    align-items: center;
    gap: 2px;
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
  }
  #float-toolbar.visible { display: flex; }

  .ft-btn {
    width: 30px; height: 30px;
    border: none; border-radius: 5px;
    background: transparent;
    color: #ccc;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600;
    transition: all 0.12s;
    font-family: 'DM Sans', sans-serif;
  }
  .ft-btn:hover { background: #333; color: #fff; }
  .ft-btn.active { background: var(--accent); color: #fff; }
  .ft-sep { width: 1px; height: 20px; background: #444; margin: 0 2px; }

  .ft-color-wrap { position: relative; }
  .ft-color-btn {
    width: 30px; height: 30px; border-radius: 5px;
    border: none; background: transparent;
    cursor: pointer; display: flex; align-items: center;
    justify-content: center; gap: 0; flex-direction: column;
    padding: 0;
  }
  .ft-color-letter { font-size: 14px; font-weight: 700; color: #fff; line-height: 1; }
  .ft-color-bar { width: 16px; height: 3px; border-radius: 2px; background: #e24b4a; margin-top: 1px; }
  #color-picker-input { position: absolute; opacity: 0; width: 0; height: 0; }

  /* LINK POPUP */
  #link-popup {
    position: fixed;
    z-index: 99999;
    background: var(--paper-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    box-shadow: var(--shadow-lg);
    width: 280px;
    display: none;
  }
  #link-popup.visible { display: block; }
  .lp-title { font-size: 12px; font-weight: 500; color: var(--ink-muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
  .lp-field { margin-bottom: 8px; }
  .lp-label { font-size: 11px; color: var(--ink-muted); margin-bottom: 4px; display: block; }
  .lp-input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    font-family: 'DM Mono', monospace;
    font-size: 12px;
    color: var(--ink);
    outline: none;
    transition: border-color 0.15s;
  }
  .lp-input:focus { border-color: var(--teal); }
  .lp-actions { display: flex; gap: 8px; margin-top: 10px; }
  .lp-save { flex: 1; padding: 7px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); font-family: 'DM Sans', sans-serif; font-size: 12px; font-weight: 500; cursor: pointer; }
  .lp-save:hover { background: var(--accent-hover); }
  .lp-cancel { padding: 7px 12px; background: var(--paper-warm); color: var(--ink-muted); border: 1px solid var(--border); border-radius: var(--radius); font-family: 'DM Sans', sans-serif; font-size: 12px; cursor: pointer; }
  .lp-cancel:hover { color: var(--ink); }

  /* PLACEHOLDER / IDLE */
  #idle-screen {
    flex: 1; display: flex; align-items: center; justify-content: center;
    flex-direction: column; gap: 16px; color: var(--ink-muted);
    text-align: center; padding: 32px;
  }
  .idle-icon { opacity: 0.25; }
  .idle-title { font-family: 'Fraunces', serif; font-size: 22px; font-weight: 300; color: var(--ink-soft); }
  .idle-sub { font-size: 13px; max-width: 280px; }

  /* NOTIFICATION */
  #notif {
    position: fixed; bottom: 20px; right: 20px;
    background: var(--ink); color: #fff;
    padding: 10px 18px; border-radius: var(--radius);
    font-size: 13px; box-shadow: var(--shadow-lg);
    opacity: 0; transform: translateY(8px);
    transition: all 0.25s; pointer-events: none; z-index: 99999;
  }
  #notif.show { opacity: 1; transform: translateY(0); }
  #notif.green { background: var(--success); }

  /* SCROLLBAR */
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
