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

:root {
    --bg: #0e1014;
    --editor-bg: #0a0c0f;
    --bar-bg: #0e1014;
    --border: #1e2127;
    --border-hover: #2e3340;
    --accent: #3fe0a0;
    --accent-dim: #1a6648;
    --accent-glow: rgba(63, 224, 160, 0.09);
    --error: #f07575;
    --error-glow: rgba(240, 117, 117, 0.09);
    --text: #d4d8e0;
    --muted: #7a8190;
    --subtle: #454952;
    --ln-text: #2e3238;
    --ln-width: 52px;
    --bar-height: 52px;
    --modal-bg: #12151c;
    --modal-surface: #0d1016;
}

[data-theme="light"] {
    --bg: #f8fafc;
    --editor-bg: #ffffff;
    --bar-bg: #f8fafc;
    --border: #e2e8f0;
    --border-hover: #cbd5e1;
    --accent: #10b981;
    --accent-dim: #6ee7b7;
    --text: #1e293b;
    --muted: #64748b;
    --subtle: #94a3b8;
    --ln-text: #94a3b8;
    --modal-bg: #ffffff;
    --modal-surface: #f1f5f9;
}

html,
body {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: "JetBrains Mono", monospace;
}

/* ── TOP BAR ───────────────────────────────────────── */
#topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--bar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--bar-bg);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.logo {
    font-family: "Syne", sans-serif;
    font-weight: 700;
    font-size: 17px;
    letter-spacing: 0.03em;
    color: var(--accent);
    user-select: none;
}

.logo span {
    color: var(--subtle);
    font-weight: 600;
}

.bar-center {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    color: var(--subtle);
}

.bar-center .dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--subtle);
    opacity: 0.4;
    flex-shrink: 0;
}

#lineInfo {
    font-size: 11.5px;
}

/* ── Language badge (topbar) ────────────────────────── */
#langDot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.7;
    flex-shrink: 0;
}

.lang-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: lowercase;
    background: rgba(63, 224, 160, 0.08);
    color: var(--accent);
    border: 1px solid rgba(63, 224, 160, 0.18);
    white-space: nowrap;
}

.lang-badge.detecting {
    color: var(--muted);
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--border);
    animation: badgePulse 1.6s ease-in-out infinite;
}

@keyframes badgePulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.45;
    }
}

/* ── IMAGE VIEWER MODAL ─────────────────────────────────────────────────── */

#image-viewer-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(10, 12, 15, 0.9);
    backdrop-filter: blur(5px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.2s ease;
}

#image-viewer-modal.hidden {
    opacity: 0;
    pointer-events: none;
}

#imageModalContent {
    max-width: 90%;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
    object-fit: contain;
}

.image-modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10000;
}

.image-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

/* ── BUTTONS ─────────────────────────────────────────── */
.bar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 16px;
    border-radius: 6px;
    font-family: "JetBrains Mono", monospace;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition:
        background 0.15s,
        border-color 0.15s,
        color 0.15s,
        opacity 0.15s;
    letter-spacing: 0.02em;
}

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--muted);
}

#downloadBtn {
    display: none;
}

#downloadBtn.show {
    display: inline-flex;
}

.btn-ghost:hover {
    border-color: var(--muted);
    color: var(--text);
}

#copyCodeBtn {
    gap: 5px;
}

#copyCodeBtn::before {
    content: "⧉";
    font-size: 13px;
    opacity: 0.7;
}

.btn-accent {
    background: var(--accent);
    color: #050c08;
    font-weight: 600;
}

.btn-accent:hover {
    background: #5aebaf;
}

.btn-accent:active {
    background: #2cc885;
}

.btn-accent:disabled {
    background: var(--accent-dim);
    color: #1a4034;
    cursor: not-allowed;
}

.nav-avatar-sm {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent-glow);
    border: 1px solid rgba(63, 224, 160, 0.2);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
}

.nav-avatar-sm:hover {
    transform: scale(1.08);
    border-color: var(--accent);
    background: rgba(63, 224, 160, 0.15);
}

/* ── EDITOR LAYOUT ──────────────────────────────────── */
#editor-wrap {
    position: fixed;
    top: var(--bar-height);
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    background: var(--editor-bg);
}

#editor-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    font-family: "JetBrains Mono", monospace;
    font-size: 14px;
}

/* CodeMirror overrides to match CodeAlive palette */
.cm-editor {
    height: 100%;
    background-color: transparent !important;
}

.cm-activeLine, .cm-activeLineGutter {
    background-color: transparent !important;
}

.cm-editor.cm-focused {
    outline: none !important;
}

.cm-scroller {
    font-family: "JetBrains Mono", monospace !important;
    line-height: 1.6 !important;
}

.cm-scroller::-webkit-scrollbar {
    width: 7px;
    height: 7px;
}

.cm-scroller::-webkit-scrollbar-track {
    background: transparent;
}

.cm-scroller::-webkit-scrollbar-thumb {
    background: #1e2430;
    border-radius: 4px;
}

.cm-selectionBackground,
.cm-focused .cm-selectionBackground {
    background: rgba(63, 224, 160, 0.25) !important;
}

.cm-gutters {
    background-color: var(--editor-bg) !important;
    border-right: 1px solid var(--border) !important;
    color: var(--ln-text) !important;
    font-size: 13px !important;
    min-width: var(--ln-width) !important;
}

.cm-gutterElement {
    padding-right: 14px !important;
}

.cm-activeLine {
    background-color: rgba(255, 255, 255, 0.02) !important;
}

.cm-activeLineGutter {
    background-color: rgba(255, 255, 255, 0.04) !important;
    color: var(--subtle) !important;
}

.cm-content {
    padding: 18px 0 !important;
}

.cm-line {
    padding: 0 20px !important;
}

/* ── IMAGE PLACEHOLDER WIDGETS ────────────────────── */
.image-placeholder-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    margin: 0 4px;
    background: rgba(63, 224, 160, 0.1);
    border: 1px solid rgba(63, 224, 160, 0.3);
    border-radius: 4px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
    vertical-align: middle;
}

.image-placeholder-btn:hover {
    background: rgba(63, 224, 160, 0.2);
    border-color: var(--accent);
    transform: translateY(-1px);
}

.image-placeholder-btn::before {
    content: "📎";
    font-size: 12px;
}

/* ── LINE HIGHLIGHT DECORATIONS ──────────────────── */
.cm-line-highlight {
    background-color: rgba(63, 224, 160, 0.08) !important;
    border-left: 3px solid var(--accent) !important;
}

#editor-hint-empty,
#editor-hint-highlight {
    position: absolute;
    bottom: 18px;
    left: calc(var(--ln-width) + 18px);
    font-size: 11.5px;
    color: #5a6478;
    pointer-events: none;
    z-index: 3;
    transition: opacity 0.4s ease;
    user-select: none;
}

#editor-hint-empty.hidden,
#editor-hint-highlight.hidden {
    opacity: 0;
}

/* ── SHARE BAR ──────────────────────────────────────── */
#share-bar {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #161a22;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0;
    pointer-events: none;
    transition:
        opacity 0.25s,
        transform 0.25s;
    z-index: 200;
    min-width: 360px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

#share-bar.visible {
    opacity: 1;
    pointer-events: all;
    transform: translateX(-50%) translateY(0);
}

#share-bar label {
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

#shareUrl {
    flex: 1;
    background: var(--editor-bg);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--accent);
    font-family: "JetBrains Mono", monospace;
    font-size: 13px;
    padding: 7px 10px;
    outline: none;
}

#copyBtn {
    padding: 7px 14px;
    font-size: 12px;
}

/* ── TOAST ──────────────────────────────────────────── */
#toast {
    position: fixed;
    bottom: 28px;
    right: 28px;
    background: var(--accent);
    color: #050c08;
    font-size: 12px;
    font-weight: 600;
    padding: 9px 18px;
    border-radius: 6px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition:
        opacity 0.2s,
        transform 0.2s;
    z-index: 300;
}

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

/* ── ERROR BAR ──────────────────────────────────────── */
#error-bar {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1c1014;
    border: 1px solid #3a1520;
    border-radius: 8px;
    padding: 11px 20px;
    color: var(--error);
    font-size: 12.5px;
    opacity: 0;
    pointer-events: none;
    transition:
        opacity 0.25s,
        transform 0.25s;
    z-index: 200;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

#error-bar.visible {
    opacity: 1;
    pointer-events: all;
    transform: translateX(-50%) translateY(0);
}

/* ── VIEW BADGE ─────────────────────────────────────── */
#view-badge {
    display: none;
    align-items: center;
    gap: 8px;
    font-size: 11.5px;
    color: var(--muted);
    background: #13161c;
    border: 1px solid var(--border);
    padding: 5px 12px;
    border-radius: 20px;
}

#view-badge.show {
    display: flex;
}

#view-badge .vdot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
}

/* ── Highlight popup ─────────────────────────────────── */
#highlight-popup {
    position: fixed;
    z-index: 400;
    display: flex;
    align-items: center;
    gap: 5px;
    background: #12151c;
    border: 1px solid #252830;
    border-radius: 8px;
    padding: 5px 7px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transform: translateY(5px);
    transition:
        opacity 0.14s,
        transform 0.14s;
}

#highlight-popup.show {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
}

.popup-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    border-radius: 5px;
    font-family: "JetBrains Mono", monospace;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    letter-spacing: 0.03em;
    white-space: nowrap;
    transition:
        background 0.12s,
        border-color 0.12s;
}

#popupHighlightBtn {
    background: rgba(63, 224, 160, 0.09);
    border-color: rgba(63, 224, 160, 0.22);
    color: var(--accent);
}

#popupHighlightBtn:hover {
    background: rgba(63, 224, 160, 0.17);
    border-color: rgba(63, 224, 160, 0.38);
}

.popup-btn-remove {
    background: rgba(240, 117, 117, 0.07);
    border-color: rgba(240, 117, 117, 0.18);
    color: var(--error);
}

.popup-btn-remove:hover {
    background: rgba(240, 117, 117, 0.14);
    border-color: rgba(240, 117, 117, 0.32);
}

/* ── SHARE MODAL OVERLAY ────────────────────────────── */
#share-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 500;
}

#share-modal.show {
    display: flex;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(12px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ── MODAL BOX ──────────────────────────────────────── */
.modal-box {
    background: var(--modal-bg);
    border: 1px solid #252830;
    border-radius: 16px;
    width: 520px;
    overflow: hidden;
    box-shadow:
        0 40px 100px rgba(0, 0, 0, 0.8),
        0 0 0 1px rgba(63, 224, 160, 0.05);
    animation: modalIn 0.24s cubic-bezier(0.34, 1.26, 0.64, 1) forwards;
}

.modal-stripe {
    height: 3px;
    background: linear-gradient(90deg,
            var(--accent) 0%,
            #1d7a56 60%,
            transparent 100%);
}

.modal-inner {
    padding: 28px 30px 30px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.modal-title-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-icon {
    width: 36px;
    height: 36px;
    background: rgba(63, 224, 160, 0.1);
    border: 1px solid rgba(63, 224, 160, 0.2);
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.modal-title {
    font-family: "Syne", sans-serif;
    font-weight: 700;
    font-size: 17px;
    color: var(--text);
}

.modal-close {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "JetBrains Mono", monospace;
    transition:
        border-color 0.15s,
        color 0.15s,
        background 0.15s;
    line-height: 1;
}

.modal-close:hover {
    border-color: var(--muted);
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
}

.modal-divider {
    height: 1px;
    background: var(--border);
    margin: 16px 0;
}

.modal-subtitle {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.65;
    margin-bottom: 22px;
}

/* ── TWO OPTION CARDS ───────────────────────────────── */
.option-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 22px;
}

.option-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 18px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--modal-surface);
    cursor: pointer;
    transition:
        border-color 0.18s,
        background 0.18s,
        box-shadow 0.18s;
    user-select: none;
}

.option-card:hover {
    border-color: #2e3340;
    background: #0f1219;
}

.option-card.selected {
    border-color: var(--accent);
    background: rgba(63, 224, 160, 0.04);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.option-radio {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: transparent;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s;
}

.option-card.selected .option-radio {
    border-color: var(--accent);
}

.option-radio-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0;
    transform: scale(0.3);
    transition:
        opacity 0.15s,
        transform 0.15s;
}

.option-card.selected .option-radio-dot {
    opacity: 1;
    transform: scale(1);
}

.option-text {
    flex: 1;
}

.option-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.option-desc {
    font-size: 11.5px;
    color: var(--muted);
    line-height: 1.55;
}

.option-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 20px;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.badge-green {
    background: rgba(63, 224, 160, 0.1);
    color: var(--accent);
    border: 1px solid rgba(63, 224, 160, 0.2);
}

.badge-muted {
    background: rgba(255, 255, 255, 0.04);
    color: var(--muted);
    border: 1px solid var(--border);
}

/* ── ADVANCED OPTIONS ───────────────────────────────── */
#advancedOptions {
    margin-bottom: 22px;
}

.option-row {
    display: flex;
    gap: 16px;
    margin-top: 12px;
}

.input-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group label {
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.input-group input,
.input-group select {
    background: var(--modal-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 10px 12px;
    font-family: "JetBrains Mono", monospace;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.input-group input:focus,
.input-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-group select {
    appearance: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a8190' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* ── CUSTOM URL SECTION ─────────────────────────────── */
#customUrlSection {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
    transition:
        max-height 0.25s ease-out,
        opacity 0.2s ease,
        margin 0.25s ease;
}


#customUrlSection.open {
    max-height: 130px;
    opacity: 1;
    margin-bottom: 22px;
    pointer-events: all;
}

.url-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.url-label {
    font-size: 11px;
    color: var(--muted);
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

#charCounter {
    font-size: 11px;
    color: var(--subtle);
    transition: color 0.15s;
}

#charCounter.warn {
    color: #d4a847;
}

#charCounter.over {
    color: var(--error);
}

.url-input-wrap {
    display: flex;
    align-items: stretch;
    background: var(--modal-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    transition:
        border-color 0.18s,
        box-shadow 0.18s;
    margin-bottom: 8px;
}

.url-input-wrap:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.url-input-wrap.valid {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.url-input-wrap.invalid {
    border-color: var(--error);
    box-shadow: 0 0 0 3px var(--error-glow);
}

.url-prefix {
    background: #0a0c11;
    border-right: 1px solid var(--border);
    padding: 11px 13px;
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    user-select: none;
}

#customCode {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-family: "JetBrains Mono", monospace;
    font-size: 13px;
    padding: 11px 10px;
    min-width: 0;
}

#customCode::placeholder {
    color: #2a3040;
}

.url-validation-icon {
    display: flex;
    align-items: center;
    padding-right: 13px;
    font-size: 15px;
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.url-validation-icon.show {
    opacity: 1;
}

.url-validation-icon.ok {
    color: var(--accent);
}

.url-validation-icon.err {
    color: var(--error);
}

.url-helper {
    font-size: 11.5px;
    color: var(--subtle);
    min-height: 17px;
    transition: color 0.15s;
}

.url-helper.error-msg {
    color: var(--error);
}

.url-helper.ok-msg {
    color: var(--accent);
}

/* ── ACTION BUTTONS ─────────────────────────────────── */
.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-actions .btn {
    flex: 1;
    padding: 12px 16px;
    font-size: 13px;
    border-radius: 9px;
}

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

.btn-spinner {
    width: 13px;
    height: 13px;
    border: 2px solid rgba(26, 64, 52, 0.5);
    border-top-color: #1a4034;
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
    flex-shrink: 0;
}

/* ── EDIT WARNING POPUP ─────────────────────────────── */
@keyframes popupIn {
    from {
        opacity: 0;
        transform: translateX(12px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

#edit-warning {
    position: fixed;
    top: calc(var(--bar-height) + 14px);
    right: 20px;
    background: #16120a;
    border: 1px solid #3d2f10;
    border-left: 3px solid #d4a847;
    border-radius: 8px;
    padding: 12px 16px;
    max-width: 260px;
    opacity: 0;
    pointer-events: none;
    transform: translateX(12px);
    transition:
        opacity 0.2s,
        transform 0.2s;
    z-index: 150;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

#edit-warning.show {
    opacity: 1;
    pointer-events: all;
    transform: translateX(0);
    animation: popupIn 0.22s ease forwards;
}

#edit-warning .ew-title {
    font-size: 12px;
    font-weight: 600;
    color: #d4a847;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

#edit-warning .ew-body {
    font-size: 11.5px;
    color: var(--muted);
    line-height: 1.6;
}

#edit-warning .ew-body strong {
    color: #d4d8e0;
    font-weight: 600;
}

#edit-warning .ew-dismiss {
    margin-top: 10px;
    font-size: 11px;
    color: var(--subtle);
    cursor: pointer;
    display: inline-block;
    border-bottom: 1px solid transparent;
    transition:
        color 0.15s,
        border-color 0.15s;
}

#edit-warning .ew-dismiss:hover {
    color: var(--muted);
    border-color: var(--subtle);
}

/* ── PASSWORD PROTECTION OVERLAY ─────────────────────── */
#password-overlay {
    position: absolute;
    inset: 0;
    z-index: 60;
    background: rgba(10, 12, 15, 0.85);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.password-card {
    background: var(--modal-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    width: 420px;
    text-align: center;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
}

.lock-icon {
    font-size: 32px;
    margin-bottom: 20px;
}

.password-card h2 {
    font-family: "Syne", sans-serif;
    font-size: 22px;
    margin-bottom: 12px;
    color: var(--text);
}

.password-card p {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.6;
    margin-bottom: 24px;
}

.password-input-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.password-input-group input {
    background: var(--modal-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 12px 16px;
    font-family: "JetBrains Mono", monospace;
    font-size: 14px;
    outline: none;
    text-align: center;
}

.password-input-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#unlockError {
    margin-top: 14px;
    font-size: 12px;
    color: var(--error);
}

/* ── WELCOME OVERLAY ────────────────────────────────── */
#welcome-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    pointer-events: none;
    animation: welcomeFadeIn 0.6s ease forwards;
}

#welcome-overlay.hidden {
    animation: welcomeFadeOut 0.3s ease forwards;
    /* pointer-events: none; */
}

@keyframes welcomeFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes welcomeFadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(-6px);
    }
}

.welcome-card {
    pointer-events: all;
    position: relative;
    max-width: 480px;
    width: 90%;
    background: rgba(10, 12, 15, 0.82);
    border: 1px solid #1e2530;
    border-top: 1px solid #2a3340;
    border-radius: 14px;
    padding: 36px 40px 32px;
    backdrop-filter: blur(12px);
    box-shadow:
        0 0 0 1px rgba(63, 224, 160, 0.04),
        0 24px 60px rgba(0, 0, 0, 0.7),
        0 0 80px rgba(63, 224, 160, 0.03);
    text-align: center;
}

.welcome-close {
    position: absolute;
    top: 13px;
    right: 15px;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--subtle);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    transition:
        color 0.15s,
        border-color 0.15s,
        background 0.15s;
    font-family: monospace;
}

.welcome-close:hover {
    color: var(--text);
    border-color: var(--border-hover);
    background: #1a1e26;
}

.welcome-tagline {
    font-family: "Syne", sans-serif;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 0.01em;
    line-height: 1.2;
    margin-bottom: 20px;
    background: linear-gradient(110deg,
            #3fe0a0 0%,
            #7ef5c8 45%,
            #b8fff0 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 18px rgba(63, 224, 160, 0.25));
}

.welcome-tagline .arrow {
    font-weight: bolder;
}

.welcome-divider {
    width: 40px;
    height: 1px;
    background: linear-gradient(90deg,
            transparent,
            var(--accent-dim),
            transparent);
    margin: 0 auto 18px;
}

.welcome-desc {
    font-family: "JetBrains Mono", monospace;
    font-size: 12.5px;
    color: var(--muted);
    line-height: 1.75;
    letter-spacing: 0.01em;
}

.welcome-desc strong {
    color: #8ecfb8;
    font-weight: 500;
}

.welcome-hint {
    margin-top: 22px;
    font-size: 11px;
    color: var(--subtle);
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

.welcome-hint::before,
.welcome-hint::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
    max-width: 48px;
}

/* Modal Overlay */
.highlight-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.hidden {
    display: none;
}

/* Modal Box - Smaller & Compact */
.highlight-modal-content {
    background: #0d1117;
    color: #fff;
    width: 840px;
    /* Reduced width */
    max-width: 94vw;
    max-height: 86vh;
    border-radius: 16px;
    padding: 24px 28px 28px;
    /* Reduced padding */
    position: relative;
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.7);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Close Button */
.highlight-close {
    position: absolute;
    top: 14px;
    right: 14px;
    background: transparent;
    border: none;
    color: #8b949e;
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
}

.highlight-close:hover {
    color: #fff;
}

/* Header */
.highlight-title {
    font-size: 22px;
    font-weight: 600;
    margin: 0 0 6px 0;
}

.highlight-subtitle {
    color: #8b949e;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 22px;
}

/* Steps Container */
.highlight-steps {
    display: flex;
    flex-direction: column;
    gap: 14px;
    /* Tighter gap between steps */
    flex: 1;
}

/* Each Step Row */
.step-row {
    display: flex;
    align-items: center;
    gap: 28px;
    background: #161b22;
    border-radius: 12px;
    padding: 14px 18px;
    /* Reduced padding inside row */
    min-height: 130px;
    /* Smaller row height */
}

/* Text Side */
.step-text {
    flex: 1;
    min-width: 0;
}

.step-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
}

.step-number {
    background: #1f6feb;
    color: white;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14.5px;
    flex-shrink: 0;
}

.step-text h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 500;
}

.step-text p {
    margin: 0;
    color: #c9d1d9;
    font-size: 13.8px;
    line-height: 1.5;
}

.tip {
    color: #58a6ff;
}

/* Image Side - Smaller but clear */
.step-image {
    width: 210px;
    /* Further reduced */
    flex-shrink: 0;
    border-radius: 8px;
    overflow: hidden;
    background: #0d1117;
    border: 1px solid #21262d;
    display: flex;
    align-items: center;
    justify-content: center;
}

.step-image img {
    width: 100%;
    height: auto;
    max-height: 118px;
    /* Reduced max height */
    display: block;
    object-fit: contain;
    image-rendering: crisp-edges;
}

/* Footer - Ensures button is always visible */
.highlight-footer {
    margin-top: auto;
    /* Pushes button to bottom */
    padding-top: 18px;
    display: flex;
    justify-content: flex-end;
}

.highlight-btn {
    background: #22c55e;
    color: #000;
    font-weight: 600;
    padding: 11px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14.8px;
}

.highlight-btn:hover {
    background: #16a34a;
}

/* ── Image upload button (toolbar) ─────────────────────────────────────────── */

#imageUploadBtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    padding: 0 10px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--subtle);
    font-size: 14px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

#imageUploadBtn:hover {
    color: var(--text);
    border-color: var(--border-hover);
    background: #1a1e26;
}

#imageUploadBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* For image placeholder buttons */
/* .image-placeholder-btn {
  color: #4da6ff;
  cursor: pointer;
  text-decoration: underline;
} */

/* ── Drag-over state on textarea ────────────────────────────────────────────── */

#codeArea.drag-over {
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
}

/* ── [image:id] rendered placeholder in viewer ──────────────────────────────── */

.image-placeholder-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 10px;
    background: rgba(63, 224, 160, 0.08);
    border: 1px solid rgba(63, 224, 160, 0.25);
    border-radius: 5px;
    color: #3fe0a0;
    font-size: 12px;
    font-family: "JetBrains Mono", monospace;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    user-select: none;
}

.image-placeholder-btn:hover {
    background: rgba(63, 224, 160, 0.15);
    border-color: rgba(63, 224, 160, 0.5);
}

/* Mobile */
@media (max-width: 768px) {
    .highlight-modal-content {
        width: 94vw;
        padding: 18px 22px 24px;
    }

    .step-row {
        flex-direction: column;
        gap: 14px;
        padding: 16px;
        min-height: auto;
    }

    .step-image {
        width: 100%;
        max-height: 140px;
    }

    .step-image img {
        max-height: 130px;
    }
}

/* ── MEDIA QUERIES ──────────────────────────────────────────────────────────── */

/* ── Tablet: 768px ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .modal-box {
        width: 92vw;
    }

    .modal-inner {
        padding: 22px 20px 24px;
    }

    #share-bar {
        min-width: 0;
        width: calc(100vw - 40px);
    }

    .url-prefix {
        font-size: 11px;
        padding: 11px 8px;
    }

    .welcome-card {
        padding: 28px 24px 24px;
    }
}

/* ── Large mobile: 600px ─────────────────────────────────────────────────── */
@media (max-width: 600px) {

    /* Topbar gets tight — hide bar-center stats */
    .bar-center {
        display: none;
    }

    .bar-right {
        gap: 6px;
    }

    /* Shrink all ghost buttons to icon-like size */
    .btn-ghost {
        padding: 7px 10px;
        font-size: 11px;
    }

    /* Keep share button readable */
    #shareBtn {
        padding: 7px 13px;
    }

    #edit-warning {
        max-width: 200px;
        right: 10px;
    }
}

/* ── Mobile: 480px ───────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    :root {
        --bar-height: 48px;
        --ln-width: 36px;
    }

    #topbar {
        padding: 0 12px;
    }

    .logo {
        font-size: 15px;
    }

    /* Hide view badge and download on mobile — share bar already shows URL */
    #view-badge,
    #downloadBtn.show {
        display: none;
    }

    /* Hide copy code text, keep just the glyph */
    #copyCodeBtn {
        padding: 7px 9px;
        font-size: 0;
        /* hides "copy" text */
    }

    #copyCodeBtn::before {
        font-size: 14px;
        /* glyph still visible */
        opacity: 1;
    }

    #line-numbers {
        padding-top: 14px;
    }

    #line-numbers span {
        font-size: 11px;
        padding-right: 8px;
    }

    #codeArea,
    #code-highlight {
        font-size: 12.5px;
        padding: 14px 12px 40px 10px;
    }

    code[class*="language-"],
    pre[class*="language-"] {
        font-size: 12.5px !important;
    }

    #share-bar {
        width: calc(100vw - 24px);
        padding: 11px 12px;
        gap: 8px;
        bottom: 16px;
    }

    #shareUrl {
        font-size: 11.5px;
    }

    #share-bar label {
        display: none;
    }

    #toast {
        bottom: 16px;
        right: 16px;
        font-size: 11px;
        padding: 8px 14px;
    }

    #error-bar {
        width: calc(100vw - 24px);
        font-size: 12px;
        padding: 10px 14px;
        bottom: 16px;
    }

    .modal-box {
        width: 96vw;
        border-radius: 12px;
    }

    .modal-inner {
        padding: 18px 16px 20px;
    }

    .modal-title {
        font-size: 15px;
    }

    .modal-subtitle {
        font-size: 12px;
        margin-bottom: 16px;
    }

    .option-card {
        padding: 12px 14px;
        gap: 12px;
    }

    .option-title {
        font-size: 12px;
    }

    .option-desc {
        font-size: 11px;
    }

    .option-badge {
        display: none;
    }

    /* Custom URL section — hide the long domain prefix, just show the input */
    .url-prefix {
        display: none;
    }

    #customCode {
        padding: 11px 12px;
    }

    .modal-actions .btn {
        padding: 11px 12px;
        font-size: 12px;
    }

    #edit-warning {
        top: calc(var(--bar-height) + 8px);
        right: 8px;
        max-width: 180px;
        padding: 10px 12px;
    }

    .welcome-card {
        padding: 24px 18px 20px;
    }

    .welcome-tagline {
        font-size: 20px;
    }

    .welcome-desc {
        font-size: 11.5px;
    }
}

/* ── Small mobile: 360px ─────────────────────────────────────────────────── */
@media (max-width: 360px) {
    .bar-right {
        gap: 4px;
    }

    #shareBtn {
        padding: 7px 10px;
        font-size: 11px;
    }

    /* Stack new + copy into minimal icons */
    #newBtn {
        padding: 7px 8px;
        font-size: 11px;
    }

    .modal-box {
        width: 100vw;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
}

/* ── SEARCH PANEL (CodeMirror) ───────────────────────────────────────────── */
.cm-panels {
    background-color: var(--bar-bg) !important;
    color: var(--text) !important;
    border-bottom: 1px solid var(--border) !important;
    position: relative !important;
}

.cm-panel.cm-search {
    padding: 12px 40px 12px 16px !important; /* Extra right padding for absolute close button */
    background-color: var(--bar-bg) !important;
    display: block !important; /* OVERRIDE FLEX */
    max-width: 100% !important;
}

/* Clearfix */
.cm-panel.cm-search::after {
    content: "" !important;
    display: table !important;
    clear: both !important;
}

/* Float all search elements */
.cm-panel.cm-search > * {
    display: block !important;
    float: left !important;
    margin-right: 8px !important;
    margin-bottom: 8px !important;
}

/* Force replace to the second row! */
.cm-panel.cm-search input[name="replace"] {
    clear: left !important;
}

/* Ensure the close button sits perfectly in the top right corner */
.cm-panel button[name=close] {
    position: absolute !important;
    top: 10px !important;
    right: 12px !important;
    float: none !important;
    margin: 0 !important;
    font-size: 16px !important;
    padding: 2px 6px !important;
    border: none !important;
    background: transparent !important;
    color: var(--muted) !important;
    cursor: pointer !important;
    line-height: 1 !important;
}

.cm-panel button[name=close]:hover {
    background: transparent !important;
    color: var(--error) !important;
    border-color: transparent !important;
}

.cm-panel input.cm-textfield {
    background-color: var(--editor-bg) !important;
    border: 1px solid var(--border) !important;
    border-radius: 6px !important;
    color: var(--text) !important;
    padding: 6px 12px !important;
    font-family: "JetBrains Mono", monospace !important;
    font-size: 12.5px !important;
    outline: none !important;
    transition: border-color 0.2s !important;
    min-width: 180px !important;
    height: 30px !important;
}

.cm-panel input.cm-textfield:focus {
    border-color: var(--accent) !important;
}

.cm-panel button:not([name=close]) {
    background-color: var(--bar-bg) !important;
    border: 1px solid var(--border) !important;
    border-radius: 6px !important;
    color: var(--muted) !important;
    padding: 6px 12px !important;
    cursor: pointer !important;
    font-size: 12px !important;
    font-family: "JetBrains Mono", monospace !important;
    transition: background 0.2s, border-color 0.2s, color 0.2s !important;
    height: 30px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.cm-panel button:not([name=close]):hover {
    background-color: rgba(63, 224, 160, 0.08) !important;
    border-color: var(--accent) !important;
    color: var(--accent) !important;
}

.cm-panel label {
    font-family: "JetBrains Mono", monospace !important;
    font-size: 11.5px !important;
    color: var(--muted) !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    cursor: pointer !important;
    height: 30px !important; /* Match inputs and buttons */
    margin-left: 4px !important;
}

.cm-panel label input[type="checkbox"] {
    accent-color: var(--accent) !important;
    cursor: pointer !important;
    margin: 0 !important;
    width: 14px !important;
    height: 14px !important;
    min-width: unset !important;
    padding: 0 !important;
}

.cm-searchMatch {
    background-color: rgba(63, 224, 160, 0.25) !important;
    border-radius: 2px !important;
}

.cm-searchMatch.cm-searchMatch-selected {
    background-color: rgba(63, 224, 160, 0.45) !important;
    outline: 1px solid var(--accent) !important;
}

/* ── Mobile responsiveness for search panel ── */
@media (max-width: 650px) {
    .cm-panel.cm-search {
        padding: 10px 30px 10px 12px !important;
    }
    .cm-panel.cm-search input.cm-textfield {
        min-width: 120px !important;
        width: 100% !important;
    }
    .cm-panel.cm-search label {
        font-size: 10.5px !important;
    }
    .cm-panel button:not([name=close]) {
        padding: 6px 8px !important;
        font-size: 11px !important;
    }
}