@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&family=JetBrains+Mono:wght@400;500&display=swap');
@import url('./tokens.css');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    scroll-behavior: smooth;
    scrollbar-color: #2a354a var(--bg-900);
    scrollbar-width: thin;
}

body {
    font-family: var(--font-sans);
    background:
        radial-gradient(1100px 520px at 18% -8%, rgba(123,144,210,0.18), transparent 58%),
        radial-gradient(900px 560px at 88% 0%, rgba(40,196,154,0.10), transparent 62%),
        radial-gradient(700px 500px at 50% 100%, rgba(123,144,210,0.08), transparent 70%),
        linear-gradient(180deg, var(--bg-900), var(--bg-950));
    color: var(--text-100);
    min-height: 100dvh;
    overflow: hidden;
    touch-action: pan-y;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    position: relative;
}

body::before{
    content:"";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0.035;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    mix-blend-mode: soft-light;
    z-index: 0;
}

#app {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
}

/* Header */
.header {
    background: var(--header-bg);
    backdrop-filter: blur(18px) saturate(1.2);
    -webkit-backdrop-filter: blur(18px) saturate(1.2);
    border-bottom: 1px solid var(--line);
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: var(--z-header);
    box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 12px 40px rgba(2,8,18,0.35);
}

.app-title {
    font-size: 1.05rem;
    font-weight: 650;
    letter-spacing: -0.03em;
    line-height: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-100);
    text-wrap: balance;
    white-space: nowrap;
}

.app-title i {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    background: linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0.03));
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    font-size: 0.82rem;
    color: var(--accent-2);
    box-shadow: 0 4px 16px rgba(18,30,58,0.25);
}

.app-title span { letter-spacing: -0.035em; }

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.btn {
    appearance: none;
    background: rgba(255,255,255,0.06);
    color: var(--text-100);
    border: 1px solid var(--line);
    padding: 0 13px;
    height: 36px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-size: 0.84rem;
    font-weight: 500;
    letter-spacing: -0.015em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    transition: all var(--dur-med) var(--ease-spring);
    white-space: nowrap;
    position: relative;
    font-family: var(--font-sans);
    line-height: 1;
    box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset;
}

.btn i { font-size: 0.84rem; opacity: 0.9; }

.btn:hover {
    background: rgba(255,255,255,0.10);
    border-color: var(--line-strong);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(2,8,18,0.35), 0 1px 0 rgba(255,255,255,0.05) inset;
}

.btn:active { transform: translateY(0px) scale(0.98); }

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-ring), 0 1px 0 rgba(255,255,255,0.05) inset;
    border-color: rgba(123,144,210,0.45);
}

.btn-success {
    background: var(--success);
    color: #061410;
    border-color: rgba(255,255,255,0.12);
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(40,196,154,0.28), 0 1px 0 rgba(255,255,255,0.22) inset;
}

.btn-success:hover {
    background: #2fd1a3;
    transform: translateY(-1px);
    box-shadow: 0 10px 28px rgba(40,196,154,0.35), 0 1px 0 rgba(255,255,255,0.22) inset;
}

.btn-success:active { background: #22b992; }

.btn-outline {
    background: transparent;
    border-color: var(--line-strong);
    color: var(--text-200);
}

.btn-outline:hover {
    background: var(--accent-soft);
    border-color: var(--line-accent);
    color: var(--text-100);
}

#save-btn, #clear-btn, #export-btn { background: rgba(255,255,255,0.05); }
#export-btn { padding-right: 11px; }

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    background: rgba(17,23,33,0.96);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    min-width: 192px;
    border: 1px solid var(--line-strong);
    border-radius: 14px;
    box-shadow: var(--shadow-soft), 0 16px 40px rgba(2,8,18,0.55);
    z-index: var(--z-dropdown);
    overflow: hidden;
    padding: 6px;
}

.dropdown-content a {
    color: var(--text-200);
    padding: 10px 12px;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.84rem;
    font-weight: 450;
    letter-spacing: -0.01em;
    border-radius: 10px;
    transition: all var(--dur-fast) ease;
}

.dropdown-content a:hover {
    background: rgba(255,255,255,0.07);
    color: var(--text-100);
}

.dropdown:hover .dropdown-content,
.dropdown:focus-within .dropdown-content {
    display: block;
    animation: dropdownIn 180ms var(--ease-spring);
}

@keyframes dropdownIn {
    from { opacity: 0; transform: translateY(6px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Tabs */
.tabs {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--tab-bg);
    border-bottom: 1px solid var(--line);
    padding: 8px 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-shrink: 0;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
    padding: 8px 14px;
    white-space: nowrap;
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    transition: all 200ms var(--ease-spring);
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 0.84rem;
    font-weight: 500;
    letter-spacing: -0.015em;
    color: var(--text-400);
    background: transparent;
    user-select: none;
}

.tab i { font-size: 0.9rem; opacity: 0.9; }
.tab:hover { color: var(--text-200); background: rgba(255,255,255,0.06); border-color: var(--line); }
.tab.active {
    color: var(--text-100);
    background: rgba(123,144,210,0.16);
    border-color: rgba(123,144,210,0.22);
    box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 4px 16px rgba(18,30,58,0.18);
}
.tab.active i { color: var(--accent-2); }

/* Editor Area */
.editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 14px 14px 10px;
    gap: 10px;
    min-height: 0;
}

.editor-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: linear-gradient(180deg, var(--bg-800), var(--bg-850));
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-soft), var(--shadow-tint);
    position: relative;
    min-height: 0;
}

.editor-wrapper::before{
    content:"";
    position:absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.02));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    opacity: 0.9;
}

.editor-header {
    height: 44px;
    padding: 0 14px;
    background: rgba(255,255,255,0.02);
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.82rem;
    color: var(--text-400);
    flex-shrink: 0;
    backdrop-filter: blur(8px);
}

#current-file {
    font-family: var(--font-mono);
    font-size: var(--text-mono-sm);
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--text-400);
    display: flex;
    align-items: center;
    gap: 8px;
}

#current-file::before{
    content:"";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 6px var(--success-soft);
}

.editor-actions .btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 10px;
    background: rgba(255,255,255,0.06);
    border-color: var(--line);
}

.editor-actions .btn:hover{ background: var(--accent-soft); border-color: var(--line-accent); }

textarea {
    flex: 1;
    background: transparent;
    color: #d6deeb;
    border: none;
    padding: 18px;
    font-family: var(--font-mono);
    font-size: 13.5px;
    line-height: 1.75;
    font-weight: 400;
    letter-spacing: -0.01em;
    resize: none;
    outline: none;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
    tab-size: 2;
    caret-color: var(--accent-2);
    font-variant-ligatures: common-ligatures;
    font-variant-numeric: tabular-nums;
    min-height: 0;
}

textarea::selection{ background: rgba(123,144,210,0.28); }
textarea::placeholder{ color: #4a5670; }

/* Quick Preview */
.quick-preview {
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--line);
    border-radius: var(--radius-pill);
    padding: 9px 14px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    backdrop-filter: blur(10px);
}

.quick-preview::before{
    content:"";
    width:6px; height:6px; border-radius:50%;
    background: var(--text-500);
    box-shadow: 0 0 0 5px rgba(255,255,255,0.04);
}

.preview-info {
    font-size: 0.80rem;
    font-weight: 450;
    letter-spacing: -0.01em;
    color: var(--text-400);
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-info i{ color: var(--text-500); font-size: 0.86rem; }

/* Toast */
.toast {
    position: fixed;
    bottom: 22px;
    left: 50%;
    transform: translateX(-50%) translateY(12px) scale(0.98);
    background: rgba(17,23,33,0.94);
    backdrop-filter: blur(16px) saturate(1.2);
    color: var(--text-100);
    padding: 11px 16px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--line-strong);
    box-shadow: var(--shadow-float);
    z-index: var(--z-toast);
    opacity: 0;
    pointer-events: none;
    transition: all var(--dur-slow) var(--ease-spring);
    font-size: 0.84rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 9px;
    white-space: nowrap;
}

.toast::before{ content:""; width: 7px; height: 7px; border-radius:50%; background: var(--success); box-shadow: 0 0 0 5px var(--success-soft); }
.toast.show { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }

/* Modal — replaces confirm() */
.modal-overlay{
    position: fixed; inset: 0;
    background: rgba(4,8,14,0.62);
    backdrop-filter: blur(8px) saturate(1.1);
    display: none; align-items: center; justify-content: center;
    z-index: var(--z-modal);
    padding: 18px;
}
.modal-overlay.open{ display:flex; animation: modalIn 200ms var(--ease-spring); }
.modal{
    background: #121822;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-md);
    box-shadow: 0 24px 60px rgba(2,8,18,0.65), 0 1px 0 rgba(255,255,255,0.05) inset;
    width: 100%; max-width: 420px;
    padding: 20px;
}
.modal-title{ font-size: 0.96rem; font-weight: 650; letter-spacing: -0.02em; color: var(--text-100); margin-bottom: 6px; }
.modal-desc{ font-size: 0.84rem; line-height: 1.6; color: var(--text-400); margin-bottom: 18px; }
.modal-actions{ display:flex; gap: 10px; justify-content: flex-end; }
.modal .btn{ height: 38px; }
.modal .btn-danger{ background: #ef4444; color: white; border-color: rgba(255,255,255,0.12); }
.modal .btn-danger:hover{ background: #f25555; }
@keyframes modalIn{ from{ opacity:0; transform: scale(0.97)} to{ opacity:1; transform: scale(1)} }

/* Mobile */
@media (max-width: 768px) {
    .header{ padding: 12px 14px; }
    .editor-container{ padding: 10px 10px 8px; }
    .btn span.text { display: none; }
    .btn { width: 38px; height: 38px; padding: 0; border-radius: 50%; }
    .btn-success{ width: auto; padding: 0 14px; border-radius: var(--radius-pill); }
    .btn-success span.text{ display: inline; }
    .tab { padding: 8px 13px; font-size: 0.82rem; }
    .app-title { font-size: 1rem; }
    .quick-preview{ border-radius: 14px; justify-content: center; }
}

@media (max-width: 360px) {
    .header { padding: 10px; }
    .tab { padding: 8px 11px; font-size: 0.80rem; }
}

/* Scrollbars */
textarea::-webkit-scrollbar { width: 8px; height: 8px; }
textarea::-webkit-scrollbar-thumb { background: #27344b; border-radius: var(--radius-pill); border: 2px solid transparent; background-clip: content-box; }
textarea::-webkit-scrollbar-track{ background: transparent; }

/* Floating Action Button */
.floating-btn-container {
    position: fixed;
    bottom: 18px;
    right: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(17,23,33,0.92);
    backdrop-filter: blur(16px) saturate(1.2);
    padding: 7px 8px 7px 14px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--line-strong);
    box-shadow: var(--shadow-float);
    z-index: 40;
}

.floating-btn { color: var(--text-200); text-decoration: none; font-size: 0.80rem; font-weight: 500; display: inline-flex; align-items: center; gap: 7px; }
.floating-btn::before{ content:""; width: 6px; height: 6px; border-radius:50%; background: var(--success); box-shadow: 0 0 0 5px var(--success-soft); }
.floating-btn:hover{ color: var(--text-100); }

.close-btn {
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--line);
    color: var(--text-400);
    font-size: 1rem;
    cursor: pointer;
    width: 28px; height: 28px; border-radius: 50%;
    display: grid; place-items: center;
    transition: all var(--dur-fast) ease;
}
.close-btn:hover{ background: rgba(255,255,255,0.10); color: var(--text-100); transform: scale(1.04); }

*:focus-visible{ outline:none; }
@media (prefers-reduced-motion: reduce){ *{ scroll-behavior:auto !important; transition:none !important; animation:none !important; } }
.skip-link:focus{ left: 12px !important; top: 12px !important; width: auto !important; height: auto !important; background: var(--bg-800); color: var(--text-100); padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line-strong); z-index: 999; }

/* Fix: remove underline on pill buttons */
a.btn, a.btn:visited, a.btn:hover, a.btn:active, .btn, .btn:visited { text-decoration: none !important; }
.header-controls a.btn, .preview-controls a.btn, .dropdown-content a { text-decoration: none !important; }
