:root {
    --bg: #191127;
    --surface: #23133a;
    --surface2: #1f1232;
    --border: #3a1c63;
    --border-hover: #5e309d;
    --text: #f0f0f0;
    --text-muted: #d6d6d6;
    --text-dim: #e0e0e0;
    --accent: #883CF0;
    --accent-dim: #1f1232;
    --accent-glow: #ac47ff4d;
    --red: #7c3aed;
    --red-dim: #ac47ff4d;
    --blue: #8b5cf6;
    --blue-dim: #ac47ff4d;
    --radius: 10px;
    --mono: 'DM Mono', monospace;
    --sans: 'Syne', sans-serif;
  }

  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--mono);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
  }

  /* grid bg */
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
      linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
      linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
  }

  /* scanline stripe */
  body::after {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0.6;
    z-index: 100;
    animation: scan 8s ease-in-out infinite;
  }
  @keyframes scan { 0%,100%{top:0;opacity:0} 10%{opacity:0.6} 90%{opacity:0.6} 100%{top:100vh;opacity:0} }

  header {
    position: relative; z-index: 1;
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 32px;
    border-bottom: 1px solid var(--border);
  }

  .logo {
    display: flex; align-items: center; gap: 10px;
  }
  .logo-mark {
    width: 32px; height: 32px;
    background: var(--accent);
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
  }
  .logo-mark svg { width: 18px; height: 18px; }
  .logo-name {
    font-family: var(--sans);
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text);
  }
  .logo-name span { color: var(--accent); }
  .logo-tag {
    font-size: 10px;
    color: var(--text-dim);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-top: 2px;
    font-family: var(--mono);
  }

  .header-right {
    display: flex; align-items: center; gap: 6px;
  }
  .pill {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 99px;
    padding: 5px 12px;
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--mono);
    cursor: default;
  }
  .pill.online { border-color: var(--accent); color: var(--accent); }
  .pill.online::before {
    content: '';
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 6px;
    animation: blink 2s infinite;
  }
  @keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.3} }

  /* ── TABS ── */
  .tabs {
    position: relative; z-index: 1;
    display: flex; gap: 0;
    padding: 0 32px;
    border-bottom: 1px solid var(--border);
  }
  .tab-btn {
    background: none; border: none; cursor: pointer;
    font-family: var(--mono); font-size: 12px;
    color: var(--text-muted);
    padding: 14px 18px 12px;
    letter-spacing: 0.05em;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    text-transform: uppercase;
  }
  .tab-btn:hover { color: var(--text); }
  .tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

  /* ── MAIN ── */
  main {
    position: relative; z-index: 1;
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 0;
    min-height: 0;
  }

  .panel {
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
  }

  .panel-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  .toolbar-left { display: flex; align-items: center; gap: 8px; }
  .toolbar-right { display: flex; align-items: center; gap: 6px; }

  .lang-select {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-family: var(--mono);
    font-size: 11px;
    padding: 4px 8px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
  }
  .lang-select:hover, .lang-select:focus { border-color: var(--border-hover); color: var(--text); }

  .char-count {
    font-size: 11px;
    color: var(--text-dim);
    letter-spacing: 0.03em;
  }
  .char-count.warn { color: #facc15; }
  .char-count.over { color: var(--red); }

  .type-badge {
    font-size: 10px;
    padding: 3px 8px;
    border-radius: 4px;
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--surface2);
    color: var(--text-dim);
    border: 1px solid var(--border);
    transition: all 0.3s;
  }
  .type-badge.url { background: var(--blue-dim); color: var(--blue); border-color: rgba(96,165,250,0.2); }
  .type-badge.code { background: var(--accent-dim); color: var(--accent); border-color: rgba(181,255,71,0.2); }
  .type-badge.json { background: rgba(251,146,60,0.1); color: #fb923c; border-color: rgba(251,146,60,0.2); }

  .editor-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
  }

  .line-nums {
    position: absolute; left: 0; top: 0;
    width: 44px; padding: 20px 0;
    text-align: right;
    font-size: 12px;
    line-height: 1.7;
    color: var(--text-dim);
    user-select: none;
    pointer-events: none;
    background: transparent;
    z-index: 1;
    overflow: hidden;
  }
  .line-nums span { display: block; padding-right: 12px; }

  textarea#editor {
    position: absolute; inset: 0;
    background: transparent;
    border: none; outline: none; resize: none;
    color: var(--text);
    font-family: var(--mono);
    font-size: 13.5px;
    line-height: 1.7;
    padding: 20px 20px 20px 54px;
    width: 100%; height: 100%;
    caret-color: var(--accent);
    tab-size: 2;
  }
  textarea#editor::placeholder {
    color: var(--text-dim);
    font-style: italic;
  }
  textarea#editor::-webkit-scrollbar { width: 4px; }
  textarea#editor::-webkit-scrollbar-track { background: transparent; }
  textarea#editor::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

  /* ── SIDEBAR ── */
  .sidebar {
    display: flex; flex-direction: column;
    overflow-y: auto;
  }
  .sidebar::-webkit-scrollbar { width: 3px; }
  .sidebar::-webkit-scrollbar-thumb { background: var(--border); }

  .sidebar-section {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-section:last-child { border-bottom: none; }

  .section-label {
    font-size: 9px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 12px;
    font-family: var(--sans);
  }

  .option-row {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px;
  }
  .option-label { font-size: 12px; color: var(--text-muted); }

  .seg-control {
    display: flex; gap: 0;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
  }
  .seg-btn {
    background: none; border: none; cursor: pointer;
    font-family: var(--mono); font-size: 11px;
    color: var(--text-muted);
    padding: 5px 10px;
    transition: all 0.15s;
    border-right: 1px solid var(--border);
  }
  .seg-btn:last-child { border-right: none; }
  .seg-btn.active {
    background: var(--accent-dim);
    color: var(--accent);
  }

  .custom-input {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    font-family: var(--mono);
    font-size: 12px;
    padding: 8px 12px;
    outline: none;
    transition: border-color 0.2s;
    margin-top: 4px;
  }
  .custom-input:focus { border-color: var(--accent); }
  .custom-input::placeholder { color: var(--text-dim); font-style: italic; }
  .custom-input.invalid { border-color: var(--red); }

  /* toggle */
  .toggle-row {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px;
  }
  .toggle-label { font-size: 12px; color: var(--text-muted); }
  .toggle {
    width: 34px; height: 18px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 99px;
    cursor: pointer; position: relative;
    transition: all 0.2s;
  }
  .toggle.on { background: var(--accent-dim); border-color: #3a1c63; }
  .toggle::after {
    content: '';
    position: absolute; top: 2px; left: 2px;
    width: 12px; height: 12px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: all 0.2s;
  }
  .toggle.on::after { left: 18px; background: var(--accent); }

  /* submit button */
  .btn-clone {
    width: 100%;
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    color: #0d0d0d;
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 13px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.2s;
    text-transform: uppercase;
  }
  .btn-clone:hover { box-shadow: 0 0 24px var(--accent-glow); transform: translateY(-1px); }
  .btn-clone:active { transform: translateY(0); box-shadow: none; }
  .btn-clone:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
  .btn-clone .loading {
    display: none; position: absolute; inset: 0;
    align-items: center; justify-content: center;
    background: var(--accent);
  }
  .btn-clone.working .loading { display: flex; }
  .btn-clone.working .btn-text { visibility: hidden; }

  .spinner {
    width: 16px; height: 16px;
    border: 2px solid rgba(0,0,0,0.2);
    border-top-color: #0d0d0d;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  .btn-secondary {
    width: 100%;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-family: var(--mono);
    font-size: 11px;
    padding: 9px;
    cursor: pointer;
    transition: all 0.15s;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 6px;
  }
  .btn-secondary:hover { border-color: var(--border-hover); color: var(--text); }

  /* ── RESULT CARD ── */
  .result-card {
    background: var(--surface);
    border: 1px solid rgba(181,255,71,0.25);
    border-radius: var(--radius);
    padding: 16px;
    display: none;
    animation: slideUp 0.3s ease;
  }
  .result-card.show { display: block; }
  @keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

  .result-url-row {
    display: flex; gap: 6px; margin-bottom: 12px;
  }
  .result-url-box {
    flex: 1;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 8px 10px;
    font-size: 12px;
    font-family: var(--mono);
    color: var(--accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: default;
  }
  .copy-url-btn {
    background: var(--accent-dim);
    border: 1px solid rgba(181,255,71,0.3);
    border-radius: 7px;
    color: var(--accent);
    font-family: var(--mono);
    font-size: 11px;
    padding: 8px 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    flex-shrink: 0;
  }
  .copy-url-btn:hover { background: var(--accent); color: #0d0d0d; }
  .copy-url-btn.done { background: var(--accent); color: #0d0d0d; }

  .qr-row {
    display: flex; gap: 12px; align-items: flex-start;
    padding-top: 12px;
    border-top: 1px solid var(--border);
  }
  #qr-canvas {
    width: 72px; height: 72px;
    flex-shrink: 0;
    border-radius: 6px;
    background: white;
    padding: 4px;
    image-rendering: pixelated;
  }
  .result-meta {
    flex: 1;
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.9;
  }
  .result-meta b { color: var(--text); font-weight: 500; }
  .expire-tag {
    display: inline-block;
    padding: 1px 6px;
    background: var(--accent-dim);
    color: var(--accent);
    border-radius: 3px;
    font-size: 10px;
    border: 1px solid rgba(181,255,71,0.2);
  }

  /* ── HISTORY ── */
  .history-list { display: flex; flex-direction: column; gap: 6px; }
  .history-item {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    cursor: pointer;
    transition: all 0.15s;
  }
  .history-item:hover { border-color: var(--border-hover); background: #222; }
  .hist-top {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 3px;
  }
  .hist-code { font-size: 11px; color: var(--accent); font-family: var(--mono); }
  .hist-time { font-size: 10px; color: var(--text-dim); }
  .hist-preview {
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .empty-hist {
    text-align: center; padding: 24px 0;
    font-size: 11px; color: var(--text-dim);
    line-height: 2;
  }

  /* ── RECEIVE PANEL (tab pane) ── */
  .pane { display: none; }
  .pane.active { display: flex; flex-direction: column; }

  .receive-wrap {
    max-width: 560px; margin: 0 auto;
    padding: 48px 32px;
    width: 100%;
  }
  .receive-title {
    font-family: var(--sans);
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
  }
  .receive-sub {
    font-size: 12px; color: var(--text-muted); margin-bottom: 28px; line-height: 1.7;
  }
  .receive-input-row {
    display: flex; gap: 8px; margin-bottom: 16px;
  }
  .receive-input {
    flex: 1;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--mono);
    font-size: 13px;
    padding: 12px 14px;
    outline: none;
    transition: border-color 0.2s;
  }
  .receive-input:focus { border-color: var(--accent); }
  .receive-input::placeholder { color: var(--text-dim); font-style: italic; }
  .btn-fetch {
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    color: #0d0d0d;
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 700;
    padding: 12px 20px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .btn-fetch:hover { box-shadow: 0 0 20px var(--accent-glow); }

  .received-result {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: none;
    animation: slideUp 0.3s ease;
  }
  .received-result.show { display: block; }
  .received-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
  }
  .received-type { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; }
  .received-actions { display: flex; gap: 6px; }
  .action-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text-muted);
    font-family: var(--mono);
    font-size: 10px;
    padding: 4px 9px;
    cursor: pointer;
    transition: all 0.15s;
  }
  .action-btn:hover { border-color: var(--border-hover); color: var(--text); }
  .action-btn.copied { color: var(--accent); border-color: rgba(181,255,71,0.3); }
  .received-body {
    padding: 16px;
    font-size: 13px;
    line-height: 1.7;
    font-family: var(--mono);
    color: var(--text);
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
  }
  .received-body::-webkit-scrollbar { width: 4px; }
  .received-body::-webkit-scrollbar-thumb { background: var(--border); }

  .not-found {
    background: var(--red-dim);
    border: 1px solid #3a1c63;
    border-radius: var(--radius);
    padding: 16px;
    font-size: 12px;
    color: var(--red);
    display: none;
  }
  .not-found.show { display: block; }

  /* ── STATS BAR ── */
  footer {
    position: relative; z-index: 1;
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 32px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }
  .stats { display: flex; gap: 28px; }
  .stat { display: flex; align-items: baseline; gap: 6px; }
  .stat-n { font-size: 13px; font-weight: 500; color: var(--text); font-family: var(--sans); }
  .stat-l { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }
  .footer-note { font-size: 10px; color: var(--text-dim); letter-spacing: 0.03em; }

  /* ── TOAST ── */
  .toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(12px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 99px;
    padding: 9px 20px;
    font-size: 12px;
    color: var(--text);
    font-family: var(--mono);
    opacity: 0;
    transition: all 0.25s;
    z-index: 999;
    white-space: nowrap;
  }
  .toast.show {
    opacity: 1; transform: translateX(-50%) translateY(0);
    border-color: var(--accent);
    color: var(--accent);
  }

  /* pane layout for send/receive */
  .send-pane {
    flex: 1; display: grid;
    grid-template-columns: 1fr 340px;
  }
  .receive-pane {
    flex: 1; display: flex; overflow-y: auto;
  }

  @media (max-width: 768px) {
    .send-pane { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    header { padding: 14px 18px; }
    .tabs { padding: 0 18px; }
    footer { padding: 10px 18px; }
    .stats { gap: 14px; }
  }