console.log("LeetSync content script loaded");const ze=["Arrays & Hashing","Two Pointers","Sliding Window","Stack","Binary Search","Linked List","Trees","Heap / Priority Queue","Backtracking","Tries","Graphs","Advanced Graphs","1-D Dynamic Programming","2-D Dynamic Programming","Greedy","Intervals","Math & Geometry","Bit Manipulation"];function Ne(l){var t,i,a,s,p;return`
# ${l.title}

**Difficulty:** ${l.difficulty}  
**Pattern:** ${l.pattern??"Uncategorized"}  
**Language:** ${l.language}  
**LeetCode:** ${l.url}

---

## Intuition
${((t=l.intuition)==null?void 0:t.trim())||"_Write your first thoughts and observations here._"}

---

## Approach
${((i=l.approach)==null?void 0:i.trim())||"_Explain the algorithm step by step._"}

---

## Example Walkthrough
${((a=l.walkthrough)==null?void 0:a.trim())||"_Walk through a small example to show how the logic works._"}

---

## Time Complexity
${((s=l.timeComplexity)==null?void 0:s.trim())||"_O(?)_"}

---

## Space Complexity
${((p=l.spaceComplexity)==null?void 0:p.trim())||"_O(?)_"}

---

## Code

\`\`\`${l.language}
${l.code}
\`\`\`

---
<p align="right"><sub>LeetSync Watermark | Synced from browser extension</sub></p>
`.trim()}function Re(){const l=window.location.pathname.match(/problems\/([^/]+)/);return l?l[1].split("-").map(t=>t[0].toUpperCase()+t.slice(1)).join(" "):"Unknown Problem"}async function _e(){var i,a,s,p,d,u;for(let g=0;g<20;g++){try{const w=(p=(s=(a=(i=window.__NEXT_DATA__)==null?void 0:i.props)==null?void 0:a.pageProps)==null?void 0:s.dehydratedState)==null?void 0:p.queries;if(Array.isArray(w))for(const k of w){const v=(u=(d=k==null?void 0:k.state)==null?void 0:d.data)==null?void 0:u.difficulty;if(v==="Easy"||v==="Medium"||v==="Hard")return v}}catch{}await new Promise(w=>setTimeout(w,100))}return"Unknown"}function De(){const l=document.createElement("script");l.src=chrome.runtime.getURL("injectMonaco.js"),l.onload=()=>l.remove(),(document.head||document.documentElement).appendChild(l)}function Ae(){return new Promise(l=>{const t=window.setTimeout(()=>{window.removeEventListener("message",i),l(null)},3500),i=a=>{var d;if(a.source!==window||((d=a.data)==null?void 0:d.type)!=="LEETSYNC_CODE")return;if(window.removeEventListener("message",i),window.clearTimeout(t),!a.data.success||!a.data.payload){l(null);return}const s=typeof a.data.payload.code=="string"?a.data.payload.code:"",p=typeof a.data.payload.language=="string"?a.data.payload.language:"text";l({code:s,language:p})};window.addEventListener("message",i),De()})}async function Ee(){const l=Re(),t=await Ae();if(!t)return null;const i=await _e();return{title:l,difficulty:i,code:t.code,language:t.language,url:window.location.href}}async function Oe(l){return new Promise((t,i)=>{chrome.runtime.sendMessage(l,a=>{if(chrome.runtime.lastError){i(new Error(chrome.runtime.lastError.message));return}t(a)})})}async function z(){const{githubToken:l,githubOwner:t,githubRepo:i}=await chrome.storage.local.get(["githubToken","githubOwner","githubRepo"]);return typeof l=="string"&&l.trim().length>0&&typeof t=="string"&&t.trim().length>0&&typeof i=="string"&&i.trim().length>0}function He(){if(window.__LEETSYNC_OVERLAY_MOUNTED__)return;window.__LEETSYNC_OVERLAY_MOUNTED__=!0;const l=document.createElement("div");l.id="leetsync-overlay-host",document.documentElement.appendChild(l);const t=l.attachShadow({mode:"open"}),i=chrome.runtime.getURL("assets/logo.PNG");t.innerHTML=`
    <style>
      :host {
        --ls-edge: 12px;
        --ls-panel-bg: #0d0f16;
        --ls-panel-bg-2: #090b12;
        --ls-line: #2a2d38;
        --ls-line-soft: #343847;
        --ls-line-strong: #facc15;
        --ls-ink: #f7f8fb;
        --ls-muted: #a2a5b3;
        --ls-accent: #facc15;
        --ls-accent-2: #eab308;
        --ls-ease: cubic-bezier(0.4, 0, 0.2, 1);
        --ls-dur: 200ms;
      }

      .ls-root {
        position: fixed;
        inset: 0;
        z-index: 2147483646;
        pointer-events: none;
        font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
        color: var(--ls-ink);
      }

      .ls-panel {
        position: absolute;
        width: min(430px, calc(100vw - (var(--ls-edge) * 2)));
        height: min(92vh, 900px);
        min-width: 340px;
        min-height: 560px;
        max-width: calc(100vw - (var(--ls-edge) * 2));
        max-height: calc(100vh - (var(--ls-edge) * 2));
        resize: both;
        overflow: hidden;
        pointer-events: auto;
        background:
          radial-gradient(120% 65% at 50% -10%, rgba(250, 204, 21, 0.09), transparent 55%),
          linear-gradient(180deg, var(--ls-panel-bg), var(--ls-panel-bg-2));
        border: 1px solid var(--ls-line);
        border-top-color: var(--ls-line-strong);
        border-radius: 16px;
        box-shadow: 0 18px 44px rgba(0, 0, 0, 0.52);
        display: flex;
        flex-direction: column;
      }

      .ls-panel.hidden {
        display: none;
      }

      .ls-panel.ls-dock-right {
        right: var(--ls-edge);
        top: var(--ls-edge);
      }

      .ls-panel.ls-dock-left {
        left: var(--ls-edge);
        top: var(--ls-edge);
      }

      .ls-panel.ls-dock-top {
        left: 50%;
        top: var(--ls-edge);
        transform: translateX(-50%);
        width: min(570px, calc(100vw - (var(--ls-edge) * 2)));
      }

      .ls-panel.ls-dock-bottom {
        left: 50%;
        bottom: var(--ls-edge);
        transform: translateX(-50%);
        width: min(570px, calc(100vw - (var(--ls-edge) * 2)));
      }

      .ls-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 12px;
        border-bottom: 1px solid #272b36;
        background: linear-gradient(180deg, #131722, #0f1320);
      }

      .ls-header-actions {
        display: inline-flex;
        align-items: center;
        gap: 8px;
      }

      .ls-brand {
        display: flex;
        align-items: center;
        gap: 10px;
      }

      .ls-logo {
        width: 36px;
        height: 36px;
        border-radius: 10px;
        object-fit: cover;
        border: 1px solid #3a3f4f;
      }

      .ls-title {
        margin: 0;
        font-size: 15px;
        font-weight: 800;
        letter-spacing: 0.2px;
        color: var(--ls-ink);
      }

      .ls-subtitle {
        margin: 2px 0 0;
        font-size: 12px;
        color: var(--ls-muted);
      }

      .ls-minimize {
        width: 34px;
        height: 34px;
        border-radius: 10px;
        border: 1px solid #363b4b;
        background: #171b27;
        color: var(--ls-accent);
        cursor: pointer;
        font-size: 18px;
        line-height: 1;
        transition: border-color var(--ls-dur) var(--ls-ease), background var(--ls-dur) var(--ls-ease);
      }

      .ls-minimize:hover {
        border-color: #505060;
        background: #1d2230;
      }

      .ls-minimize:focus-visible {
        outline: 2px solid var(--ls-accent);
        outline-offset: 2px;
      }

      .ls-setup-icon {
        width: 34px;
        height: 34px;
        border-radius: 10px;
        border: 1px solid #5b4f1d;
        background: linear-gradient(180deg, #facc15, #eab308);
        color: #181818;
        cursor: pointer;
        font-size: 16px;
        line-height: 1;
        font-weight: 800;
        transition: filter var(--ls-dur) var(--ls-ease), box-shadow var(--ls-dur) var(--ls-ease);
      }

      .ls-setup-icon:hover {
        filter: brightness(1.1);
        box-shadow: 0 4px 12px rgba(250, 204, 21, 0.3);
      }

      .ls-setup-icon:focus-visible {
        outline: 2px solid var(--ls-accent);
        outline-offset: 2px;
      }

      .ls-main {
        display: flex;
        flex-direction: column;
        gap: 12px;
        padding: 12px;
        min-height: 0;
        flex: 1;
        overflow: auto;
        scrollbar-width: thin;
        scrollbar-color: #48506a #0f1119;
      }

      .ls-main::-webkit-scrollbar {
        width: 8px;
      }

      .ls-main::-webkit-scrollbar-track {
        background: #0f1119;
      }

      .ls-main::-webkit-scrollbar-thumb {
        background: #48506a;
        border-radius: 8px;
      }

      .ls-controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
      }

      .ls-primary,
      .ls-secondary {
        border-radius: 12px;
        padding: 10px 12px;
        font-size: 14px;
        font-weight: 800;
        cursor: pointer;
        min-height: 44px;
        position: relative;
        overflow: hidden;
        transition:
          transform 150ms var(--ls-ease),
          box-shadow var(--ls-dur) var(--ls-ease),
          border-color var(--ls-dur) var(--ls-ease),
          filter var(--ls-dur) var(--ls-ease),
          background var(--ls-dur) var(--ls-ease);
      }

      .ls-primary:focus-visible,
      .ls-secondary:focus-visible {
        outline: 2px solid var(--ls-accent);
        outline-offset: 2px;
      }

      .ls-primary:active:not(:disabled),
      .ls-secondary:active:not(:disabled) {
        transform: scale(0.97);
      }

      .ls-primary {
        border: none;
        color: #131313;
        background: linear-gradient(180deg, var(--ls-accent), var(--ls-accent-2));
        box-shadow: 0 6px 16px rgba(250, 204, 21, 0.25);
      }

      .ls-primary:hover:enabled {
        transform: translateY(-1px);
        box-shadow: 0 10px 22px rgba(250, 204, 21, 0.32);
      }

      .ls-primary:disabled {
        background: #454956;
        color: #9095a4;
        cursor: not-allowed;
        box-shadow: none;
      }

      .ls-secondary {
        border: 1px solid #394055;
        background: linear-gradient(180deg, #1d2231, #141927);
        color: var(--ls-ink);
      }

      .ls-secondary:hover:not(:disabled) {
        border-color: #505060;
        background: linear-gradient(180deg, #232838, #191e2e);
      }

      /* Loading state for buttons */
      .ls-primary.ls-loading,
      .ls-secondary.ls-loading {
        color: transparent !important;
        pointer-events: none;
      }

      .ls-primary.ls-loading::after,
      .ls-secondary.ls-loading::after {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        width: 16px;
        height: 16px;
        margin: -8px 0 0 -8px;
        border: 2px solid rgba(0, 0, 0, 0.2);
        border-top-color: #111;
        border-radius: 50%;
        animation: ls-spin 600ms linear infinite;
      }

      @keyframes ls-spin {
        to { transform: rotate(360deg); }
      }

      .ls-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
      }

      .ls-section {
        display: flex;
        flex-direction: column;
        gap: 8px;
      }

      .ls-minihead {
        margin: 0;
        font-size: 10px;
        letter-spacing: 0.55px;
        text-transform: uppercase;
        color: #c9ccd6;
        font-weight: 800;
      }

      .ls-select,
      .ls-input,
      .ls-textarea {
        width: 100%;
        box-sizing: border-box;
        border-radius: 12px;
        border: 1px solid var(--ls-line-soft);
        background: #131826;
        color: var(--ls-ink);
        font-size: 13px;
        padding: 10px 12px;
        transition: border-color var(--ls-dur) var(--ls-ease), box-shadow var(--ls-dur) var(--ls-ease), background var(--ls-dur) var(--ls-ease);
      }

      .ls-select {
        appearance: none;
        background-image:
          linear-gradient(45deg, transparent 50%, #c4c5cc 50%),
          linear-gradient(135deg, #c4c5cc 50%, transparent 50%);
        background-position:
          calc(100% - 18px) calc(50% - 2px),
          calc(100% - 13px) calc(50% - 2px);
        background-size: 5px 5px, 5px 5px;
        background-repeat: no-repeat;
        padding-right: 36px;
      }

      .ls-select:focus,
      .ls-input:focus,
      .ls-textarea:focus {
        outline: none;
        border-color: var(--ls-accent);
        box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.14);
      }

      .ls-code {
        margin: 0;
        background: #0b0f1a;
        border: 1px solid #2e3547;
        color: #ebedf5;
        border-radius: 12px;
        padding: 11px 12px;
        font-size: 11px;
        line-height: 1.45;
        min-height: 72px;
        max-height: 135px;
        overflow: auto;
        white-space: pre-wrap;
        font-family: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Menlo, monospace;
        scrollbar-width: thin;
        scrollbar-color: #49516a #0b0f1a;
      }

      .ls-code.empty {
        color: #868b9b;
        font-style: italic;
      }

      .ls-notes {
        display: grid;
        grid-template-rows: 1.2fr 1.2fr 1.2fr;
        gap: 10px;
        min-height: 300px;
        transition: grid-template-rows 0.24s var(--ls-ease);
      }

      .ls-note {
        display: flex;
        flex-direction: column;
        gap: 6px;
        min-height: 88px;
        border: 1px solid #303749;
        border-radius: 13px;
        background: linear-gradient(180deg, #121824, #0d121f);
        padding: 10px;
        overflow: hidden;
        transition: transform 0.18s var(--ls-ease), border-color 0.16s var(--ls-ease), box-shadow 0.16s var(--ls-ease);
      }

      .ls-notes[data-active="intuition"] .ls-note[data-note="intuition"],
      .ls-notes[data-active="approach"] .ls-note[data-note="approach"],
      .ls-notes[data-active="walkthrough"] .ls-note[data-note="walkthrough"] {
        border-color: #635512;
        box-shadow: inset 0 0 0 1px rgba(250, 204, 21, 0.12);
      }

      .ls-notes[data-active="intuition"] {
        grid-template-rows: 1.95fr 0.9fr 0.9fr;
      }

      .ls-notes[data-active="approach"] {
        grid-template-rows: 0.9fr 1.95fr 0.9fr;
      }

      .ls-notes[data-active="walkthrough"] {
        grid-template-rows: 0.9fr 0.9fr 1.95fr;
      }

      .ls-note.ls-grow {
        animation: ls-grow-note 210ms ease;
      }

      @keyframes ls-grow-note {
        0% {
          transform: scale(1);
        }
        45% {
          transform: scale(1.008);
        }
        100% {
          transform: scale(1);
        }
      }

      .ls-label {
        font-size: 10px;
        font-weight: 800;
        letter-spacing: 0.55px;
        text-transform: uppercase;
        color: #d0d4e0;
      }

      .ls-textarea {
        flex: 1;
        min-height: 0;
        resize: none;
        line-height: 1.4;
        font-family: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Menlo, monospace;
      }

      .ls-textarea::placeholder,
      .ls-input::placeholder {
        color: #767f95;
        transition: opacity var(--ls-dur) var(--ls-ease);
      }

      .ls-textarea:focus::placeholder,
      .ls-input:focus::placeholder {
        opacity: 0.5;
      }

      .ls-complexity {
        margin-top: 0;
      }

      .ls-status {
        min-height: 20px;
        font-size: 12px;
        line-height: 1.45;
        text-align: center;
        color: #f5f7fd;
        background: #151a27;
        border: 1px solid #2f3648;
        border-radius: 10px;
        padding: 6px 8px;
        margin: 0;
        transition: all var(--ls-dur) var(--ls-ease);
      }

      .ls-status.error {
        color: #ffb3b3;
        border-color: #6c3030;
        background: #251516;
      }

      .ls-status.success {
        color: #fff2a5;
        border-color: #6d5f20;
        background: #2a2410;
      }

      .ls-bubble {
        position: absolute;
        width: 66px;
        height: 66px;
        border-radius: 50%;
        border: 1px solid #4e4317;
        background: linear-gradient(180deg, #1a2132, #0d1220);
        display: none;
        align-items: center;
        justify-content: center;
        pointer-events: auto;
        cursor: grab;
        touch-action: none;
        user-select: none;
        box-shadow:
          0 12px 24px rgba(0, 0, 0, 0.46),
          inset 0 0 0 1px rgba(250, 204, 21, 0.1);
        transition: box-shadow var(--ls-dur) var(--ls-ease), border-color var(--ls-dur) var(--ls-ease);
      }

      .ls-bubble:hover {
        border-color: #6a5b1f;
        box-shadow:
          0 14px 28px rgba(0, 0, 0, 0.5),
          0 0 20px rgba(250, 204, 21, 0.15),
          inset 0 0 0 1px rgba(250, 204, 21, 0.18);
      }

      .ls-bubble.visible {
        display: inline-flex;
      }

      .ls-bubble img {
        width: 42px;
        height: 42px;
        border-radius: 50%;
        object-fit: cover;
        user-select: none;
        -webkit-user-drag: none;
      }

      .ls-bubble.ls-dock-left {
        left: var(--ls-edge);
        top: 50%;
        transform: translateY(-50%);
      }

      .ls-bubble.ls-dock-right {
        right: var(--ls-edge);
        top: 50%;
        transform: translateY(-50%);
      }

      .ls-bubble.ls-dock-top {
        left: 50%;
        top: var(--ls-edge);
        transform: translateX(-50%);
      }

      .ls-bubble.ls-dock-bottom {
        left: 50%;
        bottom: var(--ls-edge);
        transform: translateX(-50%);
      }

      @media (max-width: 860px) {
        .ls-panel {
          width: calc(100vw - (var(--ls-edge) * 2));
          min-width: 280px;
          height: min(90vh, 800px);
          min-height: 460px;
        }

        .ls-panel.ls-dock-top,
        .ls-panel.ls-dock-bottom {
          width: calc(100vw - (var(--ls-edge) * 2));
        }
      }

      @media (max-width: 540px) {
        .ls-panel {
          resize: none;
          min-height: 400px;
        }

        .ls-controls {
          grid-template-columns: 1fr;
        }

        .ls-grid {
          grid-template-columns: 1fr;
        }

        .ls-notes {
          min-height: 290px;
        }

      }

      .hidden {
        display: none !important;
      }

      .ls-setup-view {
        padding: 12px;
        display: flex;
        flex-direction: column;
        gap: 12px;
        flex: 1;
      }

      .ls-setup-step-label {
        font-size: 10px;
        font-weight: 800;
        color: var(--ls-muted);
        margin: 0;
      }

      .ls-setup-title {
        font-size: 18px;
        font-weight: 800;
        margin: 0;
      }

      .ls-setup-help {
        font-size: 12px;
        color: var(--ls-muted);
        margin: 0;
      }

      .ls-profile-view {
        padding: 16px;
        display: flex;
        flex-direction: column;
        gap: 16px;
        flex: 1;
      }

      .ls-profile-card {
        background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
        border: 1px solid rgba(250, 204, 21, 0.2);
        border-radius: 14px;
        padding: 16px;
        display: flex;
        flex-direction: column;
        gap: 14px;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
        backdrop-filter: blur(8px);
        transition: border-color var(--ls-dur) var(--ls-ease);
      }

      .ls-profile-card:hover {
        border-color: rgba(250, 204, 21, 0.35);
      }

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

      .ls-profile-avatar {
        width: 44px;
        height: 44px;
        border-radius: 12px;
        background: #1e2333;
        border: 1px solid #3a3f4f;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        font-weight: 800;
        color: var(--ls-accent);
      }

      .ls-profile-info {
        display: flex;
        flex-direction: column;
      }

      .ls-profile-name {
        font-size: 15px;
        font-weight: 800;
        margin: 0;
      }

      .ls-profile-meta {
        font-size: 11px;
        color: var(--ls-muted);
        margin: 2px 0 0;
      }

      .ls-token-status {
        font-size: 11px;
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 8px 10px;
        background: rgba(0, 0, 0, 0.3);
        border-radius: 10px;
        border: 1px solid #2a2d3a;
        color: #d1d5db;
      }

      .ls-status-dot {
        width: 7px;
        height: 7px;
        border-radius: 50%;
        background: #10b981;
        box-shadow: 0 0 8px #10b981;
      }

      .ls-status-dot.warning {
        background: #f59e0b;
        box-shadow: 0 0 8px #f59e0b;
      }

      .ls-profile-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
      }

      .ls-setup-actions {
        display: flex;
        gap: 10px;
        margin-top: auto;
      }
    </style>

    <div class="ls-root">
      <section class="ls-panel ls-dock-right" id="lsPanel">
        <div class="ls-header">
          <div class="ls-brand">
            <img src="${i}" alt="Leet Sync logo" class="ls-logo" />
            <div>
              <h3 class="ls-title">Leet Sync</h3>
              <p class="ls-subtitle">Focus mode notes + one-click save</p>
            </div>
          </div>
          <div class="ls-header-actions">
            <button class="ls-setup-icon" id="lsSetup" type="button" aria-label="GitHub setup">⚙</button>
            <button class="ls-minimize" id="lsMinimize" type="button" aria-label="Minimize">−</button>
          </div>
        </div>

        <div class="ls-main" id="lsMainView">
          <div class="ls-controls">
            <button class="ls-primary" id="lsExtract" type="button">Extract</button>
            <button class="ls-primary" id="lsSave" type="button" disabled>Save</button>
          </div>

          <div class="ls-grid">
            <select class="ls-select" id="lsDifficulty">
              <option value="Unknown">Difficulty: Unknown</option>
              <option value="Easy">Difficulty: Easy</option>
              <option value="Medium">Difficulty: Medium</option>
              <option value="Hard">Difficulty: Hard</option>
            </select>

            <select class="ls-select" id="lsPattern">
              <option value="Uncategorized">Pattern: Uncategorized</option>
            </select>
          </div>

          <section class="ls-section">
            <p class="ls-minihead">Code Preview</p>
            <pre class="ls-code" id="lsCodePreview"></pre>
          </section>

          <section class="ls-section">
            <p class="ls-minihead">Notes</p>
            <div class="ls-notes" id="lsNotes" data-active="intuition">
              <div class="ls-note" data-note="intuition" id="lsNoteIntuition">
                <label class="ls-label" for="lsIntuition">Intuition</label>
                <textarea class="ls-textarea" id="lsIntuition" rows="3" placeholder="First thoughts, constraints, and signal..."></textarea>
              </div>

              <div class="ls-note" data-note="approach" id="lsNoteApproach">
                <label class="ls-label" for="lsApproach">Approach</label>
                <textarea class="ls-textarea" id="lsApproach" rows="4" placeholder="Step-by-step algorithm and edge cases..."></textarea>
              </div>

              <div class="ls-note" data-note="walkthrough" id="lsNoteWalkthrough">
                <label class="ls-label" for="lsWalkthrough">Example Walkthrough</label>
                <textarea class="ls-textarea" id="lsWalkthrough" rows="4" placeholder="Dry run with sample values..."></textarea>
              </div>
            </div>
          </section>

          <section class="ls-section">
            <p class="ls-minihead">Complexity</p>
            <div class="ls-grid ls-complexity">
              <input class="ls-input" id="lsTime" placeholder="Time: O(...)" />
              <input class="ls-input" id="lsSpace" placeholder="Space: O(...)" />
            </div>
          </section>
        </div>

        <div class="ls-setup-view hidden" id="lsSetupView">
          <div>
            <p id="lsSetupStepLabel" class="ls-setup-step-label">Step 1 of 3</p>
            <h3 id="lsSetupTitle" class="ls-setup-title">Connect GitHub</h3>
            <p id="lsSetupHelp" class="ls-setup-help">Enter your GitHub Personal Access Token.</p>
          </div>

          <input id="lsSetupInput" class="ls-input" placeholder="ghp_..." type="password" />

          <div class="ls-setup-actions">
            <button class="ls-secondary" id="lsSetupBack" type="button">Back</button>
            <button class="ls-primary" id="lsSetupNext" type="button">Next</button>
          </div>
        </div>

        <div class="ls-profile-view hidden" id="lsProfileView">
           <div class="ls-profile-card">
              <div class="ls-profile-header">
                <div class="ls-profile-avatar" id="lsProfileAvatar">?</div>
                <div class="ls-profile-info">
                   <h3 class="ls-profile-name" id="lsProfileName">GitHub User</h3>
                   <p class="ls-profile-meta" id="lsProfileRepo">repo-name</p>
                </div>
              </div>
           </div>

           <div class="ls-profile-actions">
              <button class="ls-secondary" id="lsProfileEdit" type="button">Edit</button>
              <button class="ls-secondary" id="lsProfileLogout" type="button" style="border-color: #632a2a; color: #ffb3b3;">Logout</button>
           </div>
           
           <button class="ls-primary" id="lsProfileFinish" type="button">Finish</button>
        </div>

        <p class="ls-status" id="lsStatus">Checking setup...</p>
      </section>

      <button class="ls-bubble ls-dock-right" id="lsBubble" type="button" aria-label="Open Leet Sync">
        <img src="${i}" alt="Leet Sync" />
      </button>
    </div>
  `;const a=t.getElementById("lsPanel"),s=t.getElementById("lsBubble"),p=t.getElementById("lsStatus"),d=t.getElementById("lsMainView"),u=t.getElementById("lsSetupView"),g=t.getElementById("lsProfileView"),w=t.getElementById("lsSetup"),k=t.getElementById("lsSetupStepLabel"),v=t.getElementById("lsSetupTitle"),$=t.getElementById("lsSetupHelp"),y=t.getElementById("lsSetupInput"),N=t.getElementById("lsSetupBack"),T=t.getElementById("lsSetupNext"),W=t.getElementById("lsProfileAvatar"),Y=t.getElementById("lsProfileName"),X=t.getElementById("lsProfileRepo"),le=t.getElementById("lsProfileEdit"),ae=t.getElementById("lsProfileLogout"),ie=t.getElementById("lsProfileFinish"),re=t.getElementById("lsMinimize"),ne=t.getElementById("lsExtract"),j=t.getElementById("lsSave"),q=t.getElementById("lsDifficulty"),J=t.getElementById("lsPattern"),B=t.getElementById("lsCodePreview"),de=t.getElementById("lsNotes"),ce=t.getElementById("lsNoteIntuition"),pe=t.getElementById("lsNoteApproach"),ue=t.getElementById("lsNoteWalkthrough"),R=t.getElementById("lsIntuition"),_=t.getElementById("lsApproach"),D=t.getElementById("lsWalkthrough"),Q=t.getElementById("lsTime"),K=t.getElementById("lsSpace");if(!a||!s||!re||!ne||!j||!w||!q||!J||!B||!de||!ce||!pe||!ue||!R||!_||!D||!Q||!K||!p||!d||!u||!k||!v||!$||!y||!N||!T||!g||!W||!Y||!X||!le||!ae||!ie)return;let E=null,b="right",A=!1,C=!1,Z=-1,ge=0,fe=0,he=0,be=0,V=0,L=!1,r=null,O=!1;const I=10;ze.forEach(e=>{const o=document.createElement("option");o.value=e,o.textContent=e,J.appendChild(o)});function me(e){if(B){if(!e||e.trim().length===0){B.textContent="Code preview appears here after extraction.",B.classList.add("empty");return}B.textContent=e,B.classList.remove("empty")}}me(null);function c(e,o="info"){p&&(p.textContent=e,p.classList.remove("error","success","hidden"),o==="error"&&p.classList.add("error"),o==="success"&&p.classList.add("success"),e||p.classList.add("hidden"))}function H(e){a.classList.remove("ls-dock-left","ls-dock-right","ls-dock-top","ls-dock-bottom"),a.classList.add(`ls-dock-${e}`)}function U(e){s.classList.remove("ls-dock-left","ls-dock-right","ls-dock-top","ls-dock-bottom"),s.classList.add(`ls-dock-${e}`),s.style.left="",s.style.top="",s.style.right="",s.style.bottom="",s.style.transform="",L=!1}function Le(e){b=e,H(e),L||U(e)}function Se(e,o){const n=s.offsetWidth||66,h=s.offsetHeight||66,f=Math.max(I,window.innerWidth-n-I),oe=Math.max(I,window.innerHeight-h-I);return{left:Math.max(I,Math.min(f,e)),top:Math.max(I,Math.min(oe,o))}}function P(e,o,n=!0){const h=Se(e,o);s.classList.remove("ls-dock-left","ls-dock-right","ls-dock-top","ls-dock-bottom"),s.style.left=`${h.left}px`,s.style.top=`${h.top}px`,s.style.right="auto",s.style.bottom="auto",s.style.transform="none",r=h,n&&(L=!0)}function Be(){if(L){const e=(r==null?void 0:r.left)??(Number.parseFloat(s.style.left||"0")||0),o=(r==null?void 0:r.top)??(Number.parseFloat(s.style.top||"0")||0);P(e,o)}else U(b);a.classList.add("hidden"),s.classList.add("visible")}function Ie(){if(L){const e=(r==null?void 0:r.left)??(Number.parseFloat(s.style.left||"0")||0),o=(r==null?void 0:r.top)??(Number.parseFloat(s.style.top||"0")||0);b=ve(e,o),H(b)}else H(b);a.classList.remove("hidden"),s.classList.remove("visible")}function F(e){de.dataset.active=e}function xe(e){e.classList.remove("ls-grow"),e.offsetWidth,e.classList.add("ls-grow"),window.setTimeout(()=>e.classList.remove("ls-grow"),220)}function ee(e,o,n){e.addEventListener("focus",()=>{F(n),xe(o)}),e.addEventListener("input",()=>{F(n),xe(o)})}ee(R,ce,"intuition"),ee(_,pe,"approach"),ee(D,ue,"walkthrough"),F("intuition");function ve(e,o){var f;const n={left:e,top:o,right:e+(s.offsetWidth||66),bottom:o+(s.offsetHeight||66)},h=[{edge:"left",value:n.left},{edge:"right",value:window.innerWidth-n.right},{edge:"top",value:n.top},{edge:"bottom",value:window.innerHeight-n.bottom}];return h.sort((oe,Me)=>oe.value-Me.value),((f=h[0])==null?void 0:f.edge)??"right"}s.addEventListener("pointerdown",e=>{if(!s.classList.contains("visible")||e.button!==0&&e.button!==2)return;e.preventDefault(),A=!0,C=!1,Z=e.pointerId,he=e.clientX,be=e.clientY,V=0,s.style.cursor="grabbing";const o=s.getBoundingClientRect();ge=e.clientX-o.left,fe=e.clientY-o.top,P(o.left,o.top,!1),s.setPointerCapture(e.pointerId)}),s.addEventListener("pointermove",e=>{if(!A)return;e.preventDefault();const o=e.clientX-ge,n=e.clientY-fe;P(o,n);const h=e.clientX-he,f=e.clientY-be;V=Math.hypot(h,f),C=V>1.5});const ye=()=>{if(A)if(A=!1,s.style.cursor="grab",s.hasPointerCapture(Z)&&s.releasePointerCapture(Z),C){O=!0,window.setTimeout(()=>{O=!1},160);const e=Number.parseFloat(s.style.left||"0")||0,o=Number.parseFloat(s.style.top||"0")||0;b=ve(e,o),P(e,o)}else L||U(b)};s.addEventListener("pointerup",ye),s.addEventListener("pointercancel",ye),s.addEventListener("contextmenu",e=>{s.classList.contains("visible")&&e.preventDefault()}),re.addEventListener("click",Be),s.addEventListener("click",e=>{if(C||O){e.preventDefault(),C=!1,O=!1;return}Ie()}),window.addEventListener("resize",()=>{if(H(b),L){const e=(r==null?void 0:r.left)??(Number.parseFloat(s.style.left||"0")||0),o=(r==null?void 0:r.top)??(Number.parseFloat(s.style.top||"0")||0);P(e,o);return}U(b)});const M=[{key:"githubToken",title:"Connect GitHub",help:"Enter your GitHub Personal Access Token.",placeholder:"ghp_...",inputType:"password"},{key:"githubOwner",title:"GitHub Username",help:"Enter the GitHub username that owns the repository.",placeholder:"your-username",inputType:"text"},{key:"githubRepo",title:"Repository / Folder",help:"Enter the repository name where LeetSync should save files.",placeholder:"leetcode",inputType:"text"}];let m=0,S={},x=null;function Te(){g==null||g.classList.add("hidden"),d==null||d.classList.add("hidden"),u==null||u.classList.remove("hidden")}function we(){g==null||g.classList.add("hidden"),u==null||u.classList.add("hidden"),d==null||d.classList.remove("hidden")}function Ce(){d==null||d.classList.add("hidden"),u==null||u.classList.add("hidden"),g==null||g.classList.remove("hidden")}function te(){const e=M[m];!e||!k||!v||!$||!y||!N||!T||(k.textContent=`Step ${m+1} of ${M.length}`,v.textContent=e.title,$.textContent=e.help,y.type=e.inputType,y.placeholder=e.placeholder,y.value=S[e.key]??"",y.focus(),N.disabled=!1,T.textContent=m===M.length-1?"Finish":"Next")}async function G(e=!1){e&&(m=0);const o=await chrome.storage.local.get(["githubToken","githubOwner","githubRepo"]);S={githubToken:o.githubToken??"",githubOwner:o.githubOwner??"",githubRepo:o.githubRepo??""},Te(),te()}async function Pe(){var o;if(!W||!Y||!X)return;const e=(x==null?void 0:x.githubOwner)||"Unknown";W.textContent=((o=e[0])==null?void 0:o.toUpperCase())||"?",Y.textContent=e,X.textContent=`Repository: ${(x==null?void 0:x.githubRepo)||"Not set"}`,c("Ready.","info")}function se(){Pe(),Ce()}N.addEventListener("click",async()=>{m>0?(m--,te()):await z()?se():we()}),le.addEventListener("click",()=>{G(!0)}),ae.addEventListener("click",async()=>{confirm("Are you sure you want to logout? All GitHub settings will be cleared.")&&(await chrome.storage.local.remove(["githubToken","githubOwner","githubRepo"]),x=null,G(!0),c("Logged out.","info"))}),ie.addEventListener("click",()=>{we()}),y.addEventListener("keydown",e=>{e.key==="Enter"&&T.click()}),T.addEventListener("click",async()=>{const e=M[m],o=y.value.trim();if(!o){c("This field is required.","error");return}S[e.key]=o,m<M.length-1?(m++,te()):(await chrome.storage.local.set({...S,setupDate:Date.now()}),x={githubToken:S.githubToken||"",githubOwner:S.githubOwner||"",githubRepo:S.githubRepo||""},se(),c("GitHub settings saved.","success"),setTimeout(()=>{c("Ready.","info")},3e3))}),(async()=>{const e=await z();if(!e&&a.classList.contains("hidden")===!1)G(!0);else if(e){const o=await chrome.storage.local.get(["githubToken","githubOwner","githubRepo"]);x={githubToken:o.githubToken,githubOwner:o.githubOwner,githubRepo:o.githubRepo}}})(),w.addEventListener("click",async()=>{await z()?se():G(!0)}),ne.addEventListener("click",async()=>{c("Extracting from page...","info");const e=await Ee();if(!e){c("Extraction failed. Make sure editor is loaded.","error");return}E=e,me(e.code),q.value=e.difficulty,j.disabled=!1,c("Extracted successfully.","success")}),j.addEventListener("click",async()=>{if(!E){c("Extract first.","error");return}if(!await z()){c("Complete GitHub setup first.","error");return}const o=q.value||"Unknown",n=J.value||"Uncategorized",h=Ne({title:E.title,difficulty:o,pattern:n,language:E.language,url:E.url,code:E.code,intuition:R.value,approach:_.value,walkthrough:D.value,timeComplexity:Q.value,spaceComplexity:K.value});c("Saving to GitHub...","info");try{const f=await Oe({type:"SAVE_TO_GITHUB",payload:{title:E.title,difficulty:o,pattern:n,markdown:h,questionId:"0567"}});if(!(f!=null&&f.success)){c((f==null?void 0:f.error)??"Save failed.","error");return}c("Saved successfully.","success"),R.value="",_.value="",D.value="",Q.value="",K.value="",F("intuition")}catch{c("Save failed.","error")}}),Le("right"),z().then(e=>{if(!e){c("GitHub setup required.","info");return}c("Ready.","info")})}var ke;try{(ke=chrome==null?void 0:chrome.runtime)!=null&&ke.onMessage&&chrome.runtime.onMessage.addListener((l,t,i)=>{if(l.type==="EXTRACT_PROBLEM")return(async()=>{const a=await Ee();if(!a){i({success:!1});return}i({success:!0,data:a})})(),!0})}catch{console.warn("[LeetSync] Extension context invalidated, message listener skipped.")}He();
